Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.90 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using WCell.Constants.Misc;
  4. using WCell.Constants.NPCs;
  5. using WCell.Core.Initialization;
  6. using WCell.Core.Timers;
  7. using WCell.RealmServer.AI.Brains;
  8. using WCell.RealmServer.AI.Groups;
  9. using WCell.RealmServer.GameObjects;
  10. using WCell.RealmServer.Instances;
  11. using WCell.RealmServer.NPCs;
  12. using WCell.RealmServer.NPCs.Spawns;
  13. using WCell.RealmServer.Spells;
  14. using WCell.RealmServer.Entities;
  15. using WCell.Constants.Spells;
  16. using WCell.Constants.World;
  17. using WCell.Constants.GameObjects;
  18. using WCell.RealmServer.AI.Actions.Combat;
  19. using System;
  20. using WCell.Util;
  21. using WCell.Util.Graphics;
  22. using WCell.RealmServer.Spells.Targeting;
  23.  
  24. ///
  25. /// This file was automatically created, using WCell's CodeFileWriter
  26. /// Date: 9/1/2009
  27. ///
  28.  
  29. namespace WCell.Addons.Default.Instances
  30. {
  31.     public class UtgardeKeep : DungeonInstance
  32.     {
  33.         #region Static Settings
  34.         private static NPCEntry princeKelesethEntry;
  35.         public const int PrinceSkeletonCount = 5;
  36.         internal static NPCEntry PrinceSkeletonEntry;
  37.         private static readonly Vector3[] PrinceSkeletonPositions = new[]
  38.         {
  39.             new Vector3(156.2559f, 259.2093f, 42.8668f),
  40.             new Vector3(156.2559f, 259.2093f, 42.8668f),
  41.             new Vector3(156.2559f, 259.2093f, 42.8668f),
  42.             new Vector3(156.2559f, 259.2093f, 42.8668f),
  43.             new Vector3(156.2559f, 259.2093f, 42.8668f)
  44.         };
  45.         private static readonly NPCSpawnEntry[] PrinceSkeletonSpawnEntries = new NPCSpawnEntry[PrinceSkeletonCount];
  46.         private static NPCEntry dragonflayerIronhelm;
  47.         #endregion
  48.  
  49.         /// <summary>
  50.         /// Instance of currently active prince.
  51.         /// Will be unset when prince leaves world, so we don't need any IsInWorld checks!
  52.         /// </summary>
  53.         private NPC PrinceKeleseth;
  54.         private int PrinceDeadSkeletonCount = 0;
  55.         private readonly NPC[] PrinceDeadSkeletons = new NPC[PrinceSkeletonCount];
  56.  
  57.         static Spell shadowbold, scourgeresurrection;
  58.  
  59.         #region Setup Content
  60.         [Initialization]
  61.         [DependentInitialization(typeof(NPCMgr))]
  62.         public static void InitNPCs()
  63.         {
  64.  
  65.             //Prince Keleseth
  66.             SetupPrinceKeleseth();
  67.  
  68.             // Dragonflayer Ironhelm
  69.             dragonflayerIronhelm = NPCMgr.GetEntry(NPCId.DragonflayerIronhelm);
  70.  
  71.             dragonflayerIronhelm.AddSpell(SpellId.HeroicStrike_9);
  72.             SpellHandler.Apply(spell => { spell.CooldownTime = 5000; },
  73.                 SpellId.HeroicStrike_9);
  74.         }
  75.  
  76.         [Initialization(InitializationPass.Second)]
  77.         public static void InitSpells()
  78.         {
  79.             shadowbold = SpellHandler.Get(SpellId.ShadowBolt_73);
  80.             shadowbold.AISettings.SetCooldown(6000);
  81.             shadowbold.OverrideAITargetDefinitions(
  82.                      DefaultTargetAdders.AddAreaSource,
  83.                      DefaultTargetEvaluators.RandomEvaluator,
  84.                      DefaultTargetFilters.IsPlayer,
  85.                      DefaultTargetFilters.IsHostile);
  86.  
  87.             scourgeresurrection = SpellHandler.Get(SpellId.ScourgeResurrection);
  88.             scourgeresurrection.Visual = 0;
  89.         }
  90.         #endregion
  91.  
  92.         #region Prince Keleseth
  93.         /// <summary>
  94.         /// Returns the index of the given skeleton for the skeleton arrays
  95.         /// </summary>
  96.         static int GetSkeletonIndex(NPC skel)
  97.         {
  98.             if (skel.SpawnPoint == null)
  99.             {
  100.                 // unrelated Skeleton
  101.                 return -1;
  102.             }
  103.  
  104.             for (var i = 0; i < PrinceSkeletonSpawnEntries.Length; i++)
  105.             {
  106.                 var spawn = PrinceSkeletonSpawnEntries[i];
  107.                 if (spawn == skel.SpawnPoint.SpawnEntry)
  108.                 {
  109.                     return i;
  110.                 }
  111.             }
  112.  
  113.             // unrelated Skeleton
  114.             return -1;
  115.         }
  116.  
  117.         /// <summary>
  118.         /// Returns the skeleton with the given index
  119.         /// </summary>
  120.         NPC GetSkeleton(int index)
  121.         {
  122.             // first check for dead skeleton
  123.             var skel = PrinceDeadSkeletons[index];
  124.             if (skel != null)
  125.             {
  126.                 return skel;
  127.             }
  128.  
  129.             // check in Prince' AIGroup
  130.             if (PrinceKeleseth == null) return null;
  131.             var spawn = PrinceSkeletonSpawnEntries[index];
  132.  
  133.             // return matching Skeleton
  134.             return PrinceKeleseth.Group.FirstOrDefault(npc => npc.SpawnPoint.SpawnEntry == spawn);
  135.         }
  136.  
  137.         /// <summary>
  138.         /// Maintain array of dead skeletons when something happens to a skeleton.
  139.         /// AIGroup is managed automagically by the pool system
  140.         /// </summary>
  141.         static void UpdateSkeleton(NPC skel)
  142.         {
  143.             var instance = skel.Map as UtgardeKeep;
  144.             if (instance == null) return;
  145.  
  146.             var index = GetSkeletonIndex(skel);
  147.             if (index >= 0)
  148.             {
  149.                 if (skel.IsAlive || skel.IsDeleted)
  150.                 {
  151.                     // skeleton is resurrected or deleted
  152.                     // remove from list of dead skeletons
  153.                     --instance.PrinceDeadSkeletonCount;
  154.                     instance.PrinceDeadSkeletons[index] = null;
  155.                 }
  156.                 else
  157.                 {
  158.                     // Skeleton has been killed
  159.                     // add to list of dead skeletons
  160.                     ++instance.PrinceDeadSkeletonCount;
  161.                     instance.PrinceDeadSkeletons[index] = skel;
  162.                 }
  163.             }
  164.         }
  165.  
  166.         private static void SetupPrinceKeleseth()
  167.         {
  168.             princeKelesethEntry = NPCMgr.GetEntry(NPCId.PrinceKeleseth);
  169.             princeKelesethEntry.BrainCreator = princeKeleseth => new PrinceKelesethBrain(princeKeleseth);
  170.  
  171.             PrinceSkeletonEntry = NPCMgr.GetEntry(NPCId.VrykulSkeleton);
  172.             //add spell to prince
  173.             princeKelesethEntry.AddSpell(shadowbold);
  174.             // add spell to skeletons
  175.             PrinceSkeletonEntry.AddSpell(SpellId.Decrepify);
  176.             SpellHandler.Apply(spell => { spell.CooldownTime = 5000; }, SpellId.Decrepify);
  177.  
  178.             var princeSpawnEntry = princeKelesethEntry.SpawnEntries[0];
  179.             var poolTemplate = princeSpawnEntry.PoolTemplate;
  180.  
  181.             // do not let Skeletons decay
  182.             PrinceSkeletonEntry.DefaultDecayDelayMillis = 0;
  183.  
  184.             // add skeleton spawn entries to pool
  185.             for (var i = 0; i < PrinceSkeletonCount; i++)
  186.             {
  187.                 var skelSpawnEntry = new NPCSpawnEntry(PrinceSkeletonEntry.NPCId, MapId.UtgardeKeep, PrinceSkeletonPositions[i])
  188.                 {
  189.                     AutoSpawns = false,                     // must not respawn automatically when dead
  190.                     IsDead = true,                          // spawn dead
  191.                     PoolId = poolTemplate.PoolId            // share Prince' pool
  192.                 };
  193.                 skelSpawnEntry.FinalizeDataHolder();        // adds to PoolTemplate automatically
  194.  
  195.                 PrinceSkeletonSpawnEntries[i] = skelSpawnEntry;
  196.             }
  197.  
  198.             // give the prince his AttackAction
  199.             princeKelesethEntry.Activated += prince =>
  200.             {
  201.                 var instance = prince.Map as UtgardeKeep;
  202.                 if (instance == null || prince.SpawnPoint == null) return;
  203.  
  204.                 ((BaseBrain)prince.Brain).DefaultCombatAction.Strategy = new PrinceKelesethAttackAction(prince);
  205.  
  206.                 instance.SpawnDeadPrinceSkeletons(prince);
  207.             };
  208.  
  209.             // prince deleted
  210.             princeKelesethEntry.Deleted += prince =>
  211.             {
  212.                 var instance = prince.Map as UtgardeKeep;
  213.                 if (instance == null) return;
  214.  
  215.                 // add this "if", in case a GM spawns more than one prince
  216.                 if (instance.PrinceKeleseth == prince)
  217.                 {
  218.                     // unset PrinceKeleseth object
  219.                     instance.PrinceKeleseth = null;
  220.                 }
  221.             };
  222.  
  223.             // prince dies
  224.             princeKelesethEntry.Died += prince =>
  225.             {
  226.                 var instance = prince.Map as UtgardeKeep;
  227.                 if (instance == null) return;
  228.  
  229.                 // kill all skeletons
  230.                 instance.KillPrinceSkeletons();
  231.             };
  232.  
  233.             // update Skeleton if it dies/lives or gets deleted
  234.             PrinceSkeletonEntry.Activated += UpdateSkeleton;
  235.             PrinceSkeletonEntry.Died += UpdateSkeleton;
  236.             PrinceSkeletonEntry.Deleted += UpdateSkeleton;
  237.  
  238.            
  239.    
  240.             //Heroic
  241.             //princeKelesethEntry.AddSpell(SpellId.ShadowBolt_99);
  242.             //SpellHandler.Apply(spell => { spell.CooldownTime = 5000; },
  243.             //    SpellId.ShadowBolt_73);
  244.  
  245.             //princeKelesethEntry.AddSpell(SpellId.FrostTomb_3);
  246.  
  247.             //princeKelesethEntry.AddSpell(SpellId.FrostTomb_3);
  248.  
  249.             //princeKelesethEntry.AddSpell(SpellId.FrostTombSummon);
  250.  
  251.             //princeKelesethEntry.AddSpell(SpellId.Decrepify);
  252.  
  253.             //princeKelesethEntry.AddSpell(SpellId.ScourgeResurrection);
  254.  
  255.         }
  256.  
  257.         #region Handle Skeleton group
  258.         /// <summary>
  259.         /// Make sure, skeletons are all dead
  260.         /// </summary>
  261.         private void KillPrinceSkeletons()
  262.         {
  263.             if (PrinceKeleseth == null) return;
  264.  
  265.             // iterate over all living skeletons
  266.             // need ToArray() to create a copy of the collection, because killing the mob will modify it
  267.             //          (unless we added a message to Map to kill it in the next tick)
  268.             foreach (var mob in PrinceKeleseth.Group.ToArray())
  269.             {
  270.                 if (mob != PrinceKeleseth)
  271.                 {
  272.                     mob.Kill();
  273.                 }
  274.             }
  275.         }
  276.  
  277.         /// <summary>
  278.         /// Spawn the dead skeletons (if any are missing or happen to be alive)
  279.         /// </summary>
  280.         void SpawnDeadPrinceSkeletons(NPC prince)
  281.         {
  282.             // set this prince to be the one prince of the instance
  283.             PrinceKeleseth = prince;
  284.  
  285.             // make Prince leader of group
  286.             PrinceKeleseth.Group.Leader = PrinceKeleseth;
  287.  
  288.             // spawn missing skeletons and add them to array of dead skeletons
  289.             for (var i = 0; i < PrinceSkeletonSpawnEntries.Length; i++)
  290.             {
  291.                 // check if skeleton still exists, else, respawn it
  292.                 var skel = GetSkeleton(i);
  293.                 if (skel == null)
  294.                 {
  295.                     // Skeleton did not exist -> get SpawnPoint and spawn a new one
  296.                     var spawn = prince.SpawnPoint.Pool.SpawnPoints[i + 1];
  297.                     spawn.SpawnNow();
  298.                 }
  299.                 else if (skel.IsAlive)
  300.                 {
  301.                     // make sure Skeleton is dead
  302.                     skel.Kill();
  303.                 }
  304.             }
  305.         }
  306.         #endregion
  307.  
  308.         public class PrinceKelesethBrain : MobBrain
  309.         {
  310.             const string TEXT_AGGRO = "Your blood is mine!";
  311.             const string TEXT_SUMMONING_SKELETOMS = "Aranal, ledel! Their fate shall be yours!";
  312.             const string TEXT_FROSTTOMB = "Not so fast.";
  313.             const string TEXT_DEATH = "I join... the night.";
  314.             const string TEXT_WAIT = "Darkness waits";
  315.  
  316.             const int SOUND_AGGRO = 13221;
  317.             const int SOUND_FROSTTOMB = 13222;
  318.             const int SOUNG_WAIT = 13223;
  319.             const int SOUND_SUMMONING_SKELETOMS = 13224;
  320.             const int SOUND_DEATH = 13225;
  321.  
  322.             [Initialization(InitializationPass.Second)]
  323.             public static void InitPrinceKeleseth()
  324.             {
  325.  
  326.             }
  327.  
  328.             public PrinceKelesethBrain(NPC princeKeleseth)
  329.                 : base(princeKeleseth)
  330.             {
  331.             }
  332.  
  333.             public override void OnEnterCombat()
  334.             {
  335.                 m_owner.Yell(TEXT_AGGRO);
  336.                 m_owner.PlaySound((int)SOUND_AGGRO);
  337.  
  338.                 base.OnEnterCombat();
  339.             }
  340.  
  341.             public override void OnDeath()
  342.             {
  343.  
  344.                 base.OnDeath();
  345.             }
  346.  
  347.         }
  348.  
  349.         public class PrinceKelesethAttackAction : AIAttackAction
  350.         {
  351.             [Initialization(InitializationPass.Second)]
  352.             public static void InitPrinceKeleseth()
  353.             {
  354.             }
  355.  
  356.             public PrinceKelesethAttackAction(NPC princeKeleseth)
  357.                 : base(princeKeleseth)
  358.             {
  359.             }
  360.  
  361.             /// <summary>
  362.             /// The instance in which this prince was spawned.
  363.             /// It is always set because this AIAction is only created for the prince if spawned in an instance
  364.             /// </summary>
  365.             public UtgardeKeep Instance { get { return (UtgardeKeep)m_owner.Map; } }
  366.  
  367.             public override void Start()
  368.             {
  369.                 // Revive the Skeletons
  370.                 ResurrectSkeletons();
  371.  
  372.                 // Cheking if Vrykul Skeleton is death
  373.                 // if all Skeleton is death ress all
  374.                 //m_owner.SpellCast.Start(SpellId.ScourgeResurrection, false, SkeletonsMinions);
  375.                 m_owner.CallPeriodically(10000, CheckVrykulSekeltonIsDead);
  376.  
  377.                 base.Start();
  378.             }
  379.  
  380.             public override void Update()
  381.             {
  382.  
  383.                 base.Update();
  384.             }
  385.  
  386.             public override void Stop()
  387.             {
  388.  
  389.                 base.Stop();
  390.             }
  391.  
  392.  
  393.             void CheckVrykulSekeltonIsDead(WorldObject owner)
  394.             {
  395.                 if (!m_owner.IsAlive || m_owner.IsDeleted) return;
  396.  
  397.                 if (Instance.PrinceDeadSkeletons.Any(mob => mob == null))
  398.                 {
  399.                     // at least one skeleton is still alive in the prince' group
  400.                     return;
  401.                 }
  402.  
  403.                 ResurrectSkeletons();
  404.             }
  405.  
  406.             void ResurrectSkeletons()
  407.             {
  408.                 foreach (var mob in Instance.PrinceDeadSkeletons)
  409.                 {
  410.                     // if Skeleton is alive, it is not in the PrinceDeadSkeletons array
  411.                     if (mob != null)
  412.                     {
  413.                         // resurrect skeleton
  414.                         //m_owner.SpellCast.Trigger(SpellId.ScourgeResurrection, mob);
  415.                         m_owner.SpellCast.Trigger(scourgeresurrection, mob);
  416.                         //mob.HealthPct = 100;
  417.                     }
  418.                 }
  419.             }
  420.         }
  421.  
  422.         #region Minion Vrykul Skeleton(23970 - NPCId.VrykulSkeleton)
  423.  
  424.         public class VrykulSkeletonAttackAction : AIAttackAction
  425.         {
  426.             internal static Spell decrepify;
  427.             private ObjectUpdateTimer decreptifyTimer;
  428.  
  429.             [Initialization(InitializationPass.Second)]
  430.             public static void InitVrykulSkeleton()
  431.             {
  432.                 decrepify = SpellHandler.Get(SpellId.Decrepify);
  433.             }
  434.  
  435.             public VrykulSkeletonAttackAction(NPC vrykulSkeleton)
  436.                 : base(vrykulSkeleton)
  437.             {
  438.             }
  439.  
  440.             public override void Start()
  441.             {
  442.                 decreptifyTimer = m_owner.CallPeriodically(Utility.Random(5000, 10000), CastDecrepify);
  443.                 base.Start();
  444.             }
  445.  
  446.             public override void Stop()
  447.             {
  448.                 base.Stop();
  449.             }
  450.  
  451.  
  452.             void CastDecrepify(WorldObject owner)
  453.             {
  454.  
  455.                 owner.Yell("Hi");
  456.  
  457.                 //Character chr = owner.GetNearbyRandomHostileCharacter();
  458.  
  459.                 //if (chr != null)
  460.                 //{
  461.                 //    m_owner.SpellCast.Start(decrepify, false, chr);
  462.                 //}
  463.  
  464.             }
  465.         }
  466.  
  467.         #endregion
  468.  
  469.         #endregion
  470.  
  471.         #region Overrides
  472.         protected override void SpawnNPCs()
  473.         {
  474.             base.SpawnNPCs();
  475.         }
  476.         #endregion
  477.  
  478.     }
  479.  
  480. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement