OpenPerpetuum / PerpetuumServer

The Open Perpetuum Project's fork of the Perpetuum Standalone Server
https://openperpetuum.com
Other
44 stars 21 forks source link

Fieldterminal transactions: player state not resetting/being set properly #403

Closed MikeJeffers closed 2 years ago

MikeJeffers commented 2 years ago

When equipping at a field terminal, modules can alter the accum/armor amounts. To make this stable before and after equip we pre-compute an existing ratio, and keep that as the stabilizing factor. https://github.com/OpenPerpetuum/PerpetuumServer/blob/Development/src/Perpetuum.RequestHandlers/Zone/Containers/ZoneChangeModule.cs#L84-L87

            // Apply ratios to prevent resetting values
            player.Armor = player.ArmorMax * hpRatio;
            player.Core = player.CoreMax * apRatio;

This works... most of the time. There is this funny 2nd set of values that are eventually derived from the player.Armor/Core values, but arent kept in lockstep. They are stored in the Entity's DynamicProperties in a key/value store designed for persistence in the DB as a genxy string (Perpetuum's version of json).
The DynamicProperties are updated on Save() and other entity transactions. But either because these values are created only after some transactions are complete, or because of the bespoke logic for the ZoneChangeModule deviate from the computed values.

One could fix this with something like this:

            player.DynamicProperties.Update(k.armor, hpRatio);
            player.DynamicProperties.Update(k.currentCore, player.Core);

before the save.

Note: armor is stored as the 0.0-1.0 ratio and core is not!