Skip to content

Commit

Permalink
Raid/Group/XTarget HP/Mana/Endurance updates now only send when perce…
Browse files Browse the repository at this point in the history
…ntage changes

Raid/Group Mana/Endurance updates should now update real-time once again
Fixed an issue with clients looking like they are 'skipping' when they are moving in view of another client
Fixed an issue with NPC's who are ghosted in plain view of a client when they are not really there
  • Loading branch information
Akkadius committed Jul 11, 2017
1 parent d47daa2 commit 8557964
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 147 deletions.
6 changes: 6 additions & 0 deletions changelog.txt
@@ -1,5 +1,11 @@
EQEMu Changelog (Started on Sept 24, 2003 15:50)
-------------------------------------------------------
== 7/11/2017 ==
Akkadius: Raid/Group/XTarget HP/Mana/Endurance updates now only send when percentage changes
Akkadius: Raid/Group Mana/Endurance updates should now update real-time once again
Akkadius: Fixed an issue with clients looking like they are 'skipping' when they are moving in view of another client
Akkadius: Fixed an issue with NPC's who are ghosted in plain view of a client when they are not really there

== 7/9/2017 ==
Akkadius: Fix HP update issues, rework logic for more accurate HP updates
Akkadius: Massive reductions in unnecessary network traffic especially during high spam combat fights
Expand Down
12 changes: 6 additions & 6 deletions zone/bot.cpp
Expand Up @@ -84,7 +84,7 @@ Bot::Bot(NPCType npcTypeData, Client* botOwner) : NPC(&npcTypeData, nullptr, glm
GenerateBaseStats();
// Calculate HitPoints Last As It Uses Base Stats
cur_hp = GenerateBaseHitPoints();
cur_mana = GenerateBaseManaPoints();
current_mana = GenerateBaseManaPoints();
cur_end = CalcBaseEndurance();
hp_regen = CalcHPRegen();
mana_regen = CalcManaRegen();
Expand Down Expand Up @@ -129,7 +129,7 @@ Bot::Bot(uint32 botID, uint32 botOwnerCharacterID, uint32 botSpellsID, double to
_baseRace = npcTypeData.race;
_baseGender = npcTypeData.gender;
cur_hp = npcTypeData.cur_hp;
cur_mana = npcTypeData.Mana;
current_mana = npcTypeData.Mana;
RestRegenHP = 0;
RestRegenMana = 0;
RestRegenEndurance = 0;
Expand Down Expand Up @@ -206,8 +206,8 @@ Bot::Bot(uint32 botID, uint32 botOwnerCharacterID, uint32 botSpellsID, double to
SpellOnTarget(756, this); // Rezz effects
}

if(cur_mana > max_mana)
cur_mana = max_mana;
if(current_mana > max_mana)
current_mana = max_mana;

cur_end = max_end;
}
Expand Down Expand Up @@ -5557,8 +5557,8 @@ int32 Bot::CalcMaxMana() {
}
}

if(cur_mana > max_mana)
cur_mana = max_mana;
if(current_mana > max_mana)
current_mana = max_mana;
else if(max_mana < 0)
max_mana = 0;

