refactor(Scripts/Duskwood): Twilight Corrupter (#12797)

This commit is contained in:
Angelo Venturini
2022-08-21 11:00:41 -03:00
committed by GitHub
parent 24f538a636
commit dc4bef94b5
@@ -15,48 +15,43 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* ScriptData
SDName: Duskwood
SD%Complete: 100
SDComment: Quest Support:8735
SDCategory: Duskwood
EndScriptData */
#include "Player.h" #include "Player.h"
#include "ScriptMgr.h" #include "ScriptMgr.h"
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
#include "TaskScheduler.h"
enum TwilightCorrupter enum Spells
{ {
ITEM_FRAGMENT = 21149,
NPC_TWILIGHT_CORRUPTER = 15625,
YELL_TWILIGHTCORRUPTOR_RESPAWN = 0,
YELL_TWILIGHTCORRUPTOR_AGGRO = 1,
YELL_TWILIGHTCORRUPTOR_KILL = 2,
SPELL_SOUL_CORRUPTION = 25805, SPELL_SOUL_CORRUPTION = 25805,
SPELL_CREATURE_OF_NIGHTMARE = 25806, SPELL_CREATURE_OF_NIGHTMARE = 25806,
SPELL_LEVEL_UP = 24312, SPELL_SWELL_OF_SOULS = 21307,
};
EVENT_SOUL_CORRUPTION = 1, enum Misc
EVENT_CREATURE_OF_NIGHTMARE = 2 {
ITEM_FRAGMENT = 21149,
NPC_TWILIGHT_CORRUPTER = 15625
};
enum Say
{
SAY_RESPAWN = 0,
SAY_AGGRO,
SAY_KILL
}; };
/*###### /*######
# boss_twilight_corrupter # boss_twilight_corrupter
######*/ ######*/
class boss_twilight_corrupter : public CreatureScript struct boss_twilight_corrupter : public ScriptedAI
{ {
public: boss_twilight_corrupter(Creature* creature) : ScriptedAI(creature) { }
boss_twilight_corrupter() : CreatureScript("boss_twilight_corrupter") { }
struct boss_twilight_corrupterAI : public ScriptedAI
{
boss_twilight_corrupterAI(Creature* creature) : ScriptedAI(creature) { }
void Reset() override void Reset() override
{ {
KillCount = 0; _scheduler.CancelAll();
me->RemoveAurasDueToSpell(SPELL_SWELL_OF_SOULS);
} }
void InitializeAI() override void InitializeAI() override
@@ -64,13 +59,14 @@ public:
// Xinef: check if copy is summoned // Xinef: check if copy is summoned
std::list<Creature*> cList; std::list<Creature*> cList;
me->GetCreatureListWithEntryInGrid(cList, me->GetEntry(), 50.0f); me->GetCreatureListWithEntryInGrid(cList, me->GetEntry(), 50.0f);
if (!cList.empty()) for (Creature* creature : cList)
for (std::list<Creature*>::const_iterator itr = cList.begin(); itr != cList.end(); ++itr) {
if ((*itr)->IsAlive() && me->GetGUID() != (*itr)->GetGUID()) if (creature->IsAlive() && me->GetGUID() != creature->GetGUID())
{ {
me->DespawnOrUnsummon(1); me->DespawnOrUnsummon(1);
break; break;
} }
}
_introSpoken = false; _introSpoken = false;
ScriptedAI::InitializeAI(); ScriptedAI::InitializeAI();
@@ -81,7 +77,7 @@ public:
if (!_introSpoken && who->GetTypeId() == TYPEID_PLAYER) if (!_introSpoken && who->GetTypeId() == TYPEID_PLAYER)
{ {
_introSpoken = true; _introSpoken = true;
Talk(YELL_TWILIGHTCORRUPTOR_RESPAWN, who); Talk(SAY_RESPAWN, who);
me->SetFaction(FACTION_MONSTER); me->SetFaction(FACTION_MONSTER);
} }
ScriptedAI::MoveInLineOfSight(who); ScriptedAI::MoveInLineOfSight(who);
@@ -89,24 +85,26 @@ public:
void EnterCombat(Unit* /*who*/) override void EnterCombat(Unit* /*who*/) override
{ {
Talk(YELL_TWILIGHTCORRUPTOR_AGGRO); Talk(SAY_AGGRO);
_events.Reset(); _scheduler
_events.ScheduleEvent(EVENT_SOUL_CORRUPTION, 15000); .Schedule(12s, 18s, [this](TaskContext context)
_events.ScheduleEvent(EVENT_CREATURE_OF_NIGHTMARE, 30000); {
DoCastRandomTarget(SPELL_CREATURE_OF_NIGHTMARE, 1, 100.f);
context.Repeat(35s, 45s);
})
.Schedule(9s, 16s, [this](TaskContext context)
{
DoCastVictim(SPELL_SOUL_CORRUPTION);
context.Repeat(5s, 9s);
});
} }
void KilledUnit(Unit* victim) override void KilledUnit(Unit* victim) override
{ {
if (victim->GetTypeId() == TYPEID_PLAYER) if (victim->GetTypeId() == TYPEID_PLAYER)
{ {
++KillCount; Talk(SAY_KILL, victim);
Talk(YELL_TWILIGHTCORRUPTOR_KILL, victim); DoCastSelf(SPELL_SWELL_OF_SOULS);
if (KillCount == 3)
{
DoCast(me, SPELL_LEVEL_UP, true);
KillCount = 0;
}
} }
} }
@@ -115,38 +113,15 @@ public:
if (!UpdateVictim()) if (!UpdateVictim())
return; return;
_events.Update(diff); _scheduler.Update(diff, [this]
while (uint32 eventId = _events.ExecuteEvent())
{ {
switch (eventId)
{
case EVENT_SOUL_CORRUPTION:
DoCastVictim(SPELL_SOUL_CORRUPTION);
_events.ScheduleEvent(EVENT_SOUL_CORRUPTION, rand() % 4000 + 15000);
break;
case EVENT_CREATURE_OF_NIGHTMARE:
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 1, 100, true))
DoCast(target, SPELL_CREATURE_OF_NIGHTMARE);
_events.ScheduleEvent(EVENT_CREATURE_OF_NIGHTMARE, 45000);
break;
default:
break;
}
}
DoMeleeAttackIfReady(); DoMeleeAttackIfReady();
});
} }
private: private:
EventMap _events;
uint8 KillCount;
bool _introSpoken; bool _introSpoken;
}; TaskScheduler _scheduler;
CreatureAI* GetAI(Creature* creature) const override
{
return new boss_twilight_corrupterAI(creature);
}
}; };
/*###### /*######
@@ -169,6 +144,6 @@ public:
void AddSC_duskwood() void AddSC_duskwood()
{ {
new boss_twilight_corrupter(); RegisterCreatureAI(boss_twilight_corrupter);
new at_twilight_grove(); new at_twilight_grove();
} }