From 808977f69a6268d11e1aaa0b999ad1666aed1f53 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Thu, 20 Feb 2014 01:35:59 -0500 Subject: [PATCH] (Performance) Corpse drag will now fetch entity by ID --- zone/client.cpp | 23 ++++++++++++----------- zone/client.h | 4 ++-- zone/client_packet.cpp | 8 ++++---- zone/entity.cpp | 4 ++-- zone/entity.h | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 114550ebc..6cf490960 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -6045,11 +6045,10 @@ void Client::NPCSpawn(NPC *target_npc, const char *identifier, uint32 extra) } } -bool Client::IsDraggingCorpse(const char *CorpseName) +bool Client::IsDraggingCorpse(uint16 CorpseID) { - for(std::list::iterator Iterator = DraggedCorpses.begin(); Iterator != DraggedCorpses.end(); ++Iterator) - { - if(!strcasecmp((*Iterator).c_str(), CorpseName)) + for (auto It = DraggedCorpses.begin(); It != DraggedCorpses.end(); ++It) { + if (It->second == CorpseID) return true; } @@ -6058,20 +6057,22 @@ bool Client::IsDraggingCorpse(const char *CorpseName) void Client::DragCorpses() { - for(std::list::iterator Iterator = DraggedCorpses.begin(); Iterator != DraggedCorpses.end(); ++Iterator) - { - Mob* corpse = entity_list.GetMob((*Iterator).c_str()); + for (auto It = DraggedCorpses.begin(); It != DraggedCorpses.end(); ++It) { + Mob *corpse = entity_list.GetMob(It->second); - if(corpse && corpse->IsPlayerCorpse() && (DistNoRootNoZ(*corpse) <= RuleR(Character, DragCorpseDistance))) + if (corpse && corpse->IsPlayerCorpse() && + (DistNoRootNoZ(*corpse) <= RuleR(Character, DragCorpseDistance))) continue; - if(!corpse || !corpse->IsPlayerCorpse() || corpse->CastToCorpse()->IsBeingLooted() || !corpse->CastToCorpse()->Summon(this, false, false)) - { + if (!corpse || !corpse->IsPlayerCorpse() || + corpse->CastToCorpse()->IsBeingLooted() || + !corpse->CastToCorpse()->Summon(this, false, false)) { Message_StringID(MT_DefaultText, CORPSEDRAG_STOP); - Iterator = DraggedCorpses.erase(Iterator); + It = DraggedCorpses.erase(It); } } } + void Client::Doppelganger(uint16 spell_id, Mob *target, const char *name_override, int pet_count, int pet_duration) { if(!target || !IsValidSpell(spell_id) || this->GetID() == target->GetID()) diff --git a/zone/client.h b/zone/client.h index d714bb007..be1c29c1c 100644 --- a/zone/client.h +++ b/zone/client.h @@ -1078,7 +1078,7 @@ public: void ClearHover(); inline bool IsBlockedBuff(int16 SpellID) { return PlayerBlockedBuffs.find(SpellID) != PlayerBlockedBuffs.end(); } inline bool IsBlockedPetBuff(int16 SpellID) { return PetBlockedBuffs.find(SpellID) != PetBlockedBuffs.end(); } - bool IsDraggingCorpse(const char* CorpseName); + bool IsDraggingCorpse(uint16 CorpseID); inline bool IsDraggingCorpse() { return (DraggedCorpses.size() > 0); } void DragCorpses(); inline void ClearDraggedCorpses() { DraggedCorpses.clear(); } @@ -1481,7 +1481,7 @@ private: std::set PlayerBlockedBuffs; std::set PetBlockedBuffs; - std::list DraggedCorpses; + std::list > DraggedCorpses; uint8 MaxXTargets; bool XTargetAutoAddHaters; diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 010d66fcb..387afa3ec 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -12379,7 +12379,7 @@ void Client::Handle_OP_CorpseDrag(const EQApplicationPacket *app) if(!corpse || !corpse->IsPlayerCorpse() || corpse->CastToCorpse()->IsBeingLooted()) return; - Client *c = entity_list.FindCorpseDragger(cds->CorpseName); + Client *c = entity_list.FindCorpseDragger(corpse->GetID()); if(c) { @@ -12394,7 +12394,7 @@ void Client::Handle_OP_CorpseDrag(const EQApplicationPacket *app) if(!corpse->CastToCorpse()->Summon(this, false, true)) return; - DraggedCorpses.push_back(cds->CorpseName); + DraggedCorpses.push_back(std::pair(cds->CorpseName, corpse->GetID())); Message_StringID(MT_DefaultText, CORPSEDRAG_BEGIN, cds->CorpseName); } @@ -12408,9 +12408,9 @@ void Client::Handle_OP_CorpseDrop(const EQApplicationPacket *app) return; } - for(std::list::iterator Iterator = DraggedCorpses.begin(); Iterator != DraggedCorpses.end(); ++Iterator) + for (auto Iterator = DraggedCorpses.begin(); Iterator != DraggedCorpses.end(); ++Iterator) { - if(!strcasecmp((*Iterator).c_str(), (const char *)app->pBuffer)) + if(!strcasecmp(Iterator->first.c_str(), (const char *)app->pBuffer)) { Message_StringID(MT_DefaultText, CORPSEDRAG_STOP); Iterator = DraggedCorpses.erase(Iterator); diff --git a/zone/entity.cpp b/zone/entity.cpp index 8f4b663ea..9103ed157 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -4512,11 +4512,11 @@ void EntityList::GetTargetsForConeArea(Mob *start, uint32 radius, uint32 height, } } -Client *EntityList::FindCorpseDragger(const char *CorpseName) +Client *EntityList::FindCorpseDragger(uint16 CorpseID) { auto it = client_list.begin(); while (it != client_list.end()) { - if (it->second->IsDraggingCorpse(CorpseName)) + if (it->second->IsDraggingCorpse(CorpseID)) return it->second; ++it; } diff --git a/zone/entity.h b/zone/entity.h index 9de73ff0e..dbdeb5dcd 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -167,7 +167,7 @@ public: Spawn2* GetSpawnByID(uint32 id); - Client* FindCorpseDragger(const char *CorpseName); + Client* FindCorpseDragger(uint16 CorpseID); inline Object *GetObjectByID(uint16 id) { return object_list.count(id) ? object_list.at(id) : nullptr; }