PDA

View Full Version : Client::SetMana corrections


cybernine186
10-30-2009, 05:13 PM
I have found some flaws in the Client::SetMana causing items like Manastone and Cannibalize to not work properly. Also Client::DoManaRegen() does a unnecessary call of the SendManaUpdatePacket(); twice.

Here is a diff of the latest version of PEQ. Please let me know how it works for you.

Index: zone/client.cpp
================================================== =================
--- zone/client.cpp (revision 1046)
+++ zone/client.cpp (working copy)
@@ -1621,17 +1621,22 @@
}

const sint32& Client::SetMana(sint32 amount) {
- bool update = false;
- if (amount < 0)
+
+ // No negative amount
+ if (amount < 0) {
amount = 0;
- if (amount > GetMaxMana())
+ }
+
+ // Do not set above the maximum amount
+ if (amount > GetMaxMana()) {
amount = GetMaxMana();
- if (amount != cur_mana)
- update = true;
- cur_mana = amount;
- if (update)
- Mob::SetMana(amount);
- SendManaUpdatePacket();
+ }
+
+ // Update mana and sent to client
+ if (amount != cur_mana) {
+ cur_mana = amount;
+ SendManaUpdatePacket();
+ }
return cur_mana;
}

Index: zone/client_process.cpp
================================================== =================
--- zone/client_process.cpp (revision 1046)
+++ zone/client_process.cpp (working copy)
@@ -1761,7 +1761,6 @@
regen = (regen * RuleI(Character, ManaRegenMultiplier)) / 100;

SetMana(GetMana() + regen + RestRegenMana);
- SendManaUpdatePacket();
}

cybernine186
11-02-2009, 10:43 AM
I meant to explain the changes but forgot.

The Client::SetMana() was calling Mob:SetMana() and in the function Mob::SetMana() it was recalculating the max mana using CalcMaxMana(). Well CalcMaxMana() was being calculated for Mobs and not Clients so the wrong max mana was being set.

I noticed on the VZTZ source this was causing things like Manastones & Cannibalize spells to only reach up to 60% mana before it would quit giving you mana.

The Client::SetMana() was already setting the cur_mana and then trying to set cur_mana again in the Mob::SetMana().

There was no need to call the Mob::SetMana() because it was 1. calculating the wrong maximum mana and 2. The cur_mana was already set in Client::SetMana().


The client_process.cpp file in function Client::DoManaRegen() was calling the functions SetMana() and SendManaUpdatePacket(). The SetMana() functions already calls the SendManaUpdatePacket() at the end of the SetMana() function. So the SendManaUpdatePacket() was being sent to the client twice.

I hope I explained it well enough for everyone to understand.