Scripts/MagistersTerrace: Fix some crashes in Selin Fireheart. His script is still a shitshow, though. Closes #20614.

This commit is contained in:
Treeston
2017-10-26 11:54:41 +02:00
parent bf81a7b207
commit cbd025f146

View File

@@ -65,6 +65,7 @@ enum Misc
ACTION_SWITCH_PHASE = 1 ACTION_SWITCH_PHASE = 1
}; };
// @todo crystals should really be a DB creature summon group, having them in `creature` like this will cause tons of despawn/respawn bugs
class boss_selin_fireheart : public CreatureScript class boss_selin_fireheart : public CreatureScript
{ {
public: public:
@@ -72,23 +73,15 @@ class boss_selin_fireheart : public CreatureScript
struct boss_selin_fireheartAI : public BossAI struct boss_selin_fireheartAI : public BossAI
{ {
boss_selin_fireheartAI(Creature* creature) : BossAI(creature, DATA_SELIN) boss_selin_fireheartAI(Creature* creature) : BossAI(creature, DATA_SELIN), _scheduledEvents(false) { }
{
_scheduledEvents = false;
}
void Reset() override void Reset() override
{ {
Crystals.clear(); std::list<Creature*> crystals;
me->GetCreatureListWithEntryInGrid(Crystals, NPC_FEL_CRYSTAL, 250.0f); me->GetCreatureListWithEntryInGrid(crystals, NPC_FEL_CRYSTAL, 250.0f);
for (Creature* creature : Crystals) for (Creature* creature : crystals)
{ creature->Respawn(true);
if (!creature->IsAlive())
creature->Respawn();
creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
}
_Reset(); _Reset();
CrystalGUID.Clear(); CrystalGUID.Clear();
@@ -115,18 +108,16 @@ class boss_selin_fireheart : public CreatureScript
if (Crystals.empty()) if (Crystals.empty())
return; return;
Crystals.sort(Trinity::ObjectDistanceOrderPred(me)); if (Creature* crystal = me->FindNearestCreature(NPC_FEL_CRYSTAL, 250.0f))
if (Creature* CrystalChosen = Crystals.front())
{ {
Talk(SAY_ENERGY); Talk(SAY_ENERGY);
Talk(EMOTE_CRYSTAL); Talk(EMOTE_CRYSTAL);
DoCast(CrystalChosen, SPELL_FEL_CRYSTAL_DUMMY); DoCast(crystal, SPELL_FEL_CRYSTAL_DUMMY);
CrystalGUID = CrystalChosen->GetGUID(); CrystalGUID = crystal->GetGUID();
Crystals.remove(CrystalChosen);
float x, y, z; float x, y, z;
CrystalChosen->GetClosePoint(x, y, z, me->GetCombatReach(), CONTACT_DISTANCE); crystal->GetClosePoint(x, y, z, me->GetCombatReach(), CONTACT_DISTANCE);
events.SetPhase(PHASE_DRAIN); events.SetPhase(PHASE_DRAIN);
me->SetWalk(false); me->SetWalk(false);
@@ -136,14 +127,11 @@ class boss_selin_fireheart : public CreatureScript
void ShatterRemainingCrystals() void ShatterRemainingCrystals()
{ {
if (Crystals.empty()) std::list<Creature*> crystals;
return; me->GetCreatureListWithEntryInGrid(crystals, NPC_FEL_CRYSTAL, 250.0f);
for (Creature* crystal : Crystals) for (Creature* crystal : crystals)
{ crystal->KillSelf();
if (crystal && crystal->IsAlive())
crystal->KillSelf();
}
} }
void EnterCombat(Unit* /*who*/) override void EnterCombat(Unit* /*who*/) override
@@ -259,7 +247,7 @@ class boss_selin_fireheart : public CreatureScript
} }
private: private:
std::list<Creature*> Crystals; std::list<ObjectGuid> Crystals;
ObjectGuid CrystalGUID; ObjectGuid CrystalGUID;
bool _scheduledEvents; bool _scheduledEvents;
}; };