RanvierMUD / core

Core engine code for Ranvier
https://ranviermud.com
MIT License
45 stars 40 forks source link

The problem with the attributes of the character in the 3.1 update #102

Open Muderru opened 5 years ago

Muderru commented 5 years ago

Character attributes do not change from wearing items. For example, I wear a +2 armor vest and my character has armor still 0.

shawncplus commented 5 years ago

Gonna need some more detail. When you say "do not change" what are you referring to? Effects modifiers aren't working, applying damage/healing isn't lowering them, computed attributes aren't calculating correctly?

Muderru commented 5 years ago

Yes, computed attributes aren't calculating correctly. For example, I wear a +2 armor vest and my character has armor still 0.

Muderru commented 5 years ago

A bit of additional information about the bug. When I wear a vest for the first time, the command “score” shows +2 armor. Then I restart the server and enter the character on which the vest is worn. The command “score” shows armor 0. After that, removing and putting on a vest does not have any effect on the character’s armor. The “score” command shows armor 0. Similarly with other attributes.

Muderru commented 5 years ago

In other words, equipped items after stopping the server lose the ability to modify the attributes of the character. If you just exit the game, then the properties of the items are saved and they behave normally. In general, all this is very strange and confusing.

Muderru commented 5 years ago

I thought it could be important, I use code from the instancing branch.

ratacat commented 5 years ago

I think maybe I partially figured this out @Muderru & @shawncplus. After you equip an item for the first time, that equip effect becomes active on your character. If you restart the server, it's reloading your character from JSON, effects get serialized and stored in JSON. For some reason, the this.state.stats of the equip effect becomes empty, I'm not sure why. Maybe something to do with a shallow copy?

Unless you specifically set the equip effect's persist config to false, you start to see certain instances where the effect remains, even when the item is gone. When that combines with empty this.state.stats object happening, you get to a place where your character doesn't get any attributes applied to them from objects equipped in that slot, because when the new effect tries to get applied, the old one is already there with the same id, making it seem like the attributes aren't being applied.

Best I can tell, once I set the persist config in the equip effect to false, problem goes away, because the equip effects don't get serialized, and the rebuilt ones on login take hold. Seems to do the trick here...