diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index 159fc4419b..6083e4d4af 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -533,6 +533,25 @@ std::list ScriptedAI::DoFindFriendlyMissingBuff(float range, uint32 s return pList; } +Player* ScriptedAI::GetPlayerAtMinimumRange(float fMinimumRange) +{ + Player* pPlayer = NULL; + + CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY())); + Cell cell(pair); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + Trinity::PlayerAtMinimumRangeAway check(m_creature, fMinimumRange); + Trinity::PlayerSearcher searcher(m_creature, pPlayer, check); + TypeContainerVisitor, GridTypeMapContainer> visitor(searcher); + + CellLock cell_lock(cell, pair); + cell_lock->Visit(cell_lock, visitor, *(m_creature->GetMap())); + + return pPlayer; +} + void ScriptedAI::SetEquipmentSlots(bool bLoadDefault, int32 uiMainHand, int32 uiOffHand, int32 uiRanged) { if (bLoadDefault) diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index 13713a5610..7c57367332 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -169,6 +169,9 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI //Returns a list of all friendly units missing a specific buff within range std::list DoFindFriendlyMissingBuff(float range, uint32 spellid); + //Return a player with at least minimumRange from m_creature + Player* GetPlayerAtMinimumRange(float fMinimumRange); + //Spawns a creature relative to m_creature Creature* DoSpawnCreature(uint32 id, float x, float y, float z, float angle, uint32 type, uint32 despawntime); Creature *DoSummon(uint32 entry, const float pos[4], uint32 despawntime = 30000, TempSummonType type = TEMPSUMMON_CORPSE_TIMED_DESPAWN); @@ -248,6 +251,5 @@ struct TRINITY_DLL_DECL BossAI : public ScriptedAI //return closest creature alive in grid, with range from pSource Creature* GetClosestCreatureWithEntry(WorldObject* pSource, uint32 Entry, float MaxSearchRange); - #endif diff --git a/src/bindings/scripts/scripts/zone/azuremyst_isle/azuremyst_isle.cpp b/src/bindings/scripts/scripts/zone/azuremyst_isle/azuremyst_isle.cpp index 9974bc80fd..f52a3bc59e 100644 --- a/src/bindings/scripts/scripts/zone/azuremyst_isle/azuremyst_isle.cpp +++ b/src/bindings/scripts/scripts/zone/azuremyst_isle/azuremyst_isle.cpp @@ -441,8 +441,6 @@ struct TRINITY_DLL_DECL npc_geezleAI : public ScriptedAI { npc_geezleAI(Creature *c) : ScriptedAI(c) {} - std::list FlagList; - uint64 SparkGUID; uint32 Step; @@ -516,17 +514,8 @@ struct TRINITY_DLL_DECL npc_geezleAI : public ScriptedAI void DespawnNagaFlag(bool despawn) { - CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY())); - Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - Trinity::AllGameObjectsWithEntryInGrid go_check(GO_NAGA_FLAG); - Trinity::GameObjectListSearcher go_search(m_creature, FlagList, go_check); - TypeContainerVisitor - , GridTypeMapContainer> go_visit(go_search); - CellLock cell_lock(cell, pair); - cell_lock->Visit(cell_lock, go_visit, *(m_creature->GetMap())); + std::list FlagList; + m_creature->GetGameObjectListWithEntryInGrid(FlagList,GO_NAGA_FLAG, 50.0f); Player* player = NULL; if (!FlagList.empty()) diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_shade_of_akama.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_shade_of_akama.cpp index 5255a443b3..0cf81a8cd6 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_shade_of_akama.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_shade_of_akama.cpp @@ -342,19 +342,8 @@ struct TRINITY_DLL_DECL boss_shade_of_akamaAI : public ScriptedAI void FindChannelers() { - CellPair pair(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY())); - Cell cell(pair); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - std::list ChannelerList; - - Trinity::AllCreaturesOfEntryInRange check(m_creature, CREATURE_CHANNELER, 50); - Trinity::CreatureListSearcher searcher(m_creature, ChannelerList, check); - TypeContainerVisitor, GridTypeMapContainer> visitor(searcher); - - CellLock cell_lock(cell, pair); - cell_lock->Visit(cell_lock, visitor, *(m_creature->GetMap())); + m_creature->GetCreatureListWithEntryInGrid(ChannelerList,CREATURE_CHANNELER,50.0f); if(!ChannelerList.empty()) { diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp index b45097d7f9..953fbcb198 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp @@ -53,21 +53,6 @@ EndScriptData */ #define SPELL_STORM_BUFF 2148 #define SPELL_STORM 26546 -class NearbyAQSentinel -{ - public: - NearbyAQSentinel(Unit const* obj) : i_obj(obj) {} - bool operator()(Unit* u) - { - if (u->GetEntry() == 15264 && i_obj->IsWithinDistInMap(u, 70) && !u->isDead()) - return true; - else - return false; - } - private: - Unit const* i_obj; -}; - struct TRINITY_DLL_DECL aqsentinelAI; class TRINITY_DLL_DECL SentinelAbilityAura : public Aura { @@ -166,18 +151,11 @@ struct TRINITY_DLL_DECL aqsentinelAI : public ScriptedAI void AddSentinelsNear(Unit *nears) { - CellPair p(Trinity::ComputeCellPair(nears->GetPositionX(), nears->GetPositionY())); - Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - std::list assistList; + m_creature->GetCreatureListWithEntryInGrid(assistList,15264,70.0f); - NearbyAQSentinel u_check(nears); - Trinity::CreatureListSearcher searcher(m_creature, assistList, u_check); - TypeContainerVisitor, GridTypeMapContainer > grid_creature_searcher(searcher); - CellLock cell_lock(cell, p); - cell_lock->Visit(cell_lock, grid_creature_searcher, *(nears->GetMap())); + if (assistList.empty()) + return; for(std::list::iterator iter = assistList.begin(); iter != assistList.end(); ++iter) AddBuddyToList((*iter)); diff --git a/src/game/GridNotifiers.h b/src/game/GridNotifiers.h index 64deb0d312..997f080636 100644 --- a/src/game/GridNotifiers.h +++ b/src/game/GridNotifiers.h @@ -1135,19 +1135,57 @@ namespace Trinity Unit const* pUnit; }; - class AllGameObjectsWithEntryInGrid + class AllGameObjectsWithEntryInRange { public: - AllGameObjectsWithEntryInGrid(uint32 ent) : entry(ent) {} - bool operator() (GameObject* g) + AllGameObjectsWithEntryInRange(const WorldObject* pObject, uint32 uiEntry, float fMaxRange) : m_pObject(pObject), m_uiEntry(uiEntry), m_fRange(fMaxRange) {} + bool operator() (GameObject* pGo) { - if(g->GetEntry() == entry) + if (pGo->GetEntry() == m_uiEntry && m_pObject->IsWithinDist(pGo,m_fRange,false)) return true; return false; } private: - uint32 entry; + const WorldObject* m_pObject; + uint32 m_uiEntry; + float m_fRange; + }; + + class AllCreaturesOfEntryInRange + { + public: + AllCreaturesOfEntryInRange(const WorldObject* pObject, uint32 uiEntry, float fMaxRange) : m_pObject(pObject), m_uiEntry(uiEntry), m_fRange(fMaxRange) {} + bool operator() (Unit* pUnit) + { + if (pUnit->GetEntry() == m_uiEntry && m_pObject->IsWithinDist(pUnit,m_fRange,false)) + return true; + + return false; + } + + private: + const WorldObject* m_pObject; + uint32 m_uiEntry; + float m_fRange; + }; + + class PlayerAtMinimumRangeAway + { + public: + PlayerAtMinimumRangeAway(Unit const* unit, float fMinRange) : pUnit(unit), fRange(fMinRange) {} + bool operator() (Player* pPlayer) + { + //No threat list check, must be done explicit if expected to be in combat with creature + if (!pPlayer->isGameMaster() && pPlayer->isAlive() && !pUnit->IsWithinDist(pPlayer,fRange,false)) + return true; + + return false; + } + + private: + Unit const* pUnit; + float fRange; }; class GameObjectInRangeCheck @@ -1162,23 +1200,6 @@ namespace Trinity float x, y, z, range; }; - class AllCreaturesOfEntryInRange - { - public: - AllCreaturesOfEntryInRange(Unit const* obj, uint32 ent, float ran) : pUnit(obj), entry(ent), range(ran) {} - bool operator() (Unit* u) - { - if(u->GetEntry() == entry && pUnit->IsWithinDistInMap(u, range)) - return true; - - return false; - } - private: - Unit const* pUnit; - uint32 entry; - float range; - }; - // Player checks and do // Prepare using Builder localized packets with caching and send to player diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 76041d8792..d565818910 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1992,6 +1992,36 @@ GameObject* WorldObject::FindNearestGameObject(uint32 entry, float range) return go; } +void WorldObject::GetGameObjectListWithEntryInGrid(std::list& lList, uint32 uiEntry, float fMaxSearchRange) +{ + CellPair pair(Trinity::ComputeCellPair(this->GetPositionX(), this->GetPositionY())); + Cell cell(pair); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + Trinity::AllGameObjectsWithEntryInRange check(this, uiEntry, fMaxSearchRange); + Trinity::GameObjectListSearcher searcher(this, lList, check); + TypeContainerVisitor, GridTypeMapContainer> visitor(searcher); + + CellLock cell_lock(cell, pair); + cell_lock->Visit(cell_lock, visitor, *(this->GetMap())); +} + +void WorldObject::GetCreatureListWithEntryInGrid(std::list& lList, uint32 uiEntry, float fMaxSearchRange) +{ + CellPair pair(Trinity::ComputeCellPair(this->GetPositionX(), this->GetPositionY())); + Cell cell(pair); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + Trinity::AllCreaturesOfEntryInRange check(this, uiEntry, fMaxSearchRange); + Trinity::CreatureListSearcher searcher(this, lList, check); + TypeContainerVisitor, GridTypeMapContainer> visitor(searcher); + + CellLock cell_lock(cell, pair); + cell_lock->Visit(cell_lock, visitor, *(this->GetMap())); +} + /* namespace MaNGOS { diff --git a/src/game/Object.h b/src/game/Object.h index 2eba206ae6..b7e5a6efa3 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -548,6 +548,9 @@ class TRINITY_DLL_SPEC WorldObject : public Object Creature* FindNearestCreature(uint32 entry, float range, bool alive = true); GameObject* FindNearestGameObject(uint32 entry, float range); + void GetGameObjectListWithEntryInGrid(std::list& lList, uint32 uiEntry, float fMaxSearchRange); + void GetCreatureListWithEntryInGrid(std::list& lList, uint32 uiEntry, float fMaxSearchRange); + bool isActiveObject() const { return m_isActive; } void setActive(bool isActiveObject); void SetWorldObject(bool apply); diff --git a/src/shared/Errors.h b/src/shared/Errors.h index 5cfd109ee0..992b1752a0 100644 --- a/src/shared/Errors.h +++ b/src/shared/Errors.h @@ -23,10 +23,6 @@ #include "Common.h" -#ifndef HAVE_CONFIG_H -#define HAVE_ACE_STACK_TRACE_H 1 -#endif - #ifdef HAVE_ACE_STACK_TRACE_H #include "ace/Stack_Trace.h" #endif