Jump to content
  • 0

A couple questions about the source flow


davidsaid06

Question

I was looking the client logic and i have a few questions about how the flow of the logic go from client to server, i hope i can explain myself.

 

For example: I am on CharacterWindow.cs, having code like this :

 

        //Init
        public CharacterWindow(Canvas gameCanvas)
        {
...

//( A )
            mCharacterWindow = new WindowControl(gameCanvas, Strings.Character.title, false, "CharacterWindow");

...

//(B)

            mAttackLabel = new Label(mCharacterWindow, "AttackLabel");

            mAddAttackBtn = new Button(mCharacterWindow, "IncreaseAttackButton");
            mAddAttackBtn.Clicked += _addAttackBtn_Clicked;


...


        //Methods
        public void Update()
        {

...

//(C)
            mAttackLabel.SetText(
                Strings.Character.stat0.ToString(Strings.Combat.stat0, Globals.Me.Stat[(int) Stats.Attack])
            );

 

In that code, i understand that in (A) it's created a WindowControl from the JSONs of the gui config files we already had on closed source, in (B) is created the label that will render on the screen and in (C) we set the text of the label to a explicit format ( Strings.Combat.stat0) passing the value of the stat of the player( having Globals.Me as a variable from the entity "Player".

 

There, if i go to Globals.Me.Stat, i find that the class "Player"  inherits from the class "Entity" , so Globals.Me.Stat[ (int) stats.attack ] comes from that class.

 

Now, my questions are: 

 

1.- Entity has all the info from the player from the moment it logs in? so i can use the values on that class without having to request every time to the server if the info that i need didn't change? 

 

2.-If i want to add a property to the "player" or "entity" classes, i will have to change classes on the server side too? 

 

3.- if want that information to save on the database, changing the entities is enough? the code will change the structure of the database or i will have to modify the structure myself on the database? 

 

 

Sorry for asking, i'm debugging and looking at the code, but i'm not very good at socket connection, so it's better to ask too.

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0
3 hours ago, davidsaid06 said:

Entity has all the info from the player from the moment it logs in? so i can use the values on that class without having to request every time to the server if the info that i need didn't change? 

 

Correct. Any time stats are updated packets get sent from the server to client with updates.  See Core/Networking/Packets/Server/EntityStatsPacket and PlayerEntityPacket. If you look and see where those are referenced you will see how they are used.

 

3 hours ago, davidsaid06 said:

2.-If i want to add a property to the "player" or "entity" classes, i will have to change classes on the server side too? 

Depends on whether it is a client side only property or not... most likely you will want to add to both since later on you mention saving to the database.

 

3 hours ago, davidsaid06 said:

3.- if want that information to save on the database, changing the entities is enough? the code will change the structure of the database or i will have to modify the structure myself on the database? 

Changing entities is the first part. Any public fields without the [NotMapped] property is automatically saved to the database. You cannot rename fields or remove fields (for now) due to sqlite shortcomings.

 

If you add more fields you will need to create a database migration through entity framework. I have it documented here.

 

 

Also, just as a note, the loading of the ui config from json actually happens here:

mCharacterWindow.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...