Implement generic script loaders to greatly reduce code duplication
This commit is contained in:
@@ -25,129 +25,124 @@ using Game.Scripting;
|
||||
namespace Scripts.EasternKingdoms
|
||||
{
|
||||
[Script]
|
||||
class npc_apprentice_mirveda : CreatureScript
|
||||
class npc_apprentice_mirveda : ScriptedAI
|
||||
{
|
||||
public npc_apprentice_mirveda() : base("npc_apprentice_mirveda") { }
|
||||
|
||||
class npc_apprentice_mirvedaAI : ScriptedAI
|
||||
public npc_apprentice_mirveda(Creature creature)
|
||||
: base(creature)
|
||||
{
|
||||
public npc_apprentice_mirvedaAI(Creature creature)
|
||||
: base(creature)
|
||||
{
|
||||
Summons = new SummonList(me);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
SetCombatMovement(false);
|
||||
KillCount = 0;
|
||||
PlayerGUID.Clear();
|
||||
Summons.DespawnAll();
|
||||
}
|
||||
|
||||
public override void sQuestReward(Player player, Quest quest, uint opt)
|
||||
{
|
||||
if (quest.Id == QUEST_CORRUPTED_SOIL)
|
||||
{
|
||||
me.RemoveFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
|
||||
_events.ScheduleEvent(EventTalk, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
public override void sQuestAccept(Player player, Quest quest)
|
||||
{
|
||||
if (quest.Id == QUEST_UNEXPECTED_RESULT)
|
||||
{
|
||||
me.SetFaction(FactionCombat);
|
||||
me.RemoveFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
|
||||
_events.ScheduleEvent(EventSummon, 1000);
|
||||
PlayerGUID = player.GetGUID();
|
||||
}
|
||||
}
|
||||
|
||||
public override void EnterCombat(Unit who)
|
||||
{
|
||||
_events.ScheduleEvent(EventFireball, 1000);
|
||||
}
|
||||
|
||||
public override void JustSummoned(Creature summoned)
|
||||
{
|
||||
// This is the best I can do because AttackStart does nothing
|
||||
summoned.GetMotionMaster().MovePoint(1, me.GetPositionX(), me.GetPositionY(), me.GetPositionZ());
|
||||
// summoned.AI().AttackStart(me);
|
||||
Summons.Summon(summoned);
|
||||
}
|
||||
|
||||
public override void SummonedCreatureDies(Creature summoned, Unit who)
|
||||
{
|
||||
Summons.Despawn(summoned);
|
||||
++KillCount;
|
||||
}
|
||||
|
||||
public override void JustDied(Unit killer)
|
||||
{
|
||||
me.SetFaction(FactionNormal);
|
||||
|
||||
if (!PlayerGUID.IsEmpty())
|
||||
{
|
||||
Player player = Global.ObjAccessor.GetPlayer(me, PlayerGUID);
|
||||
if (player)
|
||||
player.FailQuest(QUEST_UNEXPECTED_RESULT);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
if (KillCount >= 3 && !PlayerGUID.IsEmpty())
|
||||
{
|
||||
Player player = Global.ObjAccessor.GetPlayer(me, PlayerGUID);
|
||||
if (player)
|
||||
{
|
||||
if (player.GetQuestStatus(QUEST_UNEXPECTED_RESULT) == QuestStatus.Incomplete)
|
||||
{
|
||||
player.CompleteQuest(QUEST_UNEXPECTED_RESULT);
|
||||
me.SetFaction(FactionNormal);
|
||||
me.SetFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_events.Update(diff);
|
||||
_events.ExecuteEvents(eventId =>
|
||||
{
|
||||
switch (eventId)
|
||||
{
|
||||
case EventTalk:
|
||||
Talk(SayTestSoil);
|
||||
_events.ScheduleEvent(EventAddQuestGiverFlag, 7000);
|
||||
break;
|
||||
case EventAddQuestGiverFlag:
|
||||
me.SetFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
|
||||
break;
|
||||
case EventSummon:
|
||||
me.SummonCreature(NPC_GHARZUL, 8749.505f, -7132.595f, 35.31983f, 3.816502f, TempSummonType.CorpseTimedDespawn, 180000);
|
||||
me.SummonCreature(NPC_ANGERSHADE, 8755.38f, -7131.521f, 35.30957f, 3.816502f, TempSummonType.CorpseTimedDespawn, 180000);
|
||||
me.SummonCreature(NPC_ANGERSHADE, 8753.199f, -7125.975f, 35.31986f, 3.816502f, TempSummonType.CorpseTimedDespawn, 180000);
|
||||
break;
|
||||
case EventFireball:
|
||||
if (UpdateVictim())
|
||||
{
|
||||
DoCastVictim(SpellFireball, true); // Not casting in combat
|
||||
_events.ScheduleEvent(EventFireball, 3000);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
|
||||
uint KillCount;
|
||||
ObjectGuid PlayerGUID;
|
||||
SummonList Summons;
|
||||
Summons = new SummonList(me);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
SetCombatMovement(false);
|
||||
KillCount = 0;
|
||||
PlayerGUID.Clear();
|
||||
Summons.DespawnAll();
|
||||
}
|
||||
|
||||
public override void sQuestReward(Player player, Quest quest, uint opt)
|
||||
{
|
||||
if (quest.Id == QUEST_CORRUPTED_SOIL)
|
||||
{
|
||||
me.RemoveFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
|
||||
_events.ScheduleEvent(EventTalk, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
public override void sQuestAccept(Player player, Quest quest)
|
||||
{
|
||||
if (quest.Id == QUEST_UNEXPECTED_RESULT)
|
||||
{
|
||||
me.SetFaction(FactionCombat);
|
||||
me.RemoveFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
|
||||
_events.ScheduleEvent(EventSummon, 1000);
|
||||
PlayerGUID = player.GetGUID();
|
||||
}
|
||||
}
|
||||
|
||||
public override void EnterCombat(Unit who)
|
||||
{
|
||||
_events.ScheduleEvent(EventFireball, 1000);
|
||||
}
|
||||
|
||||
public override void JustSummoned(Creature summoned)
|
||||
{
|
||||
// This is the best I can do because AttackStart does nothing
|
||||
summoned.GetMotionMaster().MovePoint(1, me.GetPositionX(), me.GetPositionY(), me.GetPositionZ());
|
||||
// summoned.AI().AttackStart(me);
|
||||
Summons.Summon(summoned);
|
||||
}
|
||||
|
||||
public override void SummonedCreatureDies(Creature summoned, Unit who)
|
||||
{
|
||||
Summons.Despawn(summoned);
|
||||
++KillCount;
|
||||
}
|
||||
|
||||
public override void JustDied(Unit killer)
|
||||
{
|
||||
me.SetFaction(FactionNormal);
|
||||
|
||||
if (!PlayerGUID.IsEmpty())
|
||||
{
|
||||
Player player = Global.ObjAccessor.GetPlayer(me, PlayerGUID);
|
||||
if (player)
|
||||
player.FailQuest(QUEST_UNEXPECTED_RESULT);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
if (KillCount >= 3 && !PlayerGUID.IsEmpty())
|
||||
{
|
||||
Player player = Global.ObjAccessor.GetPlayer(me, PlayerGUID);
|
||||
if (player)
|
||||
{
|
||||
if (player.GetQuestStatus(QUEST_UNEXPECTED_RESULT) == QuestStatus.Incomplete)
|
||||
{
|
||||
player.CompleteQuest(QUEST_UNEXPECTED_RESULT);
|
||||
me.SetFaction(FactionNormal);
|
||||
me.SetFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_events.Update(diff);
|
||||
_events.ExecuteEvents(eventId =>
|
||||
{
|
||||
switch (eventId)
|
||||
{
|
||||
case EventTalk:
|
||||
Talk(SayTestSoil);
|
||||
_events.ScheduleEvent(EventAddQuestGiverFlag, 7000);
|
||||
break;
|
||||
case EventAddQuestGiverFlag:
|
||||
me.SetFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
|
||||
break;
|
||||
case EventSummon:
|
||||
me.SummonCreature(NPC_GHARZUL, 8749.505f, -7132.595f, 35.31983f, 3.816502f, TempSummonType.CorpseTimedDespawn, 180000);
|
||||
me.SummonCreature(NPC_ANGERSHADE, 8755.38f, -7131.521f, 35.30957f, 3.816502f, TempSummonType.CorpseTimedDespawn, 180000);
|
||||
me.SummonCreature(NPC_ANGERSHADE, 8753.199f, -7125.975f, 35.31986f, 3.816502f, TempSummonType.CorpseTimedDespawn, 180000);
|
||||
break;
|
||||
case EventFireball:
|
||||
if (UpdateVictim())
|
||||
{
|
||||
DoCastVictim(SpellFireball, true); // Not casting in combat
|
||||
_events.ScheduleEvent(EventFireball, 3000);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
|
||||
uint KillCount;
|
||||
ObjectGuid PlayerGUID;
|
||||
SummonList Summons;
|
||||
|
||||
const uint EventTalk = 1; // Quest 8487
|
||||
const uint EventAddQuestGiverFlag = 2; // Quest 8487
|
||||
const uint EventSummon = 3; // Quest 8488
|
||||
@@ -171,106 +166,90 @@ namespace Scripts.EasternKingdoms
|
||||
// Quest
|
||||
const uint QUEST_CORRUPTED_SOIL = 8487;
|
||||
const uint QUEST_UNEXPECTED_RESULT = 8488;
|
||||
|
||||
public override CreatureAI GetAI(Creature creature)
|
||||
{
|
||||
return new npc_apprentice_mirvedaAI(creature);
|
||||
}
|
||||
}
|
||||
|
||||
[Script]
|
||||
class npc_infused_crystal : CreatureScript
|
||||
class npc_infused_crystal : ScriptedAI
|
||||
{
|
||||
public npc_infused_crystal() : base("npc_infused_crystal") { }
|
||||
|
||||
class npc_infused_crystalAI : ScriptedAI
|
||||
public npc_infused_crystal(Creature creature) : base(creature)
|
||||
{
|
||||
public npc_infused_crystalAI(Creature creature)
|
||||
: base(creature)
|
||||
{
|
||||
SetCombatMovement(false);
|
||||
}
|
||||
SetCombatMovement(false);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
EndTimer = 0;
|
||||
Completed = false;
|
||||
Progress = false;
|
||||
PlayerGUID.Clear();
|
||||
WaveTimer = 0;
|
||||
}
|
||||
public override void Reset()
|
||||
{
|
||||
EndTimer = 0;
|
||||
Completed = false;
|
||||
Progress = false;
|
||||
PlayerGUID.Clear();
|
||||
WaveTimer = 0;
|
||||
}
|
||||
|
||||
public override void MoveInLineOfSight(Unit who)
|
||||
public override void MoveInLineOfSight(Unit who)
|
||||
{
|
||||
if (!Progress && who.IsTypeId(TypeId.Player) && me.IsWithinDistInMap(who, 10.0f))
|
||||
{
|
||||
if (!Progress && who.IsTypeId(TypeId.Player) && me.IsWithinDistInMap(who, 10.0f))
|
||||
if (who.ToPlayer().GetQuestStatus(QuestPoweringOurDefenses) == QuestStatus.Incomplete)
|
||||
{
|
||||
if (who.ToPlayer().GetQuestStatus(QuestPoweringOurDefenses) == QuestStatus.Incomplete)
|
||||
{
|
||||
PlayerGUID = who.GetGUID();
|
||||
WaveTimer = 1000;
|
||||
EndTimer = 60000;
|
||||
Progress = true;
|
||||
}
|
||||
PlayerGUID = who.GetGUID();
|
||||
WaveTimer = 1000;
|
||||
EndTimer = 60000;
|
||||
Progress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void JustSummoned(Creature summoned)
|
||||
public override void JustSummoned(Creature summoned)
|
||||
{
|
||||
summoned.GetAI().AttackStart(me);
|
||||
}
|
||||
|
||||
public override void JustDied(Unit killer)
|
||||
{
|
||||
if (!PlayerGUID.IsEmpty() && !Completed)
|
||||
{
|
||||
summoned.GetAI().AttackStart(me);
|
||||
Player player = Global.ObjAccessor.GetPlayer(me, PlayerGUID);
|
||||
if (player)
|
||||
player.FailQuest(QuestPoweringOurDefenses);
|
||||
}
|
||||
}
|
||||
|
||||
public override void JustDied(Unit killer)
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
if (EndTimer < diff && Progress)
|
||||
{
|
||||
if (!PlayerGUID.IsEmpty() && !Completed)
|
||||
Talk(Emote);
|
||||
Completed = true;
|
||||
if (!PlayerGUID.IsEmpty())
|
||||
{
|
||||
Player player = Global.ObjAccessor.GetPlayer(me, PlayerGUID);
|
||||
if (player)
|
||||
player.FailQuest(QuestPoweringOurDefenses);
|
||||
player.CompleteQuest(QuestPoweringOurDefenses);
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateAI(uint diff)
|
||||
me.DealDamage(me, (uint)me.GetHealth(), null, DamageEffectType.Direct, SpellSchoolMask.Normal, null, false);
|
||||
me.RemoveCorpse();
|
||||
}
|
||||
else EndTimer -= diff;
|
||||
|
||||
if (WaveTimer < diff && !Completed && Progress)
|
||||
{
|
||||
if (EndTimer < diff && Progress)
|
||||
{
|
||||
Talk(Emote);
|
||||
Completed = true;
|
||||
if (!PlayerGUID.IsEmpty())
|
||||
{
|
||||
Player player = Global.ObjAccessor.GetPlayer(me, PlayerGUID);
|
||||
if (player)
|
||||
player.CompleteQuest(QuestPoweringOurDefenses);
|
||||
}
|
||||
|
||||
me.DealDamage(me, (uint)me.GetHealth(), null, DamageEffectType.Direct, SpellSchoolMask.Normal, null, false);
|
||||
me.RemoveCorpse();
|
||||
}
|
||||
else EndTimer -= diff;
|
||||
|
||||
if (WaveTimer < diff && !Completed && Progress)
|
||||
{
|
||||
uint ran1 = RandomHelper.Rand32() % 8;
|
||||
uint ran2 = RandomHelper.Rand32() % 8;
|
||||
uint ran3 = RandomHelper.Rand32() % 8;
|
||||
me.SummonCreature(NpcEnragedWeaith, SpawnLocations[ran1].X, SpawnLocations[ran1].Y, SpawnLocations[ran1].Z, 0, TempSummonType.TimedOrCorpseDespawn, 10000);
|
||||
me.SummonCreature(NpcEnragedWeaith, SpawnLocations[ran2].X, SpawnLocations[ran2].Y, SpawnLocations[ran2].Z, 0, TempSummonType.TimedOrCorpseDespawn, 10000);
|
||||
me.SummonCreature(NpcEnragedWeaith, SpawnLocations[ran3].X, SpawnLocations[ran3].Y, SpawnLocations[ran3].Z, 0, TempSummonType.TimedOrCorpseDespawn, 10000);
|
||||
WaveTimer = 30000;
|
||||
}
|
||||
else WaveTimer -= diff;
|
||||
uint ran1 = RandomHelper.Rand32() % 8;
|
||||
uint ran2 = RandomHelper.Rand32() % 8;
|
||||
uint ran3 = RandomHelper.Rand32() % 8;
|
||||
me.SummonCreature(NpcEnragedWeaith, SpawnLocations[ran1].X, SpawnLocations[ran1].Y, SpawnLocations[ran1].Z, 0, TempSummonType.TimedOrCorpseDespawn, 10000);
|
||||
me.SummonCreature(NpcEnragedWeaith, SpawnLocations[ran2].X, SpawnLocations[ran2].Y, SpawnLocations[ran2].Z, 0, TempSummonType.TimedOrCorpseDespawn, 10000);
|
||||
me.SummonCreature(NpcEnragedWeaith, SpawnLocations[ran3].X, SpawnLocations[ran3].Y, SpawnLocations[ran3].Z, 0, TempSummonType.TimedOrCorpseDespawn, 10000);
|
||||
WaveTimer = 30000;
|
||||
}
|
||||
|
||||
uint EndTimer;
|
||||
uint WaveTimer;
|
||||
bool Completed;
|
||||
bool Progress;
|
||||
ObjectGuid PlayerGUID;
|
||||
else WaveTimer -= diff;
|
||||
}
|
||||
|
||||
public override CreatureAI GetAI(Creature creature)
|
||||
{
|
||||
return new npc_infused_crystalAI(creature);
|
||||
}
|
||||
uint EndTimer;
|
||||
uint WaveTimer;
|
||||
bool Completed;
|
||||
bool Progress;
|
||||
ObjectGuid PlayerGUID;
|
||||
|
||||
// Quest
|
||||
const uint QuestPoweringOurDefenses = 8490;
|
||||
|
||||
Reference in New Issue
Block a user