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
+191 -230
View File
@@ -36,81 +36,71 @@ namespace Scripts.Outlands
}
[Script]
class npc_aeranas : CreatureScript
class npc_aeranas : ScriptedAI
{
public npc_aeranas() : base("npc_aeranas") { }
public npc_aeranas(Creature creature) : base(creature) { }
class npc_aeranasAI : ScriptedAI
public override void Reset()
{
public npc_aeranasAI(Creature creature) : base(creature) { }
faction_Timer = 8000;
envelopingWinds_Timer = 9000;
shock_Timer = 5000;
public override void Reset()
me.RemoveFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
me.SetFaction(Aeranas.FactionFriendly);
Talk(Aeranas.SaySummon);
}
public override void UpdateAI(uint diff)
{
if (faction_Timer != 0)
{
faction_Timer = 8000;
envelopingWinds_Timer = 9000;
shock_Timer = 5000;
if (faction_Timer <= diff)
{
me.SetFaction(Aeranas.FactionHostile);
faction_Timer = 0;
}
else
faction_Timer -= diff;
}
me.RemoveFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
if (!UpdateVictim())
return;
if (HealthBelowPct(30))
{
me.SetFaction(Aeranas.FactionFriendly);
Talk(Aeranas.SaySummon);
me.SetFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
me.RemoveAllAuras();
me.DeleteThreatList();
me.CombatStop(true);
Talk(Aeranas.SayFree);
return;
}
public override void UpdateAI(uint diff)
if (shock_Timer <= diff)
{
if (faction_Timer != 0)
{
if (faction_Timer <= diff)
{
me.SetFaction(Aeranas.FactionHostile);
faction_Timer = 0;
}
else
faction_Timer -= diff;
}
if (!UpdateVictim())
return;
if (HealthBelowPct(30))
{
me.SetFaction(Aeranas.FactionFriendly);
me.SetFlag64(UnitFields.NpcFlags, NPCFlags.QuestGiver);
me.RemoveAllAuras();
me.DeleteThreatList();
me.CombatStop(true);
Talk(Aeranas.SayFree);
return;
}
if (shock_Timer <= diff)
{
DoCastVictim(Aeranas.SpellShock);
shock_Timer = 10000;
}
else
shock_Timer -= diff;
if (envelopingWinds_Timer <= diff)
{
DoCastVictim(Aeranas.SpellEncelopingWinds);
envelopingWinds_Timer = 25000;
}
else
envelopingWinds_Timer -= diff;
DoMeleeAttackIfReady();
DoCastVictim(Aeranas.SpellShock);
shock_Timer = 10000;
}
else
shock_Timer -= diff;
uint faction_Timer;
uint envelopingWinds_Timer;
uint shock_Timer;
if (envelopingWinds_Timer <= diff)
{
DoCastVictim(Aeranas.SpellEncelopingWinds);
envelopingWinds_Timer = 25000;
}
else
envelopingWinds_Timer -= diff;
DoMeleeAttackIfReady();
}
public override CreatureAI GetAI(Creature creature)
{
return new npc_aeranasAI(creature);
}
uint faction_Timer;
uint envelopingWinds_Timer;
uint shock_Timer;
}
struct AncestralWolf
@@ -125,70 +115,118 @@ namespace Scripts.Outlands
}
[Script]
class npc_ancestral_wolf : CreatureScript
class npc_ancestral_wolf : npc_escortAI
{
public npc_ancestral_wolf() : base("npc_ancestral_wolf") { }
class npc_ancestral_wolfAI : npc_escortAI
public npc_ancestral_wolf(Creature creature) : base(creature)
{
public npc_ancestral_wolfAI(Creature creature) : base(creature)
{
if (creature.GetOwner() && creature.GetOwner().IsTypeId(TypeId.Player))
Start(false, false, creature.GetOwner().GetGUID());
else
Log.outError(LogFilter.Scripts, "Scripts: npc_ancestral_wolf can not obtain owner or owner is not a player.");
if (creature.GetOwner() && creature.GetOwner().IsTypeId(TypeId.Player))
Start(false, false, creature.GetOwner().GetGUID());
else
Log.outError(LogFilter.Scripts, "Scripts: npc_ancestral_wolf can not obtain owner or owner is not a player.");
creature.SetSpeed(UnitMoveType.Walk, 1.5f);
Reset();
}
public override void Reset()
{
ryga = null;
DoCast(me, AncestralWolf.SpellAncestralWoldBuff, true);
}
public override void MoveInLineOfSight(Unit who)
{
if (!ryga && who.GetEntry() == AncestralWolf.NpcRyga && me.IsWithinDistInMap(who, 15.0f))
{
Creature temp = who.ToCreature();
if (temp)
ryga = temp;
}
base.MoveInLineOfSight(who);
}
public override void WaypointReached(uint waypointId)
{
switch (waypointId)
{
case 0:
Talk(AncestralWolf.EmoteWoldLiftHead);
break;
case 2:
Talk(AncestralWolf.EmoteWolfHowl);
break;
case 50:
if (ryga && ryga.IsAlive() && !ryga.IsInCombat())
ryga.GetAI().Talk(AncestralWolf.SayWolfWelcome);
break;
}
}
Creature ryga;
creature.SetSpeed(UnitMoveType.Walk, 1.5f);
Reset();
}
public override CreatureAI GetAI(Creature creature)
public override void Reset()
{
return new npc_ancestral_wolfAI(creature);
ryga = null;
DoCast(me, AncestralWolf.SpellAncestralWoldBuff, true);
}
public override void MoveInLineOfSight(Unit who)
{
if (!ryga && who.GetEntry() == AncestralWolf.NpcRyga && me.IsWithinDistInMap(who, 15.0f))
{
Creature temp = who.ToCreature();
if (temp)
ryga = temp;
}
base.MoveInLineOfSight(who);
}
public override void WaypointReached(uint waypointId)
{
switch (waypointId)
{
case 0:
Talk(AncestralWolf.EmoteWoldLiftHead);
break;
case 2:
Talk(AncestralWolf.EmoteWolfHowl);
break;
case 50:
if (ryga && ryga.IsAlive() && !ryga.IsInCombat())
ryga.GetAI().Talk(AncestralWolf.SayWolfWelcome);
break;
}
}
Creature ryga;
}
[Script]
class npc_wounded_blood_elf : CreatureScript
class npc_wounded_blood_elf : npc_escortAI
{
public npc_wounded_blood_elf(Creature creature) : base(creature) { }
public override void Reset() { }
public override void EnterCombat(Unit who)
{
if (HasEscortState(eEscortState.Escorting))
Talk(SAY_ELF_AGGRO);
}
public override void JustSummoned(Creature summoned)
{
summoned.GetAI().AttackStart(me);
}
public override void sQuestAccept(Player player, Quest quest)
{
if (quest.Id == QUEST_ROAD_TO_FALCON_WATCH)
{
me.SetFaction(FACTION_FALCON_WATCH_QUEST);
base.Start(true, false, player.GetGUID());
}
}
public override void WaypointReached(uint waypointId)
{
Player player = GetPlayerForEscort();
if (!player)
return;
switch (waypointId)
{
case 0:
Talk(SAY_ELF_START, player);
break;
case 9:
Talk(SAY_ELF_SUMMON1, player);
// Spawn two Haal'eshi Talonguard
DoSpawnCreature(NPC_HAALESHI_TALONGUARD, -15, -15, 0, 0, TempSummonType.TimedDespawnOOC, 5000);
DoSpawnCreature(NPC_HAALESHI_TALONGUARD, -17, -17, 0, 0, TempSummonType.TimedDespawnOOC, 5000);
break;
case 13:
Talk(SAY_ELF_RESTING, player);
break;
case 14:
Talk(SAY_ELF_SUMMON2, player);
// Spawn two Haal'eshi Windwalker
DoSpawnCreature(NPC_HAALESHI_WINDWALKER, -15, -15, 0, 0, TempSummonType.TimedDespawnOOC, 5000);
DoSpawnCreature(NPC_HAALESHI_WINDWALKER, -17, -17, 0, 0, TempSummonType.TimedDespawnOOC, 5000);
break;
case 27:
Talk(SAY_ELF_COMPLETE, player);
// Award quest credit
player.GroupEventHappens(QUEST_ROAD_TO_FALCON_WATCH, me);
break;
}
}
const uint SAY_ELF_START = 0;
const uint SAY_ELF_SUMMON1 = 1;
const uint SAY_ELF_RESTING = 2;
@@ -199,142 +237,65 @@ namespace Scripts.Outlands
const uint NPC_HAALESHI_WINDWALKER = 16966;
const uint NPC_HAALESHI_TALONGUARD = 16967;
const uint FACTION_FALCON_WATCH_QUEST = 775;
public npc_wounded_blood_elf() : base("npc_wounded_blood_elf") { }
class npc_wounded_blood_elfAI : npc_escortAI
{
public npc_wounded_blood_elfAI(Creature creature) : base(creature) { }
public override void Reset() { }
public override void EnterCombat(Unit who)
{
if (HasEscortState(eEscortState.Escorting))
Talk(SAY_ELF_AGGRO);
}
public override void JustSummoned(Creature summoned)
{
summoned.GetAI().AttackStart(me);
}
public override void sQuestAccept(Player player, Quest quest)
{
if (quest.Id == QUEST_ROAD_TO_FALCON_WATCH)
{
me.SetFaction(FACTION_FALCON_WATCH_QUEST);
base.Start(true, false, player.GetGUID());
}
}
public override void WaypointReached(uint waypointId)
{
Player player = GetPlayerForEscort();
if (!player)
return;
switch (waypointId)
{
case 0:
Talk(SAY_ELF_START, player);
break;
case 9:
Talk(SAY_ELF_SUMMON1, player);
// Spawn two Haal'eshi Talonguard
DoSpawnCreature(NPC_HAALESHI_TALONGUARD, -15, -15, 0, 0, TempSummonType.TimedDespawnOOC, 5000);
DoSpawnCreature(NPC_HAALESHI_TALONGUARD, -17, -17, 0, 0, TempSummonType.TimedDespawnOOC, 5000);
break;
case 13:
Talk(SAY_ELF_RESTING, player);
break;
case 14:
Talk(SAY_ELF_SUMMON2, player);
// Spawn two Haal'eshi Windwalker
DoSpawnCreature(NPC_HAALESHI_WINDWALKER, -15, -15, 0, 0, TempSummonType.TimedDespawnOOC, 5000);
DoSpawnCreature(NPC_HAALESHI_WINDWALKER, -17, -17, 0, 0, TempSummonType.TimedDespawnOOC, 5000);
break;
case 27:
Talk(SAY_ELF_COMPLETE, player);
// Award quest credit
player.GroupEventHappens(QUEST_ROAD_TO_FALCON_WATCH, me);
break;
}
}
}
public override CreatureAI GetAI(Creature creature)
{
return new npc_wounded_blood_elfAI(creature);
}
}
[Script]
class npc_fel_guard_hound : CreatureScript
class npc_fel_guard_hound : ScriptedAI
{
const uint SPELL_SUMMON_POO = 37688;
const uint NPC_DERANGED_HELBOAR = 16863;
public npc_fel_guard_hound(Creature creature) : base(creature) { }
public npc_fel_guard_hound() : base("npc_fel_guard_hound") { }
class npc_fel_guard_houndAI : ScriptedAI
public override void Reset()
{
public npc_fel_guard_houndAI(Creature creature) : base(creature) { }
checkTimer = 5000; //check for creature every 5 sec
helboarGUID.Clear();
}
public override void Reset()
public override void MovementInform(MovementGeneratorType type, uint id)
{
if (type != MovementGeneratorType.Point || id != 1)
return;
Creature helboar = me.GetMap().GetCreature(helboarGUID);
if (helboar)
{
checkTimer = 5000; //check for creature every 5 sec
helboarGUID.Clear();
helboar.RemoveCorpse();
DoCast(SPELL_SUMMON_POO);
Player owner = me.GetCharmerOrOwnerPlayerOrPlayerItself();
if (owner)
me.GetMotionMaster().MoveFollow(owner, 0.0f, 0.0f);
}
}
public override void MovementInform(MovementGeneratorType type, uint id)
public override void UpdateAI(uint diff)
{
if (checkTimer <= diff)
{
if (type != MovementGeneratorType.Point || id != 1)
return;
Creature helboar = me.GetMap().GetCreature(helboarGUID);
Creature helboar = me.FindNearestCreature(NPC_DERANGED_HELBOAR, 10.0f, false);
if (helboar)
{
helboar.RemoveCorpse();
DoCast(SPELL_SUMMON_POO);
Player owner = me.GetCharmerOrOwnerPlayerOrPlayerItself();
if (owner)
me.GetMotionMaster().MoveFollow(owner, 0.0f, 0.0f);
}
}
public override void UpdateAI(uint diff)
{
if (checkTimer <= diff)
{
Creature helboar = me.FindNearestCreature(NPC_DERANGED_HELBOAR, 10.0f, false);
if (helboar)
if (helboar.GetGUID() != helboarGUID && me.GetMotionMaster().GetCurrentMovementGeneratorType() != MovementGeneratorType.Point && !me.FindCurrentSpellBySpellId(SPELL_SUMMON_POO))
{
if (helboar.GetGUID() != helboarGUID && me.GetMotionMaster().GetCurrentMovementGeneratorType() != MovementGeneratorType.Point && !me.FindCurrentSpellBySpellId(SPELL_SUMMON_POO))
{
helboarGUID = helboar.GetGUID();
me.GetMotionMaster().MovePoint(1, helboar.GetPositionX(), helboar.GetPositionY(), helboar.GetPositionZ());
}
helboarGUID = helboar.GetGUID();
me.GetMotionMaster().MovePoint(1, helboar.GetPositionX(), helboar.GetPositionY(), helboar.GetPositionZ());
}
checkTimer = 5000;
}
else checkTimer -= diff;
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
checkTimer = 5000;
}
else checkTimer -= diff;
uint checkTimer;
ObjectGuid helboarGUID;
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
}
public override CreatureAI GetAI(Creature creature)
{
return new npc_fel_guard_houndAI(creature);
}
uint checkTimer;
ObjectGuid helboarGUID;
const uint SPELL_SUMMON_POO = 37688;
const uint NPC_DERANGED_HELBOAR = 16863;
}
}
+1 -67
View File
@@ -140,8 +140,7 @@ namespace Scripts.Outlands
class npc_cooshcooshAI : ScriptedAI
{
public npc_cooshcooshAI(Creature creature)
: base(creature)
public npc_cooshcooshAI(Creature creature) : base(creature)
{
m_uiNormFaction = creature.getFaction();
}
@@ -263,32 +262,6 @@ namespace Scripts.Outlands
const string GOSSIP_ITEM_KUR3 = "I will tell them. Farewell, elder.";
}
[Script]
class npc_mortog_steamhead : CreatureScript
{
public npc_mortog_steamhead() : base("npc_mortog_steamhead") { }
public override bool OnGossipHello(Player player, Creature creature)
{
if (creature.IsVendor() && player.GetReputationRank(942) == ReputationRank.Exalted)
player.ADD_GOSSIP_ITEM(GossipOptionIcon.Vendor, GOSSIP_TEXT_BROWSE_GOODS, eTradeskill.GossipSenderMain, eTradeskill.GossipActionTrade);
player.SEND_GOSSIP_MENU(player.GetGossipTextId(creature), creature.GetGUID());
return true;
}
public override bool OnGossipSelect(Player player, Creature creature, uint sender, uint action)
{
player.PlayerTalkClass.ClearMenus();
if (action == eTradeskill.GossipActionTrade)
player.GetSession().SendListInventory(creature.GetGUID());
return true;
}
const string GOSSIP_TEXT_BROWSE_GOODS = "I'd like to browse your goods.";
}
[Script]
class npc_kayra_longmane : CreatureScript
{
@@ -360,43 +333,4 @@ namespace Scripts.Outlands
const uint QUEST_ESCAPE_FROM = 9752;
const uint NPC_SLAVEBINDER = 18042;
}
[Script]
class npc_timothy_daniels : CreatureScript
{
public npc_timothy_daniels() : base("npc_timothy_daniels") { }
public override bool OnGossipHello(Player player, Creature creature)
{
if (creature.IsQuestGiver())
player.PrepareQuestMenu(creature.GetGUID());
if (creature.IsVendor())
player.ADD_GOSSIP_ITEM(GossipOptionIcon.Vendor, GOSSIP_TEXT_BROWSE_POISONS, eTradeskill.GossipSenderMain, eTradeskill.GossipActionTrade);
player.ADD_GOSSIP_ITEM(GossipOptionIcon.Chat, GOSSIP_TIMOTHY_DANIELS_ITEM1, eTradeskill.GossipSenderMain, eTradeskill.GossipActionInfoDef + 1);
player.SEND_GOSSIP_MENU(player.GetGossipTextId(creature), creature.GetGUID());
return true;
}
public override bool OnGossipSelect(Player player, Creature creature, uint sender, uint action)
{
player.PlayerTalkClass.ClearMenus();
switch (action)
{
case eTradeskill.GossipActionInfoDef + 1:
player.SEND_GOSSIP_MENU(GOSSIP_TEXTID_TIMOTHY_DANIELS1, creature.GetGUID());
break;
case eTradeskill.GossipActionTrade:
player.GetSession().SendListInventory(creature.GetGUID());
break;
}
return true;
}
const string GOSSIP_TIMOTHY_DANIELS_ITEM1 = "Specialist, eh? Just what kind of specialist are you, anyway?";
const string GOSSIP_TEXT_BROWSE_POISONS = "Let me browse your reagents and poison supplies.";
const uint GOSSIP_TEXTID_TIMOTHY_DANIELS1 = 9239;
}
}