diff options
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.h | 32 | ||||
-rw-r--r-- | src/server/game/Chat/Chat.cpp | 12 | ||||
-rw-r--r-- | src/server/game/Grids/Notifiers/GridNotifiers.h | 24 | ||||
-rw-r--r-- | src/server/game/Scripting/MapScripts.cpp | 42 |
4 files changed, 29 insertions, 81 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartScript.h b/src/server/game/AI/SmartScripts/SmartScript.h index 0233d1aa7d0..c5cc5aedb43 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.h +++ b/src/server/game/AI/SmartScripts/SmartScript.h @@ -177,33 +177,25 @@ class SmartScript GameObject* FindGameObjectNear(WorldObject* searchObject, ObjectGuid::LowType guid) const { - GameObject* gameObject = NULL; + auto bounds = searchObject->GetMap()->GetGameObjectBySpawnIdStore().equal_range(guid); + if (bounds.first == bounds.second) + return nullptr; - CellCoord p(Trinity::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY())); - Cell cell(p); - - Trinity::GameObjectWithDbGUIDCheck goCheck(*searchObject, guid); - Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck> checker(searchObject, gameObject, goCheck); - - TypeContainerVisitor<Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > objectChecker(checker); - cell.Visit(p, objectChecker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange()); - - return gameObject; + return bounds.first->second; } Creature* FindCreatureNear(WorldObject* searchObject, ObjectGuid::LowType guid) const { - Creature* creature = NULL; - CellCoord p(Trinity::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY())); - Cell cell(p); + auto bounds = searchObject->GetMap()->GetCreatureBySpawnIdStore().equal_range(guid); + if (bounds.first == bounds.second) + return nullptr; - Trinity::CreatureWithDbGUIDCheck target_check(searchObject, guid); - Trinity::CreatureSearcher<Trinity::CreatureWithDbGUIDCheck> checker(searchObject, creature, target_check); - - TypeContainerVisitor<Trinity::CreatureSearcher <Trinity::CreatureWithDbGUIDCheck>, GridTypeMapContainer > unit_checker(checker); - cell.Visit(p, unit_checker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange()); + auto creatureItr = std::find_if(bounds.first, bounds.second, [](Map::CreatureBySpawnIdContainer::value_type const& pair) + { + return pair.second->IsAlive(); + }); - return creature; + return creatureItr != bounds.second ? creatureItr->second : bounds.first->second; } ObjectListMap* mTargetStorage; diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index ed6aa52da5a..52c52726b73 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -796,15 +796,11 @@ GameObject* ChatHandler::GetObjectGlobalyWithGuidOrNearWithDbGuid(ObjectGuid::Lo if (!obj && sObjectMgr->GetGOData(lowguid)) // guid is DB guid of object { - // search near player then - CellCoord p(Trinity::ComputeCellCoord(pl->GetPositionX(), pl->GetPositionY())); - Cell cell(p); + auto bounds = pl->GetMap()->GetGameObjectBySpawnIdStore().equal_range(lowguid); + if (bounds.first == bounds.second) + return nullptr; - Trinity::GameObjectWithDbGUIDCheck go_check(*pl, lowguid); - Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck> checker(pl, obj, go_check); - - TypeContainerVisitor<Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > object_checker(checker); - cell.Visit(p, object_checker, *pl->GetMap(), *pl, pl->GetGridActivationRange()); + return bounds.first->second; } return obj; diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h index 8a5386684bb..aea2d8ec383 100644 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -736,18 +736,6 @@ namespace Trinity NearestGameObjectTypeInObjectRangeCheck(NearestGameObjectTypeInObjectRangeCheck const&); }; - class GameObjectWithDbGUIDCheck - { - public: - GameObjectWithDbGUIDCheck(WorldObject const& /*obj*/, ObjectGuid::LowType db_guid) : i_db_guid(db_guid) { } - bool operator()(GameObject const* go) const - { - return go->GetSpawnId() == i_db_guid; - } - private: - ObjectGuid::LowType i_db_guid; - }; - // Unit checks class MostHPMissingInRange @@ -849,18 +837,6 @@ namespace Trinity float i_range; }; - class CreatureWithDbGUIDCheck - { - public: - CreatureWithDbGUIDCheck(WorldObject const* /*obj*/, ObjectGuid::LowType lowguid) : i_lowguid(lowguid) { } - bool operator()(Creature* u) - { - return u->GetSpawnId() == i_lowguid; - } - private: - ObjectGuid::LowType i_lowguid; - }; - class AnyFriendlyUnitInObjectRangeCheck { public: diff --git a/src/server/game/Scripting/MapScripts.cpp b/src/server/game/Scripting/MapScripts.cpp index deae263e5f8..ecfc069ca78 100644 --- a/src/server/game/Scripting/MapScripts.cpp +++ b/src/server/game/Scripting/MapScripts.cpp @@ -283,18 +283,11 @@ inline void Map::_ScriptProcessDoor(Object* source, Object* target, const Script inline GameObject* Map::_FindGameObject(WorldObject* searchObject, ObjectGuid::LowType guid) const { - GameObject* gameobject = NULL; + auto bounds = searchObject->GetMap()->GetGameObjectBySpawnIdStore().equal_range(guid); + if (bounds.first == bounds.second) + return nullptr; - CellCoord p(Trinity::ComputeCellCoord(searchObject->GetPositionX(), searchObject->GetPositionY())); - Cell cell(p); - - Trinity::GameObjectWithDbGUIDCheck goCheck(*searchObject, guid); - Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck> checker(searchObject, gameobject, goCheck); - - TypeContainerVisitor<Trinity::GameObjectSearcher<Trinity::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > objectChecker(checker); - cell.Visit(p, objectChecker, *searchObject->GetMap(), *searchObject, searchObject->GetGridActivationRange()); - - return gameobject; + return bounds.first->second; } /// Process queued scripts @@ -806,26 +799,17 @@ void Map::ScriptsProcess() } Creature* cTarget = NULL; - WorldObject* wSource = dynamic_cast <WorldObject*> (source); - if (wSource) //using grid searcher + WorldObject* wSource = dynamic_cast<WorldObject*>(source); + auto creatureBounds = _creatureBySpawnIdStore.equal_range(step.script->CallScript.CreatureEntry); + if (creatureBounds.first != creatureBounds.second) { - CellCoord p(Trinity::ComputeCellCoord(wSource->GetPositionX(), wSource->GetPositionY())); - Cell cell(p); - - Trinity::CreatureWithDbGUIDCheck target_check(wSource, uint64(step.script->CallScript.CreatureEntry)); - Trinity::CreatureSearcher<Trinity::CreatureWithDbGUIDCheck> checker(wSource, cTarget, target_check); - - TypeContainerVisitor<Trinity::CreatureSearcher <Trinity::CreatureWithDbGUIDCheck>, GridTypeMapContainer > unit_checker(checker); - cell.Visit(p, unit_checker, *wSource->GetMap(), *wSource, wSource->GetGridActivationRange()); - } - else //check hashmap holders - { - if (sObjectMgr->GetCreatureData(step.script->CallScript.CreatureEntry)) + // Prefer alive (last respawned) creature + auto creatureItr = std::find_if(creatureBounds.first, creatureBounds.second, [](Map::CreatureBySpawnIdContainer::value_type const& pair) { - auto creatureBounds = _creatureBySpawnIdStore.equal_range(step.script->CallScript.CreatureEntry); - if (creatureBounds.first != creatureBounds.second) - cTarget = creatureBounds.first->second; - } + return pair.second->IsAlive(); + }); + + cTarget = creatureItr != creatureBounds.second ? creatureItr->second : creatureBounds.first->second; } if (!cTarget) |