Implement generic script loaders to greatly reduce code duplication
This commit is contained in:
@@ -36,122 +36,102 @@ namespace Scripts.EasternKingdoms.TheStockade
|
||||
}
|
||||
|
||||
[Script]
|
||||
class boss_hogger : CreatureScript
|
||||
class boss_hogger : BossAI
|
||||
{
|
||||
public boss_hogger() : base("boss_hogger") { }
|
||||
public boss_hogger(Creature creature) : base(creature, DataTypes.Hogger) { }
|
||||
|
||||
class boss_hoggerAI : BossAI
|
||||
public override void EnterCombat(Unit who)
|
||||
{
|
||||
public boss_hoggerAI(Creature creature) : base(creature, DataTypes.Hogger) { }
|
||||
_EnterCombat();
|
||||
Talk(TextIds.SayPull);
|
||||
|
||||
public override void EnterCombat(Unit who)
|
||||
_scheduler.SetValidator(() => !me.HasUnitState(UnitState.Casting));
|
||||
|
||||
_scheduler.Schedule(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(4), task =>
|
||||
{
|
||||
_EnterCombat();
|
||||
Talk(TextIds.SayPull);
|
||||
DoCastVictim(SpellIds.ViciousSlice);
|
||||
task.Repeat(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(14));
|
||||
});
|
||||
|
||||
_scheduler.SetValidator(() => !me.HasUnitState(UnitState.Casting));
|
||||
|
||||
_scheduler.Schedule(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(4), task =>
|
||||
{
|
||||
DoCastVictim(SpellIds.ViciousSlice);
|
||||
task.Repeat(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(14));
|
||||
});
|
||||
|
||||
_scheduler.Schedule(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), task =>
|
||||
{
|
||||
DoCast(SpellIds.MaddeningCall);
|
||||
task.Repeat(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(20));
|
||||
});
|
||||
}
|
||||
|
||||
public override void JustDied(Unit killer)
|
||||
_scheduler.Schedule(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), task =>
|
||||
{
|
||||
Talk(TextIds.SayDeath);
|
||||
_JustDied();
|
||||
me.SummonCreature(CreatureIds.WardenThelwater, Misc.WardenThelwaterPos);
|
||||
}
|
||||
|
||||
public override void JustSummoned(Creature summon)
|
||||
{
|
||||
base.JustSummoned(summon);
|
||||
if (summon.GetEntry() == CreatureIds.WardenThelwater)
|
||||
summon.GetMotionMaster().MovePoint(0, Misc.WardenThelwaterMovePos);
|
||||
}
|
||||
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
if (!UpdateVictim())
|
||||
return;
|
||||
|
||||
_scheduler.Update(diff);
|
||||
|
||||
if (me.HasUnitState(UnitState.Casting))
|
||||
return;
|
||||
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
|
||||
public override void DamageTaken(Unit attacker, ref uint damage)
|
||||
{
|
||||
if (me.HealthBelowPctDamaged(30, damage) && !_hasEnraged)
|
||||
{
|
||||
_hasEnraged = true;
|
||||
Talk(TextIds.SayEnrage);
|
||||
DoCastSelf(SpellIds.Enrage);
|
||||
}
|
||||
}
|
||||
|
||||
bool _hasEnraged;
|
||||
DoCast(SpellIds.MaddeningCall);
|
||||
task.Repeat(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(20));
|
||||
});
|
||||
}
|
||||
|
||||
public override CreatureAI GetAI(Creature creature)
|
||||
public override void JustDied(Unit killer)
|
||||
{
|
||||
return GetInstanceAI<boss_hoggerAI>(creature, nameof(instance_the_stockade));
|
||||
Talk(TextIds.SayDeath);
|
||||
_JustDied();
|
||||
me.SummonCreature(CreatureIds.WardenThelwater, Misc.WardenThelwaterPos);
|
||||
}
|
||||
|
||||
public override void JustSummoned(Creature summon)
|
||||
{
|
||||
base.JustSummoned(summon);
|
||||
if (summon.GetEntry() == CreatureIds.WardenThelwater)
|
||||
summon.GetMotionMaster().MovePoint(0, Misc.WardenThelwaterMovePos);
|
||||
}
|
||||
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
if (!UpdateVictim())
|
||||
return;
|
||||
|
||||
_scheduler.Update(diff);
|
||||
|
||||
if (me.HasUnitState(UnitState.Casting))
|
||||
return;
|
||||
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
|
||||
public override void DamageTaken(Unit attacker, ref uint damage)
|
||||
{
|
||||
if (me.HealthBelowPctDamaged(30, damage) && !_hasEnraged)
|
||||
{
|
||||
_hasEnraged = true;
|
||||
Talk(TextIds.SayEnrage);
|
||||
DoCastSelf(SpellIds.Enrage);
|
||||
}
|
||||
}
|
||||
|
||||
bool _hasEnraged;
|
||||
}
|
||||
|
||||
[Script]
|
||||
class npc_warden_thelwater : CreatureScript
|
||||
class npc_warden_thelwater : ScriptedAI
|
||||
{
|
||||
public npc_warden_thelwater() : base("npc_warden_thelwater") { }
|
||||
public npc_warden_thelwater(Creature creature) : base(creature) { }
|
||||
|
||||
class npc_warden_thelwaterAI : ScriptedAI
|
||||
public override void MovementInform(MovementGeneratorType type, uint id)
|
||||
{
|
||||
public npc_warden_thelwaterAI(Creature creature) : base(creature) { }
|
||||
|
||||
public override void MovementInform(MovementGeneratorType type, uint id)
|
||||
{
|
||||
if (type == MovementGeneratorType.Point && id == 0)
|
||||
_events.ScheduleEvent(Events.SayWarden1, TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
_events.Update(diff);
|
||||
|
||||
_events.ExecuteEvents(eventId =>
|
||||
{
|
||||
switch (eventId)
|
||||
{
|
||||
case Events.SayWarden1:
|
||||
Talk(TextIds.SayWarden1);
|
||||
_events.ScheduleEvent(Events.SayWarden2, TimeSpan.FromSeconds(4));
|
||||
break;
|
||||
case Events.SayWarden2:
|
||||
Talk(TextIds.SayWarden2);
|
||||
_events.ScheduleEvent(Events.SayWarden3, TimeSpan.FromSeconds(3));
|
||||
break;
|
||||
case Events.SayWarden3:
|
||||
Talk(TextIds.SayWarden3);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (type == MovementGeneratorType.Point && id == 0)
|
||||
_events.ScheduleEvent(Events.SayWarden1, TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
public override CreatureAI GetAI(Creature creature)
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
return GetInstanceAI<npc_warden_thelwaterAI>(creature, nameof(instance_the_stockade));
|
||||
_events.Update(diff);
|
||||
|
||||
_events.ExecuteEvents(eventId =>
|
||||
{
|
||||
switch (eventId)
|
||||
{
|
||||
case Events.SayWarden1:
|
||||
Talk(TextIds.SayWarden1);
|
||||
_events.ScheduleEvent(Events.SayWarden2, TimeSpan.FromSeconds(4));
|
||||
break;
|
||||
case Events.SayWarden2:
|
||||
Talk(TextIds.SayWarden2);
|
||||
_events.ScheduleEvent(Events.SayWarden3, TimeSpan.FromSeconds(3));
|
||||
break;
|
||||
case Events.SayWarden3:
|
||||
Talk(TextIds.SayWarden3);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user