OpenPerpetuum / PerpetuumServer

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

Improved some base game code #456

Closed Ramit110 closed 1 year ago

Ramit110 commented 1 year ago

Not too much, going to explain each of the code pushes.

Ramit110 commented 1 year ago
                var core = unitLock.Target.Core;
                unitLock.Target.Core -= coreNeutralized;
                coreNeutralizedDone = Math.Abs(core - unitLock.Target.Core);

                can be read as

                var core = unitLock.Target.Core;
                var newcore = unitLock.Target.Core - coreNeutralized;
                coreNeutralizedDone = Math.Abs(core - newcore);
                unitLock.Target.Core = newcore;

                can be read as

                var core = unitLock.Target.Core;
                var newcore = unitLock.Target.Core - coreNeutralized;
                coreNeutralizedDone = Math.Abs(core - newcore);
                    -> coreNeutralizedDone = Math.Abs(unitLock.Target.Core - (unitLock.Target.Core - coreNeutralized));
                    -> coreNeutralizedDone = Math.Abs(unitLock.Target.Core - unitLock.Target.Core + coreNeutralized));
                    -> coreNeutralizedDone = Math.Abs(coreNeutralized));
                unitLock.Target.Core = newcore;

                can then be read as

                var core = unitLock.Target.Core;
                var newcore = unitLock.Target.Core - coreNeutralized;
                coreNeutralizedDone = Math.Abs(coreNeutralized));
                unitLock.Target.Core = newcore;

                to become

                unitLock.Target.Core -= coreNeutralized;
                coreNeutralizedDone = Math.Abs(coreNeutralized));

Is my logic for #456 98fd582

andrey-at-home commented 1 year ago

What happens when unitLock.Target.Core is equal to the minimum boundary? In the original version, coreNeutralizedDone will be zero. In your code, coreNeutralizedDone will be equal to the module of coreNeutralized.

Ramit110 commented 1 year ago

Right of course, the core can't be negative