context: /*
   * DAWN OF LIGHT - The first free open source DAoC server emulator
   * 
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version 2
   * of the License, or (at your option) any later version.
   * 
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   *
   */
  
  using System;
  using DOL.GS;
  using DOL.GS.PacketHandler;
  using DOL.GS.Effects;
  using DOL.Database;
  using DOL.Events;
  using System.Collections;
  using System.Collections.Generic;
  
  namespace DOL.GS.Spells
  {
      //http://www.camelotherald.com/masterlevels/ma.php?ml=Stormlord
      //shared timer 1
      #region Stormlord-1
      [SpellHandlerAttribute("DazzlingArray")]
      public class DazzlingArraySpellHandler : StormSpellHandler
      {
          // constructor
          public DazzlingArraySpellHandler(GameLiving caster, Spell spell, SpellLine line)
              : base(caster, spell, line)
          {
              //Construct a new storm.
              storm = new GameStorm();
              storm.Realm = caster.Realm;
              storm.X = caster.X;
              storm.Y = caster.Y;
              storm.Z = caster.Z;
              storm.CurrentRegionID = caster.CurrentRegionID;
              storm.Heading = caster.Heading;
              storm.Owner = (GamePlayer)caster;
              storm.Movable = true;
  
              // Construct the storm spell
              dbs = new DBSpell();
              dbs.Name = spell.Name;
              dbs.Icon = 7210;
              dbs.ClientEffect = 7210;
              dbs.Damage = spell.Damage;
              dbs.DamageType = (int)spell.DamageType;
              dbs.Target = "Realm";
              dbs.Radius = 0;
              dbs.Type = "StormMissHit";
              dbs.Value = spell.Value;
              dbs.Duration = spell.ResurrectHealth; // should be 4
              dbs.Frequency = spell.ResurrectMana;
              dbs.Pulse = 0;
              dbs.PulsePower = 0;
              dbs.LifeDrainReturn = spell.LifeDrainReturn;
              dbs.Power = 0;
              dbs.CastTime = 0;
              dbs.Range = WorldMgr.VISIBILITY_DISTANCE;
              sRadius = 350;
              s = new Spell(dbs, 1);
              sl = SkillBase.GetSpellLine(GlobalSpellsLines.Reserved_Spells);
              tempest = ScriptMgr.CreateSpellHandler(m_caster, s, sl);
          }
      }
      [SpellHandlerAttribute("StormMissHit")]
      public class StormMissHit : MasterlevelBuffHandling
      {
          public override eProperty Property1 { get { return eProperty.MissHit; } }
  
          public override void ApplyEffectOnTarget(GameLiving target, double effectiveness)
          {
              GameSpellEffect neweffect = CreateSpellEffect(target, effectiveness);
              if (target == null) return;
              if (!target.IsAlive || target.ObjectState != GameLiving.eObjectState.Active) return;
              neweffect.Start(target);
  
              if (target is GamePlayer)
                  ((GamePlayer)target).Out.SendMessage("You're harder to hit!", eChatType.CT_YouWereHit, eChatLoc.CL_SystemWindow);
  
          }
  
          public override int OnEffectExpires(GameSpellEffect effect, bool noMessages)
          {
  
              effect.Owner.EffectList.Remove(effect);
              return base.OnEffectExpires(effect, noMessages);
          }
  
          public override int CalculateSpellResistChance(GameLiving target)
          {
              return 0;
          }
  
          // constructor
          public StormMissHit(GameLiving caster, Spell spell, SpellLine line) : base(caster, spell, line) { }
      }
      #endregion
  
      //no shared timer
      #region Stormlord-2
      [SpellHandlerAttribute("VacuumVortex")]
      public class VacuumVortexSpellHandler : SpellHandler
      {
          /// <summary>
          /// Execute direct damage spell
          /// </summary>
          /// <param name="target"></param>
          public override void FinishSpellCast(GameLiving target)
          {
              m_caster.Mana -= PowerCost(target);
              base.FinishSpellCast(target);
          }
  
          public override IList<GameLiving> SelectTargets(GameObject CasterTarget)
          {
              
              var list = new List<GameLiving>(8);
              foreach (GameNPC storms in Caster.GetNPCsInRadius(350))
              {
                  if ((storms is GameStorm) && (GameServer.ServerRules.IsSameRealm(storms, Caster, true))) list.Add(storms);
              }
              return list;
          }
          public override int CalculateSpellResistChance(GameLiving target)
          {
              return 0;
          }
          /// <summary>
          /// execute non duration spell effect on target
          /// </summary>
          /// <param name="target"></param>
          /// <param name="effectiveness"></param>
          public override void OnDirectEffect(GameLiving target, double effectiveness)
          {
              //base.OnDirectEffect(target, effectiveness);
              var targets = SelectTargets(Caster);
  
              if (targets == null) return;
  
              foreach (GameStorm targetStorm in targets)
              {
                  if (targetStorm.Movable)
                  {
                      GameNPC targetNPC = targetStorm as GameNPC;
                      int range = Util.Random(0, 750);
                      double angle = Util.RandomDouble() * 2 * Math.PI;
                      targetNPC.WalkTo(targetNPC.X + (int)(range * Math.Cos(angle)), targetNPC.Y + (int)(range * Math.Sin(angle)), targetNPC.Z, targetNPC.MaxSpeed);
                  }
              }
          }
  
          public VacuumVortexSpellHandler(GameLiving caster, Spell spell, SpellLine line) : base(caster, spell, line) { }
  
          public override string ShortDescription 
              => "Ground targeted effect that pushes any storms near the ground target directly away from that point.";
      }
      #endregion
  
      //shared timer 2
      #region Stormlord-3
      [SpellHandlerAttribute("EnervatingGas")]
      public class EnervatingGasSpellHandler : StormSpellHandler
      {
          // constructor
          public EnervatingGasSpellHandler(GameLiving caster, Spell spell, SpellLine line)
              : base(caster, spell, line)
          {
              //Construct a new storm.
              storm = new GameStorm();
              storm.Realm = caster.Realm;
              storm.X = caster.X;
              storm.Y = caster.Y;
              storm.Z = caster.Z;
              storm.CurrentRegionID = caster.CurrentRegionID;
              storm.Heading = caster.Heading;
              storm.Owner = (GamePlayer)caster;
              storm.Movable = true;
  
  
  
              // Construct the storm spell
              dbs = new DBSpell();
              dbs.Name = spell.Name;
              dbs.Icon = 7273;
              dbs.ClientEffect = 7273;
              dbs.Damage = Math.Abs(spell.Damage);
              dbs.DamageType = (int)spell.DamageType;
              dbs.Target = "Enemy";
              dbs.Radius = 0;
              dbs.Type = "StormEnduDrain";
              dbs.Value = spell.Value;
              dbs.Duration = spell.ResurrectHealth; //should be 2
              dbs.Frequency = spell.ResurrectMana;
              dbs.Pulse = 0;
              dbs.PulsePower = 0;
              dbs.LifeDrainReturn = spell.LifeDrainReturn;
              dbs.Power = 0;
              dbs.CastTime = 0;
              dbs.Range = WorldMgr.VISIBILITY_DISTANCE;
              sRadius = 350;
              s = new Spell(dbs, 1);
              sl = SkillBase.GetSpellLine(GlobalSpellsLines.Reserved_Spells);
              tempest = ScriptMgr.CreateSpellHandler(m_caster, s, sl);
          }
      }
      [SpellHandlerAttribute("StormEnduDrain")]
      public class StormEndudrain : SpellHandler
      {
  
          public StormEndudrain(GameLiving caster, Spell spell, SpellLine line) : base(caster, spell, line) { }
  
          public override void ApplyEffectOnTarget(GameLiving target, double effectiveness)
          {
              GameSpellEffect neweffect = CreateSpellEffect(target, effectiveness);
  
              neweffect.Start(target);
  
              if (target == null) return;
              if (!target.IsAlive || target.ObjectState != GameLiving.eObjectState.Active) return;
              //spell damage should 25;
              int end = (int)(Spell.Damage);
              target.ChangeEndurance(target, GameLiving.eEnduranceChangeType.Spell, (-end));
  
              if (target is GamePlayer)
                  ((GamePlayer)target).Out.SendMessage(" You lose " + end + " endurance!", eChatType.CT_YouWereHit, eChatLoc.CL_SystemWindow);
              (m_caster as GamePlayer).Out.SendMessage("" + target.Name + " loses " + end + " endurance!", eChatType.CT_YouWereHit, eChatLoc.CL_SystemWindow);
          }
  
          public override int OnEffectExpires(GameSpellEffect effect, bool noMessages)
          {
  
              effect.Owner.EffectList.Remove(effect);
              return base.OnEffectExpires(effect, noMessages);
          }
  
          public override int CalculateSpellResistChance(GameLiving target)
          {
              return 0;
          }
  
          public override string ShortDescription 
              => "Storm that drains fatigue from enemies who stand inside it.";
      }
      #endregion
  
      //shared timer 1
      #region Stormlord-4
      [SpellHandlerAttribute("InebriatingFumes")]
      public class InebriatingFumesSpellHandler : StormSpellHandler
      {
          // constructor
          public InebriatingFumesSpellHandler(GameLiving caster, Spell spell, SpellLine line)
              : base(caster, spell, line)
          {
              //Construct a new storm.
              storm = new GameStorm();
              storm.Realm = caster.Realm;
              storm.X = caster.X;
              storm.Y = caster.Y;
              storm.Z = caster.Z;
              storm.CurrentRegionID = caster.CurrentRegionID;
              storm.Heading = caster.Heading;
              storm.Owner = (GamePlayer)caster;
              storm.Movable = true;
  
              // Construct the storm spell
              dbs = new DBSpell();
              dbs.Name = spell.Name;
              dbs.Icon = 7258;
              dbs.ClientEffect = 7258;
              dbs.Damage = spell.Damage;
              dbs.DamageType = (int)spell.Damage;
              dbs.Target = "Enemy";
              dbs.Radius = 0;
              dbs.Type = "StormDexQuickDebuff";
              dbs.Value = spell.Value;
              dbs.Duration = spell.ResurrectHealth; // should be 2
              dbs.Frequency = spell.ResurrectMana;
              dbs.Pulse = 0;
              dbs.PulsePower = 0;
              dbs.LifeDrainReturn = spell.LifeDrainReturn;
              dbs.Power = 0;
              dbs.CastTime = 0;
              dbs.Range = WorldMgr.VISIBILITY_DISTANCE;
              sRadius = 350;
              s = new Spell(dbs, 1);
              sl = SkillBase.GetSpellLine(GlobalSpellsLines.Reserved_Spells);
              tempest = ScriptMgr.CreateSpellHandler(m_caster, s, sl);
          }
      }
      /// <summary>
      /// Dex/Qui stat specline debuff
      /// </summary>
      [SpellHandlerAttribute("StormDexQuickDebuff")]
      public class StormDexQuickDebuff : DualStatDebuff
      {
          public override eProperty Property1 { get { return eProperty.Dexterity; } }
          public override eProperty Property2 { get { return eProperty.Quickness; } }
  
          public override void ApplyEffectOnTarget(GameLiving target, double effectiveness)
          {
              GameSpellEffect neweffect = CreateSpellEffect(target, effectiveness);
              if (target == null) return;
              if (!target.IsAlive || target.ObjectState != GameLiving.eObjectState.Active) return;
              neweffect.Start(target);
  
              if (target is GamePlayer)
                  ((GamePlayer)target).Out.SendMessage("Your dexterity and quickness decreased!", eChatType.CT_YouWereHit, eChatLoc.CL_SystemWindow);
  
          }
  
          public override int OnEffectExpires(GameSpellEffect effect, bool noMessages)
          {
  
              effect.Owner.EffectList.Remove(effect);
              return base.OnEffectExpires(effect, noMessages);
          }
  
          public override int CalculateSpellResistChance(GameLiving target)
          {
              return 0;
          }
  
          // constructor
          public StormDexQuickDebuff(GameLiving caster, Spell spell, SpellLine line) : base(caster, spell, line) { }
      }
      #endregion
  
      //shared timer 2
      #region Stormlord-5
      [SpellHandlerAttribute("MentalSiphon")]
      public class MentalSiphonSpellHandler : StormSpellHandler
      {
          // constructor
          public MentalSiphonSpellHandler(GameLiving caster, Spell spell, SpellLine line)
              : base(caster, spell, line)
          {
              //Construct a new storm.
              storm = new GameStorm();
              storm.Realm = caster.Realm;
              storm.X = caster.X;
              storm.Y = caster.Y;
              storm.Z = caster.Z;
              storm.CurrentRegionID = caster.CurrentRegionID;
              storm.Heading = caster.Heading;
              storm.Owner = (GamePlayer)caster;
              storm.Movable = true;
  
              // Construct the storm spell
              dbs = new DBSpell();
              dbs.Name = spell.Name;
              dbs.Icon = 7303;
              dbs.ClientEffect = 7303;
              dbs.Damage = Math.Abs(spell.Damage);
              dbs.DamageType = (int)spell.DamageType;
              dbs.Target = "Enemy";
              dbs.Radius = 0;
              dbs.Type = "PowerDrainStorm";
              dbs.Value = spell.Value;
              dbs.Duration = spell.ResurrectHealth; // should be 2
              dbs.Frequency = spell.ResurrectMana;
              dbs.Pulse = 0;
              dbs.PulsePower = 0;
              dbs.LifeDrainReturn = spell.LifeDrainReturn;
              dbs.Power = 0;
              dbs.CastTime = 0;
              dbs.Range = WorldMgr.VISIBILITY_DISTANCE;
              sRadius = 350;
              s = new Spell(dbs, 1);
              sl = SkillBase.GetSpellLine(GlobalSpellsLines.Reserved_Spells);
  
gt:             tempest = ScriptMgr.CreateSpellHandler(m_caster, s, sl);