diff options
author | ccrs <ccrs@users.noreply.github.com> | 2019-10-22 13:36:23 +0200 |
---|---|---|
committer | ccrs <ccrs@users.noreply.github.com> | 2019-10-22 13:36:23 +0200 |
commit | bb9af06cd4ff80f078fcb6ae4871c74a1a174bcc (patch) | |
tree | 1bd151b84a38034dd9139feb5ec7faf01590ecb7 | |
parent | fe7c2c377288339a2ba95e2bba226b815d79ba55 (diff) |
Core/AI: 06443e3 followup
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 57 | ||||
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.h | 6 |
2 files changed, 39 insertions, 24 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index eb0765e6e19..96a3d8c46e7 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -243,6 +243,41 @@ float ScriptedAI::GetThreat(Unit const* victim, Unit const* who) return who->GetThreatManager().GetThreat(victim); } +void ScriptedAI::ForceCombatStop(Creature* who, bool reset /*= true*/) +{ + if (!who || !who->IsInCombat()) + return; + + who->CombatStop(true); + who->DoNotReacquireSpellFocusTarget(); + who->GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL); + + if (reset) { + who->LoadCreaturesAddon(); + who->SetLootRecipient(nullptr); + who->ResetPlayerDamageReq(); + who->SetLastDamagedTime(0); + who->SetCannotReachTarget(false); + } +} + +void ScriptedAI::ForceCombatStopForCreatureEntry(uint32 entry, float maxSearchRange /*= 250.0f*/, bool samePhase /*= true*/, bool reset /*= true*/) +{ + TC_LOG_DEBUG("scripts.ai", "ScriptedAI::ForceCombatStopForCreatureEntry: called on '%s'. Debug info: %s", me->GetGUID().ToString().c_str(), me->GetDebugInfo().c_str()); + + std::list<Creature*> creatures; + Trinity::AllCreaturesOfEntryInRange check(me, entry, maxSearchRange); + Trinity::CreatureListSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(me, creatures, check); + + if (!samePhase) + searcher.i_phaseMask = PHASEMASK_ANYWHERE; + + Cell::VisitGridObjects(me, searcher, maxSearchRange); + + for (Creature* creature : creatures) + ForceCombatStop(creature, reset); +} + Creature* ScriptedAI::DoSpawnCreature(uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, uint32 despawntime) { return me->SummonCreature(entry, me->GetPositionX() + offsetX, me->GetPositionY() + offsetY, me->GetPositionZ() + offsetZ, angle, TempSummonType(type), despawntime); @@ -517,28 +552,6 @@ void BossAI::TeleportCheaters() } } -void BossAI::ForceCombatStopForCreatureEntry(uint32 entry, float maxSearchRange /*= 250.0f*/, bool reset /*= true*/) -{ - TC_LOG_DEBUG("scripts.ai", "BossAI::ForceCombatStopForCreatureEntry: called on '%s'. Debug info: %s", me->GetGUID().ToString().c_str(), me->GetDebugInfo().c_str()); - - std::list<Creature*> creatures; - me->GetCreatureListWithEntryInGrid(creatures, entry, maxSearchRange); - - for (Creature* creature : creatures) { - creature->CombatStop(true); - creature->DoNotReacquireSpellFocusTarget(); - creature->GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL); - - if (reset) { - creature->LoadCreaturesAddon(); - creature->SetLootRecipient(nullptr); - creature->ResetPlayerDamageReq(); - creature->SetLastDamagedTime(0); - creature->SetCannotReachTarget(false); - } - } -} - void BossAI::JustSummoned(Creature* summon) { summons.Summon(summon); diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index 9fef9a9faa3..9d5767b7a52 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -186,6 +186,10 @@ struct TC_GAME_API ScriptedAI : public CreatureAI void ResetThreatList(Unit* who = nullptr); // Returns the threat level of victim towards who (or me if not specified) float GetThreat(Unit const* victim, Unit const* who = nullptr); + // Stops combat, ignoring restrictions, for the given creature + void ForceCombatStop(Creature* who, bool reset = true); + // Stops combat, ignoring restrictions, for the found creatures + void ForceCombatStopForCreatureEntry(uint32 entry, float maxSearchRange = 250.0f, bool samePhase = true, bool reset = true); void DoTeleportTo(float x, float y, float z, uint32 time = 0); void DoTeleportTo(float const pos[4]); @@ -337,8 +341,6 @@ class TC_GAME_API BossAI : public ScriptedAI void TeleportCheaters(); - void ForceCombatStopForCreatureEntry(uint32 entry, float maxSearchRange = 250.0f, bool reset = true); - EventMap events; SummonList summons; TaskScheduler scheduler; |