diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 762dc6e12..522b17e41 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -15,12 +15,13 @@ * with this program. If not, see . */ -#include "ScriptedCreature.h" #include "Cell.h" #include "CellImpl.h" +#include "Containers.h" #include "GameTime.h" #include "GridNotifiers.h" #include "ObjectMgr.h" +#include "ScriptedCreature.h" #include "Spell.h" #include "TemporarySummon.h" @@ -141,6 +142,23 @@ Creature* SummonList::GetCreatureWithEntry(uint32 entry) const return nullptr; } +Creature* SummonList::GetRandomCreatureWithEntry(uint32 entry) const +{ + std::vector candidates; + candidates.reserve(storage_.size()); + + for (auto const guid : storage_) + if (Creature* summon = ObjectAccessor::GetCreature(*me, guid)) + if (summon->GetEntry() == entry) + candidates.push_back(guid); + + if (candidates.empty()) + return nullptr; + + ObjectGuid randomGuid = Acore::Containers::SelectRandomContainerElement(candidates); + return ObjectAccessor::GetCreature(*me, randomGuid); +} + bool SummonList::IsAnyCreatureAlive() const { for (auto const& guid : storage_) diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index 4aceb3fae..47f8cf30c 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -157,6 +157,7 @@ public: uint32 GetEntryCount(uint32 entry) const; void Respawn(); Creature* GetCreatureWithEntry(uint32 entry) const; + Creature* GetRandomCreatureWithEntry(uint32 entry) const; private: Creature* me; diff --git a/src/server/scripts/Northrend/AzjolNerub/ahnkahet/boss_jedoga_shadowseeker.cpp b/src/server/scripts/Northrend/AzjolNerub/ahnkahet/boss_jedoga_shadowseeker.cpp index 6392a738e..d78077606 100644 --- a/src/server/scripts/Northrend/AzjolNerub/ahnkahet/boss_jedoga_shadowseeker.cpp +++ b/src/server/scripts/Northrend/AzjolNerub/ahnkahet/boss_jedoga_shadowseeker.cpp @@ -16,7 +16,6 @@ */ #include "AchievementCriteriaScript.h" -#include "Containers.h" #include "CreatureScript.h" #include "ObjectAccessor.h" #include "ScriptedCreature.h" @@ -209,7 +208,7 @@ struct boss_jedoga_shadowseeker : public BossAI } } - sacraficeTarget_GUID.Clear(); + sacrificeTargetGUID.Clear(); sayPreachTimer = 120000; ritualTriggered = false; volunteerWork = true; @@ -268,12 +267,12 @@ struct boss_jedoga_shadowseeker : public BossAI } case NPC_TWILIGHT_VOLUNTEER: { - if (sacraficeTarget_GUID && summon->GetGUID() != sacraficeTarget_GUID) + if (sacrificeTargetGUID && summon->GetGUID() != sacrificeTargetGUID) { break; } - if (killer != me && killer->GetGUID() != sacraficeTarget_GUID) + if (killer != me && killer->GetGUID() != sacrificeTargetGUID) { volunteerWork = false; } @@ -315,7 +314,7 @@ struct boss_jedoga_shadowseeker : public BossAI { if (action == ACTION_SACRAFICE) { - if (Creature* target = ObjectAccessor::GetCreature(*me, sacraficeTarget_GUID)) + if (Creature* target = ObjectAccessor::GetCreature(*me, sacrificeTargetGUID)) { Unit::Kill(me, target); } @@ -395,9 +394,9 @@ struct boss_jedoga_shadowseeker : public BossAI me->SetFacingTo(5.66f); if (!summons.empty()) { - sacraficeTarget_GUID = Acore::Containers::SelectRandomContainerElement(summons); - if (ObjectAccessor::GetCreature(*me, sacraficeTarget_GUID)) + if (Creature* creature = summons.GetRandomCreatureWithEntry(NPC_TWILIGHT_VOLUNTEER)) { + sacrificeTargetGUID = creature->GetGUID(); events.ScheduleEvent(EVENT_JEDGA_START_RITUAL, 3s, 0, PHASE_RITUAL); } // Something failed, let players continue but do not grant achievement @@ -518,15 +517,16 @@ struct boss_jedoga_shadowseeker : public BossAI } case EVENT_JEDGA_START_RITUAL: { - sacraficeTarget_GUID = Acore::Containers::SelectRandomContainerElement(summons); - if (Creature* volunteer = ObjectAccessor::GetCreature(*me, sacraficeTarget_GUID)) + if (Creature* creature = summons.GetRandomCreatureWithEntry(NPC_TWILIGHT_VOLUNTEER)) { + sacrificeTargetGUID = creature->GetGUID(); Talk(SAY_SACRIFICE_1); - sacraficeTarget_GUID = volunteer->GetGUID(); - volunteer->AI()->DoAction(ACTION_RITUAL_BEGIN); + creature->AI()->DoAction(ACTION_RITUAL_BEGIN); } break; } + default: + break; } } @@ -546,7 +546,7 @@ struct boss_jedoga_shadowseeker : public BossAI private: GuidList oocSummons; GuidList oocTriggers; - ObjectGuid sacraficeTarget_GUID; + ObjectGuid sacrificeTargetGUID; uint32 sayPreachTimer; bool combatSummonsSummoned; bool ritualTriggered;