Expand Down
123 changes: 72 additions & 51 deletions zone/client.cpp
Expand Up @@ -161,8 +161,10 @@ Client::Client(EQStreamInterface* ieqs)
npc_close_scan_timer(6000),
hp_self_update_throttle_timer(500)
{

for(int cf=0; cf < _FilterCount; cf++)
ClientFilters[cf] = FilterShow;

character_id = 0;
conn_state = NoPacketsReceived;
client_data_loaded = false;
Expand Down Expand Up @@ -191,7 +193,9 @@ Client::Client(EQStreamInterface* ieqs)
strcpy(account_name, "");
tellsoff = false;
last_reported_mana = 0;
last_reported_endur = 0;
last_reported_endurance = 0;
last_reported_endurance_percent = 0;
last_reported_mana_percent = 0;
gmhideme = false;
AFK = false;
LFG = false;
Expand Down Expand Up @@ -269,7 +273,7 @@ Client::Client(EQStreamInterface* ieqs)
RestRegenMana = 0;
RestRegenEndurance = 0;
XPRate = 100;
cur_end = 0;
current_endurance = 0;

m_TimeSinceLastPositionCheck = 0;
m_DistanceSinceLastPositionCheck = 0.0f;
Expand All @@ -287,7 +291,7 @@ Client::Client(EQStreamInterface* ieqs)
HideCorpseMode = HideCorpseNone;
PendingGuildInvitation = false;

cur_end = 0;
current_endurance = 0;

InitializeBuffSlots();

Expand Down Expand Up @@ -599,8 +603,8 @@ bool Client::Save(uint8 iCommitNow) {
m_pp.cur_hp = GetHP();
}

m_pp.mana = cur_mana;
m_pp.endurance = cur_end;
m_pp.mana = current_mana;
m_pp.endurance = current_endurance;

/* Save Character Currency */
database.SaveCharacterCurrency(CharacterID(), &m_pp);
Expand Down Expand Up @@ -1820,93 +1824,110 @@ const int32& Client::SetMana(int32 amount) {
amount = 0;
if (amount > GetMaxMana())
amount = GetMaxMana();
if (amount != cur_mana)
if (amount != current_mana)
update = true;
cur_mana = amount;
current_mana = amount;
if (update)
Mob::SetMana(amount);
SendManaUpdatePacket();
return cur_mana;
CheckManaEndUpdate();
return current_mana;
}

void Client::SendManaUpdatePacket() {
void Client::CheckManaEndUpdate() {
if (!Connected())
return;

if (last_reported_mana != cur_mana || last_reported_endur != cur_end) {
if (last_reported_mana != current_mana || last_reported_endurance != current_endurance) {

if (ClientVersion() >= EQEmu::versions::ClientVersion::SoD) {
SendManaUpdate();
SendEnduranceUpdate();
}

auto outapp = new EQApplicationPacket(OP_ManaChange, sizeof(ManaChange_Struct));
ManaChange_Struct* manachange = (ManaChange_Struct*)outapp->pBuffer;
manachange->new_mana = cur_mana;
manachange->stamina = cur_end;
manachange->spell_id = casting_spell_id;
manachange->keepcasting = 1;
ManaChange_Struct* mana_change = (ManaChange_Struct*)outapp->pBuffer;
mana_change->new_mana = current_mana;
mana_change->stamina = current_endurance;
mana_change->spell_id = casting_spell_id;
mana_change->keepcasting = 1;
outapp->priority = 6;
QueuePacket(outapp);
safe_delete(outapp);

Group *g = GetGroup();
/* Let others know when our mana percent has changed */
if (this->GetManaPercent() != last_reported_mana_percent) {
Group *group = this->GetGroup();
Raid *raid = this->GetRaid();

if(g)
{
outapp = new EQApplicationPacket(OP_MobManaUpdate, sizeof(MobManaUpdate_Struct));
auto outapp2 =
new EQApplicationPacket(OP_MobEnduranceUpdate, sizeof(MobEnduranceUpdate_Struct));
if (raid) {
raid->SendManaPacketFrom(this);
}
else if (group) {
group->SendManaPacketFrom(this);
}

MobManaUpdate_Struct *mmus = (MobManaUpdate_Struct *)outapp->pBuffer;
MobEnduranceUpdate_Struct *meus = (MobEnduranceUpdate_Struct *)outapp2->pBuffer;
auto mana_packet = new EQApplicationPacket(OP_ManaUpdate, sizeof(ManaUpdate_Struct));
ManaUpdate_Struct* mana_update = (ManaUpdate_Struct*)mana_packet->pBuffer;
mana_update->cur_mana = GetMana();
mana_update->max_mana = GetMaxMana();
mana_update->spawn_id = GetID();
QueuePacket(mana_packet);
entity_list.QueueClientsByXTarget(this, mana_packet, false);
safe_delete(mana_packet);

mmus->spawn_id = meus->spawn_id = GetID();
last_reported_mana_percent = this->GetManaPercent();
}

mmus->mana = GetManaPercent();
meus->endurance = GetEndurancePercent();
/* Let others know when our endurance percent has changed */
if (this->GetEndurancePercent() != last_reported_endurance_percent) {
Group *group = this->GetGroup();
Raid *raid = this->GetRaid();

if (raid) {
raid->SendEndurancePacketFrom(this);
}
else if (group) {
group->SendEndurancePacketFrom(this);
}

for(int i = 0; i < MAX_GROUP_MEMBERS; ++i)
if (g->members[i] && g->members[i]->IsClient() && (g->members[i] != this) && (g->members[i]->CastToClient()->ClientVersion() >= EQEmu::versions::ClientVersion::SoD))
{
g->members[i]->CastToClient()->QueuePacket(outapp);
g->members[i]->CastToClient()->QueuePacket(outapp2);
}
auto endurance_packet = new EQApplicationPacket(OP_EnduranceUpdate, sizeof(EnduranceUpdate_Struct));
EnduranceUpdate_Struct* endurance_update = (EnduranceUpdate_Struct*)endurance_packet->pBuffer;
endurance_update->cur_end = GetEndurance();
endurance_update->max_end = GetMaxEndurance();
endurance_update->spawn_id = GetID();
QueuePacket(endurance_packet);
entity_list.QueueClientsByXTarget(this, endurance_packet, false);
safe_delete(endurance_packet);

safe_delete(outapp);
safe_delete(outapp2);
last_reported_endurance_percent = this->GetEndurancePercent();
}


last_reported_mana = cur_mana;
last_reported_endur = cur_end;
last_reported_mana = current_mana;
last_reported_endurance = current_endurance;
}
}

// sends mana update to self
void Client::SendManaUpdate()
{
auto mana_app = new EQApplicationPacket(OP_ManaUpdate, sizeof(ManaUpdate_Struct));
ManaUpdate_Struct* mus = (ManaUpdate_Struct*)mana_app->pBuffer;
mus->cur_mana = GetMana();
mus->max_mana = GetMaxMana();
mus->spawn_id = GetID();
ManaUpdate_Struct* mana_update = (ManaUpdate_Struct*)mana_app->pBuffer;
mana_update->cur_mana = GetMana();
mana_update->max_mana = GetMaxMana();
mana_update->spawn_id = GetID();
QueuePacket(mana_app);
entity_list.QueueClientsByXTarget(this, mana_app, false);
safe_delete(mana_app);
}

// sends endurance update to self
void Client::SendEnduranceUpdate()
{
auto end_app = new EQApplicationPacket(OP_EnduranceUpdate, sizeof(EnduranceUpdate_Struct));
EnduranceUpdate_Struct* eus = (EnduranceUpdate_Struct*)end_app->pBuffer;
eus->cur_end = GetEndurance();
eus->max_end = GetMaxEndurance();
eus->spawn_id = GetID();
EnduranceUpdate_Struct* endurance_update = (EnduranceUpdate_Struct*)end_app->pBuffer;
endurance_update->cur_end = GetEndurance();
endurance_update->max_end = GetMaxEndurance();
endurance_update->spawn_id = GetID();
QueuePacket(end_app);
entity_list.QueueClientsByXTarget(this, end_app, false);
safe_delete(end_app);
}

Expand Down Expand Up @@ -3769,8 +3790,8 @@ void Client::SetEndurance(int32 newEnd)
newEnd = GetMaxEndurance();
}

cur_end = newEnd;
SendManaUpdatePacket();
current_endurance = newEnd;
CheckManaEndUpdate();
}

void Client::SacrificeConfirm(Client *caster)
Expand Down Expand Up @@ -4376,7 +4397,7 @@ bool Client::GroupFollow(Client* inviter) {
}

database.RefreshGroupFromDB(this);
group->SendHPPacketsTo(this);
group->SendHPManaEndPacketsTo(this);
//send updates to clients out of zone...
group->SendGroupJoinOOZ(this);
return true;
Expand Down
13 changes: 8 additions & 5 deletions zone/client.h
Expand Up @@ -540,11 +540,11 @@ class Client : public Mob
void CalcMaxEndurance(); //This calculates the maximum endurance we can have
int32 CalcBaseEndurance(); //Calculates Base End
int32 CalcEnduranceRegen(); //Calculates endurance regen used in DoEnduranceRegen()
int32 GetEndurance() const {return cur_end;} //This gets our current endurance
int32 GetEndurance() const {return current_endurance;} //This gets our current endurance
int32 GetMaxEndurance() const {return max_end;} //This gets our endurance from the last CalcMaxEndurance() call
int32 CalcEnduranceRegenCap();
int32 CalcHPRegenCap();
inline uint8 GetEndurancePercent() { return (uint8)((float)cur_end / (float)max_end * 100.0f); }
inline uint8 GetEndurancePercent() { return (uint8)((float)current_endurance / (float)max_end * 100.0f); }
void SetEndurance(int32 newEnd); //This sets the current endurance to the new value
void DoEnduranceRegen(); //This Regenerates endurance
void DoEnduranceUpkeep(); //does the endurance upkeep
Expand Down Expand Up @@ -661,7 +661,7 @@ class Client : public Mob
void RefreshGuildInfo();


void SendManaUpdatePacket();
void CheckManaEndUpdate();
void SendManaUpdate();
void SendEnduranceUpdate();
uint8 GetFace() const { return m_pp.face; }
Expand Down Expand Up @@ -1411,7 +1411,7 @@ class Client : public Mob
int Haste; //precalced value

int32 max_end;
int32 cur_end;
int32 current_endurance;

PlayerProfile_Struct m_pp;
ExtendedProfile_Struct m_epp;
Expand Down Expand Up @@ -1502,7 +1502,10 @@ class Client : public Mob
bool tgb;
bool instalog;
int32 last_reported_mana;
int32 last_reported_endur;
int32 last_reported_endurance;

int8 last_reported_mana_percent;
int8 last_reported_endurance_percent;

unsigned int AggroCount; // How many mobs are aggro on us.

Expand Down
16 changes: 8 additions & 8 deletions zone/client_mods.cpp
Expand Up @@ -1046,14 +1046,14 @@ int32 Client::CalcMaxMana()
if (max_mana < 0) {
max_mana = 0;
}
if (cur_mana > max_mana) {
cur_mana = max_mana;
if (current_mana > max_mana) {
current_mana = max_mana;
}
int mana_perc_cap = spellbonuses.ManaPercCap[0];
if (mana_perc_cap) {
int curMana_cap = (max_mana * mana_perc_cap) / 100;
if (cur_mana > curMana_cap || (spellbonuses.ManaPercCap[1] && cur_mana > spellbonuses.ManaPercCap[1])) {
cur_mana = curMana_cap;
if (current_mana > curMana_cap || (spellbonuses.ManaPercCap[1] && current_mana > spellbonuses.ManaPercCap[1])) {
current_mana = curMana_cap;
}
}
Log(Logs::Detail, Logs::Spells, "Client::CalcMaxMana() called for %s - returning %d", GetName(), max_mana);
Expand Down Expand Up @@ -2034,14 +2034,14 @@ void Client::CalcMaxEndurance()
if (max_end < 0) {
max_end = 0;
}
if (cur_end > max_end) {
cur_end = max_end;
if (current_endurance > max_end) {
current_endurance = max_end;
}
int end_perc_cap = spellbonuses.EndPercCap[0];
if (end_perc_cap) {
int curEnd_cap = (max_end * end_perc_cap) / 100;
if (cur_end > curEnd_cap || (spellbonuses.EndPercCap[1] && cur_end > spellbonuses.EndPercCap[1])) {
cur_end = curEnd_cap;
if (current_endurance > curEnd_cap || (spellbonuses.EndPercCap[1] && current_endurance > spellbonuses.EndPercCap[1])) {
current_endurance = curEnd_cap;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions zone/client_packet.cpp
Expand Up @@ -584,14 +584,14 @@ void Client::CompleteConnect()
if (raid->IsLocked())
raid->SendRaidLockTo(this);

raid->SendHPPacketsTo(this);
raid->SendHPManaEndPacketsTo(this);
}
}
else {
Group *group = nullptr;
group = this->GetGroup();
if (group)
group->SendHPPacketsTo(this);
group->SendHPManaEndPacketsTo(this);
}


Expand Down

0 comments on commit 8557964

Please sign in to comment.