Implement generic script loaders to greatly reduce code duplication

This commit is contained in:
hondacrx
2017-07-20 19:43:24 -04:00
parent 19220d29d9
commit 2db988576a
89 changed files with 28255 additions and 36473 deletions
@@ -53,273 +53,253 @@ namespace Scripts.EasternKingdoms.Karazhan.Midnight
}
[Script]
class boss_attumen : CreatureScript
public class boss_attumen : ScriptedAI
{
public boss_attumen() : base("boss_attumen") { }
public class boss_attumenAI : ScriptedAI
public boss_attumen(Creature creature) : base(creature)
{
public boss_attumenAI(Creature creature) : base(creature)
CleaveTimer = RandomHelper.URand(10000, 15000);
CurseTimer = 30000;
RandomYellTimer = RandomHelper.URand(30000, 60000); //Occasionally yell
ChargeTimer = 20000;
ResetTimer = 0;
}
public override void Reset()
{
ResetTimer = 0;
Midnight.Clear();
}
public override void EnterEvadeMode(EvadeReason why)
{
base.EnterEvadeMode(why);
ResetTimer = 2000;
}
public override void EnterCombat(Unit who) { }
public override void KilledUnit(Unit victim)
{
Talk(TextIds.SayKill);
}
public override void JustDied(Unit killer)
{
Talk(TextIds.SayDeath);
Unit midnight = Global.ObjAccessor.GetUnit(me, Midnight);
if (midnight)
midnight.KillSelf();
}
public override void UpdateAI(uint diff)
{
if (ResetTimer != 0)
{
if (ResetTimer <= diff)
{
ResetTimer = 0;
Unit pMidnight = Global.ObjAccessor.GetUnit(me, Midnight);
if (pMidnight)
{
pMidnight.RemoveFlag(UnitFields.Flags, UnitFlags.NonAttackable);
pMidnight.SetVisible(true);
}
Midnight.Clear();
me.SetVisible(false);
me.KillSelf();
}
else ResetTimer -= diff;
}
//Return since we have no target
if (!UpdateVictim())
return;
if (me.HasFlag(UnitFields.Flags, UnitFlags.NonAttackable | UnitFlags.NotSelectable))
return;
if (CleaveTimer <= diff)
{
DoCastVictim(SpellIds.Shadowcleave);
CleaveTimer = RandomHelper.URand(10000, 15000);
}
else CleaveTimer -= diff;
if (CurseTimer <= diff)
{
DoCastVictim(SpellIds.IntangiblePresence);
CurseTimer = 30000;
RandomYellTimer = RandomHelper.URand(30000, 60000); //Occasionally yell
ChargeTimer = 20000;
ResetTimer = 0;
}
else CurseTimer -= diff;
public override void Reset()
if (RandomYellTimer <= diff)
{
ResetTimer = 0;
Midnight.Clear();
Talk(TextIds.SayRandom);
RandomYellTimer = RandomHelper.URand(30000, 60000);
}
else RandomYellTimer -= diff;
public override void EnterEvadeMode(EvadeReason why)
if (me.GetUInt32Value(UnitFields.DisplayId) == Misc.MountedDisplayid)
{
base.EnterEvadeMode(why);
ResetTimer = 2000;
}
public override void EnterCombat(Unit who) { }
public override void KilledUnit(Unit victim)
{
Talk(TextIds.SayKill);
}
public override void JustDied(Unit killer)
{
Talk(TextIds.SayDeath);
Unit midnight = Global.ObjAccessor.GetUnit(me, Midnight);
if (midnight)
midnight.KillSelf();
}
public override void UpdateAI(uint diff)
{
if (ResetTimer != 0)
if (ChargeTimer <= diff)
{
if (ResetTimer <= diff)
var t_list = me.GetThreatManager().getThreatList();
List<Unit> target_list = new List<Unit>();
foreach (var hostileRefe in t_list)
{
ResetTimer = 0;
Unit pMidnight = Global.ObjAccessor.GetUnit(me, Midnight);
if (pMidnight)
{
pMidnight.RemoveFlag(UnitFields.Flags, UnitFlags.NonAttackable);
pMidnight.SetVisible(true);
}
Midnight.Clear();
me.SetVisible(false);
me.KillSelf();
var unit = Global.ObjAccessor.GetUnit(me, hostileRefe.getUnitGuid());
if (unit && !unit.IsWithinDist(me, SharedConst.AttackDistance, false))
target_list.Add(unit);
unit = null;
}
else ResetTimer -= diff;
Unit target = null;
if (!target_list.Empty())
target = target_list.SelectRandom();
DoCast(target, SpellIds.BerserkerCharge);
ChargeTimer = 20000;
}
//Return since we have no target
if (!UpdateVictim())
return;
if (me.HasFlag(UnitFields.Flags, UnitFlags.NonAttackable | UnitFlags.NotSelectable))
return;
if (CleaveTimer <= diff)
else ChargeTimer -= diff;
}
else
{
if (HealthBelowPct(25))
{
DoCastVictim(SpellIds.Shadowcleave);
CleaveTimer = RandomHelper.URand(10000, 15000);
}
else CleaveTimer -= diff;
if (CurseTimer <= diff)
{
DoCastVictim(SpellIds.IntangiblePresence);
CurseTimer = 30000;
}
else CurseTimer -= diff;
if (RandomYellTimer <= diff)
{
Talk(TextIds.SayRandom);
RandomYellTimer = RandomHelper.URand(30000, 60000);
}
else RandomYellTimer -= diff;
if (me.GetUInt32Value(UnitFields.DisplayId) == Misc.MountedDisplayid)
{
if (ChargeTimer <= diff)
Creature pMidnight = ObjectAccessor.GetCreature(me, Midnight);
if (pMidnight && pMidnight.IsTypeId(TypeId.Unit))
{
var t_list = me.GetThreatManager().getThreatList();
List<Unit> target_list = new List<Unit>();
foreach (var hostileRefe in t_list)
{
var unit = Global.ObjAccessor.GetUnit(me, hostileRefe.getUnitGuid());
if (unit && !unit.IsWithinDist(me, SharedConst.AttackDistance, false))
target_list.Add(unit);
unit = null;
}
Unit target = null;
if (!target_list.Empty())
target = target_list.SelectRandom();
DoCast(target, SpellIds.BerserkerCharge);
ChargeTimer = 20000;
}
else ChargeTimer -= diff;
}
else
{
if (HealthBelowPct(25))
{
Creature pMidnight = ObjectAccessor.GetCreature(me, Midnight);
if (pMidnight && pMidnight.IsTypeId(TypeId.Unit))
{
((boss_midnight.boss_midnightAI)pMidnight.GetAI()).Mount(me);
me.SetHealth(pMidnight.GetHealth());
DoResetThreat();
}
((boss_midnight)pMidnight.GetAI()).Mount(me);
me.SetHealth(pMidnight.GetHealth());
DoResetThreat();
}
}
DoMeleeAttackIfReady();
}
public override void SpellHit(Unit source, SpellInfo spell)
{
if (spell.Mechanic == Mechanics.Disarm)
Talk(TextIds.SayDisarmed);
}
public ObjectGuid Midnight;
uint CleaveTimer;
uint CurseTimer;
uint RandomYellTimer;
uint ChargeTimer; //only when mounted
uint ResetTimer;
DoMeleeAttackIfReady();
}
public override CreatureAI GetAI(Creature creature)
public override void SpellHit(Unit source, SpellInfo spell)
{
return new boss_attumenAI(creature);
if (spell.Mechanic == Mechanics.Disarm)
Talk(TextIds.SayDisarmed);
}
public ObjectGuid Midnight;
uint CleaveTimer;
uint CurseTimer;
uint RandomYellTimer;
uint ChargeTimer; //only when mounted
uint ResetTimer;
}
[Script]
class boss_midnight : CreatureScript
public class boss_midnight : ScriptedAI
{
public boss_midnight() : base("boss_midnight") { }
public boss_midnight(Creature creature) : base(creature) { }
public class boss_midnightAI : ScriptedAI
public override void Reset()
{
public boss_midnightAI(Creature creature) : base(creature) { }
Phase = 1;
Attumen.Clear();
mountTimer = 0;
public override void Reset()
me.RemoveFlag(UnitFields.Flags, UnitFlags.NonAttackable);
me.SetVisible(true);
}
public override void EnterCombat(Unit who) { }
public override void KilledUnit(Unit victim)
{
if (Phase == 2)
{
Phase = 1;
Attumen.Clear();
mountTimer = 0;
me.RemoveFlag(UnitFields.Flags, UnitFlags.NonAttackable);
me.SetVisible(true);
Unit unit = Global.ObjAccessor.GetUnit(me, Attumen);
if (unit)
Talk(TextIds.SayMidnightKill, unit);
}
}
public override void EnterCombat(Unit who) { }
public override void UpdateAI(uint diff)
{
if (!UpdateVictim())
return;
public override void KilledUnit(Unit victim)
if (Phase == 1 && HealthBelowPct(95))
{
if (Phase == 2)
Phase = 2;
Creature attumen = me.SummonCreature(Misc.SummonAttumen, 0.0f, 0.0f, 0.0f, 0.0f, TempSummonType.TimedOrDeadDespawn, 30000);
if (attumen)
{
Unit unit = Global.ObjAccessor.GetUnit(me, Attumen);
if (unit)
Talk(TextIds.SayMidnightKill, unit);
Attumen = attumen.GetGUID();
attumen.GetAI().AttackStart(me.GetVictim());
SetMidnight(attumen, me.GetGUID());
Talk(TextIds.SayAppear, attumen);
}
}
public override void UpdateAI(uint diff)
else if (Phase == 2 && HealthBelowPct(25))
{
if (!UpdateVictim())
return;
if (Phase == 1 && HealthBelowPct(95))
Unit pAttumen = Global.ObjAccessor.GetUnit(me, Attumen);
if (pAttumen)
Mount(pAttumen);
}
else if (Phase == 3)
{
if (mountTimer != 0)
{
Phase = 2;
Creature attumen = me.SummonCreature(Misc.SummonAttumen, 0.0f, 0.0f, 0.0f, 0.0f, TempSummonType.TimedOrDeadDespawn, 30000);
if (attumen)
if (mountTimer <= diff)
{
Attumen = attumen.GetGUID();
attumen.GetAI().AttackStart(me.GetVictim());
SetMidnight(attumen, me.GetGUID());
Talk(TextIds.SayAppear, attumen);
}
}
else if (Phase == 2 && HealthBelowPct(25))
{
Unit pAttumen = Global.ObjAccessor.GetUnit(me, Attumen);
if (pAttumen)
Mount(pAttumen);
}
else if (Phase == 3)
{
if (mountTimer != 0)
{
if (mountTimer <= diff)
mountTimer = 0;
me.SetVisible(false);
me.GetMotionMaster().MoveIdle();
Unit pAttumen = Global.ObjAccessor.GetUnit(me, Attumen);
if (pAttumen)
{
mountTimer = 0;
me.SetVisible(false);
me.GetMotionMaster().MoveIdle();
Unit pAttumen = Global.ObjAccessor.GetUnit(me, Attumen);
if (pAttumen)
pAttumen.SetDisplayId(Misc.MountedDisplayid);
pAttumen.RemoveFlag(UnitFields.Flags, UnitFlags.NonAttackable);
if (pAttumen.GetVictim())
{
pAttumen.SetDisplayId(Misc.MountedDisplayid);
pAttumen.RemoveFlag(UnitFields.Flags, UnitFlags.NonAttackable);
if (pAttumen.GetVictim())
{
pAttumen.GetMotionMaster().MoveChase(pAttumen.GetVictim());
pAttumen.SetTarget(pAttumen.GetVictim().GetGUID());
}
pAttumen.SetObjectScale(1);
pAttumen.GetMotionMaster().MoveChase(pAttumen.GetVictim());
pAttumen.SetTarget(pAttumen.GetVictim().GetGUID());
}
pAttumen.SetObjectScale(1);
}
else mountTimer -= diff;
}
else mountTimer -= diff;
}
if (Phase != 3)
DoMeleeAttackIfReady();
}
public void Mount(Unit pAttumen)
{
Talk(TextIds.SayMount, pAttumen);
Phase = 3;
me.SetFlag(UnitFields.Flags, UnitFlags.NonAttackable);
pAttumen.SetFlag(UnitFields.Flags, UnitFlags.NonAttackable);
float angle = me.GetAngle(pAttumen);
float distance = me.GetDistance2d(pAttumen);
float newX = me.GetPositionX() + (float)Math.Cos(angle) * (distance / 2);
float newY = me.GetPositionY() + (float)Math.Sin(angle) * (distance / 2);
float newZ = 50;
me.GetMotionMaster().Clear();
me.GetMotionMaster().MovePoint(0, newX, newY, newZ);
distance += 10;
newX = me.GetPositionX() + (float)Math.Cos(angle) * (distance / 2);
newY = me.GetPositionY() + (float)Math.Sin(angle) * (distance / 2);
pAttumen.GetMotionMaster().Clear();
pAttumen.GetMotionMaster().MovePoint(0, newX, newY, newZ);
mountTimer = 1000;
}
void SetMidnight(Creature pAttumen, ObjectGuid value)
{
((boss_attumen.boss_attumenAI)pAttumen.GetAI()).Midnight = value;
}
ObjectGuid Attumen;
byte Phase;
uint mountTimer;
if (Phase != 3)
DoMeleeAttackIfReady();
}
public override CreatureAI GetAI(Creature creature)
public void Mount(Unit pAttumen)
{
return new boss_midnightAI(creature);
Talk(TextIds.SayMount, pAttumen);
Phase = 3;
me.SetFlag(UnitFields.Flags, UnitFlags.NonAttackable);
pAttumen.SetFlag(UnitFields.Flags, UnitFlags.NonAttackable);
float angle = me.GetAngle(pAttumen);
float distance = me.GetDistance2d(pAttumen);
float newX = me.GetPositionX() + (float)Math.Cos(angle) * (distance / 2);
float newY = me.GetPositionY() + (float)Math.Sin(angle) * (distance / 2);
float newZ = 50;
me.GetMotionMaster().Clear();
me.GetMotionMaster().MovePoint(0, newX, newY, newZ);
distance += 10;
newX = me.GetPositionX() + (float)Math.Cos(angle) * (distance / 2);
newY = me.GetPositionY() + (float)Math.Sin(angle) * (distance / 2);
pAttumen.GetMotionMaster().Clear();
pAttumen.GetMotionMaster().MovePoint(0, newX, newY, newZ);
mountTimer = 1000;
}
void SetMidnight(Creature pAttumen, ObjectGuid value)
{
((boss_attumen)pAttumen.GetAI()).Midnight = value;
}
ObjectGuid Attumen;
byte Phase;
uint mountTimer;
}
}