From d777b1048dbd931966c93b04d5a2bfb1ad948f8c Mon Sep 17 00:00:00 2001 From: Akkadius Date: Tue, 28 Mar 2017 03:05:46 -0500 Subject: [PATCH] [Performance] Don't process ProjectileAttack checks for NPC's that are not engaged in any combat --- changelog.txt | 1 + zone/mob_ai.cpp | 10 +++++--- zone/npc.cpp | 55 ++++++++++++++++++++-------------------- zone/special_attacks.cpp | 1 - 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/changelog.txt b/changelog.txt index e155cf06e..850faac13 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ Akkadius: [Performance] Fixed a large overhead issue where every single NPC in a Akkadius: [Performance] Removed a timer where clients would constantly calculate light amount on equipment every 600ms, instead clients will update light when changing equipment or entering a zone Akkadius: [Performance] Disabled enraged timer checks for NPC's that do not actually have enrage as a special attack +Akkadius: [Performance] Don't process ProjectileAttack checks for NPC's that are not engaged in any combat == 03/27/2017 == Akkadius: [Performance] Reworked how client to NPC aggro checks are made diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index d0298ac55..ba0082942 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1011,8 +1011,8 @@ void Mob::AI_Process() { CastToNPC()->CheckSignal(); } - if (engaged) - { + if (engaged) { + if (!(m_PlayerState & static_cast(PlayerState::Aggressive))) SendAddPlayerState(PlayerState::Aggressive); // we are prevented from getting here if we are blind and don't have a target in range @@ -1039,8 +1039,7 @@ void Mob::AI_Process() { if (!target) return; - if (target->IsCorpse()) - { + if (target->IsCorpse()) { RemoveFromHateList(this); return; } @@ -1057,6 +1056,8 @@ void Mob::AI_Process() { if (DivineAura()) return; + ProjectileAttack(); + auto npcSpawnPoint = CastToNPC()->GetSpawnPoint(); if (GetSpecialAbility(TETHER)) { float tether_range = static_cast(GetSpecialAbilityParam(TETHER, 0)); @@ -1255,6 +1256,7 @@ void Mob::AI_Process() { } AI_EngagedCastCheck(); + } //end is within combat rangepet else { //we cannot reach our target... diff --git a/zone/npc.cpp b/zone/npc.cpp index 4dd65b1d4..a9fec20d0 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -587,8 +587,7 @@ void NPC::RemoveCash() { bool NPC::Process() { - if (IsStunned() && stunned_timer.Check()) - { + if (IsStunned() && stunned_timer.Check()) { Mob::UnStun(); this->spun_timer.Disable(); } @@ -608,58 +607,60 @@ bool NPC::Process() SpellProcess(); - if(tic_timer.Check()) - { + if (tic_timer.Check()) { parse->EventNPC(EVENT_TICK, this, nullptr, "", 0); BuffProcess(); - if(currently_fleeing) + if (currently_fleeing) ProcessFlee(); uint32 bonus = 0; - if(GetAppearance() == eaSitting) - bonus+=3; + if (GetAppearance() == eaSitting) + bonus += 3; int32 OOCRegen = 0; - if(oocregen > 0){ //should pull from Mob class + if (oocregen > 0) { //should pull from Mob class OOCRegen += GetMaxHP() * oocregen / 100; - } + } //Lieka Edit:Fixing NPC regen.NPCs should regen to full during a set duration, not based on their HPs.Increase NPC's HPs by % of total HPs / tick. - if((GetHP() < GetMaxHP()) && !IsPet()) { - if(!IsEngaged()) {//NPC out of combat - if(GetNPCHPRegen() > OOCRegen) + if ((GetHP() < GetMaxHP()) && !IsPet()) { + if (!IsEngaged()) {//NPC out of combat + if (GetNPCHPRegen() > OOCRegen) SetHP(GetHP() + GetNPCHPRegen()); else SetHP(GetHP() + OOCRegen); - } else - SetHP(GetHP()+GetNPCHPRegen()); - } else if(GetHP() < GetMaxHP() && GetOwnerID() !=0) { - if(!IsEngaged()) //pet - SetHP(GetHP()+GetNPCHPRegen()+bonus+(GetLevel()/5)); + } else - SetHP(GetHP()+GetNPCHPRegen()+bonus); - } else - SetHP(GetHP()+GetNPCHPRegen()); + SetHP(GetHP() + GetNPCHPRegen()); + } + else if (GetHP() < GetMaxHP() && GetOwnerID() != 0) { + if (!IsEngaged()) //pet + SetHP(GetHP() + GetNPCHPRegen() + bonus + (GetLevel() / 5)); + else + SetHP(GetHP() + GetNPCHPRegen() + bonus); + } + else + SetHP(GetHP() + GetNPCHPRegen()); - if(GetMana() < GetMaxMana()) { - SetMana(GetMana()+mana_regen+bonus); + if (GetMana() < GetMaxMana()) { + SetMana(GetMana() + mana_regen + bonus); } - if(zone->adv_data && !p_depop) + if (zone->adv_data && !p_depop) { ServerZoneAdventureDataReply_Struct* ds = (ServerZoneAdventureDataReply_Struct*)zone->adv_data; - if(ds->type == Adventure_Rescue && ds->data_id == GetNPCTypeID()) + if (ds->type == Adventure_Rescue && ds->data_id == GetNPCTypeID()) { Mob *o = GetOwner(); - if(o && o->IsClient()) + if (o && o->IsClient()) { float x_diff = ds->dest_x - GetX(); float y_diff = ds->dest_y - GetY(); float z_diff = ds->dest_z - GetZ(); float dist = ((x_diff * x_diff) + (y_diff * y_diff) + (z_diff * z_diff)); - if(dist < RuleR(Adventure, DistanceForRescueComplete)) + if (dist < RuleR(Adventure, DistanceForRescueComplete)) { zone->DoAdventureCountIncrease(); Say("You don't know what this means to me. Thank you so much for finding and saving me from" @@ -693,8 +694,6 @@ bool NPC::Process() viral_timer_counter = 0; } - ProjectileAttack(); - if(spellbonuses.GravityEffect == 1) { if(gravity_timer.Check()) DoGravityEffect(); diff --git a/zone/special_attacks.cpp b/zone/special_attacks.cpp index 074d707a8..11f32a630 100644 --- a/zone/special_attacks.cpp +++ b/zone/special_attacks.cpp @@ -956,7 +956,6 @@ void Mob::ProjectileAttack() { if (!HasProjectileAttack()) return; - ; Mob *target = nullptr; bool disable = true;