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
+67 -87
View File
@@ -27,111 +27,91 @@ using System.Collections.Generic;
namespace Scripts.Pets
{
[Script]
class npc_pet_dk_ebon_gargoyle : CreatureScript
class npc_pet_dk_ebon_gargoyle : CasterAI
{
public npc_pet_dk_ebon_gargoyle() : base("npc_pet_dk_ebon_gargoyle") { }
public npc_pet_dk_ebon_gargoyle(Creature creature) : base(creature) { }
class npc_pet_dk_ebon_gargoyleAI : CasterAI
public override void InitializeAI()
{
public npc_pet_dk_ebon_gargoyleAI(Creature creature) : base(creature) { }
base.InitializeAI();
ObjectGuid ownerGuid = me.GetOwnerGUID();
if (ownerGuid.IsEmpty())
return;
public override void InitializeAI()
// Find victim of Summon Gargoyle spell
List<Unit> targets = new List<Unit>();
var u_check = new AnyUnfriendlyUnitInObjectRangeCheck(me, me, 30.0f);
var searcher = new UnitListSearcher(me, targets, u_check);
Cell.VisitAllObjects(me, searcher, 30.0f);
foreach (var iter in targets)
{
base.InitializeAI();
ObjectGuid ownerGuid = me.GetOwnerGUID();
if (ownerGuid.IsEmpty())
return;
// Find victim of Summon Gargoyle spell
List<Unit> targets = new List<Unit>();
var u_check = new AnyUnfriendlyUnitInObjectRangeCheck(me, me, 30.0f);
var searcher = new UnitListSearcher(me, targets, u_check);
Cell.VisitAllObjects(me, searcher, 30.0f);
foreach (var iter in targets)
if (iter.GetAura(SpellSummonGargoyle1, ownerGuid) != null)
{
if (iter.GetAura(SpellSummonGargoyle1, ownerGuid) != null)
{
me.Attack(iter, false);
break;
}
me.Attack(iter, false);
break;
}
}
public override void JustDied(Unit killer)
{
// Stop Feeding Gargoyle when it dies
Unit owner = me.GetOwner();
if (owner)
owner.RemoveAurasDueToSpell(SpellSummonGargoyle2);
}
// Fly away when dismissed
public override void SpellHit(Unit source, SpellInfo spell)
{
if (spell.Id != SpellDismissGargoyle || !me.IsAlive())
return;
Unit owner = me.GetOwner();
if (!owner || owner != source)
return;
// Stop Fighting
me.ApplyModFlag(UnitFields.Flags, UnitFlags.NonAttackable, true);
// Sanctuary
me.CastSpell(me, SpellSanctuary, true);
me.SetReactState(ReactStates.Passive);
//! HACK: Creature's can't have MOVEMENTFLAG_FLYING
// Fly Away
me.SetCanFly(true);
me.SetSpeedRate(UnitMoveType.Flight, 0.75f);
me.SetSpeedRate(UnitMoveType.Run, 0.75f);
float x = me.GetPositionX() + 20 * (float)Math.Cos(me.GetOrientation());
float y = me.GetPositionY() + 20 * (float)Math.Sin(me.GetOrientation());
float z = me.GetPositionZ() + 40;
me.GetMotionMaster().Clear(false);
me.GetMotionMaster().MovePoint(0, x, y, z);
// Despawn as soon as possible
me.DespawnOrUnsummon(4 * Time.InMilliseconds);
}
const uint SpellSummonGargoyle1 = 49206;
const uint SpellSummonGargoyle2 = 50514;
const uint SpellDismissGargoyle = 50515;
const uint SpellSanctuary = 54661;
}
public override CreatureAI GetAI(Creature creature)
public override void JustDied(Unit killer)
{
return new npc_pet_dk_ebon_gargoyleAI(creature);
// Stop Feeding Gargoyle when it dies
Unit owner = me.GetOwner();
if (owner)
owner.RemoveAurasDueToSpell(SpellSummonGargoyle2);
}
// Fly away when dismissed
public override void SpellHit(Unit source, SpellInfo spell)
{
if (spell.Id != SpellDismissGargoyle || !me.IsAlive())
return;
Unit owner = me.GetOwner();
if (!owner || owner != source)
return;
// Stop Fighting
me.ApplyModFlag(UnitFields.Flags, UnitFlags.NonAttackable, true);
// Sanctuary
me.CastSpell(me, SpellSanctuary, true);
me.SetReactState(ReactStates.Passive);
//! HACK: Creature's can't have MOVEMENTFLAG_FLYING
// Fly Away
me.SetCanFly(true);
me.SetSpeedRate(UnitMoveType.Flight, 0.75f);
me.SetSpeedRate(UnitMoveType.Run, 0.75f);
float x = me.GetPositionX() + 20 * (float)Math.Cos(me.GetOrientation());
float y = me.GetPositionY() + 20 * (float)Math.Sin(me.GetOrientation());
float z = me.GetPositionZ() + 40;
me.GetMotionMaster().Clear(false);
me.GetMotionMaster().MovePoint(0, x, y, z);
// Despawn as soon as possible
me.DespawnOrUnsummon(4 * Time.InMilliseconds);
}
const uint SpellSummonGargoyle1 = 49206;
const uint SpellSummonGargoyle2 = 50514;
const uint SpellDismissGargoyle = 50515;
const uint SpellSanctuary = 54661;
}
[Script]
class npc_pet_dk_guardian : CreatureScript
class npc_pet_dk_guardian : AggressorAI
{
public npc_pet_dk_guardian() : base("npc_pet_dk_guardian") { }
public npc_pet_dk_guardian(Creature creature) : base(creature) { }
class npc_pet_dk_guardianAI : AggressorAI
public override bool CanAIAttack(Unit target)
{
public npc_pet_dk_guardianAI(Creature creature) : base(creature) { }
public override bool CanAIAttack(Unit target)
{
if (!target)
return false;
Unit owner = me.GetOwner();
if (owner && !target.IsInCombatWith(owner))
return false;
return base.CanAIAttack(target);
}
}
public override CreatureAI GetAI(Creature creature)
{
return new npc_pet_dk_guardianAI(creature);
if (!target)
return false;
Unit owner = me.GetOwner();
if (owner && !target.IsInCombatWith(owner))
return false;
return base.CanAIAttack(target);
}
}
}