Scripts/Naxxramas: Fixed blizzards following same player in Sapphiron encounter (#21068)

Closes #18765
This commit is contained in:
Keader
2017-12-18 08:39:35 -03:00
committed by GitHub
parent b9b667f925
commit 143b2aeac0
2 changed files with 89 additions and 12 deletions

View File

@@ -0,0 +1 @@
UPDATE `creature_template` SET `difficulty_entry_1`=0, `ScriptName`='npc_sapphiron_blizzard' WHERE `entry`=16474;

View File

@@ -78,11 +78,6 @@ enum Events
EVENT_CHECK_RESISTS
};
enum Actions
{
ACTION_BIRTH = 1
};
enum Misc
{
NPC_BLIZZARD = 16474,
@@ -91,11 +86,35 @@ enum Misc
// The Hundred Club
DATA_THE_HUNDRED_CLUB = 21462147,
MAX_FROST_RESISTANCE = 100
MAX_FROST_RESISTANCE = 100,
ACTION_BIRTH = 1,
DATA_BLIZZARD_TARGET
};
typedef std::map<ObjectGuid, ObjectGuid> IceBlockMap;
class BlizzardTargetSelector
{
public:
BlizzardTargetSelector(std::vector<Unit*> const& blizzards) : _blizzards(blizzards) { }
bool operator()(Unit* unit) const
{
if (unit->GetTypeId() != TYPEID_PLAYER)
return false;
// Check if unit is target of some blizzard
for (Unit* blizzard : _blizzards)
if (blizzard->GetAI()->GetGUID(DATA_BLIZZARD_TARGET) == unit->GetGUID())
return false;
return true;
}
private:
std::vector<Unit*> const& _blizzards;
};
class boss_sapphiron : public CreatureScript
{
public:
@@ -229,6 +248,24 @@ class boss_sapphiron : public CreatureScript
return 0;
}
ObjectGuid GetGUID(int32 data) const override
{
if (data == DATA_BLIZZARD_TARGET)
{
// Filtering blizzards from summon list
std::vector<Unit*> blizzards;
for (ObjectGuid summonGuid : summons)
if (summonGuid.GetEntry() == NPC_BLIZZARD)
if (Unit* temp = ObjectAccessor::GetUnit(*me, summonGuid))
blizzards.push_back(temp);
if (Unit* newTarget = me->AI()->SelectTarget(SELECT_TARGET_RANDOM, 1, BlizzardTargetSelector(blizzards)))
return newTarget->GetGUID();
}
return ObjectGuid::Empty;
}
void UpdateAI(uint32 diff) override
{
events.Update(diff);
@@ -373,7 +410,7 @@ class boss_sapphiron : public CreatureScript
}
private:
std::vector<ObjectGuid> _iceboltTargets;
GuidVector _iceboltTargets;
ObjectGuid _buffet;
bool _delayedDrain;
bool _canTheHundredClub;
@@ -385,6 +422,41 @@ class boss_sapphiron : public CreatureScript
}
};
struct npc_sapphiron_blizzard : public ScriptedAI
{
npc_sapphiron_blizzard(Creature* creature) : ScriptedAI(creature) { }
void Reset() override
{
me->SetReactState(REACT_PASSIVE);
_scheduler.Schedule(Seconds(3), [this](TaskContext chill)
{
DoCastSelf(me->m_spells[0], true);
chill.Repeat();
});
}
ObjectGuid GetGUID(int32 data) const override
{
return data == DATA_BLIZZARD_TARGET ? _targetGuid : ObjectGuid::Empty;
}
void SetGUID(ObjectGuid guid, int32 data) override
{
if (data == DATA_BLIZZARD_TARGET)
_targetGuid = guid;
}
void UpdateAI(uint32 diff) override
{
_scheduler.Update(diff);
}
private:
TaskScheduler _scheduler;
ObjectGuid _targetGuid;
};
class go_sapphiron_birth : public GameObjectScript
{
public:
@@ -436,11 +508,12 @@ class spell_sapphiron_change_blizzard_target : public SpellScriptLoader
TempSummon* me = GetTarget()->ToTempSummon();
if (Creature* owner = me ? me->GetSummonerCreatureBase() : nullptr)
{
Unit* newTarget = owner->AI()->SelectTarget(SELECT_TARGET_RANDOM, 1, 0.0f, true);
if (!newTarget)
newTarget = owner->getAttackerForHelper();
if (newTarget)
me->GetAI()->SetGUID(ObjectGuid::Empty, DATA_BLIZZARD_TARGET);
if (Unit* newTarget = ObjectAccessor::GetUnit(*owner, owner->AI()->GetGUID(DATA_BLIZZARD_TARGET)))
{
me->GetAI()->SetGUID(newTarget->GetGUID(), DATA_BLIZZARD_TARGET);
me->GetMotionMaster()->MoveFollow(newTarget, 0.1f, 0.0f);
}
else
{
me->StopMoving();
@@ -533,8 +606,10 @@ class spell_sapphiron_summon_blizzard : public SpellScriptLoader
blizzard->CastSpell(nullptr, blizzard->m_spells[0], TRIGGERED_NONE);
if (Creature* creatureCaster = GetCaster()->ToCreature())
{
if (Unit* newTarget = creatureCaster->AI()->SelectTarget(SELECT_TARGET_RANDOM, 1, 0.0f, true))
blizzard->AI()->SetGUID(ObjectGuid::Empty, DATA_BLIZZARD_TARGET);
if (Unit* newTarget = ObjectAccessor::GetUnit(*creatureCaster, creatureCaster->AI()->GetGUID(DATA_BLIZZARD_TARGET)))
{
blizzard->AI()->SetGUID(newTarget->GetGUID(), DATA_BLIZZARD_TARGET);
blizzard->GetMotionMaster()->MoveFollow(newTarget, 0.1f, 0.0f);
return;
}
@@ -569,6 +644,7 @@ class achievement_the_hundred_club : public AchievementCriteriaScript
void AddSC_boss_sapphiron()
{
new boss_sapphiron();
RegisterNaxxramasCreatureAI(npc_sapphiron_blizzard);
new go_sapphiron_birth();
new spell_sapphiron_change_blizzard_target();
new spell_sapphiron_icebolt();