Advertisement
XConquer

Calculate -- 6711

Oct 8th, 2020 (edited)
1,604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 424.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using COServer.Network.GamePackets;
  4. using COServer.Game.ConquerStructures;
  5.  
  6. namespace COServer.Game.Attacking
  7. {
  8.     public class Calculate
  9.     {
  10.         #region Nuevos Magics
  11.      
  12.        
  13.         public static int CreatePenetration(Player attacker, Player attacked, ref MsgInteract Packet, int Damage)
  14.         {
  15.             //EfectosPerfectos effect = EfectosPerfectos.InvisibleArrow;
  16.             //byte chance = 0;
  17.             //new MsgRefineEffect().HandleInvisibleArrow(attacker, ref chance);
  18.             //if (attacked != null && Kernel.Rate(chance))
  19.             //{
  20.             //    new MsgRefineEffect().SendEffect(attacker, attacked, effect);
  21.             //    Damage = (Int32)Math.Floor((float)Damage * 1.3);
  22.             //    Packet.Effect1 |= Attack.AttackEffects1.Penetration;
  23.             //}
  24.             if (Kernel.Rate((float)attacker.Penetration / 10f))
  25.             {
  26.                 Damage = (Int32)Math.Floor((float)Damage * 1.2);
  27.                 Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  28.             }
  29.             return Damage;
  30.         }
  31.         public static int CalculateSkillCryitical(Player AttackerClient, Player AttackedClient, ref MsgInteract Packet, int damage)
  32.         {
  33.             //if (AttackerClient != null && AttackerClient.EntityFlag == EntityFlag.Player)
  34.             //{
  35.             //    EfectosPerfectos effect = EfectosPerfectos.CoreStrike;
  36.             //    byte chance = 0;
  37.             //    new MsgRefineEffect().HandleCoreStrike(AttackerClient, ref chance);
  38.             //    if (Kernel.Rate(chance))
  39.             //    {
  40.             //        new MsgRefineEffect().SendEffect(AttackerClient, AttackedClient, effect);
  41.             //        Packet.Effect1 |= Attack.AttackEffects1.CriticalStrike;
  42.             //        return damage *= (int)1.5;
  43.             //    }
  44.             //}
  45.             if (AttackedClient == null && AttackerClient != null && AttackerClient.PlayerFlag == PlayerFlag.Player)
  46.             {
  47.                 int Critical = AttackerClient.SkillCStrike / 100;
  48.                 Critical /= 2;
  49.                 if (Kernel.Rate(Critical))
  50.                 {
  51.                     Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  52.                     return damage *= (int)1.5;
  53.  
  54.                 }
  55.  
  56.             }
  57.             if (AttackerClient.SkillCStrike == AttackedClient.Immunity)
  58.                 return damage;
  59.             if (AttackerClient.SkillCStrike > AttackedClient.Immunity)
  60.             {
  61.                 int Critical = AttackerClient.SkillCStrike / 100;
  62.                 int Immunity = AttackedClient.Immunity / 100;
  63.                 int Power = Critical - Immunity;
  64.                 if (Kernel.Rate(Power))
  65.                 {
  66.                     return damage *= (int)1.5;
  67.                 }
  68.             }
  69.             return damage;
  70.         }
  71.         public static int CalculateMagicPotencyDamage(Player AttackerClient, Player AttackedClient, int damage)
  72.         {
  73.             if (AttackerClient.BattlePower == AttackedClient.BattlePower)
  74.                 return damage;
  75.             if (AttackerClient.BattlePower > AttackedClient.BattlePower)
  76.             {
  77.                 int power = (int)(AttackerClient.BattlePower - AttackedClient.BattlePower);
  78.  
  79.                 if (power > 12)
  80.                     power = 12;
  81.                 damage += (damage * power) / 30;
  82.             }
  83.             else
  84.             {
  85.                 int power = (int)(AttackedClient.BattlePower - AttackerClient.BattlePower);
  86.                 if (power > 12)
  87.                     power = 12;
  88.                 damage -= (damage * power) / 30;
  89.             }
  90.             return damage;
  91.         }
  92.      
  93.      
  94.        
  95.        
  96.         public static Boolean ChanceSuccess(Double Chance, Double offset = 0)
  97.         {
  98.             Random Rand = new Random();
  99.             if (Chance <= 0) return false;
  100.             else if (Chance >= 100) return true;
  101.             return ((float)Rand.Next(1, 1000000) / 10000d >= (100d + offset) - Chance);
  102.         }
  103.         public static uint AtaquesMagicos(Player Attacker, Player Attacked, Database.SpellInformation SInfo, ref MsgInteract Packet, byte SkillSoul = 0)
  104.         {
  105.             if (Attacked.PlayerFlag == PlayerFlag.Player)
  106.             {
  107.                 BlessEffect.Process(Attacked);
  108.             }
  109.             if (Attacker.PlayerFlag == PlayerFlag.Player)
  110.             {
  111.                 GemEffect.Process(Attacker);
  112.             }
  113.             Boolean CritImmune = false;
  114.             switch (Attacked.PlayerFlag)
  115.             {
  116.                 case PlayerFlag.Player:
  117.                     {
  118.                        
  119.                         Int32 Damage = 0;
  120.                         Int32 Defence = 0;
  121.                         #region Float Inmunnity - Contra Otros
  122.                         if (ChanceSuccess((float)Attacked.Immunity / 100f))
  123.                         {
  124.                             CritImmune = true;
  125.                         }
  126.                         #endregion
  127.                         #region Tesoros
  128.                         Int32 Fan = 0, Tower = 0, WingThunder = 0, WingGlory = 0;
  129.                         if (Attacker.PlayerFlag == PlayerFlag.Player)
  130.                             Fan = Attacker.getFan(true);
  131.                         if (Attacker.PlayerFlag == PlayerFlag.Player)
  132.                             WingThunder = Attacker.getWingsThunder(true);
  133.                         if (Attacked.PlayerFlag == PlayerFlag.Player)
  134.                             Tower = Attacked.getTower(true);
  135.                         if (Attacked.PlayerFlag == PlayerFlag.Player)
  136.                             WingGlory = Attacked.getWingsGlory(true);
  137.                         #endregion
  138.                         #region Codigo Base Ataque / Defensa
  139.                         Double attack = SInfo.Power;
  140.                         attack += (uint)Attacker.MagicAttack;
  141.                         Damage = (int)attack;// (int)Attacker.MagicAttack;
  142.                         Defence = (Int32)Attacked.MagicDefence;
  143.                         Defence += (Int32)Attacked.MagicDamageDecrease;
  144.                         #endregion
  145.                         #region Tesoros
  146.                         Damage += Fan;
  147.                         Damage += WingThunder;
  148.                         Damage -= Tower;
  149.                         Damage -= WingGlory;
  150.                         #endregion
  151.                         #region Variable + Damage
  152.                         #region MagicDamage Increase Stat
  153.                         if (Attacker.PlayerFlag == PlayerFlag.Player)
  154.                             Damage += Attacker.MagicDamageIncrease;
  155.                         #endregion
  156.                         #region Daño Extra Por Reborns
  157.                         if (Attacked.PlayerFlag == PlayerFlag.Player)
  158.                         {
  159.                             if (Attacked.Reborn == 1)
  160.                                 Damage = (Int32)(Damage * 0.40);
  161.                             if (Attacked.Reborn == 2)
  162.                                 Damage = (Int32)(Damage * 0.60);
  163.                         }
  164.                         #endregion
  165.                         #endregion
  166.                         #region Variable - Damage
  167.                         Damage -= Defence;
  168.                         #endregion
  169.                         #region Atributos
  170.                         #region SkillCriticalStrike
  171.                         if (Kernel.Rate((int)(Attacker.SkillCStrike - Attacked.Immunity) / 100))//Para Taoistas
  172.                         {
  173.                             Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  174.                             {
  175.                                 Damage = (int)(Damage * 1.6);
  176.                             }
  177.                         }
  178.                         if (!CritImmune)//Para Otras Clases
  179.                         {
  180.                             if (ChanceSuccess((float)Attacker.SkillCStrike / 100f))
  181.                             {
  182.                                 Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  183.                                 Damage = (Int32)Math.Floor((float)Damage * 1.6);
  184.                             }
  185.                         }
  186.                         #endregion
  187.                         #region Block
  188.                         if (Attacked.PlayerFlag == PlayerFlag.Player)
  189.                         {
  190.                             if (ChanceSuccess((float)Attacked.Block / 100f))
  191.                             {
  192.                                 Packet.Effect |= MsgInteract.InteractEffects.Block;
  193.                                 Damage = (Int32)Math.Floor((float)Damage / 2);
  194.                             }
  195.                         }
  196.                         #endregion
  197.                         #region Penetration
  198.                         Damage = CreatePenetration(Attacker, null, ref Packet, Damage);
  199.                         #endregion
  200.                         #region GemBounes
  201.  
  202.                         var bonus = attacker.Gems[0];
  203.                         if (bonus > 0)
  204.                         {
  205.                             Damage += MathHelper.MulDiv((int)Damage, (int)bonus, (int)100);
  206.                         }
  207.  
  208.                         #endregion
  209.                         /// ATRIBUTOS PERFECTOS  ///
  210.                         #region All MagicsAttack
  211.                         //new MsgRefineEffect().HandleMagicPerfectsAttacks(Attacker, Attacked, ref Damage);
  212.                         #endregion
  213.                         #endregion
  214.                         #region BattlePower
  215.                         if (Attacker.BattlePower >= 379 && Attacker.BattlePower <= 406)
  216.                         {
  217.                             if (Attacker.SkillCStrike > 0)
  218.                             {
  219.                                 if (Attacker.SkillCStrike > Attacked.Immunity)
  220.                                 {
  221.                                     double Power = (double)(Attacker.SkillCStrike - Attacked.Immunity);
  222.                                     Power = (double)(Power / 100);
  223.                                     if (MyMath.Success(Power))
  224.                                         Damage += Damage * 25 / 100;
  225.                                     Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  226.                                 }
  227.                                 else
  228.                                     Packet.Effect |= MsgInteract.InteractEffects.Immu;
  229.                             }
  230.                             Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  231.                             //Damage += Damage * CustomSettings.AttackBattle.BattlePower.PowHighEnd / 100;
  232.                         }
  233.                         if (Attacker.BattlePower >= 309 && Attacker.BattlePower <= 378)
  234.                         {
  235.                             if (Attacker.Penetration > 0)
  236.                             {
  237.                                 if (Attacker.Penetration > Attacked.Counteraction)
  238.                                 {
  239.                                     double Power = (double)(Attacker.Penetration - Attacked.Counteraction);
  240.                                     Power = (double)(Power / 100);
  241.                                     if (MyMath.Success(Power))
  242.                                         Damage += Damage * 30 / 100;
  243.                                     Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  244.                                 }
  245.                                 else
  246.                                     Packet.Effect |= MsgInteract.InteractEffects.Immu;
  247.                             }
  248.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  249.                             //Damage += Damage * CustomSettings.AttackBattle.BattlePower.PowHighEnd / 100;
  250.                         }
  251.                         #endregion
  252.                         #region Extra Effect Skill Soul [Arte Marcial
  253.                        // Damage += (Damage * (SkillSoul * 10) / 100);// 10% Total Dmg From Skill Soul Level Skills
  254.                         #endregion
  255.                         AutoRespone(Attacker, Attacked, ref Damage);
  256.                         if (Attacked.PlayerFlag == PlayerFlag.Player)
  257.                             if (Attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.ShurikenVortex))
  258.                                 return 1;
  259.                         if (Constants.Damage1Map.Contains(Attacker.MapID))
  260.                             Damage = 1;
  261.  
  262.                         if (Damage <= 0)
  263.                             Damage = 1;
  264.  
  265.                         return (uint)Damage;
  266.                     }
  267.                 case PlayerFlag.Monster:
  268.                     {
  269.                         Int32 Damage = 0;
  270.                         Int32 Defence = 0;
  271.  
  272.                         Int32 Fan = 0;
  273.                         if (Attacker.PlayerFlag == PlayerFlag.Player)
  274.                             Fan = Attacker.getFan(true);
  275.  
  276.                        
  277.                         Damage = (int)Attacker.MagicAttack;
  278.                         if (SInfo != null)
  279.                             Damage += (int)SInfo.Power;
  280.                         Defence = Attacked.MonsterInfo.Level * 20;
  281.  
  282.                         if (Attacked.MonsterInfo != null)
  283.                             if (Attacked.Name == "Guard1")
  284.                                 Damage = 1;
  285.  
  286.  
  287.                         Damage += Fan;
  288.                         if (Attacker.PlayerFlag == PlayerFlag.Player)
  289.                             Damage += Attacker.MagicDamageIncrease;
  290.  
  291.  
  292.  
  293.                         Damage *= (int)(2.5);
  294.  
  295.                         //Damage += (int)bpdamage;
  296.                         Damage -= Defence;
  297.                         if (!CritImmune)
  298.                         {
  299.                             if (ChanceSuccess((float)Attacker.SkillCStrike / 100f))
  300.                             {
  301.                                 Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  302.                                 Damage = (Int32)Math.Floor((float)Damage * 1.2);
  303.                             }
  304.                         }
  305.  
  306.                         if (Damage <= 1) Damage = 1;
  307.                         if (Constants.Damage1Map.Contains(Attacker.MapID))
  308.                             Damage = 1;
  309.                         return (UInt32)Damage;
  310.                     }
  311.             }
  312.             return 0;
  313.         }
  314.  
  315.         #endregion
  316.         #region NEW MELEE TO TEST
  317.         public static int MulDiv(int number, int numerator, int denominator)
  318.         {
  319.             return (number * numerator /*+ denominator / 2*/) / denominator;
  320.         }
  321.         public static long BigMulDiv(long number, long numerator, long denominator)
  322.         {
  323.             return (number * numerator + denominator / 2) / denominator;
  324.         }
  325.         public static int CalculatePotencyDamage(int Damage, int AttackerBattle, int TargetBattle, bool range = false)
  326.         {
  327.             if (AttackerBattle == TargetBattle)
  328.                 return Damage;
  329.             int power = AttackerBattle - TargetBattle;
  330.             if (power != 0)
  331.             {
  332.  
  333.                 power = power * (range ? 10 : 3);
  334.                 //3
  335.                 if (power > 0)
  336.                 {
  337.                     power = Math.Min(60, power);
  338.                 }
  339.                 else if (power < 0)
  340.                 {
  341.                     power = Math.Max(-60, power);
  342.                 }
  343.  
  344.                 Damage = MulDiv(Damage, 100 + power, 100);
  345.             }
  346.             return Damage;
  347.         }
  348.         public static uint NewWork(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  349.         {
  350.  
  351.             if (attacked.Name == "SilverOctopus") return 1;
  352.             if (attacked.Name == "GoldenOctopus") return 1;
  353.             if (Packet != null)
  354.             {
  355.                 Packet.Effect = MsgInteract.InteractEffects.None;
  356.             }
  357.  
  358.             if (attacked.Name == "Guard1" && attacker.PlayerFlag == PlayerFlag.Monster)
  359.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  360.                 {
  361.                     #region CheakMiss
  362.                     if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  363.                         if (Kernel.ChanceSuccess(30))
  364.                         {
  365.                             MsgName str = new MsgName(true);
  366.                             str.UID = attacked.UID;
  367.                             str.TextsCount = 1;
  368.                             str.Type = MsgName.Effect;
  369.                             str.Texts.Add("poisonmiss");
  370.                             attacked.Owner.SendScreen(str, true);
  371.                             return 0;
  372.                         }
  373.                     #endregion
  374.                 }
  375.             #region PvP -- Player Vs Player -- Jugador Contra Jugador
  376.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  377.             {
  378.  
  379.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  380.                     return 1;
  381.                 if (attacked.ContainsFlag((ulong)1UL << 53))
  382.                     return 1;
  383.                 Double Damage = 0;
  384.  
  385.                 Double Reborn = 1.00;
  386.                 if (attacked.Reborn == 1)
  387.                     Reborn -= 0.30;
  388.                 else if (attacked.Reborn >= 2)
  389.                     Reborn -= 0.50;
  390.                 Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  391.  
  392.                 #region AzureShield
  393.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  394.                 {
  395.                     if (Damage > attacked.AzureShieldDefence)
  396.                     {
  397.                         Damage -= attacked.AzureShieldDefence;
  398.                         CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  399.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  400.                     }
  401.                     else
  402.                     {
  403.                         CreateAzureDmg((uint)Damage, attacker, attacked);
  404.                         attacked.AzureShieldDefence -= (ushort)Damage;
  405.                         attacked.AzureShieldPacket();
  406.                         Damage = 1;
  407.                     }
  408.                 }
  409.                 #endregion
  410.                 #region Viejos Smash & Criticos
  411.                 //#region Breakthrough
  412.                 //if (attacker.PlayerFlag == PlayerFlag.Player)
  413.                 //{
  414.                 //    if (attacker.BattlePower < attacked.BattlePower)
  415.                 //    {
  416.                 //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 5f) - (float)(attacked.Counteraction / 5f)))
  417.                 //        {
  418.                 //            Damage = (Int32)Math.Floor((float)Damage * 1.2);// 10%
  419.                 //            Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  420.                 //        }
  421.                 //    }
  422.                 //}
  423.                 //#endregion
  424.                 //#region Breakthrough -- Smash
  425.                 //if (attacker.PlayerFlag == PlayerFlag.Player)
  426.                 //{
  427.                 //    if (attacker.BattlePower >= attacked.BattlePower)
  428.                 //    {
  429.                 //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 5f) - (float)(attacked.Counteraction / 5f)))
  430.                 //        {
  431.                 //            Damage = (Int32)Math.Floor((float)Damage * 1.2);
  432.                 //            Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  433.                 //        }
  434.                 //    }
  435.                 //}
  436.                 //#endregion
  437.                 //#region CriticalStrike
  438.                 //if (attacker.PlayerFlag == PlayerFlag.Player)
  439.                 //{
  440.                 //    if (attacker.BattlePower < attacked.BattlePower)
  441.                 //    {
  442.                 //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  443.                 //        {
  444.                 //            Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  445.                 //            Damage = (UInt32)Math.Floor((float)Damage * 1.2);
  446.                 //        }
  447.                 //    }
  448.                 //}
  449.                 //#endregion
  450.                 //#region CriticalStrike
  451.                 //if (attacker.PlayerFlag == PlayerFlag.Player)
  452.                 //{
  453.                 //    if (attacker.BattlePower >= attacked.BattlePower)
  454.                 //    {
  455.                 //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 50f) - ((float)attacked.Immunity / 50f)))
  456.                 //        {
  457.                 //            Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  458.                 //            Damage = (UInt32)Math.Floor((float)Damage * 1.3);
  459.                 //        }
  460.                 //    }
  461.                 //}
  462.                 //#endregion
  463.                 #endregion
  464.                 //Damage -= attacked.Defence;
  465.                 Damage *= Reborn;
  466.                 Boolean canBT = false, CritImmune = false;
  467.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  468.                 {
  469.                     if (attacker.BattlePower < attacked.BattlePower)
  470.                     {
  471.                         canBT = true;
  472.                     }
  473.                 }
  474.                 else canBT = false;
  475.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  476.                 {
  477.                     if (canBT)
  478.                     {
  479.                         if (Kernel.Rate(((float)attacker.Breaktrough / 1f - (float)attacked.Counteraction / 2f)))
  480.                         {
  481.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  482.                             Damage = (Int32)Math.Floor((float)Damage * 1.2);//20% de Daño
  483.                         }
  484.                     }
  485.                 }
  486.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  487.                 {
  488.                     if (attacker.BattlePower >= attacked.BattlePower)
  489.                     {
  490.                         CritImmune = true;
  491.                     }
  492.                 }
  493.                 else CritImmune = false;
  494.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  495.                 {
  496.                     if (CritImmune)
  497.                     {
  498.                         if (Kernel.Rate(((float)attacker.CriticalStrike / 1f - (float)attacked.Immunity / 2f)))
  499.                         {
  500.                             Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  501.                             Damage = (Int32)Math.Floor((float)Damage * 1.4);
  502.                         }
  503.                     }
  504.                 }
  505.  
  506.  
  507.                 #region Bless Reduction
  508.  
  509.                 var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  510.                 if (reduce > 0)
  511.                 {
  512.                     Damage -= Damage * reduce / 90;
  513.                 }
  514.  
  515.                 #endregion
  516.                 if (Damage < 1)
  517.                     Damage = 1;
  518.  
  519.                 #region Sepll Bounes
  520.  
  521.                 if (spell != null)
  522.                 {
  523.                     if (spell.ID != 12290)
  524.                     {
  525.                         if (spell.PowerPercent != 0)
  526.                         {
  527.                             Damage = (Double)(Damage * spell.PowerPercent);
  528.                         }
  529.                     }
  530.                 }
  531.  
  532.                 #endregion
  533.                 #region GemBounes
  534.  
  535.                 var bonus = attacker.Gems[1];
  536.                 if (bonus > 0)
  537.                 {
  538.                     Damage += MathHelper.MulDiv((int)Damage, (int)bonus, (int)100);
  539.                 }
  540.  
  541.                 #endregion
  542.                 #region Superman & Stigma
  543.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  544.                     if (!attacker.Transformed && Damage > 1)
  545.                         Damage = (long)(Damage * 1.17);
  546.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  547.                     Damage *= 1.0; //PvP Reduction!
  548.                 #endregion
  549.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  550.                 {
  551.                     if (attacked.Action == Enums.ConquerAction.Sit)
  552.                         if (attacked.Stamina > 20)
  553.                             attacked.Stamina -= 20;
  554.                         else
  555.                             attacked.Stamina = 0;
  556.                     attacked.Action = Enums.ConquerAction.None;
  557.                 }
  558.                 if (attacker != null)
  559.                 {
  560.                     Damage += (Double)attacker.PhysicalDamageIncrease;
  561.                 }
  562.                 if (attacked != null)
  563.                 {
  564.                     Damage -= (Double)attacked.PhysicalDamageDecrease;
  565.                 }
  566.  
  567.                 AutoRespone(attacker, attacked, ref Damage);
  568.                 #region Ataque segun Nobleza - by Angel Gabriel
  569.                 #region Rey
  570.                 if (attacker.NobilityRank == ConquerStructures.NobilityRank.Rey)
  571.                 {
  572.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Rey)
  573.                     {
  574.                         Damage = (int)((double)Damage * 1.50);
  575.                     }
  576.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duque)
  577.                     {
  578.                         Damage = (int)((double)Damage * 1.5);
  579.                     }
  580.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Marques)
  581.                     {
  582.                         Damage = (int)((double)Damage * 1.6);
  583.                     }
  584.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Conde)
  585.                     {
  586.                         Damage = (int)((double)Damage * 1.7);
  587.                     }
  588.                 }
  589.                 #endregion
  590.                 #region Prince
  591.                 if (attacker.NobilityRank == ConquerStructures.NobilityRank.Duque)
  592.                 {
  593.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Rey)
  594.                     {
  595.                         Damage = (int)((double)Damage * 1.50);
  596.                     }
  597.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duque)
  598.                     {
  599.                         Damage = (int)((double)Damage * 1.80);
  600.                     }
  601.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Marques)
  602.                     {
  603.                         Damage = (int)((double)Damage * 1.55);
  604.                     }
  605.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Conde)
  606.                     {
  607.                         Damage = (int)((double)Damage * 1.5);
  608.                     }
  609.                 }
  610.                 #endregion Prince
  611.                 #region Duke
  612.                 if (attacker.NobilityRank == ConquerStructures.NobilityRank.Marques)
  613.                 {
  614.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Rey)
  615.                     {
  616.                         Damage = (int)((double)Damage * 1.43);
  617.                     }
  618.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duque)
  619.                     {
  620.                         Damage = (int)((double)Damage * 1.48);
  621.                     }
  622.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Marques)
  623.                     {
  624.                         Damage = (int)((double)Damage * 1.80);
  625.                     }
  626.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Conde)
  627.                     {
  628.                         Damage = (int)((double)Damage * 1.5);
  629.                     }
  630.                 }
  631.                 #endregion Duke
  632.                 #region Conde
  633.                 if (attacker.NobilityRank == ConquerStructures.NobilityRank.Conde)
  634.                 {
  635.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Rey)
  636.                     {
  637.                         Damage = (int)((double)Damage * 1.5);
  638.                     }
  639.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duque)
  640.                     {
  641.                         Damage = (int)((double)Damage * 1.5);
  642.                     }
  643.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Marques)
  644.                     {
  645.                         Damage = (int)((double)Damage * 1.5);
  646.                     }
  647.                     if (attacked.NobilityRank == ConquerStructures.NobilityRank.Conde)
  648.                     {
  649.                         Damage = (int)((double)Damage * 1.6);
  650.                     }
  651.                 }
  652.                 #endregion Earl
  653.                 #endregion                
  654.                 #region Block
  655.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  656.                 {
  657.                     if (Kernel.Rate(22))
  658.                     {
  659.                         if (attacked.Block > 0)
  660.                         {
  661.                             Packet.Effect |= MsgInteract.InteractEffects.Block;
  662.                             Damage = (Int32)Math.Floor((float)Damage / 2);
  663.                         }
  664.                     }
  665.                 }
  666.                 #endregion
  667.                 #region Reduction!
  668.                 #region tortoise
  669.                 double torist = (double)(attacked.Gems[GemTypes.Tortoise] / 100d);
  670.                 torist = (double)(1 - torist);
  671.                 torist = Math.Max(torist, 0.5);
  672.                 Damage *= torist;
  673.                 #endregion
  674.                 #region Clac Defence
  675.                 int nDef, defmain;
  676.                 if (!attacker.Transformed)
  677.                     nDef = defmain = attacked.Defence;
  678.                 else
  679.                     nDef = defmain = attacked.TransformationDefence;
  680.                 nDef = Handle.ShieldDefence(attacked, nDef);
  681.                 if (attacked.IsDefensiveStance)
  682.                     nDef *= 10;
  683.  
  684.                 #endregion End Defence
  685.                 #region MagicShield
  686.  
  687.                 if (!attacked.Transformed)
  688.                 {
  689.                     if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.MagicShield))
  690.                     {
  691.                         if (attacked.ShieldTime > 0)
  692.                         {
  693.                             if (Damage > (int)attacked.Defence)
  694.                             {
  695.                                 Damage -= (int)attacked.Defence;
  696.                             }
  697.                             else
  698.                                 Damage = 1;
  699.                         }
  700.                         else
  701.                         {
  702.                             if (Damage > (ushort)(attacked.Defence * attacked.MagicShieldIncrease))
  703.                                 Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  704.                             else
  705.                                 Damage = 1;
  706.                         }
  707.                     }
  708.                     else
  709.                     {
  710.                         if (Damage > (int)attacked.Defence)
  711.                         {
  712.                             Damage -= (int)attacked.Defence;
  713.                         }
  714.                         else
  715.                             Damage = 1;
  716.                     }
  717.                 }
  718.                 else
  719.                 {
  720.                     if (Damage > attacked.TransformationDefence)
  721.                     {
  722.                         Damage -= attacked.TransformationDefence;
  723.                     }
  724.                     else
  725.                         Damage = 1;
  726.                 }
  727.  
  728.                 #endregion
  729.  
  730.                 #endregion
  731.              
  732.                 if (Damage < 1)
  733.                     Damage = 1;
  734.                 return (UInt32)Math.Round(Damage, (Int32)0);
  735.             }
  736.             #endregion
  737.             #region Player Vs Monster
  738.             else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  739.             {
  740.                 int Damage = 0;
  741.                 Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  742.                 CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  743.                 return (uint)Damage;
  744.             }
  745.             #endregion
  746.             else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  747.             {
  748.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  749.                     return 1;
  750.                 if (attacked.ContainsFlag((ulong)1UL << 53))
  751.                     return 1;
  752.                 Double Damage = 0;
  753.                 Double Reborn = 1.00;
  754.                 if (attacked.Reborn == 1)
  755.                     Reborn -= 0.30; //30%
  756.                 else if (attacked.Reborn >= 2)
  757.                     Reborn -= 0.50; //50%
  758.                 Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  759.                 Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  760.                 Damage -= attacked.Defence;
  761.                 Damage *= Reborn;
  762.  
  763.                 #region Bless Reduction
  764.  
  765.                 var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  766.                 if (reduce > 0)
  767.                 {
  768.                     Damage -= Damage * reduce / 100;
  769.                 }
  770.  
  771.                 #endregion
  772.  
  773.                 if (Damage < 1)
  774.                     Damage = 1;
  775.                 Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  776.  
  777.  
  778.  
  779.  
  780.                 #region Sell Bounes
  781.  
  782.                 if (spell != null)
  783.                 {
  784.                     if (spell.PowerPercent != 0)
  785.                     {
  786.                         Damage = (long)(Damage * spell.PowerPercent);
  787.                     }
  788.                 }
  789.  
  790.                 #endregion
  791.  
  792.                 Damage -= attacked.PhysicalDamageDecrease;
  793.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  794.                 {
  795.                     if (attacked.Action == Enums.ConquerAction.Sit)
  796.                         if (attacked.Stamina > 20)
  797.                             attacked.Stamina -= 20;
  798.                         else
  799.                             attacked.Stamina = 0;
  800.                     attacked.Action = Enums.ConquerAction.None;
  801.                 }
  802.                 if (attacker.OnSuperman())
  803.                     if (attacked.PlayerFlag == PlayerFlag.Monster)
  804.                         if (attacked.MonsterInfo.Boss)
  805.                             Damage *= 2;
  806.                 if (attacker.OnSuperman())
  807.                     if (attacked.PlayerFlag == PlayerFlag.Monster)
  808.                         Damage *= 2;
  809.                 if (attacker.OnFatalStrike())
  810.                     if (attacked.PlayerFlag == PlayerFlag.Monster)
  811.                         if (!attacked.MonsterInfo.Boss)
  812.                             Damage *= 5;
  813.                         else Damage += (int)(Damage * .1);
  814.                 if (Damage < 1)
  815.                     Damage = 1;
  816.                 #region Reduction!
  817.  
  818.                 #region Clac Defence
  819.                 int nDef, defmain;
  820.                 if (!attacker.Transformed)
  821.                     nDef = defmain = attacked.Defence;
  822.                 else
  823.                     nDef = defmain = attacked.TransformationDefence;
  824.                 nDef = Handle.ShieldDefence(attacked, nDef);
  825.                 if (attacked.IsDefensiveStance)
  826.                     nDef *= 10;
  827.  
  828.                 #endregion End Defence
  829.              
  830.                 #endregion
  831.                 if (Damage < 1)
  832.                     Damage = 1;
  833.                 return (UInt32)Math.Round(Damage, (Int32)0);
  834.             }
  835.             if (attacker == null || attacked == null)
  836.                 return 0;
  837.             long attack = 0;
  838.             int defense = 0;
  839.             if (attacker.PlayerFlag == PlayerFlag.Monster)
  840.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  841.                     if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  842.                         return 0;
  843.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  844.                 return 1;
  845.             if (attacked.ContainsFlag((ulong)1UL << 53))
  846.                 return 1;
  847.             if (!attacker.Transformed)
  848.                 attack = attacker.MinAttack + random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  849.             else
  850.                 attack = attacker.TransformationMinAttack +
  851.                          random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  852.  
  853.             if (attacker != null)
  854.             {
  855.                 var bonus = attacker.Gems[1];
  856.                 if (bonus > 0)
  857.                 {
  858.                     attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  859.                 }
  860.                 // TODO: proficiency bonus
  861.             }
  862.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  863.                 if (!attacker.Transformed && attack > 1)
  864.                     attack = (long)(attack * 1.05);
  865.             if (spell != null)
  866.             {
  867.                 if (spell.PowerPercent != 0)
  868.                 {
  869.                     attack = (long)(attack * spell.PowerPercent);
  870.                 }
  871.             }
  872.             if (attacked.PlayerFlag == PlayerFlag.Player)
  873.             {
  874.                 var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  875.                 if (reducee > 0)
  876.                 {
  877.                     attack -= (attack / 2) * reducee / 100;
  878.                 }
  879.             }
  880.             if (!attacked.Transformed)
  881.             {
  882.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.MagicShield))
  883.                 {
  884.                     if (attacked.ShieldTime > 0)
  885.                         attack -= attacked.Defence;
  886.                     else
  887.                         attack -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  888.                 }
  889.                 else
  890.                 {
  891.                     defense = attacked.Defence;
  892.                 }
  893.             }
  894.             else
  895.             {
  896.                 attack -= attacked.TransformationDefence;
  897.             }
  898.  
  899.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  900.             {
  901.                 defense = (defense * 70) / 100;
  902.             }
  903.             var damage = Math.Max(1, attack - defense);
  904.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  905.             {
  906.                 damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  907.                 damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  908.                 damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  909.             }
  910.             else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  911.             {
  912.                 damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  913.                 damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  914.                     10000);
  915.                 damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  916.             }
  917.  
  918.  
  919.             var reduceee = 10;
  920.             if (attacked.PlayerFlag == PlayerFlag.Player)
  921.             {
  922.                 if (!attacked.Owner.Equipment.Free(3))
  923.                 {
  924.                     switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  925.                     {
  926.                         case 9:
  927.                             reduceee = 1000;
  928.                             break;
  929.                         case 8:
  930.                             reduceee = 500;
  931.                             break;
  932.                         case 7:
  933.                             reduceee = 200;
  934.                             break;
  935.                         case 6:
  936.                             reduceee = 100;
  937.                             break;
  938.                     }
  939.                 }
  940.             }
  941.             if (attacker.PlayerFlag == PlayerFlag.Player)
  942.             {
  943.                 var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  944.                 if (n > damage)
  945.                 {
  946.                     damage = n;
  947.                 }
  948.             }
  949.             damage = Math.Max(1, damage);
  950.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  951.             {
  952.                 damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  953.             }
  954.             if (attacked != null)
  955.             {
  956.                 var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  957.                 if (reduces > 0)
  958.                 {
  959.                     damage -= damage * reduces / 100;
  960.                 }
  961.             }
  962.             if (attacker != null)
  963.             {
  964.                 damage += attacker.PhysicalDamageIncrease;
  965.             }
  966.  
  967.             if (attacked != null)
  968.             {
  969.                 damage -= attacked.PhysicalDamageDecrease;
  970.             }
  971.          
  972.             AutoRespone(attacker, attacked, ref damage);
  973.  
  974.  
  975.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  976.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  977.                     damage *= 2;
  978.             if (attacked.Action == Enums.ConquerAction.Sit)
  979.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  980.                 {
  981.                     if (attacked.Stamina >= 20)
  982.                         attacked.Stamina -= 20;
  983.                     else
  984.                         attacked.Stamina = 0;
  985.                 }
  986.             if (attacker.OnSuperman())
  987.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  988.                     if (attacked.MonsterInfo.Boss)
  989.                         damage *= 2;
  990.  
  991.             if (attacker.OnSuperman())
  992.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  993.                     damage *= 2;
  994.             if (attacker.OnFatalStrike())
  995.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  996.                     damage *= 5;
  997.             return Math.Max((uint)1, (uint)damage);
  998.         }
  999.  
  1000.         #endregion
  1001.         private static float
  1002.         reduceValue = 0.6f,
  1003.         goldPrizePsyAttackCoefficient = .2f,
  1004.         goldPrizeMagAttackCoefficient = .2f;
  1005.  
  1006.         public static int DefaultDefense2 = 10000;
  1007.  
  1008.         public static RandomLite random = new RandomLite();
  1009.  
  1010.         private static Int32 AdjustDamageMonster2Player(Double Damage, Player Attacker, Player Target)
  1011.         {
  1012.             Byte Level = 120;
  1013.             if (Attacker.Level < 120)
  1014.                 Level = (Byte)Attacker.Level;
  1015.  
  1016.             if (Attacker.IsRed(Target))
  1017.                 Damage *= 1.5;
  1018.             else if (Attacker.IsBlack(Target))
  1019.             {
  1020.                 Int32 DeltaLvl = Target.Level - Level;
  1021.                 if (DeltaLvl >= -10 && DeltaLvl <= -5)
  1022.                     Damage *= 2.0;
  1023.                 else if (DeltaLvl >= -20 && DeltaLvl < -10)
  1024.                     Damage *= 3.5;
  1025.                 else if (DeltaLvl < -20)
  1026.                     Damage *= 5.0;
  1027.             }
  1028.  
  1029.             return Math.Max(0, (Int32)Damage);
  1030.         }
  1031.         private static Int32 AdjustMinDamagePlayer2Monster(Double Damage, Player Attacker, Player Target)
  1032.         {
  1033.             Int32 MinDmg = 1;
  1034.             MinDmg += (Int32)(Attacker.Level / 10);
  1035.             if (!Attacker.Owner.Equipment.Free(4))
  1036.             {
  1037.                 MsgItemInfo Item = Attacker.Owner.Equipment.TryGetItem(4);
  1038.                 if (Item != null)
  1039.                     MinDmg += (int)Item.ID % 10;
  1040.             }
  1041.             return Math.Max(MinDmg, (Int32)Damage);
  1042.         }
  1043.  
  1044.         private static Int32 AdjustDamagePlayer2Monster(Double Damage, Player Attacker, Player Target)
  1045.         {
  1046.             if (!Target.IsGreen(Attacker))
  1047.                 return Math.Max(0, (Int32)Damage);
  1048.  
  1049.             Int32 DeltaLvl = Attacker.Level - Target.Level;
  1050.             if (DeltaLvl >= 3 && DeltaLvl <= 5)
  1051.                 Damage *= 1.5;
  1052.             else if (DeltaLvl > 5 && DeltaLvl <= 10)
  1053.                 Damage *= 2;
  1054.             else if (DeltaLvl > 10 && DeltaLvl <= 20)
  1055.                 Damage *= 2.5;
  1056.             else if (DeltaLvl > 20)
  1057.                 Damage *= 3;
  1058.             else
  1059.                 Damage *= 1;
  1060.  
  1061.             return Math.Max(0, (Int32)Damage);
  1062.         }
  1063.         private static Int32 AdjustMinDamageMonster2Player(Double Damage, Player Attacker, Player Target)
  1064.         {
  1065.             MsgItemInfo Item = null;
  1066.             Int32 MinDmg = 7;
  1067.             if (Damage >= MinDmg || Target.Level <= 15)
  1068.                 return (Int32)Damage;
  1069.  
  1070.             MinDmg += (Int32)(Attacker.Level / 10);
  1071.             if (!Target.Owner.Equipment.Free(3))
  1072.             {
  1073.                 Item = Target.Owner.Equipment.TryGetItem(3);
  1074.                 if (Item != null)
  1075.                     MinDmg -= ((int)Item.ID % 10);
  1076.             }
  1077.             if (Item != null && (Item.ID % 10) == 0)
  1078.                 MinDmg = 1;
  1079.  
  1080.             MinDmg = Math.Max(1, MinDmg);
  1081.  
  1082.             return Math.Max(MinDmg, (Int32)Damage);
  1083.         }
  1084.  
  1085.         public static int GetDefense2(Client.GameState target, Client.GameState attacker)
  1086.         {
  1087.             if (attacker == null) return DefaultDefense2;
  1088.             if (target == null) return DefaultDefense2;
  1089.             if (attacker.Player.PlayerFlag == PlayerFlag.Player && target.Player.PlayerFlag == PlayerFlag.Player)
  1090.             {
  1091.                 if (target.Player.Reborn == 0) return DefaultDefense2;
  1092.  
  1093.                 var defense2 = (target.Player.Class % 10) >= 3 ? 7000 : DefaultDefense2;
  1094.                 if (target.Player.Reborn < 2)
  1095.                 {
  1096.                     return defense2;
  1097.                 }
  1098.  
  1099.                 var targetHero = target as Client.GameState;
  1100.                 if (targetHero != null)
  1101.                 {
  1102.                     if (attacker.Player.Reborn < 2)
  1103.                     {
  1104.                         return targetHero.Player.Reborn == 2 ? 5000 : 7000;
  1105.                     }
  1106.                 }
  1107.                 return defense2;
  1108.             }
  1109.             else
  1110.             {
  1111.                 return DefaultDefense2;
  1112.             }
  1113.         }
  1114.  
  1115.         private static int AdjustMinDamageUser2Monster(int nDamage, Player attacker, Player attacked)
  1116.         {
  1117.             int nMinDamage = 1;
  1118.             nMinDamage += attacker.Level / 10;
  1119.  
  1120.  
  1121.             if (!(attacker.PlayerFlag == PlayerFlag.Player))
  1122.                 return (nMinDamage >= nDamage) ? nMinDamage : nDamage;
  1123.  
  1124.  
  1125.             if (!attacker.Owner.Equipment.Free(Network.GamePackets.MsgItemInfo.RightWeapon))
  1126.             {
  1127.                 MsgItemInfo item = attacker.Owner.Equipment.TryGetItem(Network.GamePackets.MsgItemInfo.RightWeapon);
  1128.                 nMinDamage += (int)(item.ID % 10);
  1129.             }
  1130.             return (nMinDamage >= nDamage) ? nMinDamage : nDamage;
  1131.         }
  1132.         private static int AdjustMinDamageMonster2User(int nDamage, Player attacker, Player attacked)
  1133.         {
  1134.             int nMinDamage = 7;
  1135.             if (nDamage >= nMinDamage || attacked.Level <= 15)
  1136.                 return nDamage;
  1137.             if (!(attacked.PlayerFlag == PlayerFlag.Player))
  1138.                 return (nMinDamage >= nDamage) ? nMinDamage : nDamage;
  1139.             for (int i = 1; i < 12; i++)
  1140.             {
  1141.                 switch (i)
  1142.                 {
  1143.                     case 1:
  1144.                     case 2:
  1145.                     case 3:
  1146.                         {
  1147.                             if (!attacked.Owner.Equipment.Free((byte)i))
  1148.                             {
  1149.                                 MsgItemInfo item = attacked.Owner.Equipment.TryGetItem((byte)i);
  1150.                                 nMinDamage -= (int)(item.ID % 10) / 5;
  1151.                             }
  1152.                             break;
  1153.                         }
  1154.                 }
  1155.             }
  1156.             nMinDamage = (1 >= nMinDamage) ? 1 : nMinDamage;
  1157.             return (nMinDamage >= nDamage) ? nMinDamage : nDamage;
  1158.         }
  1159.         public static int AdjustRebirthDamage(Client.GameState target, Client.GameState attacker, int damage)
  1160.         {
  1161.             return MathHelper.MulDiv(damage, GetDefense2(target, attacker), DefaultDefense2);
  1162.         }
  1163.  
  1164.         private static int CalcDamageMonster2User(int nAtk, int nDef, int nAtkLev, int nDefLev, int nDamage)
  1165.         {
  1166.             if (nAtkLev > 120)
  1167.                 nAtkLev = 120;
  1168.             MONSTER_NAME_TYPE nNameType = GetNameType(nDefLev, nAtkLev);
  1169.             if (nNameType == MONSTER_NAME_TYPE.NAME_RED)
  1170.             {
  1171.                 nDamage = (int)(((float)nAtk * 1.5F) - nDef);
  1172.             }
  1173.             else if (nNameType == MONSTER_NAME_TYPE.NAME_BLACK)
  1174.             {
  1175.                 int nDeltaLev = nDefLev - nAtkLev;
  1176.                 if (nDeltaLev >= -10 && nDeltaLev <= -5)
  1177.                     nAtk *= 2;
  1178.                 else if (nDeltaLev >= -20 && nDeltaLev < -10)
  1179.                     nAtk = (int)((float)nAtk * 3.5F);
  1180.                 else if (nDeltaLev < -20)
  1181.                     nAtk *= 5;
  1182.                 nDamage = nAtk - nDef;
  1183.             }
  1184.             return (0 >= nDamage) ? 0 : nDamage;
  1185.         }
  1186.         private static int CalcDamageUser2Monster(int nAtk, int nDef, int nAtkLev, int nDefLev, int nDamage)
  1187.         {
  1188.             if (nAtkLev > 120)
  1189.                 nAtkLev = 120;
  1190.             if (GetNameType(nAtkLev, nDefLev) != MONSTER_NAME_TYPE.NAME_GREEN)
  1191.                 return (0 >= nDamage) ? 0 : nDamage;
  1192.             int nDeltaLev = nAtkLev - nDefLev;
  1193.             if (nDeltaLev >= 3 && nDeltaLev <= 5)
  1194.                 nAtk = (int)((float)nAtk * 1.5F);
  1195.             else if (nDeltaLev > 5 && nDeltaLev <= 10)
  1196.                 nAtk *= 2;
  1197.             else if (nDeltaLev > 10 && nDeltaLev <= 20)
  1198.                 nAtk = (int)((float)nAtk * 2.5F);
  1199.             else if (nDeltaLev > 20)
  1200.                 nAtk *= 3;
  1201.             return (0 >= nAtk - nDef) ? 0 : nAtk - nDef;
  1202.         }
  1203.  
  1204.         private enum MONSTER_NAME_TYPE
  1205.         {
  1206.             NAME_GREEN,
  1207.             NAME_WHITE,
  1208.             NAME_RED,
  1209.             NAME_BLACK,
  1210.         }
  1211.         private static MONSTER_NAME_TYPE GetNameType(int nAtkerLev, int nMonsterLev)
  1212.         {
  1213.             int nDeltaLev = nAtkerLev - nMonsterLev;
  1214.             if (nDeltaLev >= 3)
  1215.                 return MONSTER_NAME_TYPE.NAME_GREEN;
  1216.             else if (nDeltaLev >= 0)
  1217.                 return MONSTER_NAME_TYPE.NAME_WHITE;
  1218.             else if (nDeltaLev >= -5)
  1219.                 return MONSTER_NAME_TYPE.NAME_RED;
  1220.             else
  1221.                 return MONSTER_NAME_TYPE.NAME_BLACK;
  1222.         }
  1223.         #region Calculate
  1224.         public static void Immu(Player Attacked)
  1225.         {
  1226.             if (Attacked.PlayerFlag == PlayerFlag.Player)
  1227.             {
  1228.                 MsgName str = new MsgName(true);
  1229.                 str.UID = Attacked.UID;
  1230.                 str.TextsCount = 1;
  1231.                 str.Type = MsgName.Effect;
  1232.                 str.Texts.Add("bossimmunity");
  1233.                 Attacked.Owner.SendScreen(str, true);
  1234.             }
  1235.         }
  1236.         public static long RemoveExcessDamageNinja(long CurrentDamage, Player Attacker, Player Opponent)
  1237.         {
  1238.             if (Opponent.PlayerFlag != PlayerFlag.Player)
  1239.                 return CurrentDamage;
  1240.             if (Opponent.Reborn == 1)
  1241.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.8));
  1242.             else if (Opponent.Reborn == 2)
  1243.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.8));
  1244.             CurrentDamage = (long)Math.Round((double)(CurrentDamage * (Math.Max(0.1, 1.00 - (Opponent.ItemBless * 0.01)))));
  1245.             CurrentDamage -= CurrentDamage * Math.Min(Opponent.Gems[7], (ushort)75) / 100;
  1246.             return CurrentDamage;
  1247.         }
  1248.         public static long RemoveExcessDamageMonje(long CurrentDamage, Player Attacker, Player Opponent)
  1249.         {
  1250.             if (Opponent.PlayerFlag != PlayerFlag.Player)
  1251.                 return CurrentDamage;
  1252.             if (Opponent.Reborn == 1)
  1253.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.9));
  1254.             else if (Opponent.Reborn == 2)
  1255.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.8));
  1256.             CurrentDamage = (long)Math.Round((double)(CurrentDamage * (Math.Max(0.1, 1.00 - (Opponent.ItemBless * 0.01)))));
  1257.             CurrentDamage -= CurrentDamage * Math.Min(Opponent.Gems[7], (ushort)75) / 100;
  1258.             return CurrentDamage;
  1259.         }
  1260.         public static long RemoveExcessDamageWindMelee(long CurrentDamage, Player Attacker, Player Opponent)
  1261.         {
  1262.             if (Opponent.PlayerFlag != PlayerFlag.Player)
  1263.                 return CurrentDamage;
  1264.             if (Opponent.Reborn == 1)
  1265.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.8));
  1266.             else if (Opponent.Reborn == 2)
  1267.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.7));
  1268.             CurrentDamage = (long)Math.Round((double)(CurrentDamage * (Math.Max(0.1, 1.00 - (Opponent.ItemBless * 0.01)))));
  1269.             CurrentDamage -= CurrentDamage * Math.Min(Opponent.Gems[7], (ushort)75) / 100;
  1270.             return CurrentDamage;
  1271.         }
  1272.         public static long RemoveExcessDamageTroy(long CurrentDamage, Player Attacker, Player Opponent)
  1273.         {
  1274.             if (Opponent.PlayerFlag != PlayerFlag.Player)
  1275.                 return CurrentDamage;
  1276.             if (Opponent.Reborn == 1)
  1277.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.8));
  1278.             else if (Opponent.Reborn == 2)
  1279.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.7));
  1280.             CurrentDamage = (long)Math.Round((double)(CurrentDamage * (Math.Max(0.1, 1.00 - (Opponent.ItemBless * 0.01)))));
  1281.             CurrentDamage -= CurrentDamage * Math.Min(Opponent.Gems[7], (ushort)75) / 100;
  1282.             return CurrentDamage;
  1283.         }
  1284.         public static long RemoveExcessDamageGuerrero(long CurrentDamage, Player Attacker, Player Opponent)
  1285.         {
  1286.             if (Opponent.PlayerFlag != PlayerFlag.Player)
  1287.                 return CurrentDamage;
  1288.             if (Opponent.Reborn == 1)
  1289.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.8));
  1290.             else if (Opponent.Reborn == 2)
  1291.                 CurrentDamage = (long)Math.Round((double)(CurrentDamage * 1.7));
  1292.             CurrentDamage = (long)Math.Round((double)(CurrentDamage * (Math.Max(0.1, 1.00 - (Opponent.ItemBless * 0.01)))));
  1293.             CurrentDamage -= CurrentDamage * Math.Min(Opponent.Gems[7], (ushort)75) / 100;
  1294.             return CurrentDamage;
  1295.         }
  1296.         //public static uint LinearSpells(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  1297.         //{
  1298.  
  1299.         //    if (attacked.Name == "InfernalEpico") return 1;
  1300.         //    if (attacked.Name == "SilverOctopus") return 1;
  1301.         //    if (attacked.Name == "GoldenOctopus") return 1;
  1302.         //    if (Packet != null)
  1303.         //    {
  1304.         //        Packet.Effect = MsgInteract.InteractEffects.None;
  1305.         //    }
  1306.  
  1307.         //    if (attacked.Name == "Guard1" && attacker.PlayerFlag == PlayerFlag.Monster)
  1308.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  1309.         //        {
  1310.         //            #region CheakMiss
  1311.         //            if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  1312.         //                if (Kernel.ChanceSuccess(30))
  1313.         //                {
  1314.         //                    MsgName str = new MsgName(true);
  1315.         //                    str.UID = attacked.UID;
  1316.         //                    str.TextsCount = 1;
  1317.         //                    str.Type = MsgName.Effect;
  1318.         //                    str.Texts.Add("poisonmiss");
  1319.         //                    attacked.Owner.SendScreen(str, true);
  1320.         //                    return 0;
  1321.         //                }
  1322.         //            #endregion
  1323.         //        }
  1324.         //    #region PvP -- Player Vs Player -- Jugador Contra Jugador
  1325.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  1326.         //    {
  1327.  
  1328.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  1329.         //            return 1;
  1330.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  1331.         //            return 1;
  1332.         //        Double Damage = 0;
  1333.  
  1334.         //        Double Reborn = 1.00;
  1335.         //        if (attacked.Reborn == 1)
  1336.         //            Reborn -= 0.30;
  1337.         //        else if (attacked.Reborn >= 2)
  1338.         //            Reborn -= 0.50;
  1339.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  1340.         //        Boolean canBT = false, CritImmune = false;
  1341.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  1342.         //        {
  1343.         //            if (attacker.BattlePower < attacked.BattlePower)
  1344.         //            {
  1345.         //                canBT = true;
  1346.         //            }
  1347.         //        }
  1348.         //        else canBT = false;
  1349.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  1350.         //        {
  1351.         //            if (canBT)
  1352.         //            {
  1353.         //                if (Kernel.Rate(((float)attacker.Breaktrough / 1f - (float)attacked.Counteraction / 2f)))
  1354.         //                {
  1355.         //                    Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  1356.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);//30% de Daño
  1357.         //                }
  1358.         //            }
  1359.         //        }
  1360.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  1361.         //        {
  1362.         //            if (attacker.BattlePower >= attacked.BattlePower)
  1363.         //            {
  1364.         //                CritImmune = true;
  1365.         //            }
  1366.         //        }
  1367.         //        else CritImmune = false;
  1368.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  1369.         //        {
  1370.         //            if (CritImmune)
  1371.         //            {
  1372.         //                if (Kernel.Rate(((float)attacker.CriticalStrike / 1f - (float)attacked.Immunity / 2f)))
  1373.         //                {
  1374.         //                    Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  1375.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);
  1376.         //                }
  1377.         //            }
  1378.         //        }
  1379.            
  1380.         //        //#region Breakthrough -- Potencias Bajas
  1381.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  1382.         //        //{
  1383.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  1384.         //        //    {
  1385.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  1386.         //        //        {
  1387.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.4);
  1388.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  1389.         //        //        }
  1390.         //        //    }
  1391.         //        //}
  1392.         //        //#endregion
  1393.  
  1394.         //        #region Breakthrough -- Potencias Altas ((DESACTIVADO))
  1395.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  1396.         //        //{
  1397.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  1398.         //        //    {
  1399.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  1400.         //        //        {
  1401.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.05);
  1402.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  1403.         //        //        }
  1404.         //        //    }
  1405.         //        //}
  1406.         //        #endregion
  1407.  
  1408.         //        Damage *= Reborn;
  1409.         //        //#region Ataque segun Nobleza
  1410.         //        //#region Rey
  1411.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.King)
  1412.         //        //{
  1413.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  1414.         //        //    {
  1415.         //        //        Damage = (int)((double)Damage * 1.0);
  1416.         //        //    }
  1417.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  1418.         //        //    {
  1419.         //        //        Damage = (int)((double)Damage * 1.0);
  1420.         //        //    }
  1421.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  1422.         //        //    {
  1423.         //        //        Damage = (int)((double)Damage * 1.0);
  1424.         //        //    }
  1425.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  1426.         //        //    {
  1427.         //        //        Damage = (int)((double)Damage * 1.0);
  1428.         //        //    }
  1429.         //        //}
  1430.         //        //#endregion
  1431.         //        //#region Duque
  1432.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Prince)
  1433.         //        //{
  1434.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  1435.         //        //    {
  1436.         //        //        Damage = (int)((double)Damage * 1.0);
  1437.         //        //    }
  1438.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  1439.         //        //    {
  1440.         //        //        Damage = (int)((double)Damage * 1.0);
  1441.         //        //    }
  1442.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  1443.         //        //    {
  1444.         //        //        Damage = (int)((double)Damage * 1.0);
  1445.         //        //    }
  1446.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  1447.         //        //    {
  1448.         //        //        Damage = (int)((double)Damage * 1.0);
  1449.         //        //    }
  1450.         //        //}
  1451.         //        //#endregion Prince
  1452.         //        //#region Marques
  1453.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Duke)
  1454.         //        //{
  1455.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  1456.         //        //    {
  1457.         //        //        Damage = (int)((double)Damage * 1.0);
  1458.         //        //    }
  1459.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  1460.         //        //    {
  1461.         //        //        Damage = (int)((double)Damage * 1.0);
  1462.         //        //    }
  1463.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  1464.         //        //    {
  1465.         //        //        Damage = (int)((double)Damage * 1.2);
  1466.         //        //    }
  1467.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  1468.         //        //    {
  1469.         //        //        Damage = (int)((double)Damage * 1.0);
  1470.         //        //    }
  1471.         //        //}
  1472.         //        //#endregion Duke
  1473.         //        //#region Conde
  1474.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Earl)
  1475.         //        //{
  1476.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  1477.         //        //    {
  1478.         //        //        Damage = (int)((double)Damage * 1.5);
  1479.         //        //    }
  1480.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  1481.         //        //    {
  1482.         //        //        Damage = (int)((double)Damage * 1.5);
  1483.         //        //    }
  1484.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  1485.         //        //    {
  1486.         //        //        Damage = (int)((double)Damage * 1.5);
  1487.         //        //    }
  1488.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  1489.         //        //    {
  1490.         //        //        Damage = (int)((double)Damage * 1.5);
  1491.         //        //    }
  1492.         //        //}
  1493.         //        //#endregion Earl
  1494.         //        //#endregion
  1495.  
  1496.         //        #region Bless Reduction
  1497.  
  1498.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  1499.         //        if (reduce > 0)
  1500.         //        {
  1501.         //            Damage -= Damage * reduce / 100;
  1502.         //        }
  1503.  
  1504.         //        #endregion
  1505.         //        if (Damage < 1)
  1506.         //            Damage = 1;
  1507.  
  1508.         //        #region Sepll Bounes
  1509.  
  1510.         //        if (spell != null)
  1511.         //        {
  1512.         //            if (spell.ID != 12290)
  1513.         //            {
  1514.         //                if (spell.PowerPercent != 0)
  1515.         //                {
  1516.         //                    Damage = (Double)(Damage * spell.PowerPercent);
  1517.         //                }
  1518.         //            }
  1519.         //        }
  1520.  
  1521.         //        #endregion
  1522.         //        //#region CriticalStrike -- Potencias Altas VS Bajas
  1523.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  1524.         //        //{
  1525.         //        //    if (attacker.BattlePower > attacked.BattlePower)
  1526.         //        //    {
  1527.         //        //        if (attacker.CriticalStrike + 10000 > attacked.Immunity)
  1528.         //        //        {
  1529.         //        //            if (Kernel.Rate(50))
  1530.         //        //            {
  1531.         //        //                Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  1532.         //        //                Damage = (Int32)Math.Floor((float)Damage * 1.2);
  1533.         //        //                attacker.Owner.Send("Le Has Dado un Criticaso!!");
  1534.         //        //            }
  1535.         //        //        }
  1536.         //        //        else
  1537.         //        //        {
  1538.         //        //            Immu(attacked);
  1539.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Immu;
  1540.         //        //            attacker.Owner.Send("Te Anulo tu Criticaso!");
  1541.         //        //        }
  1542.         //        //    }
  1543.         //        //}
  1544.         //        //#endregion
  1545.         //        //#region CriticalStrike -- Potencias Bajas
  1546.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  1547.         //        //{
  1548.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  1549.         //        //    {
  1550.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  1551.         //        //        {
  1552.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  1553.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.2);
  1554.         //        //        }
  1555.         //        //    }
  1556.         //        //}
  1557.         //        //#endregion
  1558.         //        //#region CriticalStrike -- Potencias Altas
  1559.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  1560.         //        //{
  1561.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  1562.         //        //    {
  1563.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike) - ((float)attacked.Immunity)))
  1564.         //        //        {
  1565.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  1566.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.4);
  1567.         //        //        }
  1568.         //        //    }
  1569.         //        //}
  1570.         //        //#endregion
  1571.         //        #region Superman & Stigma
  1572.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  1573.         //            if (!attacker.Transformed && Damage > 1)
  1574.         //                Damage = (long)(Damage * 1.12);
  1575.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  1576.         //            Damage *= 1.0; //PvP Reduction!
  1577.         //        #endregion
  1578.         //        #region DragonGem
  1579.         //        var DragonBonus = attacker.Gems[GemTypes.Dragon];
  1580.         //        if (DragonBonus > 0)
  1581.         //            Damage += MathHelper.MulDiv((int)Damage, DragonBonus, 100);
  1582.         //        if (attacker.Gems[GemTypes.Dragon] >= 210)
  1583.         //            Damage += Damage * 50 / 100;
  1584.         //        #endregion
  1585.         //        #region Superman & Stigma
  1586.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  1587.         //            if (!attacker.Transformed && Damage > 1)
  1588.         //                Damage = (long)(Damage * 1.12);
  1589.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  1590.         //            Damage *= 1.0; //PvP Reduction!
  1591.  
  1592.         //        #endregion
  1593.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  1594.         //        {
  1595.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  1596.         //                if (attacked.Stamina > 20)
  1597.         //                    attacked.Stamina -= 20;
  1598.         //                else
  1599.         //                    attacked.Stamina = 0;
  1600.         //            attacked.Action = Enums.ConquerAction.None;
  1601.         //        }
  1602.         //        if (attacker != null)
  1603.         //        {
  1604.         //            Damage += (Double)attacker.PhysicalDamageIncrease;
  1605.         //        }
  1606.         //        if (attacked != null)
  1607.         //        {
  1608.         //            Damage -= (Double)attacked.PhysicalDamageDecrease;
  1609.         //        }
  1610.  
  1611.         //        AutoRespone(attacker, attacked, ref Damage);
  1612.  
  1613.         //        #region Block
  1614.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  1615.         //        {
  1616.         //            if (Kernel.Rate(22))
  1617.         //            {
  1618.         //                if (attacked.Block > 0)
  1619.         //                {
  1620.         //                    Packet.Effect |= MsgInteract.InteractEffects.Block;
  1621.         //                    Damage = (Int32)Math.Floor((float)Damage / 2);
  1622.         //                }
  1623.         //            }
  1624.         //        }
  1625.         //        #endregion
  1626.         //        #region MagicShield
  1627.  
  1628.         //        if (!attacked.Transformed)
  1629.         //        {
  1630.         //            if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.MagicShield))
  1631.         //            {
  1632.         //                if (attacked.ShieldTime > 0)
  1633.         //                {
  1634.         //                    if (Damage > (int)attacked.Defence)
  1635.         //                    {
  1636.         //                        Damage -= (int)attacked.Defence;
  1637.         //                    }
  1638.         //                    else
  1639.         //                        Damage = 1;
  1640.         //                }
  1641.         //                else
  1642.         //                {
  1643.         //                    if (Damage > (ushort)(attacked.Defence * attacked.MagicShieldIncrease))
  1644.         //                        Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  1645.         //                    else
  1646.         //                        Damage = 1;
  1647.         //                }
  1648.         //            }
  1649.         //            else
  1650.         //            {
  1651.         //                if (Damage > (int)attacked.Defence)
  1652.         //                {
  1653.         //                    Damage -= (int)attacked.Defence;
  1654.         //                }
  1655.         //                else
  1656.         //                    Damage = 1;
  1657.         //            }
  1658.         //        }
  1659.         //        else
  1660.         //        {
  1661.         //            if (Damage > attacked.TransformationDefence)
  1662.         //            {
  1663.         //                Damage -= attacked.TransformationDefence;
  1664.         //            }
  1665.         //            else
  1666.         //                Damage = 1;
  1667.         //        }
  1668.  
  1669.         //        #endregion
  1670.         //        #region Reduction!
  1671.         //        #region Clac Defence
  1672.         //        int nDef, defmain;
  1673.         //        if (!attacker.Transformed)
  1674.         //            nDef = defmain = attacked.Defence;
  1675.         //        else
  1676.         //            nDef = defmain = attacked.TransformationDefence;
  1677.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  1678.         //        if (attacked.IsDefensiveStance)
  1679.         //            nDef *= 3;
  1680.  
  1681.         //        #endregion End Defence
  1682.                
  1683.         //        #endregion
  1684.         //        Damage = RemoveExcessDamageTroy((long)Damage, attacker, attacked);
  1685.         //        if (Damage < 1)
  1686.         //            Damage = 1;
  1687.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  1688.         //    }
  1689.         //    #endregion
  1690.         //    #region Player Vs Monster
  1691.         //    else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  1692.         //    {
  1693.         //        int Damage = 0;
  1694.         //        Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  1695.         //        CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  1696.         //        return (uint)Damage;
  1697.         //    }
  1698.         //    #endregion
  1699.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  1700.         //    {
  1701.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  1702.         //            return 1;
  1703.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  1704.         //            return 1;
  1705.         //        Double Damage = 0;
  1706.         //        Double Reborn = 1.00;
  1707.         //        if (attacked.Reborn == 1)
  1708.         //            Reborn -= 0.30; //30%
  1709.         //        else if (attacked.Reborn >= 2)
  1710.         //            Reborn -= 0.50; //50%
  1711.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  1712.         //        Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  1713.         //        Damage -= attacked.Defence;
  1714.         //        Damage *= Reborn;
  1715.  
  1716.         //        #region Bless Reduction
  1717.  
  1718.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  1719.         //        if (reduce > 0)
  1720.         //        {
  1721.         //            Damage -= Damage * reduce / 100;
  1722.         //        }
  1723.  
  1724.         //        #endregion
  1725.  
  1726.         //        if (Damage < 1)
  1727.         //            Damage = 1;
  1728.         //        Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  1729.  
  1730.  
  1731.  
  1732.  
  1733.         //        #region Sell Bounes
  1734.  
  1735.         //        if (spell != null)
  1736.         //        {
  1737.         //            if (spell.PowerPercent != 0)
  1738.         //            {
  1739.         //                Damage = (long)(Damage * spell.PowerPercent);
  1740.         //            }
  1741.         //        }
  1742.  
  1743.         //        #endregion
  1744.  
  1745.         //        Damage -= attacked.PhysicalDamageDecrease;
  1746.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  1747.         //        {
  1748.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  1749.         //                if (attacked.Stamina > 20)
  1750.         //                    attacked.Stamina -= 20;
  1751.         //                else
  1752.         //                    attacked.Stamina = 0;
  1753.         //            attacked.Action = Enums.ConquerAction.None;
  1754.         //        }
  1755.         //        if (attacker.OnSuperman())
  1756.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  1757.         //                if (attacked.MonsterInfo.Boss)
  1758.         //                    Damage *= 2;
  1759.         //        if (attacker.OnSuperman())
  1760.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  1761.         //                Damage *= 2;
  1762.         //        if (attacker.OnFatalStrike())
  1763.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  1764.         //                if (!attacked.MonsterInfo.Boss)
  1765.         //                    Damage *= 5;
  1766.         //                else Damage += (int)(Damage * .1);
  1767.         //        if (Damage < 1)
  1768.         //            Damage = 1;
  1769.         //        #region Reduction!
  1770.  
  1771.         //        #region Clac Defence
  1772.         //        int nDef, defmain;
  1773.         //        if (!attacker.Transformed)
  1774.         //            nDef = defmain = attacked.Defence;
  1775.         //        else
  1776.         //            nDef = defmain = attacked.TransformationDefence;
  1777.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  1778.         //        if (attacked.IsDefensiveStance)
  1779.         //            nDef *= 3;
  1780.  
  1781.         //        #endregion End Defence
  1782.            
  1783.         //        #endregion
  1784.         //        if (Damage < 1)
  1785.         //            Damage = 1;
  1786.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  1787.         //    }
  1788.         //    if (attacker == null || attacked == null)
  1789.         //        return 0;
  1790.         //    long attack = 0;
  1791.         //    int defense = 0;
  1792.         //    if (attacker.PlayerFlag == PlayerFlag.Monster)
  1793.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  1794.         //            if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  1795.         //                return 0;
  1796.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  1797.         //        return 1;
  1798.         //    if (attacked.ContainsFlag((ulong)1UL << 53))
  1799.         //        return 1;
  1800.         //    if (!attacker.Transformed)
  1801.         //        attack = attacker.MinAttack + random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  1802.         //    else
  1803.         //        attack = attacker.TransformationMinAttack +
  1804.         //                 random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  1805.  
  1806.         //    if (attacker != null)
  1807.         //    {
  1808.         //        var bonus = attacker.Gems[1];
  1809.         //        if (bonus > 0)
  1810.         //        {
  1811.         //            attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  1812.         //        }
  1813.         //        // TODO: proficiency bonus
  1814.         //    }
  1815.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  1816.         //        if (!attacker.Transformed && attack > 1)
  1817.         //            attack = (long)(attack * 1.17);
  1818.         //    if (spell != null)
  1819.         //    {
  1820.         //        if (spell.PowerPercent != 0)
  1821.         //        {
  1822.         //            attack = (long)(attack * spell.PowerPercent);
  1823.         //        }
  1824.         //    }
  1825.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  1826.         //    {
  1827.         //        var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  1828.         //        if (reducee > 0)
  1829.         //        {
  1830.         //            attack -= (attack / 2) * reducee / 100;
  1831.         //        }
  1832.         //    }
  1833.  
  1834.  
  1835.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  1836.         //    {
  1837.         //        defense = (defense * 70) / 100;
  1838.         //    }
  1839.         //    var damage = Math.Max(1, attack - defense);
  1840.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  1841.         //    {
  1842.         //        damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  1843.         //        damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  1844.         //        damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  1845.         //    }
  1846.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  1847.         //    {
  1848.         //        damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  1849.         //        damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  1850.         //            10000);
  1851.         //        damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  1852.         //    }
  1853.  
  1854.  
  1855.         //    var reduceee = 10;
  1856.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  1857.         //    {
  1858.         //        if (!attacked.Owner.Equipment.Free(3))
  1859.         //        {
  1860.         //            switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  1861.         //            {
  1862.         //                case 9:
  1863.         //                    reduceee = 1000;
  1864.         //                    break;
  1865.         //                case 8:
  1866.         //                    reduceee = 500;
  1867.         //                    break;
  1868.         //                case 7:
  1869.         //                    reduceee = 200;
  1870.         //                    break;
  1871.         //                case 6:
  1872.         //                    reduceee = 100;
  1873.         //                    break;
  1874.         //            }
  1875.         //        }
  1876.         //    }
  1877.         //    if (attacker.PlayerFlag == PlayerFlag.Player)
  1878.         //    {
  1879.         //        var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  1880.         //        if (n > damage)
  1881.         //        {
  1882.         //            damage = n;
  1883.         //        }
  1884.         //    }
  1885.         //    damage = Math.Max(1, damage);
  1886.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  1887.         //    {
  1888.         //        damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  1889.         //    }
  1890.         //    if (attacked != null)
  1891.         //    {
  1892.         //        var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  1893.         //        if (reduces > 0)
  1894.         //        {
  1895.         //            damage -= damage * reduces / 100;
  1896.         //        }
  1897.         //    }
  1898.         //    if (attacker != null)
  1899.         //    {
  1900.         //        damage += attacker.PhysicalDamageIncrease;
  1901.         //    }
  1902.  
  1903.         //    if (attacked != null)
  1904.         //    {
  1905.         //        damage -= attacked.PhysicalDamageDecrease;
  1906.         //    }
  1907.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  1908.         //    {
  1909.         //        if (attacked.AzureDamage >= damage)
  1910.         //        {
  1911.         //            attacked.AzureDamage -= (int)damage;
  1912.         //            int sec = 60 - (Time32.Now - attacked.MagicShieldStamp).TotalMilliseconds;
  1913.         //            attacked.Owner.Send(Constants.Shield(attacked.AzureDamage, sec));
  1914.         //            return 1;
  1915.         //        }
  1916.         //        else
  1917.         //        {
  1918.         //            damage -= attacked.AzureDamage;
  1919.         //            attacked.AzureDamage = 0;
  1920.         //            attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  1921.         //        }
  1922.         //    }
  1923.         //    AutoRespone(attacker, attacked, ref damage);
  1924.  
  1925.  
  1926.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  1927.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  1928.         //            damage *= 2;
  1929.         //    if (attacked.Action == Enums.ConquerAction.Sit)
  1930.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  1931.         //        {
  1932.         //            if (attacked.Stamina >= 20)
  1933.         //                attacked.Stamina -= 20;
  1934.         //            else
  1935.         //                attacked.Stamina = 0;
  1936.         //        }
  1937.         //    if (attacker.OnSuperman())
  1938.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  1939.         //            if (attacked.MonsterInfo.Boss)
  1940.         //                damage *= 2;
  1941.  
  1942.         //    if (attacker.OnSuperman())
  1943.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  1944.         //            damage *= 2;
  1945.         //    if (attacker.OnFatalStrike())
  1946.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  1947.         //            damage *= 5;
  1948.         //    return Math.Max((uint)1, (uint)damage);
  1949.         //}
  1950.         //public static uint Guerrero(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  1951.         //{
  1952.  
  1953.         //    if (attacked.Name == "InfernalEpico") return 1;
  1954.         //    if (attacked.Name == "SilverOctopus") return 1;
  1955.         //    if (attacked.Name == "GoldenOctopus") return 1;
  1956.         //    if (Packet != null)
  1957.         //    {
  1958.         //        Packet.Effect = MsgInteract.InteractEffects.None;
  1959.         //    }
  1960.  
  1961.         //    if (attacked.Name == "Guard1" && attacker.PlayerFlag == PlayerFlag.Monster)
  1962.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  1963.         //        {
  1964.         //            #region CheakMiss
  1965.         //            if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  1966.         //                if (Kernel.ChanceSuccess(30))
  1967.         //                {
  1968.         //                    MsgName str = new MsgName(true);
  1969.         //                    str.UID = attacked.UID;
  1970.         //                    str.TextsCount = 1;
  1971.         //                    str.Type = MsgName.Effect;
  1972.         //                    str.Texts.Add("poisonmiss");
  1973.         //                    attacked.Owner.SendScreen(str, true);
  1974.         //                    return 0;
  1975.         //                }
  1976.         //            #endregion
  1977.         //        }
  1978.         //    #region PvP -- Player Vs Player -- Jugador Contra Jugador
  1979.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  1980.         //    {
  1981.  
  1982.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  1983.         //            return 1;
  1984.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  1985.         //            return 1;
  1986.         //        Double Damage = 0;
  1987.  
  1988.         //        Double Reborn = 1.00;
  1989.         //        if (attacked.Reborn == 1)
  1990.         //            Reborn -= 0.30;
  1991.         //        else if (attacked.Reborn >= 2)
  1992.         //            Reborn -= 0.50;
  1993.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  1994.         //        #region Critico e Inmunidad
  1995.         //        Boolean canBT = false, CritImmune = false;
  1996.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  1997.         //        {
  1998.         //            if (attacker.BattlePower < attacked.BattlePower)
  1999.         //            {
  2000.         //                canBT = true;
  2001.         //            }
  2002.         //        }
  2003.         //        else canBT = false;
  2004.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  2005.         //        {
  2006.         //            if (canBT)
  2007.         //            {
  2008.         //                if (Kernel.Rate(((float)attacker.Breaktrough / 1f - (float)attacked.Counteraction / 2f)))
  2009.         //                {
  2010.         //                    Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  2011.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);//30% de Daño
  2012.         //                }
  2013.         //            }
  2014.         //        }
  2015.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  2016.         //        {
  2017.         //            if (attacker.BattlePower >= attacked.BattlePower)
  2018.         //            {
  2019.         //                CritImmune = true;
  2020.         //            }
  2021.         //        }
  2022.         //        else CritImmune = false;
  2023.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  2024.         //        {
  2025.         //            if (CritImmune)
  2026.         //            {
  2027.         //                if (Kernel.Rate(((float)attacker.CriticalStrike / 1f - (float)attacked.Immunity / 2f)))
  2028.         //                {
  2029.         //                    Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  2030.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);
  2031.         //                }
  2032.         //            }
  2033.         //        }
  2034.         //        #endregion
  2035.         //        //Damage -= attacked.Defence;
  2036.         //        #region AzureShield
  2037.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  2038.         //        {
  2039.         //            if (Damage > attacked.AzureShieldDefence)
  2040.         //            {
  2041.         //                Damage -= attacked.AzureShieldDefence;
  2042.         //                CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  2043.         //                attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  2044.         //            }
  2045.         //            else
  2046.         //            {
  2047.         //                CreateAzureDmg((uint)Damage, attacker, attacked);
  2048.         //                attacked.AzureShieldDefence -= (ushort)Damage;
  2049.         //                attacked.AzureShieldPacket();
  2050.         //                Damage = 1;
  2051.         //            }
  2052.         //        }
  2053.         //        if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield))
  2054.         //        {
  2055.  
  2056.         //            if (Damage > attacked.AzureShieldDefence)
  2057.         //            {
  2058.         //                Damage -= attacked.AzureShieldDefence;
  2059.         //                CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  2060.         //                attacked.RemoveFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield);
  2061.         //            }
  2062.         //            else
  2063.         //            {
  2064.         //                CreateAzureDmg((uint)Damage, attacker, attacked);
  2065.         //                attacked.AzureShieldDefence -= (ushort)Damage;
  2066.         //                attacked.AzureShieldPacket();
  2067.         //                Damage = 1;
  2068.         //            }
  2069.         //        }
  2070.                
  2071.         //        #endregion
  2072.         //        #region Breakthrough -- Potencias Altas ((DESACTIVADO))
  2073.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2074.         //        //{
  2075.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  2076.         //        //    {
  2077.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  2078.         //        //        {
  2079.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.05);
  2080.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  2081.         //        //        }
  2082.         //        //    }
  2083.         //        //}
  2084.         //        #endregion
  2085.         //        Damage *= Reborn;
  2086.         //        #region Bless Reduction
  2087.  
  2088.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  2089.         //        if (reduce > 0)
  2090.         //        {
  2091.         //            Damage -= Damage * reduce / 100;
  2092.         //        }
  2093.  
  2094.         //        #endregion
  2095.         //        if (Damage < 1)
  2096.         //            Damage = 1;
  2097.  
  2098.         //        #region Sepll Bounes
  2099.  
  2100.         //        if (spell != null)
  2101.         //        {
  2102.         //            if (spell.ID != 12290)
  2103.         //            {
  2104.         //                if (spell.PowerPercent != 0)
  2105.         //                {
  2106.         //                    Damage = (Double)(Damage * spell.PowerPercent);
  2107.         //                }
  2108.         //            }
  2109.         //        }
  2110.  
  2111.         //        #endregion
  2112.         //        #region Codigos QUE NO SE USAN POR EL MOMENTO
  2113.         //        //#region Breakthrough -- Potencias Bajas
  2114.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2115.         //        //{
  2116.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  2117.         //        //    {
  2118.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  2119.         //        //        {
  2120.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.4);
  2121.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  2122.         //        //        }
  2123.         //        //    }
  2124.         //        //}
  2125.         //        //#endregion
  2126.         //        //#region CriticalStrike -- Potencias Altas VS Bajas
  2127.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2128.         //        //{
  2129.         //        //    if (attacker.BattlePower > attacked.BattlePower)
  2130.         //        //    {
  2131.         //        //        if (attacker.CriticalStrike + 10000 > attacked.Immunity)
  2132.         //        //        {
  2133.         //        //            if (Kernel.Rate(50))
  2134.         //        //            {
  2135.         //        //                Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  2136.         //        //                Damage = (Int32)Math.Floor((float)Damage * 1.2);
  2137.         //        //                attacker.Owner.Send("Le Has Dado un Criticaso!!");
  2138.         //        //            }
  2139.         //        //        }
  2140.         //        //        else
  2141.         //        //        {
  2142.         //        //            Immu(attacked);
  2143.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Immu;
  2144.         //        //            attacker.Owner.Send("Te Anulo tu Criticaso!");
  2145.         //        //        }
  2146.         //        //    }
  2147.         //        //}
  2148.         //        //#endregion
  2149.         //        //#region CriticalStrike -- Potencias Bajas
  2150.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2151.         //        //{
  2152.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  2153.         //        //    {
  2154.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  2155.         //        //        {
  2156.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  2157.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.2);
  2158.         //        //        }
  2159.         //        //    }
  2160.         //        //}
  2161.         //        //#endregion
  2162.         //        //#region CriticalStrike -- Potencias Altas
  2163.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2164.         //        //{
  2165.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  2166.         //        //    {
  2167.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike) - ((float)attacked.Immunity)))
  2168.         //        //        {
  2169.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  2170.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.4);
  2171.         //        //        }
  2172.         //        //    }
  2173.         //        //}
  2174.         //        //#endregion
  2175.         //        #endregion
  2176.         //        #region Superman & Stigma
  2177.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  2178.         //            if (!attacker.Transformed && Damage > 1)
  2179.         //                Damage = (long)(Damage * 1.12);
  2180.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  2181.         //            Damage *= 1.0; //PvP Reduction!
  2182.         //        #endregion
  2183.         //        #region DragonGem
  2184.         //        var DragonBonus = attacker.Gems[GemTypes.Dragon];
  2185.         //        if (DragonBonus > 0)
  2186.         //            Damage += MathHelper.MulDiv((int)Damage, DragonBonus, 100);
  2187.         //        if (attacker.Gems[GemTypes.Dragon] >= 210)
  2188.         //            Damage += Damage * 50 / 100;
  2189.         //        #endregion
  2190.         //        #region Efectos Perfectos
  2191.         //        /*
  2192.         //        if (attacker.PrefictionEffect != null)
  2193.         //        {
  2194.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  2195.         //            if (Kernel.ChanceSuccess(40))//30% Probabilidad de Que Salga
  2196.         //            {
  2197.         //                if (attacker.PrefictionLevel > attacked.PrefictionLevel)
  2198.         //                {
  2199.         //                    Network.Writer.WriteUInt16((ushort)(1 << 10), 36, Packet.ToArray());
  2200.         //                    attacker.Owner.SendScreen(MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike));
  2201.         //                    Damage += Damage * 0.8;
  2202.         //                }
  2203.         //                else
  2204.         //                {
  2205.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  2206.         //                }
  2207.         //            }
  2208.         //        }
  2209.         //        if (attacker.PrefictionEffect != null)
  2210.         //        {
  2211.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  2212.         //            if (Kernel.Rate(eff.Percant))
  2213.         //            {
  2214.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike);
  2215.         //                Damage += Damage;
  2216.         //            }
  2217.         //            eff = attacker.PrefictionEffect.GetCalmWind();
  2218.         //            if (Kernel.Rate(eff.Percant))
  2219.         //            {
  2220.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.CalmWind);
  2221.         //                foreach (var item in attacker.Owner.Spells.Values)
  2222.         //                    item.AttackStamp = Time64.Now.AddSeconds(-50);
  2223.         //            }
  2224.         //            eff = attacker.PrefictionEffect.GetDrainingTouch();
  2225.         //            if (Kernel.Rate(eff.Percant))
  2226.         //            {
  2227.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.DrainingTouch);
  2228.         //                attacker.Hitpoints = attacker.MaxHitpoints;
  2229.         //                attacker.Mana = attacker.MaxMana;
  2230.         //            }
  2231.         //            eff = attacker.PrefictionEffect.GetKillingFlash();
  2232.         //            if (Kernel.Rate(eff.Percant))
  2233.         //            {
  2234.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.MirrorofSin);
  2235.         //                attacker.Owner.XPCount = 100;
  2236.         //            }
  2237.         //            if (attacked.PrefictionLevel > attacker.PrefictionLevel)
  2238.         //            {
  2239.         //                if (Damage >= attacked.MaxHitpoints / 2)
  2240.         //                {
  2241.         //                    eff = attacker.PrefictionEffect.GetLightofStamina();
  2242.         //                    if (Kernel.Rate(eff.Percant))
  2243.         //                    {
  2244.         //                        MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.LightofStamina);
  2245.         //                        attacker.Stamina = 150;
  2246.         //                    }
  2247.         //                }
  2248.         //            }
  2249.         //        }
  2250.         //        #region Prefiction on attacked from monster
  2251.         //        if (attacked.PrefictionEffect != null)
  2252.         //        {
  2253.         //            var eff = attacked.PrefictionEffect.GetStrikeLock();
  2254.         //            if (Kernel.Rate(eff.Percant))
  2255.         //            {
  2256.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  2257.         //                return 0;
  2258.         //            }
  2259.         //            eff = attacked.PrefictionEffect.GetBloodSpawn();
  2260.         //            if (Kernel.Rate(eff.Percant))
  2261.         //            {
  2262.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.BloodSpawn);
  2263.         //                attacked.Hitpoints = attacked.MaxHitpoints;
  2264.         //                attacked.Mana = attacked.MaxMana;
  2265.         //            }
  2266.         //            eff = attacked.PrefictionEffect.GetMirrorofSin();
  2267.         //            if (Kernel.Rate(eff.Percant))
  2268.         //            {
  2269.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.MirrorofSin);
  2270.         //                attacked.Owner.XPCount = 100;
  2271.         //            }
  2272.         //            if (attacked != null && attacked.PrefictionLevel >= attacker.PrefictionLevel)
  2273.         //            {
  2274.         //                eff = attacker.PrefictionEffect.GetShieldBreak();
  2275.         //                if (Kernel.Rate(eff.Percant))
  2276.         //                {
  2277.         //                    MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.ShieldBreak);
  2278.         //                    attacked.AddFlag3(MsgUpdate.Flags.ShieldBreak);
  2279.         //                    attacked.ShieldBreakStamp = Time64.Now;
  2280.         //                }
  2281.         //            }
  2282.         //            if (attacked != null && attacked.PrefictionLevel > attacker.PrefictionLevel)
  2283.         //            {
  2284.         //                eff = attacked.PrefictionEffect.GetDivineGuard();
  2285.         //                if (Kernel.Rate(eff.Percant))
  2286.         //                {
  2287.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.DivineGuard);
  2288.         //                    attacked.AddFlag3(MsgUpdate.Flags.DivineGuard);
  2289.         //                    attacked.DivineGuardStamp = Time64.Now;
  2290.         //                }
  2291.         //            }
  2292.  
  2293.         //        }
  2294.         //        #endregion
  2295.         //        */
  2296.         //        #endregion
  2297.         //        #region Superman & Stigma
  2298.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  2299.         //            if (!attacker.Transformed && Damage > 1)
  2300.         //                Damage = (long)(Damage * 1.12);
  2301.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  2302.         //            Damage *= 1.0; //PvP Reduction!
  2303.  
  2304.         //        #endregion
  2305.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  2306.         //        {
  2307.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  2308.         //                if (attacked.Stamina > 20)
  2309.         //                    attacked.Stamina -= 20;
  2310.         //                else
  2311.         //                    attacked.Stamina = 0;
  2312.         //            attacked.Action = Enums.ConquerAction.None;
  2313.         //        }
  2314.         //        if (attacker != null)
  2315.         //        {
  2316.         //            Damage += (Double)attacker.PhysicalDamageIncrease;
  2317.         //        }
  2318.         //        if (attacked != null)
  2319.         //        {
  2320.         //            Damage -= (Double)attacked.PhysicalDamageDecrease;
  2321.         //        }
  2322.  
  2323.         //        AutoRespone(attacker, attacked, ref Damage);
  2324.  
  2325.         //        #region Block
  2326.         //        #region Block 1
  2327.         //        int nAtk = attacked.Defence;
  2328.         //        uint remove = 0;
  2329.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShieldBreak))
  2330.         //            remove = 2000;
  2331.         //        if (Kernel.Rate(((attacked.Block - remove) / 100)) && attacked.Block > 0)
  2332.         //        {
  2333.         //            Packet.Effect |= MsgInteract.InteractEffects.Block;
  2334.         //            int blockdamage = ((nAtk * (attacked.Block / 100)) / 100);
  2335.         //            if (Damage > blockdamage)
  2336.         //                Damage -= blockdamage;
  2337.         //            else
  2338.         //                Damage = 1;
  2339.         //        }
  2340.         //        #endregion
  2341.  
  2342.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  2343.         //        {
  2344.         //            if (Kernel.Rate(22))
  2345.         //            {
  2346.         //                if (attacked.Block > 0)
  2347.         //                {
  2348.         //                    Packet.Effect |= MsgInteract.InteractEffects.Block;
  2349.         //                    Damage = (Int32)Math.Floor((float)Damage / 2);
  2350.         //                }
  2351.         //            }
  2352.         //        }
  2353.         //        #endregion
  2354.         //        #region MagicShield
  2355.  
  2356.         //        if (!attacked.Transformed)
  2357.         //        {
  2358.         //            if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.MagicShield))
  2359.         //            {
  2360.         //                if (attacked.ShieldTime > 0)
  2361.         //                {
  2362.         //                    if (Damage > (int)attacked.Defence)
  2363.         //                    {
  2364.         //                        Damage -= (int)attacked.Defence;
  2365.         //                    }
  2366.         //                    else
  2367.         //                        Damage = 1;
  2368.         //                }
  2369.         //                else
  2370.         //                {
  2371.         //                    if (Damage > (ushort)(attacked.Defence * attacked.MagicShieldIncrease))
  2372.         //                        Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  2373.         //                    else
  2374.         //                        Damage = 1;
  2375.         //                }
  2376.         //            }
  2377.         //            else
  2378.         //            {
  2379.         //                if (Damage > (int)attacked.Defence)
  2380.         //                {
  2381.         //                    Damage -= (int)attacked.Defence;
  2382.         //                }
  2383.         //                else
  2384.         //                    Damage = 1;
  2385.         //            }
  2386.         //        }
  2387.         //        else
  2388.         //        {
  2389.         //            if (Damage > attacked.TransformationDefence)
  2390.         //            {
  2391.         //                Damage -= attacked.TransformationDefence;
  2392.         //            }
  2393.         //            else
  2394.         //                Damage = 1;
  2395.         //        }
  2396.  
  2397.         //        #endregion
  2398.         //        #region Reduction!
  2399.  
  2400.         //        #region Clac Defence
  2401.         //        int nDef, defmain;
  2402.         //        if (!attacker.Transformed)
  2403.         //            nDef = defmain = attacked.Defence;
  2404.         //        else
  2405.         //            nDef = defmain = attacked.TransformationDefence;
  2406.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  2407.         //        if (attacked.IsDefensiveStance)
  2408.         //            nDef *= 3;
  2409.         //        //
  2410.  
  2411.         //        //
  2412.         //        #endregion
  2413.  
  2414.         //        #endregion
  2415.         //        //Test
  2416.  
  2417.         //        Damage -= nDef;
  2418.         //        Damage = RemoveExcessDamageGuerrero((long)Damage, attacker, attacked);
  2419.         //        if (Damage < 1)
  2420.         //            Damage = 1;
  2421.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  2422.         //    }
  2423.         //    #endregion
  2424.         //    #region Player Vs Monster
  2425.         //    else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  2426.         //    {
  2427.         //        int Damage = 0;
  2428.         //        Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  2429.         //        CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  2430.         //        return (uint)Damage;
  2431.         //    }
  2432.         //    #endregion
  2433.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  2434.         //    {
  2435.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  2436.         //            return 1;
  2437.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  2438.         //            return 1;
  2439.         //        Double Damage = 0;
  2440.         //        Double Reborn = 1.00;
  2441.         //        if (attacked.Reborn == 1)
  2442.         //            Reborn -= 0.30; //30%
  2443.         //        else if (attacked.Reborn >= 2)
  2444.         //            Reborn -= 0.50; //50%
  2445.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  2446.         //        Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  2447.         //        Damage -= attacked.Defence;
  2448.         //        Damage *= Reborn;
  2449.  
  2450.         //        #region Bless Reduction
  2451.  
  2452.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  2453.         //        if (reduce > 0)
  2454.         //        {
  2455.         //            Damage -= Damage * reduce / 100;
  2456.         //        }
  2457.  
  2458.         //        #endregion
  2459.  
  2460.         //        if (Damage < 1)
  2461.         //            Damage = 1;
  2462.         //        Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  2463.  
  2464.  
  2465.  
  2466.  
  2467.         //        #region Sell Bounes
  2468.  
  2469.         //        if (spell != null)
  2470.         //        {
  2471.         //            if (spell.PowerPercent != 0)
  2472.         //            {
  2473.         //                Damage = (long)(Damage * spell.PowerPercent);
  2474.         //            }
  2475.         //        }
  2476.  
  2477.         //        #endregion
  2478.  
  2479.         //        Damage -= attacked.PhysicalDamageDecrease;
  2480.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  2481.         //        {
  2482.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  2483.         //                if (attacked.Stamina > 20)
  2484.         //                    attacked.Stamina -= 20;
  2485.         //                else
  2486.         //                    attacked.Stamina = 0;
  2487.         //            attacked.Action = Enums.ConquerAction.None;
  2488.         //        }
  2489.         //        if (attacker.OnSuperman())
  2490.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  2491.         //                if (attacked.MonsterInfo.Boss)
  2492.         //                    Damage *= 2;
  2493.         //        if (attacker.OnSuperman())
  2494.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  2495.         //                Damage *= 2;
  2496.         //        if (attacker.OnFatalStrike())
  2497.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  2498.         //                if (!attacked.MonsterInfo.Boss)
  2499.         //                    Damage *= 5;
  2500.         //                else Damage += (int)(Damage * .1);
  2501.         //        if (Damage < 1)
  2502.         //            Damage = 1;
  2503.         //        #region Reduction!
  2504.  
  2505.         //        #region Clac Defence
  2506.         //        int nDef, defmain;
  2507.         //        if (!attacker.Transformed)
  2508.         //            nDef = defmain = attacked.Defence;
  2509.         //        else
  2510.         //            nDef = defmain = attacked.TransformationDefence;
  2511.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  2512.         //        if (attacked.IsDefensiveStance)
  2513.         //            nDef *= 3;
  2514.  
  2515.         //        #endregion End Defence
  2516.              
  2517.         //        #endregion
  2518.         //        if (Damage < 1)
  2519.         //            Damage = 1;
  2520.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  2521.         //    }
  2522.         //    if (attacker == null || attacked == null)
  2523.         //        return 0;
  2524.         //    long attack = 0;
  2525.         //    int defense = 0;
  2526.         //    if (attacker.PlayerFlag == PlayerFlag.Monster)
  2527.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  2528.         //            if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  2529.         //                return 0;
  2530.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  2531.         //        return 1;
  2532.         //    if (attacked.ContainsFlag((ulong)1UL << 53))
  2533.         //        return 1;
  2534.         //    if (!attacker.Transformed)
  2535.         //        attack = attacker.MinAttack + random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  2536.         //    else
  2537.         //        attack = attacker.TransformationMinAttack +
  2538.         //                 random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  2539.  
  2540.         //    if (attacker != null)
  2541.         //    {
  2542.         //        var bonus = attacker.Gems[1];
  2543.         //        if (bonus > 0)
  2544.         //        {
  2545.         //            attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  2546.         //        }
  2547.         //        // TODO: proficiency bonus
  2548.         //    }
  2549.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  2550.         //        if (!attacker.Transformed && attack > 1)
  2551.         //            attack = (long)(attack * 1.17);
  2552.         //    if (spell != null)
  2553.         //    {
  2554.         //        if (spell.PowerPercent != 0)
  2555.         //        {
  2556.         //            attack = (long)(attack * spell.PowerPercent);
  2557.         //        }
  2558.         //    }
  2559.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  2560.         //    {
  2561.         //        var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  2562.         //        if (reducee > 0)
  2563.         //        {
  2564.         //            attack -= (attack / 2) * reducee / 100;
  2565.         //        }
  2566.         //    }
  2567.  
  2568.  
  2569.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  2570.         //    {
  2571.         //        defense = (defense * 70) / 100;
  2572.         //    }
  2573.         //    var damage = Math.Max(1, attack - defense);
  2574.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  2575.         //    {
  2576.         //        damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  2577.         //        damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  2578.         //        damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  2579.         //    }
  2580.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  2581.         //    {
  2582.         //        damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  2583.         //        damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  2584.         //            10000);
  2585.         //        damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  2586.         //    }
  2587.  
  2588.  
  2589.         //    var reduceee = 10;
  2590.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  2591.         //    {
  2592.         //        if (!attacked.Owner.Equipment.Free(3))
  2593.         //        {
  2594.         //            switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  2595.         //            {
  2596.         //                case 9:
  2597.         //                    reduceee = 1000;
  2598.         //                    break;
  2599.         //                case 8:
  2600.         //                    reduceee = 500;
  2601.         //                    break;
  2602.         //                case 7:
  2603.         //                    reduceee = 200;
  2604.         //                    break;
  2605.         //                case 6:
  2606.         //                    reduceee = 100;
  2607.         //                    break;
  2608.         //            }
  2609.         //        }
  2610.         //    }
  2611.         //    if (attacker.PlayerFlag == PlayerFlag.Player)
  2612.         //    {
  2613.         //        var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  2614.         //        if (n > damage)
  2615.         //        {
  2616.         //            damage = n;
  2617.         //        }
  2618.         //    }
  2619.         //    damage = Math.Max(1, damage);
  2620.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  2621.         //    {
  2622.         //        damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  2623.         //    }
  2624.         //    if (attacked != null)
  2625.         //    {
  2626.         //        var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  2627.         //        if (reduces > 0)
  2628.         //        {
  2629.         //            damage -= damage * reduces / 100;
  2630.         //        }
  2631.         //    }
  2632.         //    if (attacker != null)
  2633.         //    {
  2634.         //        damage += attacker.PhysicalDamageIncrease;
  2635.         //    }
  2636.  
  2637.         //    if (attacked != null)
  2638.         //    {
  2639.         //        damage -= attacked.PhysicalDamageDecrease;
  2640.         //    }
  2641.          
  2642.         //    AutoRespone(attacker, attacked, ref damage);
  2643.  
  2644.  
  2645.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  2646.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  2647.         //            damage *= 2;
  2648.         //    if (attacked.Action == Enums.ConquerAction.Sit)
  2649.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  2650.         //        {
  2651.         //            if (attacked.Stamina >= 20)
  2652.         //                attacked.Stamina -= 20;
  2653.         //            else
  2654.         //                attacked.Stamina = 0;
  2655.         //        }
  2656.         //    if (attacker.OnSuperman())
  2657.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  2658.         //            if (attacked.MonsterInfo.Boss)
  2659.         //                damage *= 2;
  2660.  
  2661.         //    if (attacker.OnSuperman())
  2662.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  2663.         //            damage *= 2;
  2664.         //    if (attacker.OnFatalStrike())
  2665.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  2666.         //            damage *= 5;
  2667.         //    return Math.Max((uint)1, (uint)damage);
  2668.         //}
  2669.         //public static uint Troy(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  2670.         //{
  2671.  
  2672.         //    if (attacked.Name == "InfernalEpico") return 1;
  2673.         //    if (attacked.Name == "SilverOctopus") return 1;
  2674.         //    if (attacked.Name == "GoldenOctopus") return 1;
  2675.         //    if (Packet != null)
  2676.         //    {
  2677.         //        Packet.Effect = MsgInteract.InteractEffects.None;
  2678.         //    }
  2679.  
  2680.         //    if (attacked.Name == "Guard1" && attacker.PlayerFlag == PlayerFlag.Monster)
  2681.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  2682.         //        {
  2683.         //            #region CheakMiss
  2684.         //            if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  2685.         //                if (Kernel.ChanceSuccess(35))
  2686.         //                {
  2687.         //                    MsgName str = new MsgName(true);
  2688.         //                    str.UID = attacked.UID;
  2689.         //                    str.TextsCount = 1;
  2690.         //                    str.Type = MsgName.Effect;
  2691.         //                    str.Texts.Add("poisonmiss");
  2692.         //                    attacked.Owner.SendScreen(str, true);
  2693.         //                    return 0;
  2694.         //                }
  2695.         //            #endregion
  2696.         //        }
  2697.         //    #region PvP -- Player Vs Player -- Jugador Contra Jugador
  2698.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  2699.         //    {
  2700.  
  2701.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  2702.         //            return 1;
  2703.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  2704.         //            return 1;
  2705.         //        Double Damage = 0;
  2706.  
  2707.         //        Double Reborn = 1.00;
  2708.         //        if (attacked.Reborn == 1)
  2709.         //            Reborn -= 0.30;
  2710.         //        else if (attacked.Reborn >= 2)
  2711.         //            Reborn -= 0.50;
  2712.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  2713.         //        Boolean canBT = false, CritImmune = false;
  2714.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  2715.         //        {
  2716.         //            if (attacker.BattlePower < attacked.BattlePower)
  2717.         //            {
  2718.         //                canBT = true;
  2719.         //            }
  2720.         //        }
  2721.         //        else canBT = false;
  2722.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  2723.         //        {
  2724.         //            if (canBT)
  2725.         //            {
  2726.         //                if (Kernel.Rate(((float)attacker.Breaktrough / 1f - (float)attacked.Counteraction / 2f)))
  2727.         //                {
  2728.         //                    Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  2729.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.4);//40% de Daño
  2730.         //                }
  2731.         //            }
  2732.         //        }
  2733.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  2734.         //        {
  2735.         //            if (attacker.BattlePower >= attacked.BattlePower)
  2736.         //            {
  2737.         //                CritImmune = true;
  2738.         //            }
  2739.         //        }
  2740.         //        else CritImmune = false;
  2741.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  2742.         //        {
  2743.         //            if (CritImmune)
  2744.         //            {
  2745.         //                if (Kernel.Rate(((float)attacker.CriticalStrike / 1f - (float)attacked.Immunity / 2f)))
  2746.         //                {
  2747.         //                    Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  2748.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);
  2749.         //                }
  2750.         //            }
  2751.         //        }
  2752.              
  2753.  
  2754.         //        #region Breakthrough -- Potencias Altas ((DESACTIVADO))
  2755.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2756.         //        //{
  2757.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  2758.         //        //    {
  2759.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  2760.         //        //        {
  2761.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.05);
  2762.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  2763.         //        //        }
  2764.         //        //    }
  2765.         //        //}
  2766.         //        #endregion
  2767.  
  2768.         //        Damage *= Reborn;
  2769.         //        if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield))
  2770.         //        {
  2771.  
  2772.         //            if (Damage > attacked.AzureShieldDefence)
  2773.         //            {
  2774.         //                Damage -= attacked.AzureShieldDefence;
  2775.         //                CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  2776.         //                attacked.RemoveFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield);
  2777.         //            }
  2778.         //            else
  2779.         //            {
  2780.         //                CreateAzureDmg((uint)Damage, attacker, attacked);
  2781.         //                attacked.AzureShieldDefence -= (ushort)Damage;
  2782.         //                attacked.AzureShieldPacket();
  2783.         //                Damage = 1;
  2784.         //            }
  2785.         //        }
  2786.  
  2787.         //        //#region Ataque segun Nobleza
  2788.         //        //#region Rey
  2789.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.King)
  2790.         //        //{
  2791.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  2792.         //        //    {
  2793.         //        //        Damage = (int)((double)Damage * 1.0);
  2794.         //        //    }
  2795.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  2796.         //        //    {
  2797.         //        //        Damage = (int)((double)Damage * 1.0);
  2798.         //        //    }
  2799.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  2800.         //        //    {
  2801.         //        //        Damage = (int)((double)Damage * 1.0);
  2802.         //        //    }
  2803.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  2804.         //        //    {
  2805.         //        //        Damage = (int)((double)Damage * 1.0);
  2806.         //        //    }
  2807.         //        //}
  2808.         //        //#endregion
  2809.         //        //#region Duque
  2810.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Prince)
  2811.         //        //{
  2812.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  2813.         //        //    {
  2814.         //        //        Damage = (int)((double)Damage * 1.0);
  2815.         //        //    }
  2816.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  2817.         //        //    {
  2818.         //        //        Damage = (int)((double)Damage * 1.0);
  2819.         //        //    }
  2820.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  2821.         //        //    {
  2822.         //        //        Damage = (int)((double)Damage * 1.0);
  2823.         //        //    }
  2824.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  2825.         //        //    {
  2826.         //        //        Damage = (int)((double)Damage * 1.0);
  2827.         //        //    }
  2828.         //        //}
  2829.         //        //#endregion Prince
  2830.         //        //#region Marques
  2831.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Duke)
  2832.         //        //{
  2833.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  2834.         //        //    {
  2835.         //        //        Damage = (int)((double)Damage * 1.0);
  2836.         //        //    }
  2837.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  2838.         //        //    {
  2839.         //        //        Damage = (int)((double)Damage * 1.0);
  2840.         //        //    }
  2841.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  2842.         //        //    {
  2843.         //        //        Damage = (int)((double)Damage * 1.2);
  2844.         //        //    }
  2845.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  2846.         //        //    {
  2847.         //        //        Damage = (int)((double)Damage * 1.0);
  2848.         //        //    }
  2849.         //        //}
  2850.         //        //#endregion Duke
  2851.         //        //#region Conde
  2852.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Earl)
  2853.         //        //{
  2854.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  2855.         //        //    {
  2856.         //        //        Damage = (int)((double)Damage * 1.5);
  2857.         //        //    }
  2858.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  2859.         //        //    {
  2860.         //        //        Damage = (int)((double)Damage * 1.5);
  2861.         //        //    }
  2862.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  2863.         //        //    {
  2864.         //        //        Damage = (int)((double)Damage * 1.5);
  2865.         //        //    }
  2866.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  2867.         //        //    {
  2868.         //        //        Damage = (int)((double)Damage * 1.5);
  2869.         //        //    }
  2870.         //        //}
  2871.         //        //#endregion Earl
  2872.         //        //#endregion
  2873.  
  2874.         //        #region Bless Reduction
  2875.  
  2876.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  2877.         //        if (reduce > 0)
  2878.         //        {
  2879.         //            Damage -= Damage * reduce / 110;
  2880.         //        }
  2881.  
  2882.         //        #endregion
  2883.         //        if (Damage < 1)
  2884.         //            Damage = 1;
  2885.  
  2886.         //        #region Sepll Bounes
  2887.  
  2888.         //        if (spell != null)
  2889.         //        {
  2890.         //            if (spell.ID != 12290)
  2891.         //            {
  2892.         //                if (spell.PowerPercent != 0)
  2893.         //                {
  2894.         //                    Damage = (Double)(Damage * spell.PowerPercent);
  2895.         //                }
  2896.         //            }
  2897.         //        }
  2898.  
  2899.         //        #endregion
  2900.         //        //#region CriticalStrike -- Potencias Altas VS Bajas
  2901.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2902.         //        //{
  2903.         //        //    if (attacker.BattlePower > attacked.BattlePower)
  2904.         //        //    {
  2905.         //        //        if (attacker.CriticalStrike + 10000 > attacked.Immunity)
  2906.         //        //        {
  2907.         //        //            if (Kernel.Rate(50))
  2908.         //        //            {
  2909.         //        //                Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  2910.         //        //                Damage = (Int32)Math.Floor((float)Damage * 1.2);
  2911.         //        //                attacker.Owner.Send("Le Has Dado un Criticaso!!");
  2912.         //        //            }
  2913.         //        //        }
  2914.         //        //        else
  2915.         //        //        {
  2916.         //        //            Immu(attacked);
  2917.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Immu;
  2918.         //        //            attacker.Owner.Send("Te Anulo tu Criticaso!");
  2919.         //        //        }
  2920.         //        //    }
  2921.         //        //}
  2922.         //        //#endregion
  2923.         //        //#region CriticalStrike -- Potencias Bajas
  2924.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2925.         //        //{
  2926.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  2927.         //        //    {
  2928.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  2929.         //        //        {
  2930.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  2931.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.2);
  2932.         //        //        }
  2933.         //        //    }
  2934.         //        //}
  2935.         //        //#endregion
  2936.         //        //#region CriticalStrike -- Potencias Altas
  2937.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  2938.         //        //{
  2939.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  2940.         //        //    {
  2941.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike) - ((float)attacked.Immunity)))
  2942.         //        //        {
  2943.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  2944.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.4);
  2945.         //        //        }
  2946.         //        //    }
  2947.         //        //}
  2948.         //        //#endregion
  2949.         //        #region Superman & Stigma
  2950.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  2951.         //            if (!attacker.Transformed && Damage > 1)
  2952.         //                Damage = (long)(Damage * 1.12);
  2953.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  2954.         //            Damage *= 1.0; //PvP Reduction!
  2955.         //        #endregion
  2956.         //        #region DragonGem
  2957.         //        var DragonBonus = attacker.Gems[GemTypes.Dragon];
  2958.         //        if (DragonBonus > 0)
  2959.         //            Damage += MathHelper.MulDiv((int)Damage, DragonBonus, 100);
  2960.         //        if (attacker.Gems[GemTypes.Dragon] >= 210)
  2961.         //            Damage += Damage * 50 / 100;
  2962.         //        #endregion
  2963.         //        #region TortoiseGem -- LO LEE DESDE EL CODIGO DE REMOVEEXCESS
  2964.         //        //double torist = (double)(attacked.Gems[COServer.AttackBedan.GemTypes.Tortoise] / 100d);
  2965.         //        //torist = (double)(1 - torist);
  2966.         //        //torist = Math.Max(torist, 0.5);
  2967.         //        //Damage *= torist;
  2968.         //        //Pezzi
  2969.  
  2970.         //        #endregion
  2971.         //        #region Superman & Stigma
  2972.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  2973.         //            if (!attacker.Transformed && Damage > 1)
  2974.         //                Damage = (long)(Damage * 1.12);
  2975.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  2976.         //            Damage *= 1.0; //PvP Reduction!
  2977.  
  2978.         //        #endregion
  2979.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  2980.         //        {
  2981.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  2982.         //                if (attacked.Stamina > 20)
  2983.         //                    attacked.Stamina -= 20;
  2984.         //                else
  2985.         //                    attacked.Stamina = 0;
  2986.         //            attacked.Action = Enums.ConquerAction.None;
  2987.         //        }
  2988.         //        if (attacker != null)
  2989.         //        {
  2990.         //            Damage += (Double)attacker.PhysicalDamageIncrease;
  2991.         //        }
  2992.         //        if (attacked != null)
  2993.         //        {
  2994.         //            Damage -= (Double)attacked.PhysicalDamageDecrease;
  2995.         //        }
  2996.  
  2997.         //        AutoRespone(attacker, attacked, ref Damage);
  2998.         //        #region Efectos Perfectos
  2999.         //        /*
  3000.         //        if (attacker.PrefictionEffect != null)
  3001.         //        {
  3002.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  3003.         //            if (Kernel.ChanceSuccess(30))//30% Probabilidad de Que Salga
  3004.         //            {
  3005.         //                if (attacker.PrefictionLevel > attacked.PrefictionLevel)
  3006.         //                {
  3007.         //                    Network.Writer.WriteUInt16((ushort)(1 << 10), 36, Packet.ToArray());
  3008.         //                    attacker.Owner.SendScreen(MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike));
  3009.         //                    Damage += Damage / 2;
  3010.         //                }
  3011.         //                else
  3012.         //                {
  3013.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  3014.         //                }
  3015.         //            }
  3016.         //        }
  3017.         //        if (attacker.PrefictionEffect != null)
  3018.         //        {
  3019.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  3020.         //            if (Kernel.Rate(eff.Percant))
  3021.         //            {
  3022.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike);
  3023.         //                Damage += Damage;
  3024.         //            }
  3025.         //            eff = attacker.PrefictionEffect.GetCalmWind();
  3026.         //            if (Kernel.Rate(eff.Percant))
  3027.         //            {
  3028.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.CalmWind);
  3029.         //                foreach (var item in attacker.Owner.Spells.Values)
  3030.         //                    item.AttackStamp = Time64.Now.AddSeconds(-50);
  3031.         //            }
  3032.         //            eff = attacker.PrefictionEffect.GetDrainingTouch();
  3033.         //            if (Kernel.Rate(eff.Percant))
  3034.         //            {
  3035.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.DrainingTouch);
  3036.         //                attacker.Hitpoints = attacker.MaxHitpoints;
  3037.         //                attacker.Mana = attacker.MaxMana;
  3038.         //            }
  3039.         //            eff = attacker.PrefictionEffect.GetKillingFlash();
  3040.         //            if (Kernel.Rate(eff.Percant))
  3041.         //            {
  3042.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.MirrorofSin);
  3043.         //                attacker.Owner.XPCount = 100;
  3044.         //            }
  3045.         //            if (attacked.PrefictionLevel > attacker.PrefictionLevel)
  3046.         //            {
  3047.         //                if (Damage >= attacked.MaxHitpoints / 2)
  3048.         //                {
  3049.         //                    eff = attacker.PrefictionEffect.GetLightofStamina();
  3050.         //                    if (Kernel.Rate(eff.Percant))
  3051.         //                    {
  3052.         //                        MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.LightofStamina);
  3053.         //                        attacker.Stamina = 150;
  3054.         //                    }
  3055.         //                }
  3056.         //            }
  3057.  
  3058.         //            var eff1 = attacked.PrefictionEffect.GetStrikeLock();
  3059.         //            if (Kernel.Rate(eff1.Percant))
  3060.         //            {
  3061.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  3062.         //                return 0;
  3063.         //            }
  3064.         //            eff1 = attacked.PrefictionEffect.GetBloodSpawn();
  3065.         //            if (Kernel.Rate(eff.Percant))
  3066.         //            {
  3067.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.BloodSpawn);
  3068.         //                attacked.Hitpoints = attacked.MaxHitpoints;
  3069.         //                attacked.Mana = attacked.MaxMana;
  3070.         //            }
  3071.         //            eff1 = attacked.PrefictionEffect.GetMirrorofSin();
  3072.         //            if (attacked != null && attacked.PrefictionLevel >= attacker.PrefictionLevel)
  3073.         //            {
  3074.         //                eff1 = attacker.PrefictionEffect.GetShieldBreak();
  3075.         //                if (Kernel.Rate(eff1.Percant))
  3076.         //                {
  3077.         //                    MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.ShieldBreak);
  3078.         //                    attacked.AddFlag3(MsgUpdate.Flags.ShieldBreak);
  3079.         //                    attacked.ShieldBreakStamp = Time64.Now;
  3080.         //                }
  3081.         //            }
  3082.         //            if (attacked != null && attacked.PrefictionLevel > attacker.PrefictionLevel)
  3083.         //            {
  3084.         //                eff1 = attacked.PrefictionEffect.GetDivineGuard();
  3085.         //                if (Kernel.Rate(eff1.Percant))
  3086.         //                {
  3087.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.DivineGuard);
  3088.         //                    attacked.AddFlag3(MsgUpdate.Flags.DivineGuard);
  3089.         //                    attacked.DivineGuardStamp = Time64.Now;
  3090.         //                }
  3091.         //            }
  3092.  
  3093.         //        }
  3094.         //        */
  3095.         //        #endregion
  3096.         //        #region Block
  3097.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  3098.         //        {
  3099.         //            if (Kernel.Rate(22))
  3100.         //            {
  3101.         //                if (attacked.Block > 0)
  3102.         //                {
  3103.         //                    Packet.Effect |= MsgInteract.InteractEffects.Block;
  3104.         //                    Damage = (Int32)Math.Floor((float)Damage / 2);
  3105.         //                }
  3106.         //            }
  3107.         //        }
  3108.         //        #endregion
  3109.         //        #region MagicShield
  3110.  
  3111.         //        if (!attacked.Transformed)
  3112.         //        {
  3113.         //            if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.MagicShield))
  3114.         //            {
  3115.         //                if (attacked.ShieldTime > 0)
  3116.         //                {
  3117.         //                    if (Damage > (int)attacked.Defence)
  3118.         //                    {
  3119.         //                        Damage -= (int)attacked.Defence;
  3120.         //                    }
  3121.         //                    else
  3122.         //                        Damage = 1;
  3123.         //                }
  3124.         //                else
  3125.         //                {
  3126.         //                    if (Damage > (ushort)(attacked.Defence * attacked.MagicShieldIncrease))
  3127.         //                        Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  3128.         //                    else
  3129.         //                        Damage = 1;
  3130.         //                }
  3131.         //            }
  3132.         //            else
  3133.         //            {
  3134.         //                if (Damage > (int)attacked.Defence)
  3135.         //                {
  3136.         //                    Damage -= (int)attacked.Defence;
  3137.         //                }
  3138.         //                else
  3139.         //                    Damage = 1;
  3140.         //            }
  3141.         //        }
  3142.         //        else
  3143.         //        {
  3144.         //            if (Damage > attacked.TransformationDefence)
  3145.         //            {
  3146.         //                Damage -= attacked.TransformationDefence;
  3147.         //            }
  3148.         //            else
  3149.         //                Damage = 1;
  3150.         //        }
  3151.  
  3152.         //        #endregion
  3153.         //        #region Reduction!
  3154.  
  3155.         //        #region Clac Defence
  3156.         //        int nDef, defmain;
  3157.         //        if (!attacker.Transformed)
  3158.         //            nDef = defmain = attacked.Defence;
  3159.         //        else
  3160.         //            nDef = defmain = attacked.TransformationDefence;
  3161.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  3162.         //        if (attacked.IsDefensiveStance)
  3163.         //            nDef *= 3;
  3164.  
  3165.         //        #endregion End Defence
  3166.         //        #endregion
  3167.         //        Damage = RemoveExcessDamageTroy((long)Damage, attacker, attacked);
  3168.         //        if (Damage < 1)
  3169.         //            Damage = 1;
  3170.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  3171.         //    }
  3172.         //    #endregion
  3173.         //    #region Player Vs Monster
  3174.         //    else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  3175.         //    {
  3176.         //        int Damage = 0;
  3177.         //        Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  3178.         //        CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  3179.         //        return (uint)Damage;
  3180.         //    }
  3181.         //    #endregion
  3182.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  3183.         //    {
  3184.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  3185.         //            return 1;
  3186.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  3187.         //            return 1;
  3188.         //        Double Damage = 0;
  3189.         //        Double Reborn = 1.00;
  3190.         //        if (attacked.Reborn == 1)
  3191.         //            Reborn -= 0.30; //30%
  3192.         //        else if (attacked.Reborn >= 2)
  3193.         //            Reborn -= 0.50; //50%
  3194.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  3195.         //        Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  3196.         //        Damage -= attacked.Defence;
  3197.         //        Damage *= Reborn;
  3198.  
  3199.         //        #region Bless Reduction
  3200.  
  3201.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  3202.         //        if (reduce > 0)
  3203.         //        {
  3204.         //            Damage -= Damage * reduce / 100;
  3205.         //        }
  3206.  
  3207.         //        #endregion
  3208.  
  3209.         //        if (Damage < 1)
  3210.         //            Damage = 1;
  3211.         //        Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  3212.  
  3213.  
  3214.  
  3215.  
  3216.         //        #region Sell Bounes
  3217.  
  3218.         //        if (spell != null)
  3219.         //        {
  3220.         //            if (spell.PowerPercent != 0)
  3221.         //            {
  3222.         //                Damage = (long)(Damage * spell.PowerPercent);
  3223.         //            }
  3224.         //        }
  3225.  
  3226.         //        #endregion
  3227.  
  3228.         //        Damage -= attacked.PhysicalDamageDecrease;
  3229.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  3230.         //        {
  3231.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  3232.         //                if (attacked.Stamina > 20)
  3233.         //                    attacked.Stamina -= 20;
  3234.         //                else
  3235.         //                    attacked.Stamina = 0;
  3236.         //            attacked.Action = Enums.ConquerAction.None;
  3237.         //        }
  3238.         //        if (attacker.OnSuperman())
  3239.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  3240.         //                if (attacked.MonsterInfo.Boss)
  3241.         //                    Damage *= 2;
  3242.         //        if (attacker.OnSuperman())
  3243.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  3244.         //                Damage *= 2;
  3245.         //        if (attacker.OnFatalStrike())
  3246.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  3247.         //                if (!attacked.MonsterInfo.Boss)
  3248.         //                    Damage *= 5;
  3249.         //                else Damage += (int)(Damage * .1);
  3250.         //        if (Damage < 1)
  3251.         //            Damage = 1;
  3252.         //        #region Reduction!
  3253.  
  3254.         //        #region Clac Defence
  3255.         //        int nDef, defmain;
  3256.         //        if (!attacker.Transformed)
  3257.         //            nDef = defmain = attacked.Defence;
  3258.         //        else
  3259.         //            nDef = defmain = attacked.TransformationDefence;
  3260.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  3261.         //        if (attacked.IsDefensiveStance)
  3262.         //            nDef *= 3;
  3263.  
  3264.         //        #endregion End Defence
  3265.         //        #endregion
  3266.         //        if (Damage < 1)
  3267.         //            Damage = 1;
  3268.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  3269.         //    }
  3270.         //    if (attacker == null || attacked == null)
  3271.         //        return 0;
  3272.         //    long attack = 0;
  3273.         //    int defense = 0;
  3274.         //    if (attacker.PlayerFlag == PlayerFlag.Monster)
  3275.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  3276.         //            if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  3277.         //                return 0;
  3278.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  3279.         //        return 1;
  3280.         //    if (attacked.ContainsFlag((ulong)1UL << 53))
  3281.         //        return 1;
  3282.         //    if (!attacker.Transformed)
  3283.         //        attack = attacker.MinAttack + random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  3284.         //    else
  3285.         //        attack = attacker.TransformationMinAttack +
  3286.         //                 random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  3287.  
  3288.         //    if (attacker != null)
  3289.         //    {
  3290.         //        var bonus = attacker.Gems[1];
  3291.         //        if (bonus > 0)
  3292.         //        {
  3293.         //            attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  3294.         //        }
  3295.         //        // TODO: proficiency bonus
  3296.         //    }
  3297.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  3298.         //        if (!attacker.Transformed && attack > 1)
  3299.         //            attack = (long)(attack * 1.17);
  3300.         //    if (spell != null)
  3301.         //    {
  3302.         //        if (spell.PowerPercent != 0)
  3303.         //        {
  3304.         //            attack = (long)(attack * spell.PowerPercent);
  3305.         //        }
  3306.         //    }
  3307.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  3308.         //    {
  3309.         //        var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  3310.         //        if (reducee > 0)
  3311.         //        {
  3312.         //            attack -= (attack / 2) * reducee / 100;
  3313.         //        }
  3314.         //    }
  3315.  
  3316.  
  3317.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  3318.         //    {
  3319.         //        defense = (defense * 70) / 100;
  3320.         //    }
  3321.         //    var damage = Math.Max(1, attack - defense);
  3322.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  3323.         //    {
  3324.         //        damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  3325.         //        damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  3326.         //        damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  3327.         //    }
  3328.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  3329.         //    {
  3330.         //        damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  3331.         //        damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  3332.         //            10000);
  3333.         //        damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  3334.         //    }
  3335.  
  3336.  
  3337.         //    var reduceee = 10;
  3338.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  3339.         //    {
  3340.         //        if (!attacked.Owner.Equipment.Free(3))
  3341.         //        {
  3342.         //            switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  3343.         //            {
  3344.         //                case 9:
  3345.         //                    reduceee = 1000;
  3346.         //                    break;
  3347.         //                case 8:
  3348.         //                    reduceee = 500;
  3349.         //                    break;
  3350.         //                case 7:
  3351.         //                    reduceee = 200;
  3352.         //                    break;
  3353.         //                case 6:
  3354.         //                    reduceee = 100;
  3355.         //                    break;
  3356.         //            }
  3357.         //        }
  3358.         //    }
  3359.         //    if (attacker.PlayerFlag == PlayerFlag.Player)
  3360.         //    {
  3361.         //        var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  3362.         //        if (n > damage)
  3363.         //        {
  3364.         //            damage = n;
  3365.         //        }
  3366.         //    }
  3367.         //    damage = Math.Max(1, damage);
  3368.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  3369.         //    {
  3370.         //        damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  3371.         //    }
  3372.         //    if (attacked != null)
  3373.         //    {
  3374.         //        var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  3375.         //        if (reduces > 0)
  3376.         //        {
  3377.         //            damage -= damage * reduces / 100;
  3378.         //        }
  3379.         //    }
  3380.         //    if (attacker != null)
  3381.         //    {
  3382.         //        damage += attacker.PhysicalDamageIncrease;
  3383.         //    }
  3384.  
  3385.         //    if (attacked != null)
  3386.         //    {
  3387.         //        damage -= attacked.PhysicalDamageDecrease;
  3388.         //    }
  3389.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  3390.         //    {
  3391.         //        if (attacked.AzureDamage >= damage)
  3392.         //        {
  3393.         //            attacked.AzureDamage -= (int)damage;
  3394.         //            int sec = 60 - (Time32.Now - attacked.MagicShieldStamp).TotalMilliseconds;
  3395.         //            attacked.Owner.Send(Constants.Shield(attacked.AzureDamage, sec));
  3396.         //            return 1;
  3397.         //        }
  3398.         //        else
  3399.         //        {
  3400.         //            damage -= attacked.AzureDamage;
  3401.         //            attacked.AzureDamage = 0;
  3402.         //            attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  3403.         //        }
  3404.         //    }
  3405.         //    AutoRespone(attacker, attacked, ref damage);
  3406.  
  3407.  
  3408.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  3409.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  3410.         //            damage *= 2;
  3411.         //    if (attacked.Action == Enums.ConquerAction.Sit)
  3412.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  3413.         //        {
  3414.         //            if (attacked.Stamina >= 20)
  3415.         //                attacked.Stamina -= 20;
  3416.         //            else
  3417.         //                attacked.Stamina = 0;
  3418.         //        }
  3419.         //    if (attacker.OnSuperman())
  3420.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  3421.         //            if (attacked.MonsterInfo.Boss)
  3422.         //                damage *= 2;
  3423.  
  3424.         //    if (attacker.OnSuperman())
  3425.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  3426.         //            damage *= 2;
  3427.         //    if (attacker.OnFatalStrike())
  3428.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  3429.         //            damage *= 5;
  3430.         //    return Math.Max((uint)1, (uint)damage);
  3431.         //}
  3432.         //public static uint WindwalkerMelee(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  3433.         //{
  3434.  
  3435.         //    if (attacked.Name == "InfernalEpico") return 1;
  3436.         //    if (attacked.Name == "SilverOctopus") return 1;
  3437.         //    if (attacked.Name == "GoldenOctopus") return 1;
  3438.         //    if (Packet != null)
  3439.         //    {
  3440.         //        Packet.Effect = MsgInteract.InteractEffects.None;
  3441.         //    }
  3442.  
  3443.         //    if (attacked.Name == "Guard1" && attacker.PlayerFlag == PlayerFlag.Monster)
  3444.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  3445.         //        {
  3446.         //            #region CheakMiss
  3447.         //            if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  3448.         //                if (Kernel.ChanceSuccess(35))
  3449.         //                {
  3450.         //                    MsgName str = new MsgName(true);
  3451.         //                    str.UID = attacked.UID;
  3452.         //                    str.TextsCount = 1;
  3453.         //                    str.Type = MsgName.Effect;
  3454.         //                    str.Texts.Add("poisonmiss");
  3455.         //                    attacked.Owner.SendScreen(str, true);
  3456.         //                    return 0;
  3457.         //                }
  3458.         //            #endregion
  3459.         //        }
  3460.         //    #region PvP -- Player Vs Player -- Jugador Contra Jugador
  3461.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  3462.         //    {
  3463.  
  3464.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  3465.         //            return 1;
  3466.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  3467.         //            return 1;
  3468.         //        Double Damage = 0;
  3469.  
  3470.         //        Double Reborn = 1.00;
  3471.         //        if (attacked.Reborn == 1)
  3472.         //            Reborn -= 0.30;
  3473.         //        else if (attacked.Reborn >= 2)
  3474.         //            Reborn -= 0.50;
  3475.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  3476.         //        Boolean canBT = false, CritImmune = false;
  3477.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  3478.         //        {
  3479.         //            if (attacker.BattlePower < attacked.BattlePower)
  3480.         //            {
  3481.         //                canBT = true;
  3482.         //            }
  3483.         //        }
  3484.         //        else canBT = false;
  3485.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  3486.         //        {
  3487.         //            if (canBT)
  3488.         //            {
  3489.         //                if (Kernel.Rate(((float)attacker.Breaktrough / 1f - (float)attacked.Counteraction / 2f)))
  3490.         //                {
  3491.         //                    Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  3492.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);//30% de Daño
  3493.         //                }
  3494.         //            }
  3495.         //        }
  3496.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  3497.         //        {
  3498.         //            if (attacker.BattlePower >= attacked.BattlePower)
  3499.         //            {
  3500.         //                CritImmune = true;
  3501.         //            }
  3502.         //        }
  3503.         //        else CritImmune = false;
  3504.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  3505.         //        {
  3506.         //            if (CritImmune)
  3507.         //            {
  3508.         //                if (Kernel.Rate(((float)attacker.CriticalStrike / 1f - (float)attacked.Immunity / 2f)))
  3509.         //                {
  3510.         //                    Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  3511.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);
  3512.         //                }
  3513.         //            }
  3514.         //        }
  3515.         //        //Damage -= attacked.Defence;
  3516.         //        #region AzureShield
  3517.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  3518.         //        {
  3519.         //            if (Damage > attacked.AzureShieldDefence)
  3520.         //            {
  3521.         //                Damage -= attacked.AzureShieldDefence;
  3522.         //                CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  3523.         //                attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  3524.         //            }
  3525.         //            else
  3526.         //            {
  3527.         //                CreateAzureDmg((uint)Damage, attacker, attacked);
  3528.         //                attacked.AzureShieldDefence -= (ushort)Damage;
  3529.         //                attacked.AzureShieldPacket();
  3530.         //                Damage = 1;
  3531.         //            }
  3532.         //        }
  3533.         //        #endregion
  3534.  
  3535.         //        //#region Breakthrough -- Potencias Bajas
  3536.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  3537.         //        //{
  3538.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  3539.         //        //    {
  3540.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  3541.         //        //        {
  3542.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.4);
  3543.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  3544.         //        //        }
  3545.         //        //    }
  3546.         //        //}
  3547.         //        //#endregion
  3548.  
  3549.         //        #region Breakthrough -- Potencias Altas ((DESACTIVADO))
  3550.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  3551.         //        //{
  3552.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  3553.         //        //    {
  3554.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  3555.         //        //        {
  3556.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.05);
  3557.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  3558.         //        //        }
  3559.         //        //    }
  3560.         //        //}
  3561.         //        #endregion
  3562.  
  3563.         //        Damage *= Reborn;
  3564.         //        if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield))
  3565.         //        {
  3566.  
  3567.         //            if (Damage > attacked.AzureShieldDefence)
  3568.         //            {
  3569.         //                Damage -= attacked.AzureShieldDefence;
  3570.         //                CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  3571.         //                attacked.RemoveFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield);
  3572.         //            }
  3573.         //            else
  3574.         //            {
  3575.         //                CreateAzureDmg((uint)Damage, attacker, attacked);
  3576.         //                attacked.AzureShieldDefence -= (ushort)Damage;
  3577.         //                attacked.AzureShieldPacket();
  3578.         //                Damage = 1;
  3579.         //            }
  3580.         //        }
  3581.  
  3582.         //        //#region Ataque segun Nobleza
  3583.         //        //#region Rey
  3584.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.King)
  3585.         //        //{
  3586.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  3587.         //        //    {
  3588.         //        //        Damage = (int)((double)Damage * 1.0);
  3589.         //        //    }
  3590.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  3591.         //        //    {
  3592.         //        //        Damage = (int)((double)Damage * 1.0);
  3593.         //        //    }
  3594.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  3595.         //        //    {
  3596.         //        //        Damage = (int)((double)Damage * 1.0);
  3597.         //        //    }
  3598.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  3599.         //        //    {
  3600.         //        //        Damage = (int)((double)Damage * 1.0);
  3601.         //        //    }
  3602.         //        //}
  3603.         //        //#endregion
  3604.         //        //#region Duque
  3605.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Prince)
  3606.         //        //{
  3607.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  3608.         //        //    {
  3609.         //        //        Damage = (int)((double)Damage * 1.0);
  3610.         //        //    }
  3611.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  3612.         //        //    {
  3613.         //        //        Damage = (int)((double)Damage * 1.0);
  3614.         //        //    }
  3615.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  3616.         //        //    {
  3617.         //        //        Damage = (int)((double)Damage * 1.0);
  3618.         //        //    }
  3619.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  3620.         //        //    {
  3621.         //        //        Damage = (int)((double)Damage * 1.0);
  3622.         //        //    }
  3623.         //        //}
  3624.         //        //#endregion Prince
  3625.         //        //#region Marques
  3626.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Duke)
  3627.         //        //{
  3628.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  3629.         //        //    {
  3630.         //        //        Damage = (int)((double)Damage * 1.0);
  3631.         //        //    }
  3632.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  3633.         //        //    {
  3634.         //        //        Damage = (int)((double)Damage * 1.0);
  3635.         //        //    }
  3636.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  3637.         //        //    {
  3638.         //        //        Damage = (int)((double)Damage * 1.2);
  3639.         //        //    }
  3640.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  3641.         //        //    {
  3642.         //        //        Damage = (int)((double)Damage * 1.0);
  3643.         //        //    }
  3644.         //        //}
  3645.         //        //#endregion Duke
  3646.         //        //#region Conde
  3647.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Earl)
  3648.         //        //{
  3649.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  3650.         //        //    {
  3651.         //        //        Damage = (int)((double)Damage * 1.5);
  3652.         //        //    }
  3653.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  3654.         //        //    {
  3655.         //        //        Damage = (int)((double)Damage * 1.5);
  3656.         //        //    }
  3657.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  3658.         //        //    {
  3659.         //        //        Damage = (int)((double)Damage * 1.5);
  3660.         //        //    }
  3661.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  3662.         //        //    {
  3663.         //        //        Damage = (int)((double)Damage * 1.5);
  3664.         //        //    }
  3665.         //        //}
  3666.         //        //#endregion Earl
  3667.         //        //#endregion
  3668.  
  3669.         //        #region Bless Reduction
  3670.  
  3671.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  3672.         //        if (reduce > 0)
  3673.         //        {
  3674.         //            Damage -= Damage * reduce / 100;//Entre mas Sube Mas Daño le hace!
  3675.         //        }
  3676.  
  3677.         //        #endregion
  3678.         //        if (Damage < 1)
  3679.         //            Damage = 1;
  3680.  
  3681.         //        #region Sepll Bounes
  3682.  
  3683.         //        if (spell != null)
  3684.         //        {
  3685.         //            if (spell.ID != 12290)
  3686.         //            {
  3687.         //                if (spell.PowerPercent != 0)
  3688.         //                {
  3689.         //                    Damage = (Double)(Damage * spell.PowerPercent);
  3690.         //                }
  3691.         //            }
  3692.         //        }
  3693.  
  3694.         //        #endregion
  3695.         //        //#region CriticalStrike -- Potencias Altas VS Bajas
  3696.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  3697.         //        //{
  3698.         //        //    if (attacker.BattlePower > attacked.BattlePower)
  3699.         //        //    {
  3700.         //        //        if (attacker.CriticalStrike + 10000 > attacked.Immunity)
  3701.         //        //        {
  3702.         //        //            if (Kernel.Rate(50))
  3703.         //        //            {
  3704.         //        //                Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  3705.         //        //                Damage = (Int32)Math.Floor((float)Damage * 1.2);
  3706.         //        //                attacker.Owner.Send("Le Has Dado un Criticaso!!");
  3707.         //        //            }
  3708.         //        //        }
  3709.         //        //        else
  3710.         //        //        {
  3711.         //        //            Immu(attacked);
  3712.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Immu;
  3713.         //        //            attacker.Owner.Send("Te Anulo tu Criticaso!");
  3714.         //        //        }
  3715.         //        //    }
  3716.         //        //}
  3717.         //        //#endregion
  3718.         //        //#region CriticalStrike -- Potencias Bajas
  3719.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  3720.         //        //{
  3721.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  3722.         //        //    {
  3723.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  3724.         //        //        {
  3725.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  3726.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.2);
  3727.         //        //        }
  3728.         //        //    }
  3729.         //        //}
  3730.         //        //#endregion
  3731.         //        //#region CriticalStrike -- Potencias Altas
  3732.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  3733.         //        //{
  3734.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  3735.         //        //    {
  3736.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike) - ((float)attacked.Immunity)))
  3737.         //        //        {
  3738.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  3739.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.4);
  3740.         //        //        }
  3741.         //        //    }
  3742.         //        //}
  3743.         //        //#endregion
  3744.         //        #region Superman & Stigma
  3745.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  3746.         //            if (!attacker.Transformed && Damage > 1)
  3747.         //                Damage = (long)(Damage * 1.12);
  3748.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  3749.         //            Damage *= 1.0; //PvP Reduction!
  3750.         //        #endregion
  3751.         //        #region DragonGem
  3752.         //        var DragonBonus = attacker.Gems[GemTypes.Dragon];
  3753.         //        if (DragonBonus > 0)
  3754.         //            Damage += MathHelper.MulDiv((int)Damage, DragonBonus, 100);
  3755.         //        if (attacker.Gems[GemTypes.Dragon] >= 210)
  3756.         //            Damage += Damage * 50 / 100;
  3757.         //        #endregion
  3758.         //        #region TortoiseGem -- LO LEE DESDE EL CODIGO DE REMOVEEXCESS
  3759.         //        //double torist = (double)(attacked.Gems[COServer.AttackBedan.GemTypes.Tortoise] / 100d);
  3760.         //        //torist = (double)(1 - torist);
  3761.         //        //torist = Math.Max(torist, 0.5);
  3762.         //        //Damage *= torist;
  3763.         //        //Pezzi
  3764.  
  3765.         //        #endregion
  3766.         //        #region Superman & Stigma
  3767.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  3768.         //            if (!attacker.Transformed && Damage > 1)
  3769.         //                Damage = (long)(Damage * 1.12);
  3770.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  3771.         //            Damage *= 1.0; //PvP Reduction!
  3772.  
  3773.         //        #endregion
  3774.         //        #region Efectos Perfectos
  3775.         //        /*
  3776.         //        if (attacker.PrefictionEffect != null)
  3777.         //        {
  3778.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  3779.         //            if (Kernel.ChanceSuccess(30))//30% Probabilidad de Que Salga
  3780.         //            {
  3781.         //                if (attacker.PrefictionLevel > attacked.PrefictionLevel)
  3782.         //                {
  3783.         //                    Network.Writer.WriteUInt16((ushort)(1 << 10), 36, Packet.ToArray());
  3784.         //                    attacker.Owner.SendScreen(MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike));
  3785.         //                    Damage += Damage / 2;
  3786.         //                }
  3787.         //                else
  3788.         //                {
  3789.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  3790.         //                }
  3791.         //            }
  3792.         //        }
  3793.         //        if (attacker.PrefictionEffect != null)
  3794.         //        {
  3795.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  3796.         //            if (Kernel.Rate(eff.Percant))
  3797.         //            {
  3798.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike);
  3799.         //                Damage += Damage;
  3800.         //            }
  3801.         //            eff = attacker.PrefictionEffect.GetCalmWind();
  3802.         //            if (Kernel.Rate(eff.Percant))
  3803.         //            {
  3804.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.CalmWind);
  3805.         //                foreach (var item in attacker.Owner.Spells.Values)
  3806.         //                    item.AttackStamp = Time64.Now.AddSeconds(-50);
  3807.         //            }
  3808.         //            eff = attacker.PrefictionEffect.GetDrainingTouch();
  3809.         //            if (Kernel.Rate(eff.Percant))
  3810.         //            {
  3811.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.DrainingTouch);
  3812.         //                attacker.Hitpoints = attacker.MaxHitpoints;
  3813.         //                attacker.Mana = attacker.MaxMana;
  3814.         //            }
  3815.         //            eff = attacker.PrefictionEffect.GetKillingFlash();
  3816.         //            if (Kernel.Rate(eff.Percant))
  3817.         //            {
  3818.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.MirrorofSin);
  3819.         //                attacker.Owner.XPCount = 100;
  3820.         //            }
  3821.         //            if (attacked.PrefictionLevel > attacker.PrefictionLevel)
  3822.         //            {
  3823.         //                if (Damage >= attacked.MaxHitpoints / 2)
  3824.         //                {
  3825.         //                    eff = attacker.PrefictionEffect.GetLightofStamina();
  3826.         //                    if (Kernel.Rate(eff.Percant))
  3827.         //                    {
  3828.         //                        MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.LightofStamina);
  3829.         //                        attacker.Stamina = 150;
  3830.         //                    }
  3831.         //                }
  3832.         //            }
  3833.         //        }
  3834.         //        #region Prefiction on attacked from monster
  3835.         //        if (attacked.PrefictionEffect != null)
  3836.         //        {
  3837.         //            var eff = attacked.PrefictionEffect.GetStrikeLock();
  3838.         //            if (Kernel.Rate(eff.Percant))
  3839.         //            {
  3840.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  3841.         //                return 0;
  3842.         //            }
  3843.         //            eff = attacked.PrefictionEffect.GetBloodSpawn();
  3844.         //            if (Kernel.Rate(eff.Percant))
  3845.         //            {
  3846.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.BloodSpawn);
  3847.         //                attacked.Hitpoints = attacked.MaxHitpoints;
  3848.         //                attacked.Mana = attacked.MaxMana;
  3849.         //            }
  3850.         //            eff = attacked.PrefictionEffect.GetMirrorofSin();
  3851.         //            if (Kernel.Rate(eff.Percant))
  3852.         //            {
  3853.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.MirrorofSin);
  3854.         //                attacked.Owner.XPCount = 100;
  3855.         //            }
  3856.         //            if (attacked != null && attacked.PrefictionLevel >= attacker.PrefictionLevel)
  3857.         //            {
  3858.         //                eff = attacker.PrefictionEffect.GetShieldBreak();
  3859.         //                if (Kernel.Rate(eff.Percant))
  3860.         //                {
  3861.         //                    MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.ShieldBreak);
  3862.         //                    attacked.AddFlag3(MsgUpdate.Flags.ShieldBreak);
  3863.         //                    attacked.ShieldBreakStamp = Time64.Now;
  3864.         //                }
  3865.         //            }
  3866.         //            if (attacked != null && attacked.PrefictionLevel > attacker.PrefictionLevel)
  3867.         //            {
  3868.         //                eff = attacked.PrefictionEffect.GetDivineGuard();
  3869.         //                if (Kernel.Rate(eff.Percant))
  3870.         //                {
  3871.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.DivineGuard);
  3872.         //                    attacked.AddFlag3(MsgUpdate.Flags.DivineGuard);
  3873.         //                    attacked.DivineGuardStamp = Time64.Now;
  3874.         //                }
  3875.         //            }
  3876.  
  3877.         //        }
  3878.         //        #endregion
  3879.         //        */
  3880.         //        #endregion
  3881.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  3882.         //        {
  3883.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  3884.         //                if (attacked.Stamina > 20)
  3885.         //                    attacked.Stamina -= 20;
  3886.         //                else
  3887.         //                    attacked.Stamina = 0;
  3888.         //            attacked.Action = Enums.ConquerAction.None;
  3889.         //        }
  3890.         //        if (attacker != null)
  3891.         //        {
  3892.         //            Damage += (Double)attacker.PhysicalDamageIncrease;
  3893.         //        }
  3894.         //        if (attacked != null)
  3895.         //        {
  3896.         //            Damage -= (Double)attacked.PhysicalDamageDecrease;
  3897.         //        }
  3898.  
  3899.         //        AutoRespone(attacker, attacked, ref Damage);
  3900.  
  3901.         //        #region Block
  3902.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  3903.         //        {
  3904.         //            if (Kernel.Rate(22))
  3905.         //            {
  3906.         //                if (attacked.Block > 0)
  3907.         //                {
  3908.         //                    Packet.Effect |= MsgInteract.InteractEffects.Block;
  3909.         //                    Damage = (Int32)Math.Floor((float)Damage / 2);
  3910.         //                }
  3911.         //            }
  3912.         //        }
  3913.         //        #endregion
  3914.         //        #region MagicShield
  3915.  
  3916.         //        if (!attacked.Transformed)
  3917.         //        {
  3918.         //            if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.MagicShield))
  3919.         //            {
  3920.         //                if (attacked.ShieldTime > 0)
  3921.         //                {
  3922.         //                    if (Damage > (int)attacked.Defence)
  3923.         //                    {
  3924.         //                        Damage -= (int)attacked.Defence;
  3925.         //                    }
  3926.         //                    else
  3927.         //                        Damage = 1;
  3928.         //                }
  3929.         //                else
  3930.         //                {
  3931.         //                    if (Damage > (ushort)(attacked.Defence * attacked.MagicShieldIncrease))
  3932.         //                        Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  3933.         //                    else
  3934.         //                        Damage = 1;
  3935.         //                }
  3936.         //            }
  3937.         //            else
  3938.         //            {
  3939.         //                if (Damage > (int)attacked.Defence)
  3940.         //                {
  3941.         //                    Damage -= (int)attacked.Defence;
  3942.         //                }
  3943.         //                else
  3944.         //                    Damage = 1;
  3945.         //            }
  3946.         //        }
  3947.         //        else
  3948.         //        {
  3949.         //            if (Damage > attacked.TransformationDefence)
  3950.         //            {
  3951.         //                Damage -= attacked.TransformationDefence;
  3952.         //            }
  3953.         //            else
  3954.         //                Damage = 1;
  3955.         //        }
  3956.  
  3957.         //        #endregion
  3958.         //        #region Reduction!
  3959.  
  3960.         //        #region Clac Defence
  3961.         //        int nDef, defmain;
  3962.         //        if (!attacker.Transformed)
  3963.         //            nDef = defmain = attacked.Defence;
  3964.         //        else
  3965.         //            nDef = defmain = attacked.TransformationDefence;
  3966.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  3967.         //        if (attacked.IsDefensiveStance)
  3968.         //            nDef *= 3;
  3969.  
  3970.         //        #endregion End Defence
  3971.                
  3972.         //        #endregion
  3973.         //        Damage = RemoveExcessDamageWindMelee((long)Damage, attacker, attacked);//2
  3974.         //        if (Damage < 1)
  3975.         //            Damage = 1;
  3976.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  3977.         //    }
  3978.         //    #endregion
  3979.         //    #region Player Vs Monster
  3980.         //    else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  3981.         //    {
  3982.         //        int Damage = 0;
  3983.         //        Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  3984.         //        CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  3985.         //        return (uint)Damage;
  3986.         //    }
  3987.         //    #endregion
  3988.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  3989.         //    {
  3990.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  3991.         //            return 1;
  3992.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  3993.         //            return 1;
  3994.         //        Double Damage = 0;
  3995.         //        Double Reborn = 1.00;
  3996.         //        if (attacked.Reborn == 1)
  3997.         //            Reborn -= 0.30; //30%
  3998.         //        else if (attacked.Reborn >= 2)
  3999.         //            Reborn -= 0.50; //50%
  4000.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  4001.         //        Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  4002.         //        Damage -= attacked.Defence;
  4003.         //        Damage *= Reborn;
  4004.  
  4005.         //        #region Bless Reduction
  4006.  
  4007.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  4008.         //        if (reduce > 0)
  4009.         //        {
  4010.         //            Damage -= Damage * reduce / 100;
  4011.         //        }
  4012.  
  4013.         //        #endregion
  4014.  
  4015.         //        if (Damage < 1)
  4016.         //            Damage = 1;
  4017.         //        Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  4018.  
  4019.  
  4020.  
  4021.  
  4022.         //        #region Sell Bounes
  4023.  
  4024.         //        if (spell != null)
  4025.         //        {
  4026.         //            if (spell.PowerPercent != 0)
  4027.         //            {
  4028.         //                Damage = (long)(Damage * spell.PowerPercent);
  4029.         //            }
  4030.         //        }
  4031.  
  4032.         //        #endregion
  4033.  
  4034.         //        Damage -= attacked.PhysicalDamageDecrease;
  4035.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4036.         //        {
  4037.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  4038.         //                if (attacked.Stamina > 20)
  4039.         //                    attacked.Stamina -= 20;
  4040.         //                else
  4041.         //                    attacked.Stamina = 0;
  4042.         //            attacked.Action = Enums.ConquerAction.None;
  4043.         //        }
  4044.         //        if (attacker.OnSuperman())
  4045.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  4046.         //                if (attacked.MonsterInfo.Boss)
  4047.         //                    Damage *= 2;
  4048.         //        if (attacker.OnSuperman())
  4049.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  4050.         //                Damage *= 2;
  4051.         //        if (attacker.OnFatalStrike())
  4052.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  4053.         //                if (!attacked.MonsterInfo.Boss)
  4054.         //                    Damage *= 5;
  4055.         //                else Damage += (int)(Damage * .1);
  4056.         //        if (Damage < 1)
  4057.         //            Damage = 1;
  4058.         //        #region Reduction!
  4059.  
  4060.         //        #region Clac Defence
  4061.         //        int nDef, defmain;
  4062.         //        if (!attacker.Transformed)
  4063.         //            nDef = defmain = attacked.Defence;
  4064.         //        else
  4065.         //            nDef = defmain = attacked.TransformationDefence;
  4066.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  4067.         //        if (attacked.IsDefensiveStance)
  4068.         //            nDef *= 3;
  4069.  
  4070.         //        #endregion End Defence
  4071.              
  4072.         //        #endregion
  4073.         //        if (Damage < 1)
  4074.         //            Damage = 1;
  4075.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  4076.         //    }
  4077.         //    if (attacker == null || attacked == null)
  4078.         //        return 0;
  4079.         //    long attack = 0;
  4080.         //    int defense = 0;
  4081.         //    if (attacker.PlayerFlag == PlayerFlag.Monster)
  4082.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4083.         //            if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  4084.         //                return 0;
  4085.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  4086.         //        return 1;
  4087.         //    if (attacked.ContainsFlag((ulong)1UL << 53))
  4088.         //        return 1;
  4089.         //    if (!attacker.Transformed)
  4090.         //        attack = attacker.MinAttack + random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  4091.         //    else
  4092.         //        attack = attacker.TransformationMinAttack +
  4093.         //                 random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  4094.  
  4095.         //    if (attacker != null)
  4096.         //    {
  4097.         //        var bonus = attacker.Gems[1];
  4098.         //        if (bonus > 0)
  4099.         //        {
  4100.         //            attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  4101.         //        }
  4102.         //        // TODO: proficiency bonus
  4103.         //    }
  4104.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  4105.         //        if (!attacker.Transformed && attack > 1)
  4106.         //            attack = (long)(attack * 1.17);
  4107.         //    if (spell != null)
  4108.         //    {
  4109.         //        if (spell.PowerPercent != 0)
  4110.         //        {
  4111.         //            attack = (long)(attack * spell.PowerPercent);
  4112.         //        }
  4113.         //    }
  4114.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  4115.         //    {
  4116.         //        var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  4117.         //        if (reducee > 0)
  4118.         //        {
  4119.         //            attack -= (attack / 2) * reducee / 100;
  4120.         //        }
  4121.         //    }
  4122.  
  4123.  
  4124.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  4125.         //    {
  4126.         //        defense = (defense * 70) / 100;
  4127.         //    }
  4128.         //    var damage = Math.Max(1, attack - defense);
  4129.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  4130.         //    {
  4131.         //        damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  4132.         //        damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  4133.         //        damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  4134.         //    }
  4135.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  4136.         //    {
  4137.         //        damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  4138.         //        damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  4139.         //            10000);
  4140.         //        damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  4141.         //    }
  4142.  
  4143.  
  4144.         //    var reduceee = 10;
  4145.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  4146.         //    {
  4147.         //        if (!attacked.Owner.Equipment.Free(3))
  4148.         //        {
  4149.         //            switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  4150.         //            {
  4151.         //                case 9:
  4152.         //                    reduceee = 1000;
  4153.         //                    break;
  4154.         //                case 8:
  4155.         //                    reduceee = 500;
  4156.         //                    break;
  4157.         //                case 7:
  4158.         //                    reduceee = 200;
  4159.         //                    break;
  4160.         //                case 6:
  4161.         //                    reduceee = 100;
  4162.         //                    break;
  4163.         //            }
  4164.         //        }
  4165.         //    }
  4166.         //    if (attacker.PlayerFlag == PlayerFlag.Player)
  4167.         //    {
  4168.         //        var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  4169.         //        if (n > damage)
  4170.         //        {
  4171.         //            damage = n;
  4172.         //        }
  4173.         //    }
  4174.         //    damage = Math.Max(1, damage);
  4175.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  4176.         //    {
  4177.         //        damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  4178.         //    }
  4179.         //    if (attacked != null)
  4180.         //    {
  4181.         //        var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  4182.         //        if (reduces > 0)
  4183.         //        {
  4184.         //            damage -= damage * reduces / 100;
  4185.         //        }
  4186.         //    }
  4187.         //    if (attacker != null)
  4188.         //    {
  4189.         //        damage += attacker.PhysicalDamageIncrease;
  4190.         //    }
  4191.  
  4192.         //    if (attacked != null)
  4193.         //    {
  4194.         //        damage -= attacked.PhysicalDamageDecrease;
  4195.         //    }
  4196.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  4197.         //    {
  4198.         //        if (attacked.AzureDamage >= damage)
  4199.         //        {
  4200.         //            attacked.AzureDamage -= (int)damage;
  4201.         //            int sec = 60 - (Time32.Now - attacked.MagicShieldStamp).TotalMilliseconds;
  4202.         //            attacked.Owner.Send(Constants.Shield(attacked.AzureDamage, sec));
  4203.         //            return 1;
  4204.         //        }
  4205.         //        else
  4206.         //        {
  4207.         //            damage -= attacked.AzureDamage;
  4208.         //            attacked.AzureDamage = 0;
  4209.         //            attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  4210.         //        }
  4211.         //    }
  4212.         //    AutoRespone(attacker, attacked, ref damage);
  4213.  
  4214.  
  4215.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  4216.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  4217.         //            damage *= 2;
  4218.         //    if (attacked.Action == Enums.ConquerAction.Sit)
  4219.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4220.         //        {
  4221.         //            if (attacked.Stamina >= 20)
  4222.         //                attacked.Stamina -= 20;
  4223.         //            else
  4224.         //                attacked.Stamina = 0;
  4225.         //        }
  4226.         //    if (attacker.OnSuperman())
  4227.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  4228.         //            if (attacked.MonsterInfo.Boss)
  4229.         //                damage *= 2;
  4230.  
  4231.         //    if (attacker.OnSuperman())
  4232.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  4233.         //            damage *= 2;
  4234.         //    if (attacker.OnFatalStrike())
  4235.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  4236.         //            damage *= 5;
  4237.         //    return Math.Max((uint)1, (uint)damage);
  4238.         //}
  4239.         //public static uint Ninja(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  4240.         //{
  4241.  
  4242.         //    if (attacked.Name == "InfernalEpico") return 1;
  4243.         //    if (attacked.Name == "SilverOctopus") return 1;
  4244.         //    if (attacked.Name == "GoldenOctopus") return 1;
  4245.         //    if (Packet != null)
  4246.         //    {
  4247.         //        Packet.Effect = MsgInteract.InteractEffects.None;
  4248.         //    }
  4249.  
  4250.         //    if (attacked.Name == "Guard1" && attacker.PlayerFlag == PlayerFlag.Monster)
  4251.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4252.         //        {
  4253.         //            #region CheakMiss
  4254.         //            if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  4255.         //                if (Kernel.ChanceSuccess(35))
  4256.         //                {
  4257.         //                    MsgName str = new MsgName(true);
  4258.         //                    str.UID = attacked.UID;
  4259.         //                    str.TextsCount = 1;
  4260.         //                    str.Type = MsgName.Effect;
  4261.         //                    str.Texts.Add("poisonmiss");
  4262.         //                    attacked.Owner.SendScreen(str, true);
  4263.         //                    return 0;
  4264.         //                }
  4265.         //            #endregion
  4266.         //        }
  4267.         //    #region PvP -- Player Vs Player -- Jugador Contra Jugador
  4268.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  4269.         //    {
  4270.  
  4271.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  4272.         //            return 1;
  4273.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  4274.         //            return 1;
  4275.         //        Double Damage = 0;
  4276.  
  4277.         //        Double Reborn = 1.00;
  4278.         //        if (attacked.Reborn == 1)
  4279.         //            Reborn -= 0.30;
  4280.         //        else if (attacked.Reborn >= 2)
  4281.         //            Reborn -= 0.50;
  4282.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  4283.         //        #region Efectos Perfectos
  4284.         //        /*
  4285.         //        if (attacker.PrefictionEffect != null)
  4286.         //        {
  4287.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  4288.         //            if (Kernel.ChanceSuccess(40))//40% Probabilidad de Que Salga
  4289.         //            {
  4290.         //                if (attacker.PrefictionLevel > attacked.PrefictionLevel)
  4291.         //                {
  4292.         //                    Network.Writer.WriteUInt16((ushort)(1 << 10), 36, Packet.ToArray());
  4293.         //                    attacker.Owner.SendScreen(MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike));
  4294.         //                    Damage += Damage * 0.8;
  4295.         //                }
  4296.         //                else
  4297.         //                {
  4298.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  4299.         //                }
  4300.         //            }
  4301.         //        }
  4302.         //        if (attacker.PrefictionEffect != null)
  4303.         //        {
  4304.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  4305.         //            eff = attacker.PrefictionEffect.GetCalmWind();
  4306.         //            if (Kernel.Rate(eff.Percant))
  4307.         //            {
  4308.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.CalmWind);
  4309.         //                foreach (var item in attacker.Owner.Spells.Values)
  4310.         //                    item.AttackStamp = Time64.Now.AddSeconds(-50);
  4311.         //            }
  4312.         //            eff = attacker.PrefictionEffect.GetDrainingTouch();
  4313.         //            if (Kernel.Rate(eff.Percant))
  4314.         //            {
  4315.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.DrainingTouch);
  4316.         //                attacker.Hitpoints = attacker.MaxHitpoints;
  4317.         //                attacker.Mana = attacker.MaxMana;
  4318.         //            }
  4319.         //            eff = attacker.PrefictionEffect.GetKillingFlash();
  4320.         //            if (Kernel.Rate(eff.Percant))
  4321.         //            {
  4322.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.MirrorofSin);
  4323.         //                attacker.Owner.XPCount = 100;
  4324.         //            }
  4325.         //            if (attacked.PrefictionLevel > attacker.PrefictionLevel)
  4326.         //            {
  4327.         //                if (Damage >= attacked.MaxHitpoints / 2)
  4328.         //                {
  4329.         //                    eff = attacker.PrefictionEffect.GetLightofStamina();
  4330.         //                    if (Kernel.Rate(eff.Percant))
  4331.         //                    {
  4332.         //                        MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.LightofStamina);
  4333.         //                        attacker.Stamina = 150;
  4334.         //                    }
  4335.         //                }
  4336.         //            }
  4337.         //        }
  4338.         //        #region Prefiction on attacked from monster
  4339.         //        if (attacked.PrefictionEffect != null)
  4340.         //        {
  4341.         //            var eff = attacked.PrefictionEffect.GetStrikeLock();
  4342.         //            if (Kernel.Rate(eff.Percant))
  4343.         //            {
  4344.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  4345.         //                return 0;
  4346.         //            }
  4347.         //            eff = attacked.PrefictionEffect.GetBloodSpawn();
  4348.         //            if (Kernel.Rate(eff.Percant))
  4349.         //            {
  4350.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.BloodSpawn);
  4351.         //                attacked.Hitpoints = attacked.MaxHitpoints;
  4352.         //                attacked.Mana = attacked.MaxMana;
  4353.         //            }
  4354.         //            eff = attacked.PrefictionEffect.GetMirrorofSin();
  4355.         //            if (Kernel.Rate(eff.Percant))
  4356.         //            {
  4357.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.MirrorofSin);
  4358.         //                attacked.Owner.XPCount = 100;
  4359.         //            }
  4360.         //            if (attacked != null && attacked.PrefictionLevel >= attacker.PrefictionLevel)
  4361.         //            {
  4362.         //                eff = attacker.PrefictionEffect.GetShieldBreak();
  4363.         //                if (Kernel.Rate(eff.Percant))
  4364.         //                {
  4365.         //                    MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.ShieldBreak);
  4366.         //                    attacked.AddFlag3(MsgUpdate.Flags.ShieldBreak);
  4367.         //                    attacked.ShieldBreakStamp = Time64.Now;
  4368.         //                }
  4369.         //            }
  4370.         //            if (attacked != null && attacked.PrefictionLevel > attacker.PrefictionLevel)
  4371.         //            {
  4372.         //                eff = attacked.PrefictionEffect.GetDivineGuard();
  4373.         //                if (Kernel.Rate(eff.Percant))
  4374.         //                {
  4375.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.DivineGuard);
  4376.         //                    attacked.AddFlag3(MsgUpdate.Flags.DivineGuard);
  4377.         //                    attacked.DivineGuardStamp = Time64.Now;
  4378.         //                }
  4379.         //            }
  4380.  
  4381.         //        }
  4382.         //        #endregion
  4383.         //        */
  4384.         //        #endregion
  4385.         //        #region Critico & Smash
  4386.         //        Boolean canBT = false, CritInmmune = false;
  4387.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  4388.         //        {
  4389.         //            if (attacker.BattlePower < attacked.BattlePower)
  4390.         //            {
  4391.         //                canBT = true;
  4392.         //            }
  4393.         //        }
  4394.         //        else canBT = false;
  4395.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  4396.         //        {
  4397.         //            if (canBT)
  4398.         //            {
  4399.         //                if (Kernel.Rate(((float)attacker.Breaktrough / 1f - (float)attacked.Counteraction / 2f)))
  4400.         //                {
  4401.         //                    Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  4402.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.5);
  4403.         //                }
  4404.         //            }
  4405.         //            else
  4406.         //            {
  4407.  
  4408.         //            }
  4409.         //        }
  4410.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  4411.         //        {
  4412.         //            if (attacker.BattlePower >= attacked.BattlePower)
  4413.         //            {
  4414.         //                CritInmmune = true;
  4415.         //            }
  4416.         //        }
  4417.         //        else CritInmmune = false;
  4418.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  4419.         //        {
  4420.         //            if (CritInmmune)
  4421.         //            {
  4422.         //                if (Kernel.Rate(((float)attacker.CriticalStrike / 1f - (float)attacked.Immunity / 2f)))
  4423.         //                {
  4424.         //                    Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  4425.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);
  4426.         //                }
  4427.         //            }
  4428.         //            else
  4429.         //            {
  4430.         //                Immu(attacked);
  4431.         //            }
  4432.         //        }
  4433.         //        #endregion
  4434.         //        #region Breakthrough -- Potencia Baja ((DESACTIVADO)
  4435.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  4436.         //        //{
  4437.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  4438.         //        //    {
  4439.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 5f) - (float)(attacked.Counteraction / 10f)))
  4440.         //        //        {
  4441.  
  4442.         //        //             Damage = (Int32)Math.Floor((float)Damage * 1.3);
  4443.  
  4444.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  4445.         //        //            attacker.Owner.Send("Le Has Dado un Smash!");
  4446.         //        //        }
  4447.         //        //    }
  4448.         //        //}
  4449.  
  4450.  
  4451.         //        #endregion
  4452.         //        #region Breakthrough -- Potencia Alta ((DESACTIVADO))
  4453.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  4454.         //        //{
  4455.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  4456.         //        //    {
  4457.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  4458.         //        //        {
  4459.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.2);
  4460.  
  4461.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  4462.         //        //            attacker.Owner.Send("Successs Smashhh");
  4463.         //        //        }
  4464.         //        //    }
  4465.         //        //}
  4466.         //        #endregion
  4467.         //        //Damage -= attacked.Defence;
  4468.         //        #region MagicShield
  4469.  
  4470.         //        if (!attacked.Transformed)
  4471.         //        {
  4472.         //            if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.MagicShield))
  4473.         //            {
  4474.         //                if (attacked.ShieldTime > 0)
  4475.         //                {
  4476.         //                    if (Damage > (int)attacked.Defence)
  4477.         //                    {
  4478.         //                        Damage -= (int)attacked.Defence;
  4479.         //                    }
  4480.         //                    else
  4481.         //                        Damage = 1;
  4482.         //                }
  4483.         //                else
  4484.         //                {
  4485.         //                    if (Damage > (ushort)(attacked.Defence * attacked.MagicShieldIncrease))
  4486.         //                        Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  4487.         //                    else
  4488.         //                        Damage = 1;
  4489.         //                }
  4490.         //            }
  4491.         //            else
  4492.         //            {
  4493.         //                if (Damage > (int)attacked.Defence)
  4494.         //                {
  4495.         //                    Damage -= (int)attacked.Defence;
  4496.         //                }
  4497.         //                else
  4498.         //                    Damage = 1;
  4499.         //            }
  4500.         //        }
  4501.         //        else
  4502.         //        {
  4503.         //            if (Damage > attacked.TransformationDefence)
  4504.         //            {
  4505.         //                Damage -= attacked.TransformationDefence;
  4506.         //            }
  4507.         //            else
  4508.         //                Damage = 1;
  4509.         //        }
  4510.  
  4511.         //        #endregion
  4512.         //        Damage *= Reborn;
  4513.         //        if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield))
  4514.         //        {
  4515.  
  4516.         //            if (Damage > attacked.AzureShieldDefence)
  4517.         //            {
  4518.         //                Damage -= attacked.AzureShieldDefence;
  4519.         //                CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  4520.         //                attacked.RemoveFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield);
  4521.         //            }
  4522.         //            else
  4523.         //            {
  4524.         //                CreateAzureDmg((uint)Damage, attacker, attacked);
  4525.         //                attacked.AzureShieldDefence -= (ushort)Damage;
  4526.         //                attacked.AzureShieldPacket();
  4527.         //                Damage = 1;
  4528.         //            }
  4529.         //        }
  4530.  
  4531.         //        #region Bless Reduction
  4532.  
  4533.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  4534.         //        if (reduce > 0)
  4535.         //        {
  4536.         //            if (attacked.Class == 165)
  4537.         //            {
  4538.         //                Damage -= Damage * reduce / 100;//Daño Aunmentado contra Windwalker
  4539.         //            }
  4540.         //            else
  4541.         //            {
  4542.         //                Damage -= Damage * reduce / 100;//Daño Reducido contra otras Clases
  4543.         //            }
  4544.         //        }
  4545.  
  4546.         //        #endregion
  4547.         //        #region Sepll Bounes
  4548.  
  4549.         //        if (spell != null)
  4550.         //        {
  4551.         //            if (spell.ID != 12290)
  4552.         //            {
  4553.         //                if (spell.PowerPercent != 0)
  4554.         //                {
  4555.         //                    Damage = (Double)(Damage * spell.PowerPercent);
  4556.         //                }
  4557.         //            }
  4558.         //        }
  4559.  
  4560.         //        #endregion
  4561.         //        //////TESTT/////////
  4562.         //        //if (attacker.CriticalStrike > attacked.Immunity)
  4563.         //        //{
  4564.         //        //    Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  4565.         //        //    Damage = (Int32)Math.Floor((float)Damage * 1.2);
  4566.         //        // //   attacker.Owner.Send("Critico V0");
  4567.         //        //}
  4568.         //        //else
  4569.         //        //{
  4570.         //        //    Immu(attacked);
  4571.         //        //    Packet.Effect1 |= MsgInteract.InteractEffects.Immu;
  4572.         //        //  //  attacker.Owner.Send("Critico V0 Anulado");
  4573.         //        //}
  4574.  
  4575.         //        /////////////////////
  4576.         //        //#region CriticalStrike -- Potencia Baja
  4577.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  4578.         //        //{
  4579.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  4580.         //        //    {
  4581.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 5f) - ((float)attacked.Immunity / 10f)))
  4582.         //        //        {
  4583.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  4584.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.3);
  4585.         //        //        }
  4586.         //        //        else
  4587.         //        //        {
  4588.         //        //            Immu(attacked);
  4589.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Immu;
  4590.         //        //            //  attacker.Owner.Send("Critico V0 Anulado");
  4591.         //        //        }
  4592.         //        //    }
  4593.  
  4594.         //        //}
  4595.         //        //#endregion
  4596.         //        //#region CriticalStrike -- Potencia Alta
  4597.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  4598.         //        //{
  4599.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  4600.         //        //    {
  4601.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 10f) - ((float)attacked.Immunity / 10f)))
  4602.         //        //        {
  4603.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  4604.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.2);
  4605.         //        //        }
  4606.         //        //        else
  4607.         //        //        {
  4608.         //        //            Immu(attacked);
  4609.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Immu;
  4610.         //        //            //  attacker.Owner.Send("Critico V0 Anulado");
  4611.         //        //        }
  4612.         //        //    }
  4613.         //        //}
  4614.         //        //#endregion
  4615.         //        #region Superman & Stigma
  4616.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  4617.         //            if (!attacker.Transformed && Damage > 1)
  4618.         //                Damage = (long)(Damage * 1.2);
  4619.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  4620.         //            Damage *= 1.0; //PvP Reduction!
  4621.         //        #endregion
  4622.         //        #region DragonGem
  4623.         //        var DragonBonus = attacker.Gems[GemTypes.Dragon];
  4624.         //        if (DragonBonus > 0)
  4625.         //            Damage += MathHelper.MulDiv((int)Damage, DragonBonus, 100);
  4626.         //        if (attacker.Gems[GemTypes.Dragon] >= 210)
  4627.         //            Damage += Damage * 50 / 100;
  4628.         //        #endregion
  4629.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4630.         //        {
  4631.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  4632.         //                if (attacked.Stamina > 20)
  4633.         //                    attacked.Stamina -= 20;
  4634.         //                else
  4635.         //                    attacked.Stamina = 0;
  4636.         //            attacked.Action = Enums.ConquerAction.None;
  4637.         //        }
  4638.         //        if (attacker != null)
  4639.         //        {
  4640.         //            Damage += (Double)attacker.PhysicalDamageIncrease;
  4641.         //        }
  4642.         //        if (attacked != null)
  4643.         //        {
  4644.         //            Damage -= (Double)attacked.PhysicalDamageDecrease;
  4645.         //        }
  4646.  
  4647.         //        AutoRespone(attacker, attacked, ref Damage);
  4648.  
  4649.         //        #region Block
  4650.         //        #region Block 1
  4651.         //        int nAtk = attacked.Defence;
  4652.         //        uint remove = 0;
  4653.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShieldBreak))
  4654.         //            remove = 2000;
  4655.         //        if (Kernel.Rate(((attacked.Block - remove) / 100)) && attacked.Block > 0)
  4656.         //        {
  4657.         //            Packet.Effect |= MsgInteract.InteractEffects.Block;
  4658.         //            int blockdamage = ((nAtk * (attacked.Block / 100)) / 100);
  4659.         //            if (Damage > blockdamage)
  4660.         //                Damage -= blockdamage;
  4661.         //            else
  4662.         //                Damage = 1;
  4663.         //        }
  4664.         //        #endregion
  4665.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4666.         //        {
  4667.         //            if (Kernel.Rate(22))
  4668.         //            {
  4669.         //                if (attacked.Block > 0)
  4670.         //                {
  4671.         //                    Packet.Effect |= MsgInteract.InteractEffects.Block;
  4672.         //                    Damage = (Int32)Math.Floor((float)Damage / 2);
  4673.         //                }
  4674.         //            }
  4675.         //        }
  4676.         //        #endregion
  4677.         //        #region Reduction!
  4678.  
  4679.         //        #region Clac Defence
  4680.         //        int nDef, defmain;
  4681.         //        if (!attacker.Transformed)
  4682.         //            nDef = defmain = attacked.Defence;
  4683.         //        else
  4684.         //            nDef = defmain = attacked.TransformationDefence;
  4685.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  4686.         //        if (attacked.IsDefensiveStance)
  4687.         //            nDef *= 3;
  4688.         //        #endregion
  4689.                
  4690.         //        #endregion
  4691.         //        Damage = RemoveExcessDamageNinja((long)Damage, attacker, attacked);
  4692.         //        //Damage -= nDef;
  4693.         //        if (Damage < 1)
  4694.         //            Damage = 1;
  4695.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  4696.         //    }
  4697.         //    #endregion
  4698.         //    #region Player Vs Monster
  4699.         //    else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  4700.         //    {
  4701.         //        int Damage = 0;
  4702.         //        Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  4703.         //        CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  4704.         //        return (uint)Damage;
  4705.         //    }
  4706.         //    #endregion
  4707.         //    #region Monster Vs Player
  4708.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  4709.         //    {
  4710.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  4711.         //            return 1;
  4712.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  4713.         //            return 1;
  4714.         //        Double Damage = 0;
  4715.         //        Double Reborn = 1.00;
  4716.         //        if (attacked.Reborn == 1)
  4717.         //            Reborn -= 0.30; //30%
  4718.         //        else if (attacked.Reborn >= 2)
  4719.         //            Reborn -= 0.50; //50%
  4720.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  4721.         //        Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  4722.         //        Damage -= attacked.Defence;
  4723.         //        Damage *= Reborn;
  4724.  
  4725.         //        #region Bless Reduction
  4726.  
  4727.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  4728.         //        if (reduce > 0)
  4729.         //        {
  4730.         //            Damage -= Damage * reduce / 100;
  4731.         //        }
  4732.  
  4733.         //        #endregion
  4734.  
  4735.         //        if (Damage < 1)
  4736.         //            Damage = 1;
  4737.         //        Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  4738.  
  4739.  
  4740.  
  4741.  
  4742.         //        #region Sell Bounes
  4743.  
  4744.         //        if (spell != null)
  4745.         //        {
  4746.         //            if (spell.PowerPercent != 0)
  4747.         //            {
  4748.         //                Damage = (long)(Damage * spell.PowerPercent);
  4749.         //            }
  4750.         //        }
  4751.  
  4752.         //        #endregion
  4753.  
  4754.         //        Damage -= attacked.PhysicalDamageDecrease;
  4755.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4756.         //        {
  4757.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  4758.         //                if (attacked.Stamina > 20)
  4759.         //                    attacked.Stamina -= 20;
  4760.         //                else
  4761.         //                    attacked.Stamina = 0;
  4762.         //            attacked.Action = Enums.ConquerAction.None;
  4763.         //        }
  4764.         //        if (attacker.OnSuperman())
  4765.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  4766.         //                if (attacked.MonsterInfo.Boss)
  4767.         //                    Damage *= 2;
  4768.         //        if (attacker.OnSuperman())
  4769.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  4770.         //                Damage *= 2;
  4771.         //        if (attacker.OnFatalStrike())
  4772.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  4773.         //                if (!attacked.MonsterInfo.Boss)
  4774.         //                    Damage *= 5;
  4775.         //                else Damage += (int)(Damage * .1);
  4776.         //        if (Damage < 1)
  4777.         //            Damage = 1;
  4778.         //        #region Reduction!
  4779.  
  4780.         //        #region Clac Defence
  4781.         //        int nDef, defmain;
  4782.         //        if (!attacker.Transformed)
  4783.         //            nDef = defmain = attacked.Defence;
  4784.         //        else
  4785.         //            nDef = defmain = attacked.TransformationDefence;
  4786.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  4787.         //        if (attacked.IsDefensiveStance)
  4788.         //            nDef *= 3;
  4789.  
  4790.         //        #endregion
  4791.              
  4792.         //        #endregion
  4793.         //        if (Damage < 1)
  4794.         //            Damage = 1;
  4795.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  4796.         //    }
  4797.         //    #endregion
  4798.         //    #region Codigos Extras
  4799.         //    if (attacker == null || attacked == null)
  4800.         //        return 0;
  4801.         //    long attack = 0;
  4802.         //    int defense = 0;
  4803.         //    if (attacker.PlayerFlag == PlayerFlag.Monster)
  4804.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4805.         //            if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  4806.         //                return 0;
  4807.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  4808.         //        return 1;
  4809.         //    if (attacked.ContainsFlag((ulong)1UL << 53))
  4810.         //        return 1;
  4811.         //    if (!attacker.Transformed)
  4812.         //        attack = attacker.MinAttack + random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  4813.         //    else
  4814.         //        attack = attacker.TransformationMinAttack +
  4815.         //                 random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  4816.  
  4817.         //    if (attacker != null)
  4818.         //    {
  4819.         //        var bonus = attacker.Gems[1];
  4820.         //        if (bonus > 0)
  4821.         //        {
  4822.         //            attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  4823.         //        }
  4824.         //        // TODO: proficiency bonus
  4825.         //    }
  4826.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  4827.         //        if (!attacker.Transformed && attack > 1)
  4828.         //            attack = (long)(attack * 1.17);
  4829.         //    if (spell != null)
  4830.         //    {
  4831.         //        if (spell.PowerPercent != 0)
  4832.         //        {
  4833.         //            attack = (long)(attack * spell.PowerPercent);
  4834.         //        }
  4835.         //    }
  4836.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  4837.         //    {
  4838.         //        var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  4839.         //        if (reducee > 0)
  4840.         //        {
  4841.         //            attack -= (attack / 2) * reducee / 100;
  4842.         //        }
  4843.         //    }
  4844.  
  4845.  
  4846.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  4847.         //    {
  4848.         //        defense = (defense * 70) / 100;
  4849.         //    }
  4850.         //    var damage = Math.Max(1, attack - defense);
  4851.         //    #endregion
  4852.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  4853.         //    {
  4854.         //        damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  4855.         //        damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  4856.         //        damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  4857.         //    }
  4858.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  4859.         //    {
  4860.         //        damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  4861.         //        damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  4862.         //            10000);
  4863.         //        damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  4864.         //    }
  4865.  
  4866.  
  4867.         //    var reduceee = 10;
  4868.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  4869.         //    {
  4870.         //        if (!attacked.Owner.Equipment.Free(3))
  4871.         //        {
  4872.         //            switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  4873.         //            {
  4874.         //                case 9:
  4875.         //                    reduceee = 1000;
  4876.         //                    break;
  4877.         //                case 8:
  4878.         //                    reduceee = 500;
  4879.         //                    break;
  4880.         //                case 7:
  4881.         //                    reduceee = 200;
  4882.         //                    break;
  4883.         //                case 6:
  4884.         //                    reduceee = 100;
  4885.         //                    break;
  4886.         //            }
  4887.         //        }
  4888.         //    }
  4889.         //    if (attacker.PlayerFlag == PlayerFlag.Player)
  4890.         //    {
  4891.         //        var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  4892.         //        if (n > damage)
  4893.         //        {
  4894.         //            damage = n;
  4895.         //        }
  4896.         //    }
  4897.         //    damage = Math.Max(1, damage);
  4898.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  4899.         //    {
  4900.         //        damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  4901.         //    }
  4902.         //    if (attacked != null)
  4903.         //    {
  4904.         //        var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  4905.         //        if (reduces > 0)
  4906.         //        {
  4907.         //            damage -= damage * reduces / 100;
  4908.         //        }
  4909.         //    }
  4910.         //    if (attacker != null)
  4911.         //    {
  4912.         //        damage += attacker.PhysicalDamageIncrease;
  4913.         //    }
  4914.  
  4915.         //    if (attacked != null)
  4916.         //    {
  4917.         //        damage -= attacked.PhysicalDamageDecrease;
  4918.         //    }
  4919.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  4920.         //    {
  4921.         //        if (attacked.AzureDamage >= damage)
  4922.         //        {
  4923.         //            attacked.AzureDamage -= (int)damage;
  4924.         //            int sec = 60 - (Time32.Now - attacked.MagicShieldStamp).TotalMilliseconds;
  4925.         //            attacked.Owner.Send(Constants.Shield(attacked.AzureDamage, sec));
  4926.         //            return 1;
  4927.         //        }
  4928.         //        else
  4929.         //        {
  4930.         //            damage -= attacked.AzureDamage;
  4931.         //            attacked.AzureDamage = 0;
  4932.         //            attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  4933.         //        }
  4934.         //    }
  4935.         //    AutoRespone(attacker, attacked, ref damage);
  4936.  
  4937.  
  4938.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  4939.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  4940.         //            damage *= 2;
  4941.         //    if (attacked.Action == Enums.ConquerAction.Sit)
  4942.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4943.         //        {
  4944.         //            if (attacked.Stamina >= 20)
  4945.         //                attacked.Stamina -= 20;
  4946.         //            else
  4947.         //                attacked.Stamina = 0;
  4948.         //        }
  4949.         //    if (attacker.OnSuperman())
  4950.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  4951.         //            if (attacked.MonsterInfo.Boss)
  4952.         //                damage *= 2;
  4953.  
  4954.         //    if (attacker.OnSuperman())
  4955.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  4956.         //            damage *= 2;
  4957.         //    if (attacker.OnFatalStrike())
  4958.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  4959.         //            damage *= 5;
  4960.         //    return Math.Max((uint)1, (uint)damage);
  4961.         //}
  4962.         //public static uint Monje(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  4963.         //{
  4964.  
  4965.         //    if (attacked.Name == "InfernalEpico") return 1;
  4966.         //    if (attacked.Name == "SilverOctopus") return 1;
  4967.         //    if (attacked.Name == "GoldenOctopus") return 1;
  4968.         //    if (Packet != null)
  4969.         //    {
  4970.         //        Packet.Effect = MsgInteract.InteractEffects.None;
  4971.         //    }
  4972.  
  4973.         //    if (attacked.Name == "Guard1" && attacker.PlayerFlag == PlayerFlag.Monster)
  4974.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  4975.         //        {
  4976.         //            #region CheakMiss
  4977.         //            if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  4978.         //                if (Kernel.ChanceSuccess(30))
  4979.         //                {
  4980.         //                    MsgName str = new MsgName(true);
  4981.         //                    str.UID = attacked.UID;
  4982.         //                    str.TextsCount = 1;
  4983.         //                    str.Type = MsgName.Effect;
  4984.         //                    str.Texts.Add("poisonmiss");
  4985.         //                    attacked.Owner.SendScreen(str, true);
  4986.         //                    return 0;
  4987.         //                }
  4988.         //            #endregion
  4989.         //        }
  4990.         //    #region PvP -- Player Vs Player -- Jugador Contra Jugador
  4991.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  4992.         //    {
  4993.  
  4994.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  4995.         //            return 1;
  4996.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  4997.         //            return 1;
  4998.         //        Double Damage = 0;
  4999.  
  5000.         //        Double Reborn = 1.00;
  5001.         //        if (attacked.Reborn == 1)
  5002.         //            Reborn -= 0.30;
  5003.         //        else if (attacked.Reborn >= 2)
  5004.         //            Reborn -= 0.50;
  5005.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  5006.         //        Boolean canBT = false, CritImmune = false;
  5007.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  5008.         //        {
  5009.         //            if (attacker.BattlePower < attacked.BattlePower)
  5010.         //            {
  5011.         //                canBT = true;
  5012.         //            }
  5013.         //        }
  5014.         //        else canBT = false;
  5015.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  5016.         //        {
  5017.         //            if (canBT)
  5018.         //            {
  5019.         //                if (Kernel.Rate(((float)attacker.Breaktrough / 1f - (float)attacked.Counteraction / 2f)))
  5020.         //                {
  5021.         //                    Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  5022.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.6);//60% de Daño
  5023.         //                }
  5024.         //            }
  5025.         //        }
  5026.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  5027.         //        {
  5028.         //            if (attacker.BattlePower >= attacked.BattlePower)
  5029.         //            {
  5030.         //                CritImmune = true;
  5031.         //            }
  5032.         //        }
  5033.         //        else CritImmune = false;
  5034.         //        if (attacker.PlayerFlag == PlayerFlag.Player)
  5035.         //        {
  5036.         //            if (CritImmune)
  5037.         //            {
  5038.         //                if (Kernel.Rate(((float)attacker.CriticalStrike / 1f - (float)attacked.Immunity / 2f)))
  5039.         //                {
  5040.         //                    Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  5041.         //                    Damage = (Int32)Math.Floor((float)Damage * 1.3);
  5042.         //                }
  5043.         //            }
  5044.         //        }
  5045.         //        //Damage -= attacked.Defence;
  5046.         //        #region AzureShield
  5047.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  5048.         //        {
  5049.         //            if (Damage > attacked.AzureShieldDefence)
  5050.         //            {
  5051.         //                Damage -= attacked.AzureShieldDefence;
  5052.         //                CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  5053.         //                attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  5054.         //            }
  5055.         //            else
  5056.         //            {
  5057.         //                CreateAzureDmg((uint)Damage, attacker, attacked);
  5058.         //                attacked.AzureShieldDefence -= (ushort)Damage;
  5059.         //                attacked.AzureShieldPacket();
  5060.         //                Damage = 1;
  5061.         //            }
  5062.         //        }
  5063.         //        #endregion
  5064.  
  5065.         //        //#region Breakthrough -- Potencias Bajas
  5066.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  5067.         //        //{
  5068.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  5069.         //        //    {
  5070.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  5071.         //        //        {
  5072.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.4);
  5073.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  5074.         //        //        }
  5075.         //        //    }
  5076.         //        //}
  5077.         //        //#endregion
  5078.  
  5079.         //        #region Breakthrough -- Potencias Altas ((DESACTIVADO))
  5080.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  5081.         //        //{
  5082.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  5083.         //        //    {
  5084.         //        //        if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  5085.         //        //        {
  5086.         //        //            Damage = (Int32)Math.Floor((float)Damage * 1.05);
  5087.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Penetration;
  5088.         //        //        }
  5089.         //        //    }
  5090.         //        //}
  5091.         //        #endregion
  5092.  
  5093.         //        Damage *= Reborn;
  5094.         //        if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield))
  5095.         //        {
  5096.  
  5097.         //            if (Damage > attacked.AzureShieldDefence)
  5098.         //            {
  5099.         //                Damage -= attacked.AzureShieldDefence;
  5100.         //                CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  5101.         //                attacked.RemoveFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield);
  5102.         //            }
  5103.         //            else
  5104.         //            {
  5105.         //                CreateAzureDmg((uint)Damage, attacker, attacked);
  5106.         //                attacked.AzureShieldDefence -= (ushort)Damage;
  5107.         //                attacked.AzureShieldPacket();
  5108.         //                Damage = 1;
  5109.         //            }
  5110.         //        }
  5111.  
  5112.         //        //#region Ataque segun Nobleza
  5113.         //        //#region Rey
  5114.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.King)
  5115.         //        //{
  5116.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  5117.         //        //    {
  5118.         //        //        Damage = (int)((double)Damage * 1.0);
  5119.         //        //    }
  5120.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  5121.         //        //    {
  5122.         //        //        Damage = (int)((double)Damage * 1.0);
  5123.         //        //    }
  5124.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  5125.         //        //    {
  5126.         //        //        Damage = (int)((double)Damage * 1.0);
  5127.         //        //    }
  5128.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  5129.         //        //    {
  5130.         //        //        Damage = (int)((double)Damage * 1.0);
  5131.         //        //    }
  5132.         //        //}
  5133.         //        //#endregion
  5134.         //        //#region Duque
  5135.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Prince)
  5136.         //        //{
  5137.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  5138.         //        //    {
  5139.         //        //        Damage = (int)((double)Damage * 1.0);
  5140.         //        //    }
  5141.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  5142.         //        //    {
  5143.         //        //        Damage = (int)((double)Damage * 1.0);
  5144.         //        //    }
  5145.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  5146.         //        //    {
  5147.         //        //        Damage = (int)((double)Damage * 1.0);
  5148.         //        //    }
  5149.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  5150.         //        //    {
  5151.         //        //        Damage = (int)((double)Damage * 1.0);
  5152.         //        //    }
  5153.         //        //}
  5154.         //        //#endregion Prince
  5155.         //        //#region Marques
  5156.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Duke)
  5157.         //        //{
  5158.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  5159.         //        //    {
  5160.         //        //        Damage = (int)((double)Damage * 1.0);
  5161.         //        //    }
  5162.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  5163.         //        //    {
  5164.         //        //        Damage = (int)((double)Damage * 1.0);
  5165.         //        //    }
  5166.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  5167.         //        //    {
  5168.         //        //        Damage = (int)((double)Damage * 1.2);
  5169.         //        //    }
  5170.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  5171.         //        //    {
  5172.         //        //        Damage = (int)((double)Damage * 1.0);
  5173.         //        //    }
  5174.         //        //}
  5175.         //        //#endregion Duke
  5176.         //        //#region Conde
  5177.         //        //if (attacker.NobilityRank == ConquerStructures.NobilityRank.Earl)
  5178.         //        //{
  5179.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.King)
  5180.         //        //    {
  5181.         //        //        Damage = (int)((double)Damage * 1.5);
  5182.         //        //    }
  5183.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Prince)
  5184.         //        //    {
  5185.         //        //        Damage = (int)((double)Damage * 1.5);
  5186.         //        //    }
  5187.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Duke)
  5188.         //        //    {
  5189.         //        //        Damage = (int)((double)Damage * 1.5);
  5190.         //        //    }
  5191.         //        //    if (attacked.NobilityRank == ConquerStructures.NobilityRank.Earl)
  5192.         //        //    {
  5193.         //        //        Damage = (int)((double)Damage * 1.5);
  5194.         //        //    }
  5195.         //        //}
  5196.         //        //#endregion Earl
  5197.         //        //#endregion
  5198.         //        #region Efectos Perfectos
  5199.         //        /*
  5200.         //        if (attacker.PrefictionEffect != null)
  5201.         //        {
  5202.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  5203.         //            if (Kernel.ChanceSuccess(30))//30% Probabilidad de Que Salga
  5204.         //            {
  5205.         //                if (attacker.PrefictionLevel > attacked.PrefictionLevel)
  5206.         //                {
  5207.         //                    Network.Writer.WriteUInt16((ushort)(1 << 10), 36, Packet.ToArray());
  5208.         //                    attacker.Owner.SendScreen(MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike));
  5209.         //                    Damage += Damage / 2;
  5210.         //                }
  5211.         //                else
  5212.         //                {
  5213.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  5214.         //                }
  5215.         //            }
  5216.         //        }
  5217.         //        if (attacker.PrefictionEffect != null)
  5218.         //        {
  5219.         //            var eff = attacker.PrefictionEffect.GetLuckyStrike();
  5220.         //            if (Kernel.Rate(eff.Percant))
  5221.         //            {
  5222.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.LuckyStrike);
  5223.         //                Damage += Damage;
  5224.         //            }
  5225.         //            eff = attacker.PrefictionEffect.GetCalmWind();
  5226.         //            if (Kernel.Rate(eff.Percant))
  5227.         //            {
  5228.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.CalmWind);
  5229.         //                foreach (var item in attacker.Owner.Spells.Values)
  5230.         //                    item.AttackStamp = Time64.Now.AddSeconds(-50);
  5231.         //            }
  5232.         //            eff = attacker.PrefictionEffect.GetDrainingTouch();
  5233.         //            if (Kernel.Rate(eff.Percant))
  5234.         //            {
  5235.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, attacked.UID, prefeff.DrainingTouch);
  5236.         //                attacker.Hitpoints = attacker.MaxHitpoints;
  5237.         //                attacker.Mana = attacker.MaxMana;
  5238.         //            }
  5239.         //            eff = attacker.PrefictionEffect.GetKillingFlash();
  5240.         //            if (Kernel.Rate(eff.Percant))
  5241.         //            {
  5242.         //                MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.MirrorofSin);
  5243.         //                attacker.Owner.XPCount = 100;
  5244.         //            }
  5245.         //            if (attacked.PrefictionLevel > attacker.PrefictionLevel)
  5246.         //            {
  5247.         //                if (Damage >= attacked.MaxHitpoints / 2)
  5248.         //                {
  5249.         //                    eff = attacker.PrefictionEffect.GetLightofStamina();
  5250.         //                    if (Kernel.Rate(eff.Percant))
  5251.         //                    {
  5252.         //                        MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.LightofStamina);
  5253.         //                        attacker.Stamina = 150;
  5254.         //                    }
  5255.         //                }
  5256.         //            }
  5257.  
  5258.  
  5259.         //        }
  5260.         //        #region Prefiction on attacked from monster
  5261.         //        if (attacked.PrefictionEffect != null)
  5262.         //        {
  5263.         //            var eff = attacked.PrefictionEffect.GetStrikeLock();
  5264.         //            if (Kernel.Rate(eff.Percant))
  5265.         //            {
  5266.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.Stricklock);
  5267.         //                return 0;
  5268.         //            }
  5269.         //            eff = attacked.PrefictionEffect.GetBloodSpawn();
  5270.         //            if (Kernel.Rate(eff.Percant))
  5271.         //            {
  5272.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, attacker.UID, prefeff.BloodSpawn);
  5273.         //                attacked.Hitpoints = attacked.MaxHitpoints;
  5274.         //                attacked.Mana = attacked.MaxMana;
  5275.         //            }
  5276.         //            eff = attacked.PrefictionEffect.GetMirrorofSin();
  5277.         //            if (Kernel.Rate(eff.Percant))
  5278.         //            {
  5279.         //                MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.MirrorofSin);
  5280.         //                attacked.Owner.XPCount = 100;
  5281.         //            }
  5282.         //            if (attacked != null && attacked.PrefictionLevel >= attacker.PrefictionLevel)
  5283.         //            {
  5284.         //                eff = attacker.PrefictionEffect.GetShieldBreak();
  5285.         //                if (Kernel.Rate(eff.Percant))
  5286.         //                {
  5287.         //                    MsgRefineEffect.SendPrefictioneffect(attacker.UID, 0, prefeff.ShieldBreak);
  5288.         //                    attacked.AddFlag3(MsgUpdate.Flags.ShieldBreak);
  5289.         //                    attacked.ShieldBreakStamp = Time64.Now;
  5290.         //                }
  5291.         //            }
  5292.         //            if (attacked != null && attacked.PrefictionLevel > attacker.PrefictionLevel)
  5293.         //            {
  5294.         //                eff = attacked.PrefictionEffect.GetDivineGuard();
  5295.         //                if (Kernel.Rate(eff.Percant))
  5296.         //                {
  5297.         //                    MsgRefineEffect.SendPrefictioneffect(attacked.UID, 0, prefeff.DivineGuard);
  5298.         //                    attacked.AddFlag3(MsgUpdate.Flags.DivineGuard);
  5299.         //                    attacked.DivineGuardStamp = Time64.Now;
  5300.         //                }
  5301.         //            }
  5302.  
  5303.         //        }
  5304.         //        #endregion
  5305.         //        */
  5306.         //        #endregion
  5307.         //        #region Bless Reduction
  5308.  
  5309.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  5310.         //        if (reduce > 0)
  5311.         //        {
  5312.         //            Damage -= Damage * reduce / 115;
  5313.         //        }
  5314.  
  5315.         //        #endregion
  5316.         //        if (Damage < 1)
  5317.         //            Damage = 1;
  5318.  
  5319.         //        #region Sepll Bounes
  5320.  
  5321.         //        if (spell != null)
  5322.         //        {
  5323.         //            if (spell.ID != 12290)
  5324.         //            {
  5325.         //                if (spell.PowerPercent != 0)
  5326.         //                {
  5327.         //                    Damage = (Double)(Damage * spell.PowerPercent);
  5328.         //                }
  5329.         //            }
  5330.         //        }
  5331.  
  5332.         //        #endregion
  5333.         //        //#region CriticalStrike -- Potencias Altas VS Bajas
  5334.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  5335.         //        //{
  5336.         //        //    if (attacker.BattlePower > attacked.BattlePower)
  5337.         //        //    {
  5338.         //        //        if (attacker.CriticalStrike + 10000 > attacked.Immunity)
  5339.         //        //        {
  5340.         //        //            if (Kernel.Rate(50))
  5341.         //        //            {
  5342.         //        //                Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  5343.         //        //                Damage = (Int32)Math.Floor((float)Damage * 1.2);
  5344.         //        //                attacker.Owner.Send("Le Has Dado un Criticaso!!");
  5345.         //        //            }
  5346.         //        //        }
  5347.         //        //        else
  5348.         //        //        {
  5349.         //        //            Immu(attacked);
  5350.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.Immu;
  5351.         //        //            attacker.Owner.Send("Te Anulo tu Criticaso!");
  5352.         //        //        }
  5353.         //        //    }
  5354.         //        //}
  5355.         //        //#endregion
  5356.         //        //#region CriticalStrike -- Potencias Bajas
  5357.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  5358.         //        //{
  5359.         //        //    if (attacker.BattlePower < attacked.BattlePower)
  5360.         //        //    {
  5361.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  5362.         //        //        {
  5363.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  5364.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.2);
  5365.         //        //        }
  5366.         //        //    }
  5367.         //        //}
  5368.         //        //#endregion
  5369.         //        //#region CriticalStrike -- Potencias Altas
  5370.         //        //if (attacker.PlayerFlag == PlayerFlag.Player)
  5371.         //        //{
  5372.         //        //    if (attacker.BattlePower >= attacked.BattlePower)
  5373.         //        //    {
  5374.         //        //        if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike) - ((float)attacked.Immunity)))
  5375.         //        //        {
  5376.         //        //            Packet.Effect1 |= MsgInteract.InteractEffects.CriticalStrike;
  5377.         //        //            Damage = (UInt32)Math.Floor((float)Damage * 1.4);
  5378.         //        //        }
  5379.         //        //    }
  5380.         //        //}
  5381.         //        //#endregion
  5382.         //        #region Superman & Stigma
  5383.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  5384.         //            if (!attacker.Transformed && Damage > 1)
  5385.         //                Damage = (long)(Damage * 1.12);
  5386.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  5387.         //            Damage *= 1.0; //PvP Reduction!
  5388.         //        #endregion
  5389.         //        #region DragonGem
  5390.         //        var DragonBonus = attacker.Gems[GemTypes.Dragon];
  5391.         //        if (DragonBonus > 0)
  5392.         //            Damage += MathHelper.MulDiv((int)Damage, DragonBonus, 100);
  5393.         //        if (attacker.Gems[GemTypes.Dragon] >= 210)
  5394.         //            Damage += Damage * 50 / 100;
  5395.         //        #endregion
  5396.         //        #region TortoiseGem -- LO LEE DESDE EL CODIGO DE REMOVEEXCESS
  5397.         //        //double torist = (double)(attacked.Gems[COServer.AttackBedan.GemTypes.Tortoise] / 100d);
  5398.         //        //torist = (double)(1 - torist);
  5399.         //        //torist = Math.Max(torist, 0.5);
  5400.         //        //Damage *= torist;
  5401.         //        //Pezzi
  5402.  
  5403.         //        #endregion
  5404.         //        #region Superman & Stigma
  5405.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  5406.         //            if (!attacker.Transformed && Damage > 1)
  5407.         //                Damage = (long)(Damage * 1.12);
  5408.         //        if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  5409.         //            Damage *= 1.0; //PvP Reduction!
  5410.  
  5411.         //        #endregion
  5412.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  5413.         //        {
  5414.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  5415.         //                if (attacked.Stamina > 20)
  5416.         //                    attacked.Stamina -= 20;
  5417.         //                else
  5418.         //                    attacked.Stamina = 0;
  5419.         //            attacked.Action = Enums.ConquerAction.None;
  5420.         //        }
  5421.         //        if (attacker != null)
  5422.         //        {
  5423.         //            Damage += (Double)attacker.PhysicalDamageIncrease;
  5424.         //        }
  5425.         //        if (attacked != null)
  5426.         //        {
  5427.         //            Damage -= (Double)attacked.PhysicalDamageDecrease;
  5428.         //        }
  5429.  
  5430.         //        AutoRespone(attacker, attacked, ref Damage);
  5431.  
  5432.         //        #region Block
  5433.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  5434.         //        {
  5435.         //            if (Kernel.Rate(22))
  5436.         //            {
  5437.         //                if (attacked.Block > 0)
  5438.         //                {
  5439.         //                    Packet.Effect |= MsgInteract.InteractEffects.Block;
  5440.         //                    Damage = (Int32)Math.Floor((float)Damage / 2);
  5441.         //                }
  5442.         //            }
  5443.         //        }
  5444.         //        #endregion
  5445.         //        #region MagicShield
  5446.  
  5447.         //        if (!attacked.Transformed)
  5448.         //        {
  5449.         //            if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.MagicShield))
  5450.         //            {
  5451.         //                if (attacked.ShieldTime > 0)
  5452.         //                {
  5453.         //                    if (Damage > (int)attacked.Defence)
  5454.         //                    {
  5455.         //                        Damage -= (int)attacked.Defence;
  5456.         //                    }
  5457.         //                    else
  5458.         //                        Damage = 1;
  5459.         //                }
  5460.         //                else
  5461.         //                {
  5462.         //                    if (Damage > (ushort)(attacked.Defence * attacked.MagicShieldIncrease))
  5463.         //                        Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  5464.         //                    else
  5465.         //                        Damage = 1;
  5466.         //                }
  5467.         //            }
  5468.         //            else
  5469.         //            {
  5470.         //                if (Damage > (int)attacked.Defence)
  5471.         //                {
  5472.         //                    Damage -= (int)attacked.Defence;
  5473.         //                }
  5474.         //                else
  5475.         //                    Damage = 1;
  5476.         //            }
  5477.         //        }
  5478.         //        else
  5479.         //        {
  5480.         //            if (Damage > attacked.TransformationDefence)
  5481.         //            {
  5482.         //                Damage -= attacked.TransformationDefence;
  5483.         //            }
  5484.         //            else
  5485.         //                Damage = 1;
  5486.         //        }
  5487.  
  5488.         //        #endregion
  5489.         //        #region Reduction!
  5490.  
  5491.         //        #region Clac Defence
  5492.         //        int nDef, defmain;
  5493.         //        if (!attacker.Transformed)
  5494.         //            nDef = defmain = attacked.Defence;
  5495.         //        else
  5496.         //            nDef = defmain = attacked.TransformationDefence;
  5497.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  5498.         //        if (attacked.IsDefensiveStance)
  5499.         //            nDef *= 3;
  5500.  
  5501.         //        #endregion End Defence
  5502.                
  5503.         //        #endregion
  5504.         //        Damage = RemoveExcessDamageMonje((long)Damage, attacker, attacked);//1
  5505.         //        if (Damage < 1)
  5506.         //            Damage = 1;
  5507.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  5508.         //    }
  5509.         //    #endregion
  5510.         //    #region Player Vs Monster
  5511.         //    else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  5512.         //    {
  5513.         //        int Damage = 0;
  5514.         //        Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  5515.         //        CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  5516.         //        return (uint)Damage;
  5517.         //    }
  5518.         //    #endregion
  5519.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  5520.         //    {
  5521.         //        if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  5522.         //            return 1;
  5523.         //        if (attacked.ContainsFlag((ulong)1UL << 53))
  5524.         //            return 1;
  5525.         //        Double Damage = 0;
  5526.         //        Double Reborn = 1.00;
  5527.         //        if (attacked.Reborn == 1)
  5528.         //            Reborn -= 0.30; //30%
  5529.         //        else if (attacked.Reborn >= 2)
  5530.         //            Reborn -= 0.50; //50%
  5531.         //        Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  5532.         //        Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  5533.         //        Damage -= attacked.Defence;
  5534.         //        Damage *= Reborn;
  5535.  
  5536.         //        #region Bless Reduction
  5537.  
  5538.         //        var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  5539.         //        if (reduce > 0)
  5540.         //        {
  5541.         //            Damage -= Damage * reduce / 100;
  5542.         //        }
  5543.  
  5544.         //        #endregion
  5545.  
  5546.         //        if (Damage < 1)
  5547.         //            Damage = 1;
  5548.         //        Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  5549.  
  5550.  
  5551.  
  5552.  
  5553.         //        #region Sell Bounes
  5554.  
  5555.         //        if (spell != null)
  5556.         //        {
  5557.         //            if (spell.PowerPercent != 0)
  5558.         //            {
  5559.         //                Damage = (long)(Damage * spell.PowerPercent);
  5560.         //            }
  5561.         //        }
  5562.  
  5563.         //        #endregion
  5564.  
  5565.         //        Damage -= attacked.PhysicalDamageDecrease;
  5566.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  5567.         //        {
  5568.         //            if (attacked.Action == Enums.ConquerAction.Sit)
  5569.         //                if (attacked.Stamina > 20)
  5570.         //                    attacked.Stamina -= 20;
  5571.         //                else
  5572.         //                    attacked.Stamina = 0;
  5573.         //            attacked.Action = Enums.ConquerAction.None;
  5574.         //        }
  5575.         //        if (attacker.OnSuperman())
  5576.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  5577.         //                if (attacked.MonsterInfo.Boss)
  5578.         //                    Damage *= 2;
  5579.         //        if (attacker.OnSuperman())
  5580.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  5581.         //                Damage *= 2;
  5582.         //        if (attacker.OnFatalStrike())
  5583.         //            if (attacked.PlayerFlag == PlayerFlag.Monster)
  5584.         //                if (!attacked.MonsterInfo.Boss)
  5585.         //                    Damage *= 5;
  5586.         //                else Damage += (int)(Damage * .1);
  5587.         //        if (Damage < 1)
  5588.         //            Damage = 1;
  5589.         //        #region Reduction!
  5590.  
  5591.         //        #region Clac Defence
  5592.         //        int nDef, defmain;
  5593.         //        if (!attacker.Transformed)
  5594.         //            nDef = defmain = attacked.Defence;
  5595.         //        else
  5596.         //            nDef = defmain = attacked.TransformationDefence;
  5597.         //        nDef = Handle.ShieldDefence(attacked, nDef);
  5598.         //        if (attacked.IsDefensiveStance)
  5599.         //            nDef *= 3;
  5600.  
  5601.         //        #endregion End Defence
  5602.              
  5603.         //        #endregion
  5604.         //        if (Damage < 1)
  5605.         //            Damage = 1;
  5606.         //        return (UInt32)Math.Round(Damage, (Int32)0);
  5607.         //    }
  5608.         //    if (attacker == null || attacked == null)
  5609.         //        return 0;
  5610.         //    long attack = 0;
  5611.         //    int defense = 0;
  5612.         //    if (attacker.PlayerFlag == PlayerFlag.Monster)
  5613.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  5614.         //            if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  5615.         //                return 0;
  5616.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  5617.         //        return 1;
  5618.         //    if (attacked.ContainsFlag((ulong)1UL << 53))
  5619.         //        return 1;
  5620.         //    if (!attacker.Transformed)
  5621.         //        attack = attacker.MinAttack + random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  5622.         //    else
  5623.         //        attack = attacker.TransformationMinAttack +
  5624.         //                 random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  5625.  
  5626.         //    if (attacker != null)
  5627.         //    {
  5628.         //        var bonus = attacker.Gems[1];
  5629.         //        if (bonus > 0)
  5630.         //        {
  5631.         //            attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  5632.         //        }
  5633.         //        // TODO: proficiency bonus
  5634.         //    }
  5635.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  5636.         //        if (!attacker.Transformed && attack > 1)
  5637.         //            attack = (long)(attack * 1.17);
  5638.         //    if (spell != null)
  5639.         //    {
  5640.         //        if (spell.PowerPercent != 0)
  5641.         //        {
  5642.         //            attack = (long)(attack * spell.PowerPercent);
  5643.         //        }
  5644.         //    }
  5645.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  5646.         //    {
  5647.         //        var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  5648.         //        if (reducee > 0)
  5649.         //        {
  5650.         //            attack -= (attack / 2) * reducee / 100;
  5651.         //        }
  5652.         //    }
  5653.  
  5654.  
  5655.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  5656.         //    {
  5657.         //        defense = (defense * 70) / 100;
  5658.         //    }
  5659.         //    var damage = Math.Max(1, attack - defense);
  5660.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  5661.         //    {
  5662.         //        damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  5663.         //        damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  5664.         //        damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  5665.         //    }
  5666.         //    else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  5667.         //    {
  5668.         //        damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  5669.         //        damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  5670.         //            10000);
  5671.         //        damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  5672.         //    }
  5673.  
  5674.  
  5675.         //    var reduceee = 10;
  5676.         //    if (attacked.PlayerFlag == PlayerFlag.Player)
  5677.         //    {
  5678.         //        if (!attacked.Owner.Equipment.Free(3))
  5679.         //        {
  5680.         //            switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  5681.         //            {
  5682.         //                case 9:
  5683.         //                    reduceee = 1000;
  5684.         //                    break;
  5685.         //                case 8:
  5686.         //                    reduceee = 500;
  5687.         //                    break;
  5688.         //                case 7:
  5689.         //                    reduceee = 200;
  5690.         //                    break;
  5691.         //                case 6:
  5692.         //                    reduceee = 100;
  5693.         //                    break;
  5694.         //            }
  5695.         //        }
  5696.         //    }
  5697.         //    if (attacker.PlayerFlag == PlayerFlag.Player)
  5698.         //    {
  5699.         //        var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  5700.         //        if (n > damage)
  5701.         //        {
  5702.         //            damage = n;
  5703.         //        }
  5704.         //    }
  5705.         //    damage = Math.Max(1, damage);
  5706.         //    if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  5707.         //    {
  5708.         //        damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  5709.         //    }
  5710.         //    if (attacked != null)
  5711.         //    {
  5712.         //        var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  5713.         //        if (reduces > 0)
  5714.         //        {
  5715.         //            damage -= damage * reduces / 100;
  5716.         //        }
  5717.         //    }
  5718.         //    if (attacker != null)
  5719.         //    {
  5720.         //        damage += attacker.PhysicalDamageIncrease;
  5721.         //    }
  5722.  
  5723.         //    if (attacked != null)
  5724.         //    {
  5725.         //        damage -= attacked.PhysicalDamageDecrease;
  5726.         //    }
  5727.         //    if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  5728.         //    {
  5729.         //        if (attacked.AzureDamage >= damage)
  5730.         //        {
  5731.         //            attacked.AzureDamage -= (int)damage;
  5732.         //            int sec = 60 - (Time32.Now - attacked.MagicShieldStamp).TotalMilliseconds;
  5733.         //            attacked.Owner.Send(Constants.Shield(attacked.AzureDamage, sec));
  5734.         //            return 1;
  5735.         //        }
  5736.         //        else
  5737.         //        {
  5738.         //            damage -= attacked.AzureDamage;
  5739.         //            attacked.AzureDamage = 0;
  5740.         //            attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  5741.         //        }
  5742.         //    }
  5743.         //    AutoRespone(attacker, attacked, ref damage);
  5744.  
  5745.  
  5746.         //    if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  5747.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  5748.         //            damage *= 2;
  5749.         //    if (attacked.Action == Enums.ConquerAction.Sit)
  5750.         //        if (attacked.PlayerFlag == PlayerFlag.Player)
  5751.         //        {
  5752.         //            if (attacked.Stamina >= 20)
  5753.         //                attacked.Stamina -= 20;
  5754.         //            else
  5755.         //                attacked.Stamina = 0;
  5756.         //        }
  5757.         //    if (attacker.OnSuperman())
  5758.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  5759.         //            if (attacked.MonsterInfo.Boss)
  5760.         //                damage *= 2;
  5761.  
  5762.         //    if (attacker.OnSuperman())
  5763.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  5764.         //            damage *= 2;
  5765.         //    if (attacker.OnFatalStrike())
  5766.         //        if (attacked.PlayerFlag == PlayerFlag.Monster)
  5767.         //            damage *= 5;
  5768.         //    return Math.Max((uint)1, (uint)damage);
  5769.         //}
  5770.         #endregion
  5771.         public static uint Melee(Player attacker, MsgNpcInfoEX attacked, ref MsgInteract Packet)
  5772.         {
  5773.             long Damage = 0;
  5774.             Boolean CritImmune = false;
  5775.             Durability(attacker, null, null);
  5776.             if (!attacker.Transformed)
  5777.                 Damage = Kernel.Random.Next((int)Math.Min((long)attacker.MinAttack, (long)attacker.MaxAttack),
  5778.                     (int)Math.Max((long)attacker.MinAttack, (long)attacker.MaxAttack) + 1);
  5779.             else
  5780.                 Damage = Kernel.Random.Next((int)attacker.TransformationMinAttack,
  5781.                     (int)attacker.TransformationMaxAttack + 1);
  5782.             if (attacker.Gems[1] != 0)
  5783.             {
  5784.                 Damage += (uint)Math.Floor(Damage * (double)(attacker.Gems[1] * 0.01));
  5785.             }
  5786.             if (attacker.WearsGoldPrize) Damage += (long)(Damage * goldPrizePsyAttackCoefficient);
  5787.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  5788.                 if (!attacker.Transformed)
  5789.                     Damage = (long)(Damage * 1.1);
  5790.             Damage += attacker.PhysicalDamageIncrease;
  5791.             if (Kernel.ChanceSuccess(5))
  5792.             {
  5793.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  5794.                 {
  5795.                     if (attacker.Owner.BlessTime > 0)
  5796.                     {
  5797.                         Damage *= 2;
  5798.                         MsgName str = new MsgName(true);
  5799.                         str.UID = attacker.UID;
  5800.                         str.TextsCount = 1;
  5801.                         str.Action = MsgName.Effect;
  5802.                         str.Texts.Add("LuckyGuy");
  5803.                         attacker.Owner.SendScreen(str, true);
  5804.                     }
  5805.                 }
  5806.             }
  5807.             if (attacker.PlayerFlag == PlayerFlag.Player)
  5808.             {
  5809.                 if (!CritImmune)
  5810.                 {
  5811.                     if (Kernel.ChanceSuccess((float)attacker.CriticalStrike / 100f))
  5812.                     {
  5813.                         Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  5814.                         Damage = (Int32)Math.Floor((float)Damage * 1.0);
  5815.                     }
  5816.                 }
  5817.             }
  5818.             Damage = Damage * 2;
  5819.             if (Damage <= 0)
  5820.                 Damage = 1;
  5821.  
  5822.             return (uint)(Damage * reduceValue);
  5823.         }
  5824.         public static int RemoveExcessDamage(int CurrentDamage, Player Attacker, Player Opponent)
  5825.         {
  5826.             if (Opponent.PlayerFlag != PlayerFlag.Player)
  5827.                 return CurrentDamage;
  5828.             if (Opponent.Reborn == 1)
  5829.                 CurrentDamage = (int)Math.Round((double)(CurrentDamage * 1.6));
  5830.             else if (Opponent.Reborn == 2)
  5831.                 CurrentDamage = (int)Math.Round((double)(CurrentDamage * 1.4));
  5832.             CurrentDamage = (int)Math.Round((double)(CurrentDamage * (Math.Max(0.1, 1.00 - (Opponent.ItemBless * 0.01)))));
  5833.             CurrentDamage -= CurrentDamage * Math.Min(Opponent.Gems[7], (ushort)75) / 100;
  5834.             return CurrentDamage;
  5835.         }
  5836.         public static uint Fisicos(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  5837.         {
  5838.  
  5839.             if (attacked.Name == "InfernalEpico") return 1;
  5840.             if (attacked.Name == "SilverOctopus") return 1;
  5841.             if (attacked.Name == "GoldenOctopus") return 1;
  5842.             if (Packet != null)
  5843.             {
  5844.                 Packet.Effect = MsgInteract.InteractEffects.None;
  5845.             }
  5846.  
  5847.             if (attacked.Name == "Guard1" && attacker.PlayerFlag == PlayerFlag.Monster)
  5848.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  5849.                 {
  5850.                     #region CheakMiss
  5851.                     if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  5852.                         if (Kernel.ChanceSuccess(30))
  5853.                         {
  5854.                             MsgName str = new MsgName(true);
  5855.                             str.UID = attacked.UID;
  5856.                             str.TextsCount = 1;
  5857.                             str.Type = MsgName.Effect;
  5858.                             str.Texts.Add("poisonmiss");
  5859.                             attacked.Owner.SendScreen(str, true);
  5860.                             return 0;
  5861.                         }
  5862.                     #endregion
  5863.                 }
  5864.             #region PvP -- Player Vs Player -- Jugador Contra Jugador
  5865.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  5866.             {
  5867.  
  5868.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  5869.                     return 1;
  5870.                 if (attacked.ContainsFlag((ulong)1UL << 53))
  5871.                     return 1;
  5872.                 Double Damage = 0;
  5873.  
  5874.                 Double Reborn = 1.00;
  5875.                 if (attacked.Reborn == 1)
  5876.                     Reborn -= 0.30;
  5877.                 else if (attacked.Reborn >= 2)
  5878.                     Reborn -= 0.50;
  5879.                 Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  5880.  
  5881.                 #region AzureShield
  5882.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  5883.                 {
  5884.                     if (Damage > attacked.AzureShieldDefence)
  5885.                     {
  5886.                         Damage -= attacked.AzureShieldDefence;
  5887.                         CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  5888.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  5889.                     }
  5890.                     else
  5891.                     {
  5892.                         CreateAzureDmg((uint)Damage, attacker, attacked);
  5893.                         attacked.AzureShieldDefence -= (ushort)Damage;
  5894.                         attacked.AzureShieldPacket();
  5895.                         Damage = 1;
  5896.                     }
  5897.                 }
  5898.                 #endregion
  5899.  
  5900.                 #region Breakthrough
  5901.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  5902.                 {
  5903.                     if (attacker.BattlePower < attacked.BattlePower)
  5904.                     {
  5905.                         if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  5906.                         {
  5907.                             Damage = (Int32)Math.Floor((float)Damage * 1.4);
  5908.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  5909.                         }
  5910.                     }
  5911.                 }
  5912.                 #endregion
  5913.                 #region Breakthrough
  5914.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  5915.                 {
  5916.                     if (attacker.BattlePower >= attacked.BattlePower)
  5917.                     {
  5918.                         if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  5919.                         {
  5920.                             Damage = (Int32)Math.Floor((float)Damage * 1.1);
  5921.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  5922.                         }
  5923.                     }
  5924.                 }
  5925.                 #endregion
  5926.                 //Damage -= attacked.Defence;
  5927.                 Damage *= Reborn;
  5928.                 if (attacked.ContainsFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield))
  5929.                 {
  5930.  
  5931.                     if (Damage > attacked.AzureShieldDefence)
  5932.                     {
  5933.                         Damage -= attacked.AzureShieldDefence;
  5934.                         CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  5935.                         attacked.RemoveFlag((ulong)Network.GamePackets.MsgUpdate.Flags.AzureShield);
  5936.                     }
  5937.                     else
  5938.                     {
  5939.                         CreateAzureDmg((uint)Damage, attacker, attacked);
  5940.                         attacked.AzureShieldDefence -= (ushort)Damage;
  5941.                         attacked.AzureShieldPacket();
  5942.                         Damage = 1;
  5943.                     }
  5944.                 }
  5945.  
  5946.              
  5947.                 #region Bless Reduction
  5948.  
  5949.                 var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  5950.                 if (reduce > 0)
  5951.                 {
  5952.                     Damage -= Damage * reduce / 100;
  5953.                 }
  5954.  
  5955.                 #endregion
  5956.                 if (Damage < 1)
  5957.                     Damage = 1;
  5958.  
  5959.                 #region Sepll Bounes
  5960.  
  5961.                 if (spell != null)
  5962.                 {
  5963.                     if (spell.ID != 12290)
  5964.                     {
  5965.                         if (spell.PowerPercent != 0)
  5966.                         {
  5967.                             Damage = (Double)(Damage * spell.PowerPercent);
  5968.                         }
  5969.                     }
  5970.                 }
  5971.  
  5972.                 #endregion
  5973.                 #region CriticalStrike
  5974.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  5975.                 {
  5976.                     if (attacker.BattlePower < attacked.BattlePower)
  5977.                     {
  5978.                         if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  5979.                         {
  5980.                             Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  5981.                             Damage = (UInt32)Math.Floor((float)Damage * 1.1);
  5982.                         }
  5983.                     }
  5984.                 }
  5985.                 #endregion
  5986.                 #region CriticalStrike
  5987.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  5988.                 {
  5989.                     if (attacker.BattlePower >= attacked.BattlePower)
  5990.                     {
  5991.                         if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  5992.                         {
  5993.                             Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  5994.                             Damage = (UInt32)Math.Floor((float)Damage * 1.4);
  5995.                         }
  5996.                     }
  5997.                 }
  5998.                 #endregion
  5999.                 #region Superman & Stigma
  6000.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  6001.                     if (!attacker.Transformed && Damage > 1)
  6002.                         Damage = (long)(Damage * 1.12);
  6003.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  6004.                     Damage *= 1.0; //PvP Reduction!
  6005.                 #endregion
  6006.                 #region DragonGem
  6007.                 var DragonBonus = attacker.Gems[GemTypes.Dragon];
  6008.                 if (DragonBonus > 0)
  6009.                     Damage += MathHelper.MulDiv((int)Damage, DragonBonus, 100);
  6010.                 if (attacker.Gems[GemTypes.Dragon] >= 210)
  6011.                     Damage += Damage * 50 / 100;
  6012.                 #endregion
  6013.                 #region TortoiseGem -- LO LEE DESDE EL CODIGO DE REMOVEEXCESS
  6014.                 //double torist = (double)(attacked.Gems[COServer.AttackBedan.GemTypes.Tortoise] / 100d);
  6015.                 //torist = (double)(1 - torist);
  6016.                 //torist = Math.Max(torist, 0.5);
  6017.                 //Damage *= torist;
  6018.                 //Pezzi
  6019.  
  6020.                 #endregion
  6021.                 #region Superman & Stigma
  6022.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  6023.                     if (!attacker.Transformed && Damage > 1)
  6024.                         Damage = (long)(Damage * 1.12);
  6025.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  6026.                     Damage *= 1.0; //PvP Reduction!
  6027.  
  6028.                 #endregion
  6029.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6030.                 {
  6031.                     if (attacked.Action == Enums.ConquerAction.Sit)
  6032.                         if (attacked.Stamina > 20)
  6033.                             attacked.Stamina -= 20;
  6034.                         else
  6035.                             attacked.Stamina = 0;
  6036.                     attacked.Action = Enums.ConquerAction.None;
  6037.                 }
  6038.                 if (attacker != null)
  6039.                 {
  6040.                     Damage += (Double)attacker.PhysicalDamageIncrease;
  6041.                 }
  6042.                 if (attacked != null)
  6043.                 {
  6044.                     Damage -= (Double)attacked.PhysicalDamageDecrease;
  6045.                 }
  6046.  
  6047.                 AutoRespone(attacker, attacked, ref Damage);
  6048.  
  6049.                 #region Block
  6050.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6051.                 {
  6052.                     if (Kernel.Rate(22))
  6053.                     {
  6054.                         if (attacked.Block > 0)
  6055.                         {
  6056.                             Packet.Effect |= MsgInteract.InteractEffects.Block;
  6057.                             Damage = (Int32)Math.Floor((float)Damage / 2);
  6058.                         }
  6059.                     }
  6060.                 }
  6061.                 #endregion
  6062.                 #region Reduction!
  6063.  
  6064.                 #region Clac Defence
  6065.                 int nDef, defmain;
  6066.                 if (!attacker.Transformed)
  6067.                     nDef = defmain = attacked.Defence;
  6068.                 else
  6069.                     nDef = defmain = attacked.TransformationDefence;
  6070.                 nDef = Handle.ShieldDefence(attacked, nDef);
  6071.                 if (attacked.IsDefensiveStance)
  6072.                     nDef *= 3;
  6073.  
  6074.                 #endregion End Defence
  6075.                 #endregion
  6076.                 //Damage = RemoveExcessDamage((long)Damage, attacker, attacked);
  6077.                 if (Damage < 1)
  6078.                     Damage = 1;
  6079.                 return (UInt32)Math.Round(Damage, (Int32)0);
  6080.             }
  6081.             #endregion
  6082.             #region Player Vs Monster
  6083.             else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  6084.             {
  6085.                 int Damage = 0;
  6086.                 Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  6087.                 CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  6088.                 return (uint)Damage;
  6089.             }
  6090.             #endregion
  6091.             else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  6092.             {
  6093.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  6094.                     return 1;
  6095.                 if (attacked.ContainsFlag((ulong)1UL << 53))
  6096.                     return 1;
  6097.                 Double Damage = 0;
  6098.                 Double Reborn = 1.00;
  6099.                 if (attacked.Reborn == 1)
  6100.                     Reborn -= 0.30; //30%
  6101.                 else if (attacked.Reborn >= 2)
  6102.                     Reborn -= 0.50; //50%
  6103.                 Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  6104.                 Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  6105.                 Damage -= attacked.Defence;
  6106.                 Damage *= Reborn;
  6107.  
  6108.                 #region Bless Reduction
  6109.  
  6110.                 var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  6111.                 if (reduce > 0)
  6112.                 {
  6113.                     Damage -= Damage * reduce / 100;
  6114.                 }
  6115.  
  6116.                 #endregion
  6117.  
  6118.                 if (Damage < 1)
  6119.                     Damage = 1;
  6120.                 Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  6121.  
  6122.  
  6123.  
  6124.  
  6125.                 #region Sell Bounes
  6126.  
  6127.                 if (spell != null)
  6128.                 {
  6129.                     if (spell.PowerPercent != 0)
  6130.                     {
  6131.                         Damage = (long)(Damage * spell.PowerPercent);
  6132.                     }
  6133.                 }
  6134.  
  6135.                 #endregion
  6136.  
  6137.                 Damage -= attacked.PhysicalDamageDecrease;
  6138.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6139.                 {
  6140.                     if (attacked.Action == Enums.ConquerAction.Sit)
  6141.                         if (attacked.Stamina > 20)
  6142.                             attacked.Stamina -= 20;
  6143.                         else
  6144.                             attacked.Stamina = 0;
  6145.                     attacked.Action = Enums.ConquerAction.None;
  6146.                 }
  6147.                 if (attacker.OnSuperman())
  6148.                     if (attacked.PlayerFlag == PlayerFlag.Monster)
  6149.                         if (attacked.MonsterInfo.Boss)
  6150.                             Damage *= 2;
  6151.                 if (attacker.OnSuperman())
  6152.                     if (attacked.PlayerFlag == PlayerFlag.Monster)
  6153.                         Damage *= 2;
  6154.                 if (attacker.OnFatalStrike())
  6155.                     if (attacked.PlayerFlag == PlayerFlag.Monster)
  6156.                         if (!attacked.MonsterInfo.Boss)
  6157.                             Damage *= 5;
  6158.                         else Damage += (int)(Damage * .1);
  6159.                 if (Damage < 1)
  6160.                     Damage = 1;
  6161.                 #region Reduction!
  6162.  
  6163.                 #region Clac Defence
  6164.                 int nDef, defmain;
  6165.                 if (!attacker.Transformed)
  6166.                     nDef = defmain = attacked.Defence;
  6167.                 else
  6168.                     nDef = defmain = attacked.TransformationDefence;
  6169.                 nDef = Handle.ShieldDefence(attacked, nDef);
  6170.                 if (attacked.IsDefensiveStance)
  6171.                     nDef *= 3;
  6172.  
  6173.                 #endregion End Defence
  6174.              
  6175.                 #endregion
  6176.                 if (Damage < 1)
  6177.                     Damage = 1;
  6178.                 return (UInt32)Math.Round(Damage, (Int32)0);
  6179.             }
  6180.             if (attacker == null || attacked == null)
  6181.                 return 0;
  6182.             long attack = 0;
  6183.             int defense = 0;
  6184.             if (attacker.PlayerFlag == PlayerFlag.Monster)
  6185.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6186.                     if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  6187.                         return 0;
  6188.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  6189.                 return 1;
  6190.             if (attacked.ContainsFlag((ulong)1UL << 53))
  6191.                 return 1;
  6192.             if (!attacker.Transformed)
  6193.                 attack = attacker.MinAttack + random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  6194.             else
  6195.                 attack = attacker.TransformationMinAttack +
  6196.                          random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  6197.  
  6198.             if (attacker != null)
  6199.             {
  6200.                 var bonus = attacker.Gems[1];
  6201.                 if (bonus > 0)
  6202.                 {
  6203.                     attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  6204.                 }
  6205.                 // TODO: proficiency bonus
  6206.             }
  6207.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  6208.                 if (!attacker.Transformed && attack > 1)
  6209.                     attack = (long)(attack * 1.17);
  6210.             if (spell != null)
  6211.             {
  6212.                 if (spell.PowerPercent != 0)
  6213.                 {
  6214.                     attack = (long)(attack * spell.PowerPercent);
  6215.                 }
  6216.             }
  6217.             if (attacked.PlayerFlag == PlayerFlag.Player)
  6218.             {
  6219.                 var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  6220.                 if (reducee > 0)
  6221.                 {
  6222.                     attack -= (attack / 2) * reducee / 100;
  6223.                 }
  6224.             }
  6225.             if (!attacked.Transformed)
  6226.             {
  6227.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.MagicShield))
  6228.                 {
  6229.                     if (attacked.ShieldTime > 0)
  6230.                         attack -= attacked.Defence;
  6231.                     else
  6232.                         attack -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  6233.                 }
  6234.                 else
  6235.                 {
  6236.                     defense = attacked.Defence;
  6237.                 }
  6238.             }
  6239.             else
  6240.             {
  6241.                 attack -= attacked.TransformationDefence;
  6242.             }
  6243.  
  6244.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  6245.             {
  6246.                 defense = (defense * 70) / 100;
  6247.             }
  6248.             var damage = Math.Max(1, attack - defense);
  6249.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  6250.             {
  6251.                 damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  6252.                 damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  6253.                 damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  6254.             }
  6255.             else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  6256.             {
  6257.                 damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  6258.                 damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  6259.                     10000);
  6260.                 damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  6261.             }
  6262.  
  6263.  
  6264.             var reduceee = 10;
  6265.             if (attacked.PlayerFlag == PlayerFlag.Player)
  6266.             {
  6267.                 if (!attacked.Owner.Equipment.Free(3))
  6268.                 {
  6269.                     switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  6270.                     {
  6271.                         case 9:
  6272.                             reduceee = 1000;
  6273.                             break;
  6274.                         case 8:
  6275.                             reduceee = 500;
  6276.                             break;
  6277.                         case 7:
  6278.                             reduceee = 200;
  6279.                             break;
  6280.                         case 6:
  6281.                             reduceee = 100;
  6282.                             break;
  6283.                     }
  6284.                 }
  6285.             }
  6286.             if (attacker.PlayerFlag == PlayerFlag.Player)
  6287.             {
  6288.                 var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  6289.                 if (n > damage)
  6290.                 {
  6291.                     damage = n;
  6292.                 }
  6293.             }
  6294.             damage = Math.Max(1, damage);
  6295.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  6296.             {
  6297.                 damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  6298.             }
  6299.             if (attacked != null)
  6300.             {
  6301.                 var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  6302.                 if (reduces > 0)
  6303.                 {
  6304.                     damage -= damage * reduces / 100;
  6305.                 }
  6306.             }
  6307.             if (attacker != null)
  6308.             {
  6309.                 damage += attacker.PhysicalDamageIncrease;
  6310.             }
  6311.  
  6312.             if (attacked != null)
  6313.             {
  6314.                 damage -= attacked.PhysicalDamageDecrease;
  6315.             }
  6316.            
  6317.             AutoRespone(attacker, attacked, ref damage);
  6318.  
  6319.  
  6320.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  6321.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  6322.                     damage *= 2;
  6323.             if (attacked.Action == Enums.ConquerAction.Sit)
  6324.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6325.                 {
  6326.                     if (attacked.Stamina >= 20)
  6327.                         attacked.Stamina -= 20;
  6328.                     else
  6329.                         attacked.Stamina = 0;
  6330.                 }
  6331.             if (attacker.OnSuperman())
  6332.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  6333.                     if (attacked.MonsterInfo.Boss)
  6334.                         damage *= 2;
  6335.  
  6336.             if (attacker.OnSuperman())
  6337.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  6338.                     damage *= 2;
  6339.             if (attacker.OnFatalStrike())
  6340.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  6341.                     damage *= 5;
  6342.             return Math.Max((uint)1, (uint)damage);
  6343.         }
  6344.         public static uint Melee(Player attacker, Player attacked, ref MsgInteract Packet, Database.SpellInformation spell = null)
  6345.         {
  6346.             if (Packet != null)
  6347.             {
  6348.                 Packet.Effect = MsgInteract.InteractEffects.None;
  6349.             }
  6350.             #region HideGui
  6351.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  6352.             {
  6353.                 MsgAction Data = new MsgAction(true);
  6354.                 Data.UID = attacker.UID;
  6355.                 Data.UID = attacked.UID;
  6356.                 Data.ID = MsgAction.Mode.HideGui;
  6357.                 attacker.Owner.Send(Data);
  6358.                 attacked.Owner.Send(Data);
  6359.             }
  6360.             #endregion
  6361.             #region MyClones
  6362.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  6363.             {
  6364.                 if (attacked.MyClones.Count > 0)
  6365.                 {
  6366.                     foreach (var item in attacked.MyClones.Values)
  6367.                     {
  6368.                         attacked.Owner.Map.RemoveEntity(item);
  6369.                         MsgAction data = new MsgAction(true);
  6370.                         data.UID = item.UID;
  6371.                         data.ID = MsgAction.Mode.RemoveEntity;
  6372.                         item.MonsterInfo.SendScreen(data);
  6373.                     }
  6374.                    attacked.MyClones.Clear();
  6375.                     return 0;
  6376.                 }
  6377.             }
  6378.             #endregion
  6379.  
  6380.             if (attacked.PlayerFlag == PlayerFlag.Player)
  6381.             {
  6382.                 int Damage = 0;
  6383.  
  6384.                 AutoRespone(attacker, attacked, ref Damage);
  6385.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.DragonSwing))
  6386.                 {
  6387.                     if (Kernel.Rate(20))
  6388.                     {
  6389.                         MsgName str = new MsgName(true);
  6390.                         str.UID = attacked.UID;
  6391.                         str.TextsCount = 1;
  6392.                         str.Action = MsgName.Effect;
  6393.                         str.Texts.Add("poisonmiss");
  6394.                         if (attacked.PlayerFlag == PlayerFlag.Player)
  6395.                             attacked.Owner.SendScreen(str, true);
  6396.                         return 0;
  6397.                     }
  6398.                 }
  6399.  
  6400.  
  6401.             }
  6402.  
  6403.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  6404.             {
  6405.                 Durability(attacker, attacked, null);
  6406.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  6407.                     return 1;
  6408.                 Double Damage = 0;
  6409.                 Double Reborn = 1.00;
  6410.                 if (attacked.Reborn == 1)
  6411.                     Reborn -= 0.30;
  6412.                 else if (attacked.Reborn >= 2)
  6413.                     Reborn -= 0.50;
  6414.                 Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  6415.                 #region Breakthrough
  6416.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  6417.                 {
  6418.                     if (attacker.BattlePower < attacked.BattlePower)
  6419.                     {
  6420.                         if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  6421.                         {
  6422.                             Damage = (Int32)attacker.MaxAttack;
  6423.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  6424.                         }
  6425.                     }
  6426.                 }
  6427.                 #endregion
  6428.                 #region GemBounes
  6429.                 var bonus = attacker.Gems[1];
  6430.                 if (bonus > 0)
  6431.                 {
  6432.                     Damage += MathHelper.MulDiv((int)Damage, (int)bonus, (int)100);
  6433.                 }
  6434.                 #endregion
  6435.                 Damage -= attacked.Defence;
  6436.                 Damage *= Reborn;
  6437.                
  6438.                 #region Bless Reduction
  6439.                 var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  6440.                 if (reduce > 0)
  6441.                 {
  6442.                     Damage -= Damage * reduce / 100;
  6443.                 }
  6444.                 #endregion
  6445.                 if (Damage < 1)
  6446.                     Damage = 1;
  6447.                 #region LuckyTime Bounes
  6448.                 if (Kernel.ChanceSuccess(5))
  6449.                 {
  6450.                     if (attacker.PlayerFlag == PlayerFlag.Player)
  6451.                     {
  6452.                         if (attacker.Owner.BlessTime > 0)
  6453.                         {
  6454.                             Damage *= 2;
  6455.                             MsgName str = new MsgName(true);
  6456.                             str.UID = attacker.UID;
  6457.                             str.TextsCount = 1;
  6458.                             str.Action = MsgName.Effect;
  6459.                             str.Texts.Add("LuckyGuy");
  6460.                             attacker.Owner.SendScreen(str, true);
  6461.                         }
  6462.                     }
  6463.                 }
  6464.                 if (Kernel.ChanceSuccess(5))
  6465.                 {
  6466.                     if (attacked.PlayerFlag == PlayerFlag.Player)
  6467.                     {
  6468.                         if (attacked.Owner.BlessTime > 0)
  6469.                         {
  6470.                             Damage = 1;
  6471.                             MsgName str = new MsgName(true);
  6472.                             str.UID = attacked.UID;
  6473.                             str.TextsCount = 1;
  6474.                             str.Action = MsgName.Effect;
  6475.                             str.Texts.Add("LuckyGuy");
  6476.                             attacked.Owner.SendScreen(str, true);
  6477.                         }
  6478.                     }
  6479.                 }
  6480.                 #endregion
  6481.                 #region Sepll Bounes
  6482.                 if (spell != null)
  6483.                 {
  6484.                     if (spell.ID != 12290)
  6485.                     {
  6486.                         if (spell.PowerPercent != 0)
  6487.                         {
  6488.                             Damage = (Double)(Damage * spell.PowerPercent);
  6489.                         }
  6490.                     }
  6491.                 }
  6492.                 #endregion
  6493.                 int strike = Math.Max(110, 130);
  6494.                 if (attacker.CriticalStrike > 0u)
  6495.                 {
  6496.                     if (Base.GetRefinery((uint)attacker.CriticalStrike / 100, (uint)attacked.Immunity / 100))
  6497.                     {
  6498.                         Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  6499.                         Damage = Base.MulDiv((int)Damage, strike, 100);
  6500.                     }
  6501.                 }
  6502.                 #region Superman & Stigma
  6503.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  6504.                     if (!attacker.Transformed && Damage > 1)
  6505.                         Damage = (long)(Damage * 1.1);
  6506.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  6507.                     Damage *= 0.2;
  6508.                 #endregion
  6509.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6510.                 {
  6511.                     uint TortoisePercent = attacked.Owner.GemValues(Enums.Gem.NormalTortoiseGem);
  6512.                     if (TortoisePercent > 0u) Damage -= Damage * Math.Min((int)TortoisePercent, 20) / 150;
  6513.                 }
  6514.                 if (attacked.Action == Enums.ConquerAction.Sit)
  6515.                 {
  6516.                     if (attacked.PlayerFlag == PlayerFlag.Player)
  6517.                     {
  6518.                         if (attacked.Stamina >= 0)
  6519.                             attacked.Stamina = (byte)(attacked.Stamina / 2);
  6520.                     }
  6521.                 }
  6522.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Ride))
  6523.                 {
  6524.                     if (attacked.PlayerFlag == PlayerFlag.Player)
  6525.                     {
  6526.                         if (attacked.Stamina >= 0)
  6527.                             attacked.Stamina = (byte)(attacked.Stamina / 1.60);
  6528.                     }
  6529.                 }
  6530.                 if (attacker != null)
  6531.                 {
  6532.                     Damage += (Double)attacker.PhysicalDamageIncrease;
  6533.                 }
  6534.                 if (attacked != null)
  6535.                 {
  6536.                     Damage -= (Double)attacked.PhysicalDamageDecrease;
  6537.                 }
  6538.                
  6539.                 AutoRespone(attacker, attacked, ref Damage);
  6540.                 if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  6541.                 {
  6542.                     Damage *= 2;
  6543.                     attacker.OnIntensify = false;
  6544.                     attacker.RemoveFlag((ulong)MsgUpdate.Flags.Intensify);
  6545.                 }
  6546.                 #region Block
  6547.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6548.                 {
  6549.                     if (Kernel.ChanceSuccess((float)attacked.Block / 100f))
  6550.                     {
  6551.                         Packet.Effect |= MsgInteract.InteractEffects.Block;
  6552.                         Damage = (Int32)Math.Floor((float)Damage / 2);
  6553.                     }
  6554.                 }
  6555.                 #endregion
  6556.                 #region Reduction!
  6557.                 if (attacked.IsDefensiveStance)
  6558.                 {
  6559.                     if (attacked.FatigueSecs > 120)
  6560.                     {
  6561.                         Damage -= attacked.Defence + (Double)(attacked.Defence * 0.40);
  6562.                     }
  6563.                     else
  6564.                     {
  6565.                         Damage -= attacked.Defence + (Double)(attacked.Defence * 0.20);
  6566.                     }
  6567.                 }
  6568.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  6569.                 {
  6570.                     if (Damage > attacked.AzureShieldDefence)
  6571.                     {
  6572.                         Damage -= attacked.AzureShieldDefence;
  6573.                         CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  6574.                         attacked.AzuredShield = true;
  6575.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  6576.                     }
  6577.                     else
  6578.                     {
  6579.                         CreateAzureDmg((uint)Damage, attacker, attacked);
  6580.                         attacked.AzureShieldDefence -= (ushort)Damage;
  6581.                         attacked.AzureShieldPacket();
  6582.                         Damage = 1;
  6583.                     }
  6584.                 }
  6585.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  6586.                 {
  6587.  
  6588.                     if (Damage > attacked.IronShieldDefence)
  6589.                     {
  6590.                         Damage -= (int)attacked.IronShieldDefence;
  6591.                         CreateAzureDmg(attacked.IronShieldDefence, attacker, attacked);
  6592.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  6593.                     }
  6594.                     else
  6595.                     {
  6596.                         CreateAzureDmg((uint)Damage, attacker, attacked);
  6597.                         attacked.IronShieldDefence -= (uint)Damage;
  6598.                         attacked.IronShieldPacket();
  6599.                         Damage = 1;
  6600.                     }
  6601.                 }
  6602.                 #endregion
  6603.                 if (Damage < 1)
  6604.                     Damage = 1;
  6605.                 return (UInt32)Math.Round(Damage, (Int32)0);
  6606.             }
  6607.             else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  6608.             {
  6609.                 int Damage = 0;
  6610.                 Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Melee, ref Packet);
  6611.                 CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  6612.                 return (uint)Damage;
  6613.             }
  6614.             else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  6615.             {
  6616.                 Durability(attacker, attacked, null);
  6617.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  6618.                     return 1;
  6619.                 Double Damage = 0;
  6620.                 Double Reborn = 1.00;
  6621.                 if (attacked.Reborn == 1)
  6622.                     Reborn -= 0.30;
  6623.                 else if (attacked.Reborn >= 2)
  6624.                     Reborn -= 0.50;
  6625.                 Damage = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  6626.                 Damage = AdjustDamageMonster2Player(Damage, attacker, attacked);
  6627.                 Damage -= attacked.Defence;
  6628.                 Damage *= Reborn;
  6629.                 #region Bless Reduction
  6630.                 var reduce = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  6631.                 if (reduce > 0)
  6632.                 {
  6633.                     Damage -= Damage * reduce / 100;
  6634.                 }
  6635.                 #endregion
  6636.                 if (Damage < 1)
  6637.                     Damage = 1;
  6638.                 Damage = AdjustMinDamageMonster2Player(Damage, attacker, attacked);
  6639.                 #region LuckyTime Bounes
  6640.                 if (Kernel.ChanceSuccess(5))
  6641.                 {
  6642.                     if (attacked.PlayerFlag == PlayerFlag.Player)
  6643.                     {
  6644.                         if (attacked.Owner.BlessTime > 0)
  6645.                         {
  6646.                             Damage = 1;
  6647.                             MsgName str = new MsgName(true);
  6648.                             str.UID = attacked.UID;
  6649.                             str.TextsCount = 1;
  6650.                             str.Action = MsgName.Effect;
  6651.                             str.Texts.Add("LuckyGuy");
  6652.                             attacked.Owner.SendScreen(str, true);
  6653.                         }
  6654.                     }
  6655.                 }
  6656.                 #endregion
  6657.                 #region Sell Bounes
  6658.                 if (spell != null)
  6659.                 {
  6660.                     if (spell.PowerPercent != 0)
  6661.                     {
  6662.                         Damage = (long)(Damage * spell.PowerPercent);
  6663.                     }
  6664.                 }
  6665.                 #endregion
  6666.                 Damage -= attacked.PhysicalDamageDecrease;
  6667.                 if (attacked.Action == Enums.ConquerAction.Sit)
  6668.                 {
  6669.                     if (attacked.PlayerFlag == PlayerFlag.Player)
  6670.                     {
  6671.                         if (attacked.Stamina >= 0)
  6672.                             attacked.Stamina = (byte)(attacked.Stamina / 2);
  6673.                     }
  6674.                 }
  6675.                 if (Damage < 1)
  6676.                     Damage = 1;
  6677.                 #region Reduction!
  6678.                 if (attacked.IsDefensiveStance)
  6679.                 {
  6680.                     if (attacked.FatigueSecs > 120)
  6681.                     {
  6682.                         Damage -= attacked.Defence + (Double)(attacked.Defence * 0.40);
  6683.                     }
  6684.                     else
  6685.                     {
  6686.                         Damage -= attacked.Defence + (Double)(attacked.Defence * 0.20);
  6687.                     }
  6688.                 }
  6689.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  6690.                 {
  6691.                     if (Damage > attacked.AzureShieldDefence)
  6692.                     {
  6693.                         Damage -= attacked.AzureShieldDefence;
  6694.                         CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  6695.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  6696.                         attacked.AzuredShield = true;
  6697.                     }
  6698.                     else
  6699.                     {
  6700.                         CreateAzureDmg((uint)Damage, attacker, attacked);
  6701.                         attacked.AzureShieldDefence -= (ushort)Damage;
  6702.                         attacked.AzureShieldPacket();
  6703.                         Damage = 1;
  6704.                     }
  6705.                 }
  6706.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  6707.                 {
  6708.  
  6709.                     if (Damage > attacked.IronShieldDefence)
  6710.                     {
  6711.                         Damage -= (int)attacked.IronShieldDefence;
  6712.                         CreateAzureDmg(attacked.IronShieldDefence, attacker, attacked);
  6713.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  6714.                     }
  6715.                     else
  6716.                     {
  6717.                         CreateAzureDmg((uint)Damage, attacker, attacked);
  6718.                         attacked.IronShieldDefence -= (uint)Damage;
  6719.                         attacked.IronShieldPacket();
  6720.                         Damage = 1;
  6721.                     }
  6722.                 }
  6723.                 #endregion
  6724.                 if (Damage < 1)
  6725.                     Damage = 1;
  6726.                 return (UInt32)Math.Round(Damage, (Int32)0);
  6727.             }
  6728.             if (attacker == null || attacked == null) return 0;
  6729.             long attack = 0;
  6730.             int defense = 0;
  6731.             if (attacker.PlayerFlag == PlayerFlag.Monster)
  6732.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6733.                     if (Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  6734.                         return 0;
  6735.             Durability(attacker, attacked, null);
  6736.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  6737.                 return 1;
  6738.             if (!attacker.Transformed)
  6739.                 attack = attacker.MinAttack + Kernel.Random.Next((int)(attacker.MaxAttack - attacker.MinAttack));
  6740.             else
  6741.                 attack = attacker.TransformationMinAttack + Kernel.Random.Next((int)(attacker.TransformationMaxAttack - attacker.TransformationMinAttack));
  6742.             if (attacker != null)
  6743.             {
  6744.                 var bonus = attacker.Gems[1];
  6745.                 if (bonus > 0)
  6746.                 {
  6747.                     attack += MathHelper.MulDiv((int)attack, (int)bonus, (int)100);
  6748.                 }
  6749.             }
  6750.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  6751.                 if (!attacker.Transformed && attack > 1)
  6752.                     attack = (long)(attack * 1.1);
  6753.             if (spell != null)
  6754.             {
  6755.                 if (spell.PowerPercent != 0)
  6756.                 {
  6757.                     attack = (long)(attack * spell.PowerPercent);
  6758.                 }
  6759.             }
  6760.             if (attacked.PlayerFlag == PlayerFlag.Player)
  6761.             {
  6762.                 var reducee = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  6763.                 if (reducee > 0)
  6764.                 {
  6765.                     attack -= (attack / 2) * reducee / 10;
  6766.                 }
  6767.             }
  6768.             if (!attacked.Transformed)
  6769.             {
  6770.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.MagicShield))
  6771.                 {
  6772.                     if (attacked.ShieldTime > 0)
  6773.                         attack -= attacked.Defence;
  6774.                     else
  6775.                         attack -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  6776.                 }
  6777.                 else
  6778.                 {
  6779.                     defense = attacked.Defence;
  6780.                 }
  6781.             }
  6782.             else
  6783.             {
  6784.                 attack -= attacked.TransformationDefence;
  6785.             }
  6786.             if (attacked.IsDefensiveStance)
  6787.             {
  6788.                 if (attacked.FatigueSecs > 120)
  6789.                 {
  6790.                     attack -= attacked.Defence + (long)(attacked.Defence * 0.40);
  6791.                 }
  6792.                 else
  6793.                 {
  6794.                     attack -= attacked.Defence + (long)(attacked.Defence * 0.20);
  6795.                 }
  6796.             }
  6797.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Superman))
  6798.             {
  6799.                 defense = (defense * 50) / 100;
  6800.             }
  6801.             var damage = Math.Max(1, attack - defense);
  6802.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  6803.             {
  6804.                 damage = CalcDamageUser2Monster((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  6805.                 damage = MathHelper.MulDiv((int)damage, 10000, 10000);
  6806.                 damage = AdjustMinDamageUser2Monster((int)damage, attacker, attacked);
  6807.             }
  6808.             else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  6809.             {
  6810.                 damage = CalcDamageMonster2User((int)attack, defense, attacker.Level, attacked.Level, (int)damage);
  6811.                 damage = MathHelper.MulDiv((int)damage, (attacked.Reborn != 0 && attacked.Class % 10 >= 3) ? 7000 : 10000,
  6812.                     10000);
  6813.                 damage = AdjustMinDamageMonster2User((int)damage, attacker, attacked);
  6814.             }
  6815.             #region LuckyTime Bounes
  6816.             if (Kernel.ChanceSuccess(5))
  6817.             {
  6818.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  6819.                 {
  6820.                     if (attacker.Owner.BlessTime > 0)
  6821.                     {
  6822.                         attack *= 2;
  6823.                         MsgName str = new MsgName(true);
  6824.                         str.UID = attacker.UID;
  6825.                         str.TextsCount = 1;
  6826.                         str.Action = MsgName.Effect;
  6827.                         str.Texts.Add("LuckyGuy");
  6828.                         attacker.Owner.SendScreen(str, true);
  6829.                     }
  6830.                 }
  6831.             }
  6832.             if (Kernel.ChanceSuccess(5))
  6833.             {
  6834.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6835.                 {
  6836.                     if (attacked.Owner.BlessTime > 0)
  6837.                     {
  6838.                         attack = 1;
  6839.                         MsgName str = new MsgName(true);
  6840.                         str.UID = attacked.UID;
  6841.                         str.TextsCount = 1;
  6842.                         str.Action = MsgName.Effect;
  6843.                         str.Texts.Add("LuckyGuy");
  6844.                         attacked.Owner.SendScreen(str, true);
  6845.                     }
  6846.                 }
  6847.             }
  6848.             #endregion
  6849.             var reduceee = 10;
  6850.             if (attacked.PlayerFlag == PlayerFlag.Player)
  6851.             {
  6852.                 if (!attacked.Owner.Equipment.Free(3))
  6853.                 {
  6854.                     switch (attacked.Owner.Equipment.TryGetItem(3).ID % 10)
  6855.                     {
  6856.                         case 9:
  6857.                             reduceee = 1000;
  6858.                             break;
  6859.                         case 8:
  6860.                             reduceee = 500;
  6861.                             break;
  6862.                         case 7:
  6863.                             reduceee = 200;
  6864.                             break;
  6865.                         case 6:
  6866.                             reduceee = 100;
  6867.                             break;
  6868.                     }
  6869.                 }
  6870.             }
  6871.             if (attacker.PlayerFlag == PlayerFlag.Player)
  6872.             {
  6873.                 var n = Math.Max(1, attacker.Owner.Player.Strength / reduceee);
  6874.                 if (n > damage)
  6875.                 {
  6876.                     damage = n;
  6877.                 }
  6878.             }
  6879.             damage = Math.Max(1, damage);
  6880.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  6881.             {
  6882.                 damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  6883.             }
  6884.             if (attacked != null)
  6885.             {
  6886.                 var reduces = Math.Max(0, Math.Min((int)100, (int)attacked.ItemBless));
  6887.                 if (reduces > 0)
  6888.                 {
  6889.                     damage -= damage * reduces / 100;
  6890.                 }
  6891.             }
  6892.             if (attacker != null)
  6893.             {
  6894.                 damage += attacker.PhysicalDamageIncrease;
  6895.             }
  6896.  
  6897.             if (attacked != null)
  6898.             {
  6899.                 damage -= attacked.PhysicalDamageDecrease;
  6900.             }
  6901.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  6902.             {
  6903.                 if (damage > attacked.AzureShieldDefence)
  6904.                 {
  6905.                     damage -= attacked.AzureShieldDefence;
  6906.                     CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  6907.                     attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  6908.                     attacked.AzuredShield = true;
  6909.                 }
  6910.                 else
  6911.                 {
  6912.                     CreateAzureDmg((uint)damage, attacker, attacked);
  6913.                     attacked.AzureShieldDefence -= (ushort)damage;
  6914.                     attacked.AzureShieldPacket();
  6915.                     damage = 1;
  6916.                 }
  6917.             }
  6918.             #region IronShield
  6919.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  6920.             {
  6921.  
  6922.                 if (damage > attacked.IronShieldDefence)
  6923.                 {
  6924.                     damage -= (int)attacked.IronShieldDefence;
  6925.                     CreateAzureDmg(attacked.IronShieldDefence, attacker, attacked);
  6926.                     attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  6927.                 }
  6928.                 else
  6929.                 {
  6930.                     CreateAzureDmg((uint)damage, attacker, attacked);
  6931.                     attacked.IronShieldDefence -= (uint)damage;
  6932.                     attacked.IronShieldPacket();
  6933.                     damage = 1;
  6934.                 }
  6935.             }
  6936.             #endregion
  6937.             AutoRespone(attacker, attacked, ref damage);
  6938.             if (attacker.NobilityRank < attacked.NobilityRank)
  6939.             {
  6940.                 var dif = attacked.NobilityRank - attacker.NobilityRank;
  6941.                 switch (dif)
  6942.                 {
  6943.                     case 1:
  6944.                         damage = (damage * 70) / 100;
  6945.                         break;
  6946.                     case 2:
  6947.                         damage = (damage * 60) / 100;
  6948.                         break;
  6949.                     case 3:
  6950.                         damage = (damage * 50) / 100;
  6951.                         break;
  6952.                     case 4:
  6953.                         damage = (damage * 40) / 100;
  6954.                         break;
  6955.                     case 5:
  6956.                         damage = (damage * 30) / 100;
  6957.                         break;
  6958.                     default:
  6959.                         damage = (damage * 30) / 100;
  6960.                         break;
  6961.                 }
  6962.             }
  6963.             //if (attacker.Assassin())
  6964.             //{
  6965.             //    damage = damage * (random.Next(20, 25)) / 100;
  6966.             //}
  6967.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Oblivion))
  6968.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  6969.                     damage *= 2;
  6970.             if (attacked.Action == Enums.ConquerAction.Sit)
  6971.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  6972.                 {
  6973.                     if (attacked.Stamina >= 20)
  6974.                         attacked.Stamina -= 20;
  6975.                     else
  6976.                         attacked.Stamina = 0;
  6977.                 }
  6978.             if (attacker.OnFatalStrike())
  6979.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  6980.                     damage *= 5;
  6981.             return Math.Max((uint)1, (uint)damage);
  6982.         }
  6983.  
  6984.         public static uint Magic(Player Attacker, Player Attacked, Database.SpellInformation SInfo, ref MsgInteract Packet)
  6985.         {
  6986.             if (Attacker == null) return 0;
  6987.             if (Attacked == null) return 0;
  6988.             #region HideGui
  6989.             if (Attacker.PlayerFlag == PlayerFlag.Player && Attacked.PlayerFlag == PlayerFlag.Player)
  6990.             {
  6991.                 MsgAction Data = new MsgAction(true);
  6992.                 Data.UID = Attacker.UID;
  6993.                 Data.UID = Attacked.UID;
  6994.                 Data.ID = MsgAction.Mode.HideGui;
  6995.                 Attacker.Owner.Send(Data);
  6996.                 Attacked.Owner.Send(Data);
  6997.             }
  6998.             #endregion
  6999.             #region MyClones
  7000.             if (Attacker.PlayerFlag == PlayerFlag.Player && Attacked.PlayerFlag == PlayerFlag.Player)
  7001.             {
  7002.                 if (Attacked.MyClones.Count > 0)
  7003.                 {
  7004.                     foreach (var item in Attacked.MyClones.Values)
  7005.                     {
  7006.                         MsgAction data = new MsgAction(true);
  7007.                         data.UID = item.UID;
  7008.                         data.ID = MsgAction.Mode.RemoveEntity;
  7009.                         item.MonsterInfo.SendScreen(data);
  7010.                         Attacked.Owner.Map.RemoveEntity(item);
  7011.                         Attacked.Owner.Send(data);
  7012.                     }
  7013.                     Attacked.MyClones.Clear();
  7014.                     return 0;
  7015.                 }
  7016.             }
  7017.             #endregion
  7018.  
  7019.             if (Attacker.PlayerFlag == PlayerFlag.Player && Attacked.PlayerFlag == PlayerFlag.Player)
  7020.             {
  7021.                 Durability(Attacker, Attacked, null);
  7022.                 if (Attacker.PlayerFlag == PlayerFlag.Player)
  7023.                 {
  7024.                     if (Kernel.Rate(50))
  7025.                     {
  7026.                         GemEffect.Process(Attacker);
  7027.                     }
  7028.                 }
  7029.                 if (Attacked.PlayerFlag == PlayerFlag.Player)
  7030.                     if (Attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex)) return 1;
  7031.                 Double attack = SInfo.Power;
  7032.                 if (Attacker.PlayerFlag == PlayerFlag.Player)
  7033.                 {
  7034.                     attack += (uint)Attacker.MagicAttack;
  7035.                 }
  7036.                 AutoRespone(Attacker, Attacked, ref attack);
  7037.                 #region Breakthrough
  7038.                 if (Attacker.PlayerFlag == PlayerFlag.Player)
  7039.                 {
  7040.                     if (Attacker.BattlePower < Attacked.BattlePower)
  7041.                     {
  7042.                         if (Kernel.ChanceSuccess(((float)Attacker.Breaktrough / 10f) - (float)(Attacked.Counteraction / 10f)))
  7043.                         {
  7044.                             attack = (Int32)Attacker.MagicAttack;
  7045.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  7046.                         }
  7047.                     }
  7048.                 }
  7049.                 #endregion
  7050.                 var defense = Attacked.MagicDefence;
  7051.                 attack -= defense;
  7052.                 if (Attacker.PlayerFlag == PlayerFlag.Player)
  7053.                 {
  7054.                     var effect = Attacker.Gems[0];
  7055.                     attack += attack * effect / 100;
  7056.                     if (effect >= 180)
  7057.                     {
  7058.                         attack += attack / 20;
  7059.                     }
  7060.                     #region LuckyTime Bounes
  7061.                     if (Kernel.ChanceSuccess(5))
  7062.                     {
  7063.                         if (Attacker.PlayerFlag == PlayerFlag.Player)
  7064.                         {
  7065.                             if (Attacker.Owner.BlessTime > 0)
  7066.                             {
  7067.                                 attack *= 2;
  7068.                                 MsgName str = new MsgName(true);
  7069.                                 str.UID = Attacker.UID;
  7070.                                 str.TextsCount = 1;
  7071.                                 str.Action = MsgName.Effect;
  7072.                                 str.Texts.Add("LuckyGuy");
  7073.                                 Attacker.Owner.SendScreen(str, true);
  7074.                             }
  7075.                         }
  7076.                     }
  7077.                     if (Kernel.ChanceSuccess(5))
  7078.                     {
  7079.                         if (Attacked.PlayerFlag == PlayerFlag.Player)
  7080.                         {
  7081.                             if (Attacked.Owner.BlessTime > 0)
  7082.                             {
  7083.                                 attack = 1;
  7084.                                 MsgName str = new MsgName(true);
  7085.                                 str.UID = Attacked.UID;
  7086.                                 str.TextsCount = 1;
  7087.                                 str.Action = MsgName.Effect;
  7088.                                 str.Texts.Add("LuckyGuy");
  7089.                                 Attacked.Owner.SendScreen(str, true);
  7090.                             }
  7091.                         }
  7092.                     }
  7093.                     #endregion
  7094.                 }
  7095.                 if (Attacked.PlayerFlag == PlayerFlag.Player)
  7096.                 {
  7097.                     attack -= (attack / 2) * Attacked.Gems[7] / 10;
  7098.                 }
  7099.                 if (Attacked.PlayerFlag == PlayerFlag.Player)
  7100.                 {
  7101.                     if (attack > 0)
  7102.                     {
  7103.                         uint TortoisePercent = Attacked.Owner.GemValues(Enums.Gem.NormalTortoiseGem);
  7104.                         if (TortoisePercent > 0u) attack -= attack * Math.Min((int)TortoisePercent, 20) / 150;
  7105.                     }
  7106.                 }
  7107.  
  7108.                 attack = Math.Max(0, attack);
  7109.                 if (Attacker.PlayerFlag == PlayerFlag.Player)
  7110.                 {
  7111.                     if (Attacked.PlayerFlag == PlayerFlag.Player)
  7112.                     {
  7113.                         attack = (uint)AdjustRebirthDamage(Attacked.Owner, Attacker.Owner, (int)attack);
  7114.                     }
  7115.                 }
  7116.                 if (Attacked.PlayerFlag == PlayerFlag.Player)
  7117.                 {
  7118.                     var reduce = Math.Max(0, Math.Min(100, (int)Attacked.ItemBless));
  7119.                     if (reduce > 0)
  7120.                     {
  7121.                         attack -= (uint)(attack * reduce / 100);
  7122.                     }
  7123.                 }
  7124.                 Double Damage = attack;
  7125.                 if (Damage < 1)
  7126.                     Damage = 1;
  7127.                 AutoRespone(Attacker, Attacked, ref Damage);
  7128.                 if (Attacker != null)
  7129.                 {
  7130.                     Damage += Attacker.MagicDamageIncrease;
  7131.                 }
  7132.                 if (Attacked != null)
  7133.                 {
  7134.                     Damage -= Attacked.MagicDamageDecrease;
  7135.                 }
  7136.                 if (Attacked.HasMagicDefender && (Attacker.BattlePower - Attacked.BattlePower) <= 3)
  7137.                 {
  7138.                     Damage = 0;
  7139.                     MsgName str = new MsgName(true);
  7140.                     str.UID = Attacked.UID;
  7141.                     str.TextsCount = 1;
  7142.                     str.Action = MsgName.Effect;
  7143.                     str.Texts.Add("bossimmunity");
  7144.                     Attacked.Owner.SendScreen(str, true);
  7145.                 }
  7146.                 else
  7147.                 {
  7148.                     Attacked.RemoveMagicDefender();
  7149.                 }
  7150.                 #region CriticalStrike
  7151.                 int strike = Math.Max(110, 120);
  7152.                 if (Attacker.PlayerFlag == PlayerFlag.Player)
  7153.                 {
  7154.                     if (Base.GetRefinery((uint)Attacker.CriticalStrike / 100, (uint)Attacked.Immunity / 100))
  7155.                     {
  7156.                         Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  7157.                         Damage = Base.MulDiv((int)Damage, strike, 100);
  7158.  
  7159.                     }
  7160.                 }
  7161.                 #endregion
  7162.                 #region Reduction!
  7163.                 if (Attacked.IsDefensiveStance)
  7164.                 {
  7165.                     if (Attacked.FatigueSecs > 120)
  7166.                     {
  7167.                         Damage -= Attacked.Defence + (Double)(Attacked.Defence * 0.40);
  7168.                     }
  7169.                     else
  7170.                     {
  7171.                         Damage -= Attacked.Defence + (Double)(Attacked.Defence * 0.20);
  7172.                     }
  7173.                 }
  7174.                 if (Attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  7175.                 {
  7176.                     if (Damage > Attacked.AzureShieldDefence)
  7177.                     {
  7178.                         Damage -= Attacked.AzureShieldDefence;
  7179.                         CreateAzureDmg(Attacked.AzureShieldDefence, Attacker, Attacked);
  7180.                         Attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  7181.                         Attacked.AzuredShield = true;
  7182.                     }
  7183.                     else
  7184.                     {
  7185.                         CreateAzureDmg((uint)Damage, Attacker, Attacked);
  7186.                         Attacked.AzureShieldDefence -= (ushort)Damage;
  7187.                         Attacked.AzureShieldPacket();
  7188.                         Damage = 1;
  7189.                     }
  7190.                 }
  7191.                 if (Attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  7192.                 {
  7193.  
  7194.                     if (Damage > Attacked.IronShieldDefence)
  7195.                     {
  7196.                         Damage -= (int)Attacked.IronShieldDefence;
  7197.                         CreateAzureDmg(Attacked.IronShieldDefence, Attacker, Attacked);
  7198.                         Attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  7199.                     }
  7200.                     else
  7201.                     {
  7202.                         CreateAzureDmg((uint)Damage, Attacker, Attacked);
  7203.                         Attacked.IronShieldDefence -= (uint)Damage;
  7204.                         Attacked.IronShieldPacket();
  7205.                         Damage = 1;
  7206.                     }
  7207.                 }
  7208.                 #endregion
  7209.                 if (SInfo.ID == 10310)
  7210.                 {
  7211.                     Damage = Damage / 2;
  7212.                 }
  7213.                 if (Damage < 1)
  7214.                     Damage = 1;
  7215.                 return Math.Max(1, (uint)Damage);
  7216.             }
  7217.             else
  7218.             {
  7219.                 switch (Attacker.PlayerFlag)
  7220.                 {
  7221.                     case PlayerFlag.Monster:
  7222.                         {
  7223.                             long Damage = 0;
  7224.                             Int32 Defence = 0;
  7225.                             if (Kernel.ChanceSuccess((float)Attacked.Immunity / 100f))
  7226.                             {
  7227.  
  7228.                             }
  7229.                             Int32 Fan = 0, Tower = 0;
  7230.                             #region Resist
  7231.                             if (Attacker.PlayerFlag == PlayerFlag.Monster && Attacked.PlayerFlag == PlayerFlag.Player)
  7232.                             {
  7233.                                 if (Attacker.Name == "SnowBanshee")
  7234.                                 {
  7235.                                     if (Kernel.Rate((float)Attacked.WaterResistance / 100f))
  7236.                                     {
  7237.                                         Packet.Effect |= MsgInteract.InteractEffects.WaterResist;
  7238.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7239.                                     }
  7240.                                     else if (Kernel.Rate((float)Attacked.WoodResistance / 100f))
  7241.                                     {
  7242.                                         Packet.Effect |= MsgInteract.InteractEffects.WoodResist;
  7243.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7244.                                     }
  7245.                                 }
  7246.                                 if (Attacker.Name == "SnowBansheeSoul" || Attacker.Name == "PurpleBanshee")
  7247.                                 {
  7248.                                     if (Kernel.Rate((float)Attacked.WaterResistance / 100f))
  7249.                                     {
  7250.                                         Packet.Effect |= MsgInteract.InteractEffects.WaterResist;
  7251.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7252.                                     }
  7253.                                     else if (Kernel.Rate((float)Attacked.MetalResistance / 100f))
  7254.                                     {
  7255.                                         Packet.Effect |= MsgInteract.InteractEffects.MetalResist;
  7256.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7257.                                     }
  7258.                                     else if (Kernel.Rate((float)Attacked.WoodResistance / 100f))
  7259.                                     {
  7260.                                         Packet.Effect |= MsgInteract.InteractEffects.WoodResist;
  7261.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7262.                                     }
  7263.                                 }
  7264.                                 if (Attacker.Name == "SwordMaster")
  7265.                                 {
  7266.                                     if (Kernel.Rate((float)Attacked.MetalResistance / 100f))
  7267.                                     {
  7268.                                         Packet.Effect |= MsgInteract.InteractEffects.MetalResist;
  7269.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7270.                                     }
  7271.                                     else if (Kernel.Rate((float)Attacked.WoodResistance / 100f))
  7272.                                     {
  7273.                                         Packet.Effect |= MsgInteract.InteractEffects.WoodResist;
  7274.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7275.                                     }
  7276.                                 }
  7277.                                 if (Attacker.Name == "TeratoDragon")
  7278.                                 {
  7279.                                     if (Kernel.Rate((float)Attacked.FireResistance / 100f))
  7280.                                     {
  7281.                                         Packet.Effect |= MsgInteract.InteractEffects.FireResist;
  7282.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7283.                                     }
  7284.                                     else if (Kernel.Rate((float)Attacked.WoodResistance / 100f))
  7285.                                     {
  7286.                                         Packet.Effect |= MsgInteract.InteractEffects.WoodResist;
  7287.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7288.                                     }
  7289.                                 }
  7290.                                 if (Attacker.Name == "ThrillingSpook" || Attacker.Name == "ThrillingSpook2" || Attacker.Name == "ThrillingSpook2" || Attacker.Name == "ChillingSpook")
  7291.                                 {
  7292.                                     if (Kernel.Rate((float)Attacked.EarthResistance / 100f))
  7293.                                     {
  7294.                                         Packet.Effect |= MsgInteract.InteractEffects.EarthResist;
  7295.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7296.                                     }
  7297.                                     else if (Kernel.Rate((float)Attacked.WoodResistance / 100f))
  7298.                                     {
  7299.                                         Packet.Effect |= MsgInteract.InteractEffects.WoodResist;
  7300.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7301.                                     }
  7302.                                 }
  7303.                                 if (Attacker.Name == "NemesisTyrant")
  7304.                                 {
  7305.                                     if (Kernel.Rate((float)Attacked.MetalResistance / 100f))
  7306.                                     {
  7307.                                         Packet.Effect |= MsgInteract.InteractEffects.MetalResist;
  7308.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7309.                                     }
  7310.                                     else if (Kernel.Rate((float)Attacked.FireResistance / 100f))
  7311.                                     {
  7312.                                         Packet.Effect |= MsgInteract.InteractEffects.FireResist;
  7313.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7314.                                     }
  7315.                                     else if (Kernel.Rate((float)Attacked.EarthResistance / 100f))
  7316.                                     {
  7317.                                         Packet.Effect |= MsgInteract.InteractEffects.EarthResist;
  7318.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7319.                                     }
  7320.                                     else if (Kernel.Rate((float)Attacked.WaterResistance / 100f))
  7321.                                     {
  7322.                                         Packet.Effect |= MsgInteract.InteractEffects.WaterResist;
  7323.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7324.                                     }
  7325.                                     else if (Kernel.Rate((float)Attacked.WoodResistance / 100f))
  7326.                                     {
  7327.                                         Packet.Effect |= MsgInteract.InteractEffects.WoodResist;
  7328.                                         Damage = (Int32)Math.Floor((float)Damage * 1.1);
  7329.                                     }
  7330.                                 }
  7331.                             }
  7332.                             #endregion
  7333.                             if (Attacker.PlayerFlag == PlayerFlag.Player)
  7334.                                 Fan = Attacker.getFan(true);
  7335.                             if (Attacked.PlayerFlag == PlayerFlag.Player)
  7336.                                 Tower = Attacked.getTower(true);
  7337.                             if (Attacked.PlayerFlag == PlayerFlag.Player)
  7338.                                 if (Attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex)) return 1;
  7339.                             Defence = (Int32)Attacked.MagicDefence;
  7340.                             if (Attacker.Penetration > 0)
  7341.                                 Defence -= (ushort)((float)Defence / 100 * (Attacker.Penetration / 100));
  7342.                             Damage = (Int32)Attacker.BaseMagicAttack;
  7343.                             Damage += (Int32)SInfo.Power;
  7344.                             if (Attacked.PlayerFlag == PlayerFlag.Player)
  7345.                             {
  7346.                                 if (Attacked.Reborn == 1)
  7347.                                     Damage = (Int32)(Damage * 0.69);
  7348.                                 if (Attacked.Reborn == 2)
  7349.                                     Damage = (Int32)(Damage * 0.49);
  7350.  
  7351.                             }
  7352.                             Damage += Fan;
  7353.                             if (Attacker.PlayerFlag == PlayerFlag.Player)
  7354.                                 Damage += Attacker.MagicDamageIncrease;
  7355.                             if (Attacker.PlayerFlag == PlayerFlag.Player)
  7356.                             {
  7357.                                 if (Damage > 0)
  7358.                                 {
  7359.                                     Damage +=
  7360.                                         (Int32)(Math.Floor((Double)Damage * Attacker.GemBonus(ItemSocket.Phoenix)));
  7361.                                 }
  7362.                             }
  7363.                             Damage -= Defence;
  7364.                             Damage -= Tower;
  7365.                             if (Attacked.PlayerFlag == PlayerFlag.Player)
  7366.                             {
  7367.                                 if (Kernel.ChanceSuccess((float)Attacked.Block / 100f))
  7368.                                 {
  7369.                                     Packet.Effect |= MsgInteract.InteractEffects.Block;
  7370.                                     Damage = (Int32)Math.Floor((float)Damage / 2);
  7371.                                 }
  7372.                             }
  7373.                             if (Attacked.PlayerFlag == PlayerFlag.Player)
  7374.                             {
  7375.                                 if (Damage > 0)
  7376.                                 {
  7377.                                     uint TortoisePercent = Attacked.Owner.GemValues(Enums.Gem.NormalTortoiseGem);
  7378.                                     if (TortoisePercent > 0u) Damage -= Damage * Math.Min((int)TortoisePercent, 20) / 150;
  7379.                                 }
  7380.                             }
  7381.                             if (Damage <= 0)
  7382.                                 Damage = 1;
  7383.                             Damage = Damage / 6;
  7384.                             AutoRespone(Attacker, Attacked, ref Damage);
  7385.                             #region AzureShield
  7386.                             if (Attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  7387.                             {
  7388.                                 if (Damage > Attacked.AzureShieldDefence)
  7389.                                 {
  7390.                                     Damage -= Attacked.AzureShieldDefence;
  7391.                                     CreateAzureDmg(Attacked.AzureShieldDefence, Attacker, Attacked);
  7392.                                     Attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  7393.                                     Attacked.AzuredShield = true;
  7394.                                 }
  7395.                                 else
  7396.                                 {
  7397.                                     CreateAzureDmg((uint)Damage, Attacker, Attacked);
  7398.                                     Attacked.AzureShieldDefence -= (ushort)Damage;
  7399.                                     Attacked.AzureShieldPacket();
  7400.                                     Damage = 1;
  7401.                                 }
  7402.                             }
  7403.                             #endregion
  7404.                             if (Attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  7405.                             {
  7406.  
  7407.                                 if (Damage > Attacked.IronShieldDefence)
  7408.                                 {
  7409.                                     Damage -= (int)Attacked.IronShieldDefence;
  7410.                                     CreateAzureDmg(Attacked.IronShieldDefence, Attacker, Attacked);
  7411.                                     Attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  7412.                                 }
  7413.                                 else
  7414.                                 {
  7415.                                     CreateAzureDmg((uint)Damage, Attacker, Attacked);
  7416.                                     Attacked.IronShieldDefence -= (uint)Damage;
  7417.                                     Attacked.IronShieldPacket();
  7418.                                     Damage = 1;
  7419.                                 }
  7420.                             }
  7421.                             if (Attacked.HasMagicDefender && (Attacker.BattlePower - Attacked.BattlePower) <= 3)
  7422.                             {
  7423.                                 Damage = 0;
  7424.                                 MsgName str = new MsgName(true);
  7425.                                 str.UID = Attacked.UID;
  7426.                                 str.TextsCount = 1;
  7427.                                 str.Action = MsgName.Effect;
  7428.                                 str.Texts.Add("bossimmunity");
  7429.                                 Attacked.Owner.SendScreen(str, true);
  7430.                             }
  7431.                             else
  7432.                                 Attacked.RemoveMagicDefender();
  7433.                             return (uint)Damage;
  7434.                         }
  7435.                     case PlayerFlag.Player:
  7436.                         {
  7437.                             long Damage = 0;
  7438.                             Int32 Defence = 0;
  7439.                             Int32 Fan = 0;
  7440.                             if (Attacker.PlayerFlag == PlayerFlag.Player)
  7441.                                 Fan = Attacker.getFan(true);
  7442.                             if (Miss((int)SInfo.Percent)) return 0;
  7443.                             Defence = Attacked.MonsterInfo.Level * 2;
  7444.                             Damage = (Int32)Attacker.BaseMagicAttack;
  7445.                             Damage += (Int32)SInfo.Power;
  7446.                             #region Breakthrough
  7447.                             if (Attacker.PlayerFlag == PlayerFlag.Player)
  7448.                             {
  7449.                                 if (Attacker.BattlePower < Attacked.BattlePower)
  7450.                                 {
  7451.                                     if (Kernel.ChanceSuccess(((float)Attacker.Breaktrough / 10f) - (float)(Attacked.Counteraction / 10f)))
  7452.                                     {
  7453.                                         Damage = (Int32)Attacker.BaseMagicAttack;
  7454.                                         Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  7455.                                     }
  7456.                                 }
  7457.                             }
  7458.                             #endregion
  7459.                             if (Attacker.WearsGoldPrize) Damage += (long)(Damage * goldPrizeMagAttackCoefficient);
  7460.                             if (Attacked.Hitpoints <= Damage)
  7461.                             {
  7462.                                 Attacked.Die(Attacker);
  7463.                                 Attacked.IsDropped = true;
  7464.                             }
  7465.                             Damage += Fan;
  7466.                             if (Attacker.PlayerFlag == PlayerFlag.Player)
  7467.                                 Damage += Attacker.MagicDamageIncrease;
  7468.                             if (Attacker.PlayerFlag == PlayerFlag.Player)
  7469.                             {
  7470.                                 if (Damage > 0)
  7471.                                 {
  7472.                                     Damage += (Int32)(Math.Floor((Double)Damage * Attacker.GemBonus(ItemSocket.Phoenix)));
  7473.                                 }
  7474.                             }
  7475.                             Damage *= (long)(2.5);
  7476.                             Damage -= Defence;
  7477.                             int strike = Math.Max(110, 120);
  7478.                             if (Attacker.CriticalStrike > 0u)
  7479.                             {
  7480.                                 if (Base.GetRefinery((uint)Attacker.CriticalStrike / 100, (uint)Attacked.Immunity / 100))
  7481.                                 {
  7482.                                     Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  7483.                                     Damage = Base.MulDiv((int)Damage, strike, 100);
  7484.                                 }
  7485.                             }
  7486.                             if (Damage <= 1) Damage = 1;
  7487.                             return (UInt32)Damage;
  7488.                         }
  7489.                 }
  7490.                 return 0;
  7491.             }
  7492.         }
  7493.         public static uint Magic(Player attacker, Player attacked, ushort spellID, byte spellLevel, ref MsgInteract Packet)
  7494.         {
  7495.             if (Database.SpellTable.SpellInformations.ContainsKey(spellID))
  7496.             {
  7497.                 Database.SpellInformation spell = Database.SpellTable.SpellInformations[spellID][spellLevel];
  7498.                 return Magic(attacker, attacked, spell, ref Packet);
  7499.             }
  7500.             return 0;
  7501.         }
  7502.         public static uint Magic(Player attacker, MsgNpcInfoEX attacked, Database.SpellInformation spell, ref MsgInteract Packet)
  7503.         {
  7504.             if (attacker.PlayerFlag == PlayerFlag.Player)
  7505.             {
  7506.                 if (Kernel.Rate(50))
  7507.                 {
  7508.                     GemEffect.Process(attacker);
  7509.                 }
  7510.             }
  7511.             if (spell != null)
  7512.                 if (!Kernel.ChanceSuccess(spell.Percent))
  7513.                     return 0;
  7514.             if (spell != null)
  7515.                 Durability(attacker, null, spell);
  7516.             if (attacker.Transformed)
  7517.                 return 0;
  7518.             long Damage = 0;
  7519.             Damage = (long)attacker.MagicAttack;
  7520.             if (attacker.Gems[0] != 0)
  7521.             {
  7522.                 Damage += (uint)Math.Floor(Damage * (double)(attacker.Gems[0] * 0.01));
  7523.             }
  7524.             if (spell != null)
  7525.                 Damage += spell.Power;
  7526.             if (attacker.WearsGoldPrize) Damage += (long)(Damage * goldPrizeMagAttackCoefficient);
  7527.             if (Kernel.ChanceSuccess(5))
  7528.             {
  7529.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  7530.                 {
  7531.                     if (attacker.Owner.BlessTime > 0)
  7532.                     {
  7533.                         Damage *= 2;
  7534.                         MsgName str = new MsgName(true);
  7535.                         str.UID = attacker.UID;
  7536.                         str.TextsCount = 1;
  7537.                         str.Action = MsgName.Effect;
  7538.                         str.Texts.Add("LuckyGuy");
  7539.                         attacker.Owner.SendScreen(str, true);
  7540.                     }
  7541.                 }
  7542.             }
  7543.  
  7544.             if (attacker.PlayerFlag == PlayerFlag.Player)
  7545.             {
  7546.                 if (Damage > 0)
  7547.                 {
  7548.                     Damage += (Int32)(Math.Floor((Double)Damage * attacker.GemBonus(ItemSocket.Phoenix)));
  7549.                 }
  7550.             }
  7551.             if (attacker.Class > 100)
  7552.                 Damage -= Damage * 7 / 10;
  7553.             Damage += attacker.MagicDamageIncrease;
  7554.             if (Damage <= 0)
  7555.                 Damage = 1;
  7556.             return (uint)Damage;
  7557.         }
  7558.  
  7559.         public static uint Ranged(Player attacker, Player attacked, ref MsgInteract Packet)
  7560.         {
  7561.             if (Packet != null)
  7562.             {
  7563.                 Packet.Effect = MsgInteract.InteractEffects.None;
  7564.             }
  7565.             #region HideGui
  7566.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  7567.             {
  7568.                 MsgAction Data = new MsgAction(true);
  7569.                 Data.UID = attacker.UID;
  7570.                 Data.UID = attacked.UID;
  7571.                 Data.ID = MsgAction.Mode.HideGui;
  7572.                 attacker.Owner.Send(Data);
  7573.                 attacked.Owner.Send(Data);
  7574.             }
  7575.             #endregion
  7576.             #region MyClones
  7577.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  7578.             {
  7579.                 if (attacked.MyClones.Count > 0)
  7580.                 {
  7581.                     foreach (var item in attacked.MyClones.Values)
  7582.                     {
  7583.                         MsgAction data = new MsgAction(true);
  7584.                         data.UID = item.UID;
  7585.                         data.ID = MsgAction.Mode.RemoveEntity;
  7586.                         item.MonsterInfo.SendScreen(data);
  7587.                         attacked.Owner.Map.RemoveEntity(item);
  7588.                         attacked.Owner.Send(data);
  7589.                     }
  7590.                     attacked.MyClones.Clear();
  7591.                     return 0;
  7592.                 }
  7593.             }
  7594.             #endregion
  7595.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  7596.             {
  7597.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex)) return 1;
  7598.                 if (attacker.Transformed) return 0;
  7599.                 if (attacker == null) return 0;
  7600.                 if (attacked == null) return 0;
  7601.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  7602.                 {
  7603.                     if (Kernel.Rate(50))
  7604.                     {
  7605.                         GemEffect.Process(attacker);
  7606.                     }
  7607.                 }
  7608.                 Durability(attacker, attacked, null);
  7609.                 if (attacker.Transformed)
  7610.                     return 0;
  7611.                 Double attack = attacker.MinAttack + Kernel.Random.Next((int)attacker.MaxAttack - (int)attacker.MinAttack);
  7612.                 #region Breakthrough
  7613.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  7614.                 {
  7615.                     if (attacker.BattlePower < attacked.BattlePower)
  7616.                     {
  7617.                         if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  7618.                         {
  7619.                             attack = (Int32)attacker.MaxAttack;
  7620.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  7621.                         }
  7622.                     }
  7623.                 }
  7624.                 #endregion
  7625.                 AutoRespone(attacker, attacked, ref attack);
  7626.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  7627.                 {
  7628.                     var bonus = attacker.Gems[1];
  7629.                     if (bonus > 0)
  7630.                     {
  7631.                         attack += MathHelper.MulDiv((int)attack, bonus, 100);
  7632.                     }
  7633.                 }
  7634.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  7635.                     if (!attacker.Transformed)
  7636.                         attack = (long)(attack * 1.1);
  7637.                 Double defense = attacked.Defence;
  7638.                 Double damage = attack - defense;
  7639.              
  7640.                 var targetLevel = attacked.Level;
  7641.                 if (targetLevel < 22) damage = MathHelper.MulDiv((int)damage, 35, 100);
  7642.                 else if (targetLevel < 50) damage = MathHelper.MulDiv((int)damage, 25, 100);
  7643.                 else if (targetLevel < 90) damage = MathHelper.MulDiv((int)damage, 20, 100);
  7644.                 else if (targetLevel < 110) damage = MathHelper.MulDiv((int)damage, 15, 100);
  7645.                 else damage = MathHelper.MulDiv((int)damage, 12, 100);
  7646.                 int strike = Math.Max(110, 120);
  7647.                 if (attacker.CriticalStrike > 0u)
  7648.                 {
  7649.                     if (Base.GetRefinery((uint)attacker.CriticalStrike / 100, (uint)attacked.Immunity / 100))
  7650.                     {
  7651.                         Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  7652.                         damage = Base.MulDiv((int)damage, strike, 100);
  7653.                     }
  7654.                 }
  7655.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  7656.                 {
  7657.                     var reduce = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  7658.                     if (reduce > 0)
  7659.                     {
  7660.                         damage -= (damage / 2) * reduce / 10;
  7661.                     }
  7662.                 }
  7663.                 damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  7664.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  7665.                 {
  7666.                     var reduce = Math.Max(0, Math.Min(100, (int)attacked.ItemBless));
  7667.                     if (reduce > 0)
  7668.                     {
  7669.                         damage -= damage * (int)reduce / 100;
  7670.                     }
  7671.                 }
  7672.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  7673.                     damage = damage * 3;
  7674.                 if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  7675.                 {
  7676.                     damage *= 2;
  7677.                     attacker.OnIntensify = false;
  7678.                     attacker.RemoveFlag((ulong)MsgUpdate.Flags.Intensify);
  7679.                 }
  7680.                 #region Block
  7681.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  7682.                 {
  7683.                     if (Kernel.ChanceSuccess((float)attacked.Block / 100f))
  7684.                     {
  7685.                         Packet.Effect |= MsgInteract.InteractEffects.Block;
  7686.                         damage = (Int32)Math.Floor((float)damage / 2);
  7687.                     }
  7688.                 }
  7689.                 #endregion
  7690.                 #region Reduction!
  7691.                 if (attacked.IsDefensiveStance)
  7692.                 {
  7693.                     if (attacked.FatigueSecs > 120)
  7694.                     {
  7695.                         damage -= attacked.Defence + (Double)(attacked.Defence * 0.40);
  7696.                     }
  7697.                     else
  7698.                     {
  7699.                         damage -= attacked.Defence + (Double)(attacked.Defence * 0.20);
  7700.                     }
  7701.                 }
  7702.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  7703.                 {
  7704.                     if (damage > attacked.AzureShieldDefence)
  7705.                     {
  7706.                         damage -= attacked.AzureShieldDefence;
  7707.                         CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  7708.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  7709.                         attacked.AzuredShield = true;
  7710.                     }
  7711.                     else
  7712.                     {
  7713.                         CreateAzureDmg((uint)damage, attacker, attacked);
  7714.                         attacked.AzureShieldDefence -= (ushort)damage;
  7715.                         attacked.AzureShieldPacket();
  7716.                         damage = 1;
  7717.                     }
  7718.                 }
  7719.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  7720.                 {
  7721.  
  7722.                     if (damage > attacked.IronShieldDefence)
  7723.                     {
  7724.                         damage -= (int)attacked.IronShieldDefence;
  7725.                         CreateAzureDmg(attacked.IronShieldDefence, attacker, attacked);
  7726.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  7727.                     }
  7728.                     else
  7729.                     {
  7730.                         CreateAzureDmg((uint)damage, attacker, attacked);
  7731.                         attacked.IronShieldDefence -= (uint)damage;
  7732.                         attacked.IronShieldPacket();
  7733.                         damage = 1;
  7734.                     }
  7735.                 }
  7736.                 #endregion
  7737.                 if (damage < 0)
  7738.                     damage = 1;
  7739.                 return Math.Max((uint)1, (uint)damage);
  7740.             }
  7741.             else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  7742.             {
  7743.                 int Damage = 0;
  7744.                 Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, MsgInteract.Ranged, ref Packet);
  7745.                 CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  7746.                 return (uint)Damage;
  7747.             }
  7748.             else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  7749.             {
  7750.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  7751.                     return 1;
  7752.                 if (attacker.Transformed)
  7753.                     return 0;
  7754.                 if (attacker == null)
  7755.                     return 0;
  7756.                 if (attacked == null)
  7757.                     return 0;
  7758.                 #region Effect By Maxs
  7759.  
  7760.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  7761.                 {
  7762.                     if (Kernel.Rate(50))
  7763.                     {
  7764.                         GemEffect.Process(attacker);
  7765.                     }
  7766.                 }
  7767.  
  7768.                 #endregion
  7769.                 Durability(attacker, attacked, null);
  7770.                 if (attacker.Transformed)
  7771.                     return 0;
  7772.                 Double attack = attacker.MinAttack + Kernel.Random.Next((int)attacker.MaxAttack - (int)attacker.MinAttack);
  7773.                 #region Breakthrough
  7774.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  7775.                 {
  7776.                     if (attacker.BattlePower < attacked.BattlePower)
  7777.                     {
  7778.                         if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  7779.                         {
  7780.                             attack = (Int32)attacker.MaxAttack/* + 3000*/;
  7781.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  7782.                         }
  7783.                     }
  7784.                 }
  7785.                 #endregion
  7786.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  7787.                 {
  7788.                     var bonus = attacker.Gems[1];
  7789.                     if (bonus > 0)
  7790.                     {
  7791.                         attack += MathHelper.MulDiv((int)attack, bonus, 100);
  7792.                     }
  7793.                 }
  7794.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  7795.                     if (!attacker.Transformed)
  7796.                         attack = (long)(attack * 1.1);
  7797.                 Double defense = attacked.Defence;
  7798.                 Double damage = attack - defense;
  7799.                
  7800.                 var targetLevel = attacked.Level;
  7801.                 if (targetLevel < 22) damage = MathHelper.MulDiv((int)damage, 35, 100);
  7802.                 else if (targetLevel < 50) damage = MathHelper.MulDiv((int)damage, 25, 100);
  7803.                 else if (targetLevel < 90) damage = MathHelper.MulDiv((int)damage, 20, 100);
  7804.                 else if (targetLevel < 110) damage = MathHelper.MulDiv((int)damage, 15, 100);
  7805.                 else damage = MathHelper.MulDiv((int)damage, 12, 100);
  7806.                 int strike = Math.Max(110, 120);
  7807.                 if (attacker.CriticalStrike > 0u)
  7808.                 {
  7809.                     if (Base.GetRefinery((uint)attacker.CriticalStrike / 100, (uint)attacked.Immunity / 100))
  7810.                     {
  7811.                         Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  7812.                         damage = Base.MulDiv((int)damage, strike, 100);
  7813.                     }
  7814.                 }
  7815.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  7816.                 {
  7817.                     var reduce = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  7818.                     if (reduce > 0)
  7819.                     {
  7820.                         damage -= (damage / 2) * reduce / 10;
  7821.                     }
  7822.                 }
  7823.                 damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  7824.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  7825.                 {
  7826.                     var reduce = Math.Max(0, Math.Min(100, (int)attacked.ItemBless));
  7827.                     if (reduce > 0)
  7828.                     {
  7829.                         damage -= damage * (int)reduce / 100;
  7830.                     }
  7831.                 }
  7832.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  7833.                     damage = damage * 3;
  7834.                 if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  7835.                 {
  7836.                     damage *= 2;
  7837.                     attacker.OnIntensify = false;
  7838.                     attacker.RemoveFlag((ulong)MsgUpdate.Flags.Intensify);
  7839.                 }
  7840.                 #region Block
  7841.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  7842.                 {
  7843.                     if (Kernel.ChanceSuccess((float)attacked.Block / 100f))
  7844.                     {
  7845.                         Packet.Effect |= MsgInteract.InteractEffects.Block;
  7846.                         damage = (Int32)Math.Floor((float)damage / 2);
  7847.                     }
  7848.                 }
  7849.                 #endregion
  7850.                 #region Reduction!
  7851.  
  7852.                 if (attacked.IsDefensiveStance)
  7853.                 {
  7854.                     if (attacked.FatigueSecs > 120)
  7855.                     {
  7856.                         damage -= attacked.Defence + (Double)(attacked.Defence * 0.40);
  7857.                     }
  7858.                     else
  7859.                     {
  7860.                         damage -= attacked.Defence + (Double)(attacked.Defence * 0.20);
  7861.                     }
  7862.                 }
  7863.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  7864.                 {
  7865.                     if (damage > attacked.AzureShieldDefence)
  7866.                     {
  7867.                         damage -= attacked.AzureShieldDefence;
  7868.                         CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  7869.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  7870.                         attacked.AzuredShield = true;
  7871.                     }
  7872.                     else
  7873.                     {
  7874.                         CreateAzureDmg((uint)damage, attacker, attacked);
  7875.                         attacked.AzureShieldDefence -= (ushort)damage;
  7876.                         attacked.AzureShieldPacket();
  7877.                         damage = 1;
  7878.                     }
  7879.                 }
  7880.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  7881.                 {
  7882.  
  7883.                     if (damage > attacked.IronShieldDefence)
  7884.                     {
  7885.                         damage -= (int)attacked.IronShieldDefence;
  7886.                         CreateAzureDmg(attacked.IronShieldDefence, attacker, attacked);
  7887.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  7888.                     }
  7889.                     else
  7890.                     {
  7891.                         CreateAzureDmg((uint)damage, attacker, attacked);
  7892.                         attacked.IronShieldDefence -= (uint)damage;
  7893.                         attacked.IronShieldPacket();
  7894.                         damage = 1;
  7895.                     }
  7896.                 }
  7897.                 #endregion
  7898.                 if (damage < 0)
  7899.                     damage = 1;
  7900.                 return Math.Max((uint)1, (uint)damage);
  7901.             }
  7902.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex)) return 1;
  7903.             if (attacker.Transformed) return 0;
  7904.             if (attacker == null) return 0;
  7905.             if (attacked == null) return 0;
  7906.             #region Effect By Maxs
  7907.  
  7908.             if (attacker.PlayerFlag == PlayerFlag.Player)
  7909.             {
  7910.                 if (Kernel.Rate(50))
  7911.                 {
  7912.                     GemEffect.Process(attacker);
  7913.                 }
  7914.             }
  7915.  
  7916.             #endregion
  7917.             Durability(attacker, attacked, null);
  7918.             if (attacker.Transformed)
  7919.                 return 0;
  7920.             Double attacke = attacker.MinAttack + Kernel.Random.Next((int)attacker.MaxAttack - (int)attacker.MinAttack);
  7921.             #region Breakthrough
  7922.             if (attacker.PlayerFlag == PlayerFlag.Player)
  7923.             {
  7924.                 if (attacker.BattlePower < attacked.BattlePower)
  7925.                 {
  7926.                     if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  7927.                     {
  7928.                         attacke = (Int32)attacker.MaxAttack/* + 3000*/;
  7929.                         Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  7930.                     }
  7931.                 }
  7932.             }
  7933.             #endregion
  7934.             if (attacker.PlayerFlag == PlayerFlag.Player)
  7935.             {
  7936.                 var bonus = attacker.Gems[1];
  7937.                 if (bonus > 0)
  7938.                 {
  7939.                     attacke += MathHelper.MulDiv((int)attacke, bonus, 100);
  7940.                 }
  7941.             }
  7942.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  7943.                 if (!attacker.Transformed)
  7944.                     attacke = (long)(attacke * 1.1);
  7945.             Double defensee = attacked.Defence;
  7946.             Double damagee = attacke - defensee;
  7947.          
  7948.             var targetLevell = attacked.Level;
  7949.             if (targetLevell < 22) damagee = MathHelper.MulDiv((int)damagee, 35, 100);
  7950.             else if (targetLevell < 50) damagee = MathHelper.MulDiv((int)damagee, 25, 100);
  7951.             else if (targetLevell < 90) damagee = MathHelper.MulDiv((int)damagee, 20, 100);
  7952.             else if (targetLevell < 110) damagee = MathHelper.MulDiv((int)damagee, 15, 100);
  7953.             else damagee = MathHelper.MulDiv((int)damagee, 12, 100);
  7954.             //int strikee = Math.Max(110, 120);
  7955.             //if (attacker.CriticalStrike > 0u)
  7956.             //{
  7957.             //    if (Base.GetRefinery((uint)attacker.CriticalStrike / 100, (uint)attacked.Immunity / 100))
  7958.             //    {
  7959.             //        Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  7960.             //        damagee = Base.MulDiv((int)damagee, strikee, 100);
  7961.             //    }
  7962.             //}
  7963.             if (attacked.PlayerFlag == PlayerFlag.Player)
  7964.             {
  7965.                 var reduce = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  7966.                 if (reduce > 0)
  7967.                 {
  7968.                     damagee -= (damagee / 2) * reduce / 10;
  7969.                 }
  7970.             }
  7971.             damagee = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damagee);
  7972.             if (attacked.PlayerFlag == PlayerFlag.Player)
  7973.             {
  7974.                 var reduce = Math.Max(0, Math.Min(100, (int)attacked.ItemBless));
  7975.                 if (reduce > 0)
  7976.                 {
  7977.                     damagee -= damagee * (int)reduce / 100;
  7978.                 }
  7979.             }
  7980.             if (attacked.PlayerFlag == PlayerFlag.Monster)
  7981.                 damagee = damagee * 3;
  7982.             if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  7983.             {
  7984.                 damagee *= 2;
  7985.                 attacker.OnIntensify = false;
  7986.                 attacker.RemoveFlag((ulong)MsgUpdate.Flags.Intensify);
  7987.             }
  7988.             #region Block
  7989.             if (attacked.PlayerFlag == PlayerFlag.Player)
  7990.             {
  7991.                 if (Kernel.ChanceSuccess((float)attacked.Block / 100f))
  7992.                 {
  7993.                     Packet.Effect |= MsgInteract.InteractEffects.Block;
  7994.                     damagee = (Int32)Math.Floor((float)damagee / 2);
  7995.                 }
  7996.             }
  7997.             #endregion
  7998.             #region Reduction!
  7999.  
  8000.             if (attacked.IsDefensiveStance)
  8001.             {
  8002.                 if (attacked.FatigueSecs > 120)
  8003.                 {
  8004.                     damagee -= attacked.Defence + (Double)(attacked.Defence * 0.40);
  8005.                 }
  8006.                 else
  8007.                 {
  8008.                     damagee -= attacked.Defence + (Double)(attacked.Defence * 0.20);
  8009.                 }
  8010.             }
  8011.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  8012.             {
  8013.                 if (damagee > attacked.AzureShieldDefence)
  8014.                 {
  8015.                     damagee -= attacked.AzureShieldDefence;
  8016.                     CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  8017.                     attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  8018.                     attacked.AzuredShield = true;
  8019.                 }
  8020.                 else
  8021.                 {
  8022.                     CreateAzureDmg((uint)damagee, attacker, attacked);
  8023.                     attacked.AzureShieldDefence -= (ushort)damagee;
  8024.                     attacked.AzureShieldPacket();
  8025.                     damagee = 1;
  8026.                 }
  8027.             }
  8028.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  8029.             {
  8030.  
  8031.                 if (damagee > attacked.IronShieldDefence)
  8032.                 {
  8033.                     damagee -= (int)attacked.IronShieldDefence;
  8034.                     CreateAzureDmg(attacked.IronShieldDefence, attacker, attacked);
  8035.                     attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  8036.                 }
  8037.                 else
  8038.                 {
  8039.                     CreateAzureDmg((uint)damagee, attacker, attacked);
  8040.                     attacked.IronShieldDefence -= (uint)damagee;
  8041.                     attacked.IronShieldPacket();
  8042.                     damagee = 1;
  8043.                 }
  8044.             }
  8045.             #endregion
  8046.             if (damagee < 0)
  8047.                 damagee = 1;
  8048.             return Math.Max((uint)1, (uint)damagee);
  8049.         }
  8050.         public static uint Ranged(Player attacker, MsgNpcInfoEX attacked, ref MsgInteract Packet)
  8051.         {
  8052.             long Damage = 0;
  8053.             Durability(attacker, null, null);
  8054.             if (attacker.Transformed) return 0;
  8055.             Damage = Kernel.Random.Next((int)Math.Min(attacker.MinAttack, attacker.MaxAttack),
  8056.                 (int)Math.Max(attacker.MinAttack, attacker.MaxAttack) + 1);
  8057.             if (attacker.Gems[1] != 0)
  8058.             {
  8059.                 Damage += (uint)Math.Floor(Damage * (double)(attacker.Gems[1] * 0.01));
  8060.             }
  8061.             if (attacker.WearsGoldPrize) Damage += (long)(Damage * goldPrizePsyAttackCoefficient);
  8062.             if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  8063.             {
  8064.                 Damage *= 2;
  8065.                 attacker.OnIntensify = false;
  8066.                 attacker.RemoveFlag((ulong)MsgUpdate.Flags.Intensify);
  8067.             }
  8068.  
  8069.             if (Kernel.ChanceSuccess(5))
  8070.             {
  8071.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8072.                 {
  8073.                     if (attacker.Owner.BlessTime > 0)
  8074.                     {
  8075.                         Damage *= 2;
  8076.                         MsgName str = new MsgName(true);
  8077.                         str.UID = attacker.UID;
  8078.                         str.TextsCount = 1;
  8079.                         str.Action = MsgName.Effect;
  8080.                         str.Texts.Add("LuckyGuy");
  8081.                         attacker.Owner.SendScreen(str, true);
  8082.                     }
  8083.                 }
  8084.             }
  8085.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  8086.                 if (!attacker.Transformed)
  8087.                     Damage = (long)(Damage * 1.1);
  8088.             Damage += attacker.PhysicalDamageIncrease;
  8089.             Damage += Damage;
  8090.             Damage += Damage / 4;
  8091.             if (Damage <= 0)
  8092.                 Damage = 1;
  8093.             return (uint)(Damage * reduceValue);
  8094.         }
  8095.         public static uint Ranged(Player attacker, Player attacked, Database.SpellInformation spell, ref MsgInteract Packet)
  8096.         {
  8097.             if (Packet != null)
  8098.             {
  8099.                 Packet.Effect = MsgInteract.InteractEffects.None;
  8100.             }
  8101.             #region HideGui
  8102.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  8103.             {
  8104.                 MsgAction Data = new MsgAction(true);
  8105.                 Data.UID = attacker.UID;
  8106.                 Data.UID = attacked.UID;
  8107.                 Data.ID = MsgAction.Mode.HideGui;
  8108.                 attacker.Owner.Send(Data);
  8109.                 attacked.Owner.Send(Data);
  8110.             }
  8111.             #endregion
  8112.             #region MyClones
  8113.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  8114.             {
  8115.                 if (attacked.MyClones.Count > 0)
  8116.                 {
  8117.                     foreach (var clone in attacked.MyClones.Values)
  8118.                     {
  8119.                         MsgAction data = new MsgAction(true);
  8120.                         data.UID = clone.UID;
  8121.                         data.ID = MsgAction.Mode.RemoveEntity;
  8122.                         clone.MonsterInfo.SendScreen(data);
  8123.                         attacked.Owner.Map.RemoveEntity(clone);
  8124.                         attacked.Owner.Send(data);
  8125.                     }
  8126.                     attacked.MyClones.Clear();
  8127.                     return 0;
  8128.                 }
  8129.             }
  8130.             #endregion
  8131.             if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Player)
  8132.             {
  8133.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex))
  8134.                     return 1;
  8135.                 if (attacked.ContainsFlag((ulong)1UL << 53))
  8136.                     return 1;
  8137.                 if (attacker.Transformed)
  8138.                     return 0;
  8139.                 if (attacker == null)
  8140.                     return 0;
  8141.                 if (attacked == null)
  8142.                     return 0;
  8143.  
  8144.                 #region Effect
  8145.  
  8146.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8147.                 {
  8148.                     if (Kernel.Rate(50))
  8149.                     {
  8150.                         GemEffect.Process(attacker);
  8151.                     }
  8152.                 }
  8153.  
  8154.                 #endregion
  8155.                 if (attacker.Transformed)
  8156.                     return 0;
  8157.  
  8158.                 Double attack = MyMath.Generate((int)attacker.MinAttack, (int)attacker.MaxAttack);
  8159.                 //Double attack = attacker.MinAttack + random.Next((int)attacker.MaxAttack - (int)attacker.MinAttack);
  8160.                 #region Breakthrough
  8161.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8162.                 {
  8163.                     if (attacker.BattlePower < attacked.BattlePower)
  8164.                     {
  8165.                         if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  8166.                         {
  8167.                             attack = (Int32)Math.Floor((float)attack * 1.6);
  8168.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  8169.                         }
  8170.                     }
  8171.                 }
  8172.                 #endregion
  8173.                 #region Breakthrough
  8174.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8175.                 {
  8176.                     if (attacker.BattlePower >= attacked.BattlePower)
  8177.                     {
  8178.                         if (Kernel.ChanceSuccess(((float)attacker.Breaktrough / 10f) - (float)(attacked.Counteraction / 10f)))
  8179.                         {
  8180.                             attack = (Int32)Math.Floor((float)attack * 1.05);
  8181.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  8182.                         }
  8183.                     }
  8184.                 }
  8185.                 #endregion
  8186.                 #region Spell Bounes
  8187.  
  8188.                 if (spell != null)
  8189.                 {
  8190.                     if (spell.PowerPercent != 0)
  8191.                     {
  8192.                         attack = (long)(attack * spell.PowerPercent);
  8193.                     }
  8194.                 }
  8195.  
  8196.                 #endregion
  8197.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8198.                 {
  8199.                     var bonus = attacker.Gems[1];
  8200.                     if (bonus > 0)
  8201.                     {
  8202.                         attack += MathHelper.MulDiv((int)attack, bonus, 100);
  8203.                     }
  8204.                 }
  8205.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  8206.                     if (!attacker.Transformed)
  8207.                         attack = (long)(attack * 1.17);
  8208.  
  8209.                 Double defense = attacked.Defence;
  8210.                 Double damage = attack - defense;
  8211.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8212.                 {
  8213.                     #region BattelPower
  8214.                     if (Packet.Effect != MsgInteract.InteractEffects.Penetration)
  8215.                     {
  8216.                         if (attacker.BattlePower < attacked.BattlePower)
  8217.                         {
  8218.                             ushort BattlePower = (ushort)(attacked.BattlePower - attacker.BattlePower);
  8219.                             if (BattlePower == 1)
  8220.                             {
  8221.                                 damage = (damage * 70) / 100;
  8222.                             }
  8223.                             else if (BattlePower == 2)
  8224.                             {
  8225.                                 damage = (damage * 60) / 100;
  8226.                             }
  8227.                             else if (BattlePower == 3)
  8228.                             {
  8229.                                 damage = (damage * 50) / 100;
  8230.                             }
  8231.                             else if (BattlePower == 4)
  8232.                             {
  8233.                                 damage = (damage * 40) / 100;
  8234.                             }
  8235.                             else if (BattlePower >= 5)
  8236.                             {
  8237.                                 damage = (damage * 30) / 100;
  8238.                             }
  8239.                         }
  8240.                     }
  8241.                     #endregion
  8242.                 }
  8243.                 var targetLevel = attacked.Level;
  8244.                 if (targetLevel < 22) damage = MathHelper.MulDiv((int)damage, 35, 100);
  8245.                 else if (targetLevel < 50) damage = MathHelper.MulDiv((int)damage, 25, 100);
  8246.                 else if (targetLevel < 90) damage = MathHelper.MulDiv((int)damage, 20, 100);
  8247.                 else if (targetLevel < 110) damage = MathHelper.MulDiv((int)damage, 15, 100);
  8248.                 else damage = MathHelper.MulDiv((int)damage, 12, 100);
  8249.                 #region CriticalStrike
  8250.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8251.                 {
  8252.                     if (attacker.BattlePower < attacked.BattlePower)
  8253.                     {
  8254.                         if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  8255.                         {
  8256.                             Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  8257.                             damage = (UInt32)Math.Floor((float)damage * 1.0);
  8258.                         }
  8259.                     }
  8260.                 }
  8261.                 #endregion
  8262.                 #region CriticalStrike
  8263.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8264.                 {
  8265.                     if (attacker.BattlePower >= attacked.BattlePower)
  8266.                     {
  8267.                         if (Kernel.ChanceSuccess(((float)attacker.CriticalStrike / 100f) - ((float)attacked.Immunity / 100f)))
  8268.                         {
  8269.                             Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  8270.                             damage = (UInt32)Math.Floor((float)damage * 1.5);
  8271.                         }
  8272.                     }
  8273.                 }
  8274.                 #endregion
  8275.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8276.                 {
  8277.                     var reduce = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  8278.                     if (reduce > 0)
  8279.                     {
  8280.                         damage -= (damage / 2) * reduce / 100;
  8281.                     }
  8282.                 }
  8283.  
  8284.                 damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  8285.  
  8286.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8287.                 {
  8288.                     var reduce = Math.Max(0, Math.Min(100, (int)attacked.ItemBless));
  8289.                     if (reduce > 0)
  8290.                     {
  8291.                         damage -= damage * (int)reduce / 100;
  8292.                     }
  8293.                 }
  8294.  
  8295.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  8296.                     damage = damage * 3;
  8297.  
  8298.                 #region Block
  8299.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8300.                 {
  8301.                     if (Kernel.Rate(22))
  8302.                     {
  8303.                         if (attacked.Block > 0)
  8304.                         {
  8305.                             Packet.Effect |= MsgInteract.InteractEffects.Block;
  8306.                             damage = (Int32)Math.Floor((float)damage / 2);
  8307.                         }
  8308.                     }
  8309.                 }
  8310.                 #endregion
  8311.                 #region Reduction!
  8312.  
  8313.                 #region Clac Defence
  8314.                 int nDef, defmain;
  8315.                 if (!attacker.Transformed)
  8316.                     nDef = defmain = attacked.Defence;
  8317.                 else
  8318.                     nDef = defmain = attacked.TransformationDefence;
  8319.                 nDef = Handle.ShieldDefence(attacked, nDef);
  8320.                 if (attacked.IsDefensiveStance)
  8321.                     nDef *= 3;
  8322.  
  8323.                 #endregion End Defence
  8324.            
  8325.  
  8326.                 #endregion
  8327.  
  8328.                 if (damage < 0)
  8329.                     damage = 1;
  8330.  
  8331.                 return Math.Max((uint)1, (uint)damage);
  8332.             }
  8333.             else if (attacker.PlayerFlag == PlayerFlag.Player && attacked.PlayerFlag == PlayerFlag.Monster)
  8334.             {
  8335.                 int Damage = 0;
  8336.                 Damage = CalculateMonster.GetDamageEntity2Monster(attacker, attacked, spell.ID, spell.Level, ref Packet);
  8337.                 CalculateMonster.CheckDamage(attacker, attacked, ref Damage, ref Packet, false);
  8338.                 return (uint)Damage;
  8339.             }
  8340.             else if (attacker.PlayerFlag == PlayerFlag.Monster && attacked.PlayerFlag == PlayerFlag.Player)
  8341.             {
  8342.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex)) return 1;
  8343.                 if (attacker.Transformed) return 0;
  8344.                 if (attacker == null) return 0;
  8345.                 if (attacked == null) return 0;
  8346.                 #region GemEffect
  8347.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8348.                 {
  8349.                     if (Kernel.Rate(50))
  8350.                     {
  8351.                         GemEffect.Process(attacker);
  8352.                     }
  8353.                 }
  8354.                 #endregion
  8355.                 Durability(attacker, attacked, null);
  8356.                 if (attacker.Transformed) return 0;
  8357.                 Double attack = attacker.MinAttack + Kernel.Random.Next((int)attacker.MaxAttack - (int)attacker.MinAttack);
  8358.                 #region Breakthrough
  8359.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8360.                 {
  8361.                     if (attacker.BattlePower < attacked.BattlePower)
  8362.                     {
  8363.                         if (Kernel.ChanceSuccess(attacker.Breaktrough / 10f - attacked.Counteraction / 10f))
  8364.                         {
  8365.                             attack = attacker.MaxAttack;
  8366.                             Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  8367.                         }
  8368.                     }
  8369.                 }
  8370.                 #endregion
  8371.                 #region Spell Bounes
  8372.                 if (spell != null)
  8373.                 {
  8374.                     if (spell.PowerPercent != 0)
  8375.                     {
  8376.                         attack = (long)(attack * spell.PowerPercent);
  8377.                     }
  8378.                 }
  8379.                 #endregion
  8380.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8381.                 {
  8382.                     var bonus = attacker.Gems[1];
  8383.                     if (bonus > 0)
  8384.                     {
  8385.                         attack += MathHelper.MulDiv((int)attack, bonus, 100);
  8386.                     }
  8387.                 }
  8388.                 if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  8389.                     if (!attacker.Transformed)
  8390.                         attack = (long)(attack * 1.1);
  8391.                 Double defense = attacked.Defence;
  8392.                 Double damage = attack - defense;
  8393.              
  8394.                 var targetLevel = attacked.Level;
  8395.                 if (targetLevel < 22) damage = MathHelper.MulDiv((int)damage, 35, 100);
  8396.                 else if (targetLevel < 50) damage = MathHelper.MulDiv((int)damage, 25, 100);
  8397.                 else if (targetLevel < 90) damage = MathHelper.MulDiv((int)damage, 20, 100);
  8398.                 else if (targetLevel < 110) damage = MathHelper.MulDiv((int)damage, 15, 100);
  8399.                 else damage = MathHelper.MulDiv((int)damage, 12, 100);
  8400.                 //int strike = Math.Max(110, 120);
  8401.                 //if (attacker.CriticalStrike > 0u)
  8402.                 //{
  8403.                 //    if (Base.GetRefinery((uint)attacker.CriticalStrike / 100, (uint)attacked.Immunity / 100))
  8404.                 //    {
  8405.                 //        Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  8406.                 //        damage = Base.MulDiv((int)damage, strike, 100);
  8407.                 //    }
  8408.                 //}
  8409.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8410.                 {
  8411.                     var reduce = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  8412.                     if (reduce > 0)
  8413.                     {
  8414.                         damage -= (damage / 2) * reduce / 10;
  8415.                     }
  8416.                 }
  8417.                 damage = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damage);
  8418.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8419.                 {
  8420.                     var reduce = Math.Max(0, Math.Min(100, (int)attacked.ItemBless));
  8421.                     if (reduce > 0)
  8422.                     {
  8423.                         damage -= damage * (int)reduce / 100;
  8424.                     }
  8425.                 }
  8426.                 if (attacked.PlayerFlag == PlayerFlag.Monster)
  8427.                     damage = damage * 3;
  8428.                 if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  8429.                 {
  8430.                     damage *= 2;
  8431.                     attacker.OnIntensify = false;
  8432.                     attacker.RemoveFlag((ulong)MsgUpdate.Flags.Intensify);
  8433.                 }
  8434.                 #region Block
  8435.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8436.                 {
  8437.                     if (Kernel.ChanceSuccess((float)attacked.Block / 100f))
  8438.                     {
  8439.                         Packet.Effect |= MsgInteract.InteractEffects.Block;
  8440.                         damage = (Int32)Math.Floor((float)damage / 2);
  8441.                     }
  8442.                 }
  8443.                 #endregion
  8444.                 #region Reduction!
  8445.  
  8446.                 if (attacked.IsDefensiveStance)
  8447.                 {
  8448.                     if (attacked.FatigueSecs > 120)
  8449.                     {
  8450.                         damage -= attacked.Defence + (Double)(attacked.Defence * 0.40);
  8451.                     }
  8452.                     else
  8453.                     {
  8454.                         damage -= attacked.Defence + (Double)(attacked.Defence * 0.20);
  8455.                     }
  8456.                 }
  8457.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  8458.                 {
  8459.                     if (damage > attacked.AzureShieldDefence)
  8460.                     {
  8461.                         damage -= attacked.AzureShieldDefence;
  8462.                         CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  8463.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  8464.                         attacked.AzuredShield = true;
  8465.                     }
  8466.                     else
  8467.                     {
  8468.                         CreateAzureDmg((uint)damage, attacker, attacked);
  8469.                         attacked.AzureShieldDefence -= (ushort)damage;
  8470.                         attacked.AzureShieldPacket();
  8471.                         damage = 1;
  8472.                     }
  8473.                 }
  8474.                 if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  8475.                 {
  8476.  
  8477.                     if (damage > attacked.IronShieldDefence)
  8478.                     {
  8479.                         damage -= (int)attacked.IronShieldDefence;
  8480.                         CreateAzureDmg(attacked.IronShieldDefence, attacker, attacked);
  8481.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  8482.                     }
  8483.                     else
  8484.                     {
  8485.                         CreateAzureDmg((uint)damage, attacker, attacked);
  8486.                         attacked.IronShieldDefence -= (uint)damage;
  8487.                         attacked.IronShieldPacket();
  8488.                         damage = 1;
  8489.                     }
  8490.                 }
  8491.                 #endregion
  8492.                 if (damage < 0)
  8493.                     damage = 1;
  8494.                 return Math.Max((uint)1, (uint)damage);
  8495.             }
  8496.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.ShurikenVortex)) return 1;
  8497.             if (attacker.Transformed) return 0;
  8498.             if (attacker == null) return 0;
  8499.             if (attacked == null) return 0;
  8500.             #region Effect
  8501.             if (attacker.PlayerFlag == PlayerFlag.Player)
  8502.             {
  8503.                 if (Kernel.Rate(50))
  8504.                 {
  8505.                     GemEffect.Process(attacker);
  8506.                 }
  8507.             }
  8508.             #endregion
  8509.             Durability(attacker, attacked, null);
  8510.             if (attacker.Transformed) return 0;
  8511.             double attacke = attacker.MinAttack + Kernel.Random.Next((int)attacker.MaxAttack - (int)attacker.MinAttack);
  8512.             #region Breakthrough
  8513.             if (attacker.PlayerFlag == PlayerFlag.Player)
  8514.             {
  8515.                 if (attacker.BattlePower < attacked.BattlePower)
  8516.                 {
  8517.                     if (Kernel.ChanceSuccess(attacker.Breaktrough / 10f - attacked.Counteraction / 10f))
  8518.                     {
  8519.                         attacke = attacker.MaxAttack;
  8520.                         Packet.Effect |= MsgInteract.InteractEffects.Penetration;
  8521.                     }
  8522.                 }
  8523.             }
  8524.             #endregion
  8525.             #region Spell Bounes
  8526.             if (spell != null)
  8527.             {
  8528.                 if (spell.PowerPercent != 0)
  8529.                 {
  8530.                     attacke = (long)(attacke * spell.PowerPercent);
  8531.                 }
  8532.             }
  8533.             #endregion
  8534.             if (attacker.PlayerFlag == PlayerFlag.Player)
  8535.             {
  8536.                 var bonus = attacker.Gems[1];
  8537.                 if (bonus > 0)
  8538.                 {
  8539.                     attacke += MathHelper.MulDiv((int)attacke, bonus, 100);
  8540.                 }
  8541.             }
  8542.             if (attacker.ContainsFlag((ulong)MsgUpdate.Flags.Stigma))
  8543.                 if (!attacker.Transformed)
  8544.                     attacke = (long)(attacke * 1.1);
  8545.             double defensee = attacked.Defence;
  8546.             double damagee = attacke - defensee;
  8547.          
  8548.             var targetLevell = attacked.Level;
  8549.             if (targetLevell < 22) damagee = MathHelper.MulDiv((int)damagee, 35, 100);
  8550.             else if (targetLevell < 50) damagee = MathHelper.MulDiv((int)damagee, 25, 100);
  8551.             else if (targetLevell < 90) damagee = MathHelper.MulDiv((int)damagee, 20, 100);
  8552.             else if (targetLevell < 110) damagee = MathHelper.MulDiv((int)damagee, 15, 100);
  8553.             else damagee = MathHelper.MulDiv((int)damagee, 12, 100);
  8554.             int strikee = Math.Max(110, 120);
  8555.             if (attacker.CriticalStrike > 0u)
  8556.             {
  8557.                 if (Base.GetRefinery((uint)attacker.CriticalStrike / 100, (uint)attacked.Immunity / 100))
  8558.                 {
  8559.                     Packet.Effect |= MsgInteract.InteractEffects.CriticalStrike;
  8560.                     damagee = Base.MulDiv((int)damagee, strikee, 100);
  8561.                 }
  8562.             }
  8563.             if (attacked.PlayerFlag == PlayerFlag.Player)
  8564.             {
  8565.                 var reduce = Math.Max(0, Math.Min(100, (int)attacked.Gems[7]));
  8566.                 if (reduce > 0)
  8567.                 {
  8568.                     damagee -= (damagee / 2) * reduce / 10;
  8569.                 }
  8570.             }
  8571.             damagee = AdjustRebirthDamage(attacked.Owner, attacker.Owner, (int)damagee);
  8572.             if (attacked.PlayerFlag == PlayerFlag.Player)
  8573.             {
  8574.                 var reduce = Math.Max(0, Math.Min(100, (int)attacked.ItemBless));
  8575.                 if (reduce > 0)
  8576.                 {
  8577.                     damagee -= damagee * reduce / 100;
  8578.                 }
  8579.             }
  8580.             if (attacked.PlayerFlag == PlayerFlag.Monster)
  8581.                 damagee = damagee * 3;
  8582.             if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  8583.             {
  8584.                 damagee *= 2;
  8585.                 attacker.OnIntensify = false;
  8586.                 attacker.RemoveFlag((ulong)MsgUpdate.Flags.Intensify);
  8587.             }
  8588.             #region Block
  8589.             if (attacked.PlayerFlag == PlayerFlag.Player)
  8590.             {
  8591.                 if (Kernel.ChanceSuccess(attacked.Block / 100f))
  8592.                 {
  8593.                     Packet.Effect |= MsgInteract.InteractEffects.Block;
  8594.                     damagee = (int)Math.Floor((float)damagee / 2);
  8595.                 }
  8596.             }
  8597.             #endregion
  8598.             #region Reduction!
  8599.             if (attacked.IsDefensiveStance)
  8600.             {
  8601.                 if (attacked.FatigueSecs > 120)
  8602.                 {
  8603.                     damagee -= attacked.Defence + attacked.Defence * 0.40;
  8604.                 }
  8605.                 else
  8606.                 {
  8607.                     damagee -= attacked.Defence + attacked.Defence * 0.20;
  8608.                 }
  8609.             }
  8610.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.AzureShield))
  8611.             {
  8612.                 if (damagee > attacked.AzureShieldDefence)
  8613.                 {
  8614.                     damagee -= attacked.AzureShieldDefence;
  8615.                     CreateAzureDmg(attacked.AzureShieldDefence, attacker, attacked);
  8616.                     attacked.RemoveFlag((ulong)MsgUpdate.Flags.AzureShield);
  8617.                     attacked.AzuredShield = true;
  8618.                 }
  8619.                 else
  8620.                 {
  8621.                     CreateAzureDmg((uint)damagee, attacker, attacked);
  8622.                     attacked.AzureShieldDefence -= (ushort)damagee;
  8623.                     attacked.AzureShieldPacket();
  8624.                     damagee = 1;
  8625.                 }
  8626.             }
  8627.             if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.IronShield))
  8628.             {
  8629.  
  8630.                 if (damagee > attacked.IronShieldDefence)
  8631.                 {
  8632.                     damagee -= (int)attacked.IronShieldDefence;
  8633.                     CreateAzureDmg(attacked.IronShieldDefence, attacker, attacked);
  8634.                     attacked.RemoveFlag((ulong)MsgUpdate.Flags.IronShield);
  8635.                 }
  8636.                 else
  8637.                 {
  8638.                     CreateAzureDmg((uint)damagee, attacker, attacked);
  8639.                     attacked.IronShieldDefence -= (uint)damagee;
  8640.                     attacked.IronShieldPacket();
  8641.                     damagee = 1;
  8642.                 }
  8643.             }
  8644.             #endregion
  8645.             if (damagee < 0)
  8646.                 damagee = 1;
  8647.             return Math.Max(1, (uint)damagee);
  8648.         }
  8649.  
  8650.         public static bool Miss(int Percent)
  8651.         {
  8652.             if (Percent >= 100)
  8653.                 return false;
  8654.             return Kernel.Rate(Percent, 100);
  8655.         }
  8656.         public static uint Percent(int target, float percent)
  8657.         {
  8658.             return (uint)(target * percent);
  8659.         }
  8660.         public static uint Percent(Player attacked, float percent)
  8661.         {
  8662.             return (uint)(attacked.Hitpoints * percent);
  8663.         }
  8664.         public static uint Percent(MsgNpcInfoEX attacked, float percent)
  8665.         {
  8666.             return (uint)(attacked.Hitpoints * percent);
  8667.         }
  8668.  
  8669.  
  8670.         public static void AutoRespone(Player attacker, Player attacked, ref double Damage)//1
  8671.         {
  8672.             try
  8673.             {
  8674.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8675.                 {
  8676.                     if (attacker.Owner.Spells.ContainsKey(11120))
  8677.                     {
  8678.                         var s = attacker.Owner.Spells[11120];
  8679.                         var spell = Database.SpellTable.SpellInformations[s.ID][s.Level];
  8680.                         if (spell != null)
  8681.                         {
  8682.                             if (Kernel.Rate(spell.Percent))
  8683.                             {
  8684.                                 var ent = attacked as Player;
  8685.                                 if (!ent.IsBlackSpotted)
  8686.                                 {
  8687.                                     ent.IsBlackSpotted = true;
  8688.                                     ent.BlackSpotStamp = Time32.Now;
  8689.                                     ent.BlackSpotStepSecs = spell.Duration;
  8690.                                     Kernel.BlackSpoted.TryAdd(ent.UID, ent);
  8691.                                     BlackSpotPacket bsp = new BlackSpotPacket();
  8692.                                     foreach (var h in Server.Values)
  8693.                                     {
  8694.                                         h.Send(bsp.ToArray(true, ent.UID));
  8695.                                     }
  8696.                                 }
  8697.                             }
  8698.                         }
  8699.                     }
  8700.                 }
  8701.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8702.                 {
  8703.                     if (attacked.Owner.Spells.ContainsKey(11130) && attacked.Owner.Player.IsEagleEyeShooted)
  8704.                     {
  8705.                         var s = attacked.Owner.Spells[11130];
  8706.                         var spell = Database.SpellTable.SpellInformations[s.ID][s.Level];
  8707.                         if (spell != null)
  8708.                         {
  8709.                             if (Kernel.Rate(spell.Percent))
  8710.                             {
  8711.                                 attacked.Owner.Player.IsEagleEyeShooted = false;
  8712.                                 MsgMagicEffect ssuse = new MsgMagicEffect(true);
  8713.                                 ssuse.Attacker = attacked.UID;
  8714.                                 ssuse.SpellID = spell.ID;
  8715.                                 ssuse.SpellLevel = spell.Level;
  8716.                                 ssuse.AddTarget(attacked.Owner.Player.UID, new MsgMagicEffect.DamageClass().Damage = 11030,
  8717.                                                                  null);
  8718.                                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8719.                                 {
  8720.                                     attacked.Owner.SendScreen(ssuse, true);
  8721.                                 }
  8722.                             }
  8723.                         }
  8724.                     }
  8725.                     if (attacked.CounterKillSwitch && Kernel.Rate(30) && !attacker.ContainsFlag((ulong)MsgUpdate.Flags.Fly) && Time32.Now > attacked.CounterKillStamp.AddSeconds(15))
  8726.                     {
  8727.                  
  8728.                         var spell = Database.SpellTable.GetSpell(6003, attacker.Owner);
  8729.                         attacked.CounterKillStamp = Time32.Now;
  8730.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  8731.                         attack.Effect = MsgInteract.InteractEffects.None;
  8732.                         if (attacked.PlayerFlag == PlayerFlag.Player)
  8733.                         {
  8734.                             uint damage = NewWork(attacked, attacker, ref attack);
  8735.                             //Physical.OnPlayer(attacked, attacker, spell, out SpellObj, ref attack);
  8736.                             attack.Attacked = attacker.UID;
  8737.                             attack.Attacker = attacked.UID;
  8738.                             attack.InteractType = Network.GamePackets.MsgInteract.Scapegoat;
  8739.                             attack.Damage = 0;
  8740.                             attack.ResponseDamage = damage;
  8741.                             attack.X = attacked.X;
  8742.                             attack.Y = attacked.Y;
  8743.                             if (attacker.Hitpoints <= damage)
  8744.                             {
  8745.                                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8746.                                 {
  8747.                                     attacked.Owner.UpdateQualifier(damage);
  8748.                                     attacker.Owner.SendScreen(attack, true);
  8749.                                     attacked.AttackPacket = null;
  8750.                                 }
  8751.                                 else
  8752.                                 {
  8753.                                     attacker.MonsterInfo.SendScreen(attack);
  8754.                                 }
  8755.                                 attacker.Die(attacked);
  8756.                             }
  8757.                             else
  8758.                             {
  8759.                                 attacker.Hitpoints -= damage;
  8760.                                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8761.                                 {
  8762.                                     attacked.Owner.UpdateQualifier(attacker.Hitpoints);
  8763.                                     attacker.Owner.SendScreen(attack, true);
  8764.                                 }
  8765.                                 else
  8766.                                 {
  8767.                                     attacker.MonsterInfo.SendScreen(attack);
  8768.                                 }
  8769.                             }
  8770.                         }
  8771.                         else
  8772.                         {
  8773.                             uint damage = NewWork(attacked, attacker, ref attack);
  8774.                             //damage = damage * spell.IncreaseDMG;
  8775.                             //damage = damage / spell.DecreaseDMG;
  8776.                             attack.Attacked = attacker.UID;
  8777.                             attack.Attacker = attacked.UID;
  8778.                             attack.InteractType = Network.GamePackets.MsgInteract.Scapegoat;
  8779.                             attack.Damage = 0;
  8780.                             attack.ResponseDamage = damage;
  8781.                             attack.X = attacked.X;
  8782.                             attack.Y = attacked.Y;
  8783.  
  8784.                             if (attacker.Hitpoints <= damage)
  8785.                             {
  8786.                                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8787.                                 {
  8788.                                     attacked.Owner.UpdateQualifier(damage);
  8789.                                     attacker.Owner.SendScreen(attack, true);
  8790.                                     attacked.AttackPacket = null;
  8791.                                 }
  8792.                                 else
  8793.                                 {
  8794.                                     attacker.MonsterInfo.SendScreen(attack);
  8795.                                 }
  8796.                                 attacker.Die(attacked);
  8797.                             }
  8798.                             else
  8799.                             {
  8800.                                 attacker.Hitpoints -= damage;
  8801.                                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8802.                                 {
  8803.                                     attacked.Owner.UpdateQualifier(attacker.Hitpoints);
  8804.                                     attacker.Owner.SendScreen(attack, true);
  8805.                                 }
  8806.                                 else
  8807.                                 {
  8808.                                     attacker.MonsterInfo.SendScreen(attack);
  8809.                                 }
  8810.                             }
  8811.                         }
  8812.                         Damage = 0;
  8813.                     }
  8814.  
  8815.                     else if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.BackFire) && Kernel.Rate(30))
  8816.                     {
  8817.                         var spell = Database.SpellTable.GetSpell(12680, attacker.Owner);
  8818.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  8819.                         uint damage = NewWork(attacked, attacker, ref attack);
  8820.                         //damage = damage * spell.IncreaseDMG;
  8821.                         //damage = damage / spell.DecreaseDMG;
  8822.  
  8823.  
  8824.                         attack.Attacked = attacker.UID;
  8825.                         attack.Attacker = attacked.UID;
  8826.                         attack.InteractType = MsgInteract.BackFire;
  8827.                         attack.Damage = damage;
  8828.                         attack.ResponseDamage = damage;
  8829.                         attack.X = attacked.X;
  8830.                         attack.Y = attacked.Y;
  8831.  
  8832.                         if (attacker.Hitpoints <= damage)
  8833.                         {
  8834.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  8835.                             {
  8836.                                 attacked.Owner.UpdateQualifier(damage);
  8837.                                 attacker.Owner.SendScreen(attack, true);
  8838.                                 attacked.AttackPacket = null;
  8839.                             }
  8840.                             else
  8841.                             {
  8842.                                 attacker.MonsterInfo.SendScreen(attack);
  8843.                             }
  8844.                             attacker.Die(attacked);
  8845.                         }
  8846.                         else
  8847.                         {
  8848.                             attacker.Hitpoints -= damage;
  8849.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  8850.                             {
  8851.                                 attacked.Owner.UpdateQualifier(damage);
  8852.                                 attacker.Owner.SendScreen(attack, true);
  8853.                             }
  8854.                             else
  8855.                             {
  8856.                                 attacker.MonsterInfo.SendScreen(attack);
  8857.                             }
  8858.                         }
  8859.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.BackFire);
  8860.                         Damage = 0;
  8861.                     }
  8862.                     else if (attacked.Owner.Spells.ContainsKey(3060) && Kernel.Rate(30))
  8863.                     {
  8864.                         uint damage = (uint)(Damage / 2);
  8865.                         if (damage <= 0)
  8866.                             damage = 1;
  8867.                         if (damage > 10000) damage = 10000;
  8868.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  8869.                         attack.Attacked = attacker.UID;
  8870.                         attack.Attacker = attacked.UID;
  8871.                         attack.InteractType = Network.GamePackets.MsgInteract.Reflect;
  8872.                         attack.Damage = damage;
  8873.                         attack.ResponseDamage = damage;
  8874.                         attack.X = attacked.X;
  8875.                         attack.Y = attacked.Y;
  8876.  
  8877.                         if (attacker.Hitpoints <= damage)
  8878.                         {
  8879.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  8880.                             {
  8881.                                 attacked.Owner.UpdateQualifier(damage);
  8882.                                 attacker.Owner.SendScreen(attack, true);
  8883.                                 attacked.AttackPacket = null;
  8884.                             }
  8885.                             else
  8886.                             {
  8887.                                 attacker.MonsterInfo.SendScreen(attack);
  8888.                             }
  8889.                             attacker.Die(attacked);
  8890.                         }
  8891.                         else
  8892.                         {
  8893.                             attacker.Hitpoints -= damage;
  8894.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  8895.                             {
  8896.                                 attacked.Owner.UpdateQualifier(damage);
  8897.                                 attacker.Owner.SendScreen(attack, true);
  8898.                             }
  8899.                             else
  8900.                             {
  8901.                                 attacker.MonsterInfo.SendScreen(attack);
  8902.                             }
  8903.                         }
  8904.                         Damage = 0;
  8905.                     }
  8906.                 }
  8907.             }
  8908.             catch (Exception e) { Server.SaveException(e); }
  8909.         }
  8910.         public static void AutoRespone(Player attacker, Player attacked, ref long Damage)//2
  8911.         {
  8912.             try
  8913.             {
  8914.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  8915.                 {
  8916.                     if (attacker.Owner.Spells.ContainsKey(11120))
  8917.                     {
  8918.                         var s = attacker.Owner.Spells[11120];
  8919.                         var spell = Database.SpellTable.SpellInformations[s.ID][s.Level];
  8920.                         if (spell != null)
  8921.                         {
  8922.                             if (Kernel.Rate(spell.Percent))
  8923.                             {
  8924.                                 var ent = attacked as Player;
  8925.                                 if (!ent.IsBlackSpotted)
  8926.                                 {
  8927.                                     ent.IsBlackSpotted = true;
  8928.                                     ent.BlackSpotStamp = Time32.Now;
  8929.                                     ent.BlackSpotStepSecs = spell.Duration;
  8930.                                     Kernel.BlackSpoted.TryAdd(ent.UID, ent);
  8931.                                     BlackSpotPacket bsp = new BlackSpotPacket();
  8932.                                     foreach (var h in Server.Values)
  8933.                                     {
  8934.                                         h.Send(bsp.ToArray(true, ent.UID));
  8935.                                     }
  8936.                                 }
  8937.                             }
  8938.                         }
  8939.                     }
  8940.                 }
  8941.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8942.                 {
  8943.                     if (attacked.Owner.Spells.ContainsKey(11130) && attacked.Owner.Player.IsEagleEyeShooted)
  8944.                     {
  8945.                         var s = attacked.Owner.Spells[11130];
  8946.                         var spell = Database.SpellTable.SpellInformations[s.ID][s.Level];
  8947.                         if (spell != null)
  8948.                         {
  8949.                             if (Kernel.Rate(spell.Percent))
  8950.                             {
  8951.                                 attacked.Owner.Player.IsEagleEyeShooted = false;
  8952.                                 MsgMagicEffect ssuse = new MsgMagicEffect(true);
  8953.                                 ssuse.Attacker = attacked.UID;
  8954.                                 ssuse.SpellID = spell.ID;
  8955.                                 ssuse.SpellLevel = spell.Level;
  8956.                                 ssuse.AddTarget(attacked.Owner.Player.UID, new MsgMagicEffect.DamageClass().Damage = 11030,
  8957.                                                                  null);
  8958.                                 if (attacked.PlayerFlag == PlayerFlag.Player)
  8959.                                 {
  8960.                                     attacked.Owner.SendScreen(ssuse, true);
  8961.                                 }
  8962.                             }
  8963.                         }
  8964.                     }
  8965.                     if (attacked.CounterKillSwitch && Kernel.Rate(30) && !attacker.ContainsFlag((ulong)MsgUpdate.Flags.Fly) && Time32.Now > attacked.CounterKillStamp.AddSeconds(15))
  8966.                     {
  8967.                         var spell = Database.SpellTable.GetSpell(6003, attacker.Owner);
  8968.                         attacked.CounterKillStamp = Time32.Now;
  8969.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  8970.                         attack.Effect = MsgInteract.InteractEffects.None;
  8971.                         uint damage = NewWork(attacked, attacker, ref attack);
  8972.                         //damage = damage * spell.IncreaseDMG;
  8973.                         //damage = damage / spell.DecreaseDMG;
  8974.                         attack.Attacked = attacker.UID;
  8975.                         attack.Attacker = attacked.UID;
  8976.                         attack.InteractType = Network.GamePackets.MsgInteract.Scapegoat;
  8977.                         attack.Damage = 0;
  8978.                         attack.ResponseDamage = damage;
  8979.                         attack.X = attacked.X;
  8980.                         attack.Y = attacked.Y;
  8981.  
  8982.                         if (attacker.Hitpoints <= damage)
  8983.                         {
  8984.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  8985.                             {
  8986.                                 attacked.Owner.UpdateQualifier(damage);
  8987.                                 attacker.Owner.SendScreen(attack, true);
  8988.                                 attacked.AttackPacket = null;
  8989.                             }
  8990.                             else
  8991.                             {
  8992.                                 attacker.MonsterInfo.SendScreen(attack);
  8993.                             }
  8994.                             attacker.Die(attacked);
  8995.                         }
  8996.                         else
  8997.                         {
  8998.                             attacker.Hitpoints -= damage;
  8999.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9000.                             {
  9001.                                 attacked.Owner.UpdateQualifier(attacker.Hitpoints);
  9002.                                 attacker.Owner.SendScreen(attack, true);
  9003.                             }
  9004.                             else
  9005.                             {
  9006.                                 attacker.MonsterInfo.SendScreen(attack);
  9007.                             }
  9008.                         }
  9009.                         Damage = 0;
  9010.                     }
  9011.  
  9012.                     else if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.BackFire) && Kernel.Rate(30))
  9013.                     {
  9014.                         var spell = Database.SpellTable.GetSpell(12680, attacker.Owner);
  9015.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  9016.                         uint damage = Melee(attacked, attacker, ref attack);
  9017.                         //damage = damage * spell.IncreaseDMG;
  9018.                         //damage = damage / spell.DecreaseDMG;
  9019.  
  9020.  
  9021.                         attack.Attacked = attacker.UID;
  9022.                         attack.Attacker = attacked.UID;
  9023.                         attack.InteractType = MsgInteract.BackFire;
  9024.                         attack.Damage = damage;
  9025.                         attack.ResponseDamage = damage;
  9026.                         attack.X = attacked.X;
  9027.                         attack.Y = attacked.Y;
  9028.  
  9029.                         if (attacker.Hitpoints <= damage)
  9030.                         {
  9031.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9032.                             {
  9033.                                 attacked.Owner.UpdateQualifier(damage);
  9034.                                 attacker.Owner.SendScreen(attack, true);
  9035.                                 attacked.AttackPacket = null;
  9036.                             }
  9037.                             else
  9038.                             {
  9039.                                 attacker.MonsterInfo.SendScreen(attack);
  9040.                             }
  9041.                             attacker.Die(attacked);
  9042.                         }
  9043.                         else
  9044.                         {
  9045.                             attacker.Hitpoints -= damage;
  9046.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9047.                             {
  9048.                                 attacked.Owner.UpdateQualifier(damage);
  9049.                                 attacker.Owner.SendScreen(attack, true);
  9050.                             }
  9051.                             else
  9052.                             {
  9053.                                 attacker.MonsterInfo.SendScreen(attack);
  9054.                             }
  9055.                         }
  9056.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.BackFire);
  9057.                         Damage = 0;
  9058.                     }
  9059.                     else if (attacked.Owner.Spells.ContainsKey(3060) && Kernel.Rate(30))
  9060.                     {
  9061.                         uint damage = (uint)(Damage / 2);
  9062.                         if (damage <= 0)
  9063.                             damage = 1;
  9064.                         if (damage > 10000) damage = 10000;
  9065.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  9066.                         attack.Attacked = attacker.UID;
  9067.                         attack.Attacker = attacked.UID;
  9068.                         attack.InteractType = Network.GamePackets.MsgInteract.Reflect;
  9069.                         attack.Damage = damage;
  9070.                         attack.ResponseDamage = damage;
  9071.                         attack.X = attacked.X;
  9072.                         attack.Y = attacked.Y;
  9073.  
  9074.                         if (attacker.Hitpoints <= damage)
  9075.                         {
  9076.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9077.                             {
  9078.                                 attacked.Owner.UpdateQualifier(damage);
  9079.                                 attacker.Owner.SendScreen(attack, true);
  9080.                                 attacked.AttackPacket = null;
  9081.                             }
  9082.                             else
  9083.                             {
  9084.                                 attacker.MonsterInfo.SendScreen(attack);
  9085.                             }
  9086.                             attacker.Die(attacked);
  9087.                         }
  9088.                         else
  9089.                         {
  9090.                             attacker.Hitpoints -= damage;
  9091.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9092.                             {
  9093.                                 attacked.Owner.UpdateQualifier(damage);
  9094.                                 attacker.Owner.SendScreen(attack, true);
  9095.                             }
  9096.                             else
  9097.                             {
  9098.                                 attacker.MonsterInfo.SendScreen(attack);
  9099.                             }
  9100.                         }
  9101.                         Damage = 0;
  9102.                     }
  9103.                 }
  9104.             }
  9105.             catch (Exception e) { Server.SaveException(e); }
  9106.         }
  9107.         public static void AutoRespone(Player attacker, Player attacked, ref int Damage)//0
  9108.         {
  9109.             try
  9110.             {
  9111.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  9112.                 {
  9113.                     if (attacker.Owner.Spells.ContainsKey(11120))
  9114.                     {
  9115.                         var s = attacker.Owner.Spells[11120];
  9116.                         var spell = Database.SpellTable.SpellInformations[s.ID][s.Level];
  9117.                         if (spell != null)
  9118.                         {
  9119.                             if (Kernel.Rate(spell.Percent))
  9120.                             {
  9121.                                 var ent = attacked as Player;
  9122.                                 if (!ent.IsBlackSpotted)
  9123.                                 {
  9124.                                     ent.IsBlackSpotted = true;
  9125.                                     ent.BlackSpotStamp = Time32.Now;
  9126.                                     ent.BlackSpotStepSecs = spell.Duration;
  9127.                                     Kernel.BlackSpoted.TryAdd(ent.UID, ent);
  9128.                                     BlackSpotPacket bsp = new BlackSpotPacket();
  9129.                                     foreach (var h in Server.Values)
  9130.                                     {
  9131.                                         h.Send(bsp.ToArray(true, ent.UID));
  9132.                                     }
  9133.                                 }
  9134.                             }
  9135.                         }
  9136.                     }
  9137.                 }
  9138.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  9139.                 {
  9140.                     if (attacked.Owner.Spells.ContainsKey(11130) && attacked.Owner.Player.IsEagleEyeShooted)
  9141.                     {
  9142.                         var s = attacked.Owner.Spells[11130];
  9143.                         var spell = Database.SpellTable.SpellInformations[s.ID][s.Level];
  9144.                         if (spell != null)
  9145.                         {
  9146.                             if (Kernel.Rate(spell.Percent))
  9147.                             {
  9148.                                 attacked.Owner.Player.IsEagleEyeShooted = false;
  9149.                                 MsgMagicEffect ssuse = new MsgMagicEffect(true);
  9150.                                 ssuse.Attacker = attacked.UID;
  9151.                                 ssuse.SpellID = spell.ID;
  9152.                                 ssuse.SpellLevel = spell.Level;
  9153.                                 ssuse.AddTarget(attacked.Owner.Player.UID, new MsgMagicEffect.DamageClass().Damage = 11030,
  9154.                                                                  null);
  9155.                                 if (attacked.PlayerFlag == PlayerFlag.Player)
  9156.                                 {
  9157.                                     attacked.Owner.SendScreen(ssuse, true);
  9158.                                 }
  9159.                             }
  9160.                         }
  9161.                     }
  9162.                     if (attacked.CounterKillSwitch && Kernel.Rate(30) && !attacker.ContainsFlag((ulong)MsgUpdate.Flags.Fly) && Time32.Now > attacked.CounterKillStamp.AddSeconds(15))
  9163.                     {
  9164.                         var spell = Database.SpellTable.GetSpell(6003, attacker.Owner);
  9165.                         attacked.CounterKillStamp = Time32.Now;
  9166.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  9167.                         attack.Effect = MsgInteract.InteractEffects.None;
  9168.                         uint damage = NewWork(attacked, attacker, ref attack);
  9169.                         //damage = damage * spell.IncreaseDMG;
  9170.                         //damage = damage / spell.DecreaseDMG;
  9171.                         attack.Attacked = attacker.UID;
  9172.                         attack.Attacker = attacked.UID;
  9173.                         attack.InteractType = Network.GamePackets.MsgInteract.Scapegoat;
  9174.                         attack.Damage = 0;
  9175.                         attack.ResponseDamage = damage;
  9176.                         attack.X = attacked.X;
  9177.                         attack.Y = attacked.Y;
  9178.  
  9179.                         if (attacker.Hitpoints <= damage)
  9180.                         {
  9181.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9182.                             {
  9183.                                 attacked.Owner.UpdateQualifier(damage);
  9184.                                 attacker.Owner.SendScreen(attack, true);
  9185.                                 attacked.AttackPacket = null;
  9186.                             }
  9187.                             else
  9188.                             {
  9189.                                 attacker.MonsterInfo.SendScreen(attack);
  9190.                             }
  9191.                             attacker.Die(attacked);
  9192.                         }
  9193.                         else
  9194.                         {
  9195.                             attacker.Hitpoints -= damage;
  9196.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9197.                             {
  9198.                                 attacked.Owner.UpdateQualifier(attacker.Hitpoints);
  9199.                                 attacker.Owner.SendScreen(attack, true);
  9200.                             }
  9201.                             else
  9202.                             {
  9203.                                 attacker.MonsterInfo.SendScreen(attack);
  9204.                             }
  9205.                         }
  9206.                         Damage = 0;
  9207.                     }
  9208.  
  9209.                     else if (attacked.ContainsFlag((ulong)MsgUpdate.Flags.BackFire) && Kernel.Rate(30))
  9210.                     {
  9211.                         var spell = Database.SpellTable.GetSpell(12680, attacker.Owner);
  9212.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  9213.                         uint damage = Melee(attacked, attacker, ref attack);
  9214.                         //damage = damage * spell.IncreaseDMG;
  9215.                         //damage = damage / spell.DecreaseDMG;
  9216.  
  9217.                         attack.Attacked = attacker.UID;
  9218.                         attack.Attacker = attacked.UID;
  9219.                         attack.InteractType = MsgInteract.BackFire;
  9220.                         attack.Damage = damage;
  9221.                         attack.ResponseDamage = damage;
  9222.                         attack.X = attacked.X;
  9223.                         attack.Y = attacked.Y;
  9224.  
  9225.                         if (attacker.Hitpoints <= damage)
  9226.                         {
  9227.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9228.                             {
  9229.                                 attacked.Owner.UpdateQualifier(damage);
  9230.                                 attacker.Owner.SendScreen(attack, true);
  9231.                                 attacked.AttackPacket = null;
  9232.                             }
  9233.                             else
  9234.                             {
  9235.                                 attacker.MonsterInfo.SendScreen(attack);
  9236.                             }
  9237.                             attacker.Die(attacked);
  9238.                         }
  9239.                         else
  9240.                         {
  9241.                             attacker.Hitpoints -= damage;
  9242.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9243.                             {
  9244.                                 attacked.Owner.UpdateQualifier(damage);
  9245.                                 attacker.Owner.SendScreen(attack, true);
  9246.                             }
  9247.                             else
  9248.                             {
  9249.                                 attacker.MonsterInfo.SendScreen(attack);
  9250.                             }
  9251.                         }
  9252.                         attacked.RemoveFlag((ulong)MsgUpdate.Flags.BackFire);
  9253.                         Damage = 0;
  9254.                     }
  9255.  
  9256.  
  9257.                     else if (attacked.Owner.Spells.ContainsKey(14470))
  9258.                     {
  9259.                         var spell = Database.SpellTable.GetSpell(14470, attacker.Owner);
  9260.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  9261.                         uint damage = Melee(attacked, attacker, ref attack);
  9262.                         RunesSystem.HandleRedBlueRunesSkills(attack, attacked, attacker, spell, attacked.X, attacked.Y, damage);
  9263.  
  9264.                     }
  9265.                     else if (attacked.Owner.Spells.ContainsKey(3060) && Kernel.Rate(30))
  9266.                     {
  9267.                         uint damage = (uint)(Damage);
  9268.                         if (damage <= 0)
  9269.                             damage = 0;
  9270.                         if (damage > 0) damage = 0;
  9271.                         Network.GamePackets.MsgInteract attack = new COServer.Network.GamePackets.MsgInteract(true);
  9272.                         attack.Attacked = attacker.UID;
  9273.                         attack.Attacker = attacked.UID;
  9274.                         attack.InteractType = Network.GamePackets.MsgInteract.Reflect;
  9275.                         attack.Damage = damage;
  9276.                         attack.ResponseDamage = damage;
  9277.                         attack.X = attacked.X;
  9278.                         attack.Y = attacked.Y;
  9279.  
  9280.                         if (attacker.Hitpoints <= damage)
  9281.                         {
  9282.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9283.                             {
  9284.                                 attacked.Owner.UpdateQualifier(damage);
  9285.                                 attacker.Owner.SendScreen(attack, true);
  9286.                                 attacked.AttackPacket = null;
  9287.                             }
  9288.                             else
  9289.                             {
  9290.                                 attacker.MonsterInfo.SendScreen(attack);
  9291.                             }
  9292.                             attacker.Die(attacked);
  9293.                         }
  9294.                         else
  9295.                         {
  9296.                             attacker.Hitpoints -= damage;
  9297.                             if (attacker.PlayerFlag == PlayerFlag.Player)
  9298.                             {
  9299.                                 attacked.Owner.UpdateQualifier(damage);
  9300.                                 attacker.Owner.SendScreen(attack, true);
  9301.                             }
  9302.                             else
  9303.                             {
  9304.                                 attacker.MonsterInfo.SendScreen(attack);
  9305.                             }
  9306.                         }
  9307.                         Damage = 0;
  9308.                     }
  9309.                 }
  9310.             }
  9311.             catch (Exception e) { Server.SaveException(e); }
  9312.         }
  9313.         public static int GetLevelBonus(int l1, int l2)
  9314.         {
  9315.             int num = l1 - l2;
  9316.             int bonus = 0;
  9317.             if (num >= 3)
  9318.             {
  9319.                 num -= 3;
  9320.                 bonus = 1 + (num / 5);
  9321.             }
  9322.             return bonus;
  9323.         }
  9324.         private static double AttackMultiplier(Player attacker, Player attacked)
  9325.         {
  9326.             if (attacked.Level > attacker.Level)
  9327.                 return 1;
  9328.             return ((double)(attacker.Level - attacked.Level)) / 10 + 1;
  9329.         }
  9330.         public static void CreateAzureDmg(uint dmg, Player attacker, Player attacked)
  9331.         {
  9332.             MsgInteract Interact = new MsgInteract(true);
  9333.             Interact.Attacker = attacker.UID;
  9334.             Interact.Attacked = attacked.UID;
  9335.             Interact.X = attacked.X;
  9336.             Interact.Y = attacked.Y;
  9337.             Interact.InteractType = MsgInteract.BlueDamage;
  9338.             Interact.Damage = dmg;
  9339.             attacked.Owner.SendScreen(Interact, true);
  9340.         }
  9341.         public static ulong CalculateExpBonus(ushort Level, ushort MonsterLevel, ulong Experience)
  9342.         {
  9343.             int leveldiff = (2 + Level - MonsterLevel);
  9344.             if (leveldiff < -5)
  9345.                 Experience = (ulong)(Experience * 1.3);
  9346.             else if (leveldiff < -1)
  9347.                 Experience = (ulong)(Experience * 1.2);
  9348.             else if (leveldiff == 4)
  9349.                 Experience = (ulong)(Experience * 0.8);
  9350.             else if (leveldiff == 5)
  9351.                 Experience = (ulong)(Experience * 0.3);
  9352.             else if (leveldiff > 5)
  9353.                 Experience = (ulong)(Experience * 0.1);
  9354.             return Experience;
  9355.         }
  9356.         private static void Durability(Player attacker, Player attacked, Database.SpellInformation spell)
  9357.         {
  9358.             if (spell != null)
  9359.                 if (!spell.CanKill) return;
  9360.             if (attacker.PlayerFlag == PlayerFlag.Player)
  9361.                 if (attacker.Owner.Map.ID == 1039) return;
  9362.             #region Attack
  9363.             if (attacker != null)
  9364.                 if (attacker.PlayerFlag == PlayerFlag.Player)
  9365.                 {
  9366.                     for (byte i = 4; i <= 6; i++)
  9367.                     {
  9368.                         if (!attacker.Owner.Equipment.Free(i))
  9369.                         {
  9370.                             var item = attacker.Owner.Equipment.TryGetItem(i);
  9371.                             if (i == 5)
  9372.                             {
  9373.                                 if (ItemHandler.IsArrow(item.ID))
  9374.                                 {
  9375.                                     continue;
  9376.                                 }
  9377.                             }
  9378.                             if (Kernel.Rate(20, 100))
  9379.                             {
  9380.                                 if (item.Durability != 0)
  9381.                                 {
  9382.                                     if (item.ID == 1050002) return;
  9383.                                     item.Durability--;
  9384.                                     Database.ConquerItemTable.UpdateDurabilityItem2(item, item.ID);
  9385.                                     Database.ConquerItemTable.UpdateDurabilityItem(item);
  9386.                                     item.Mode = Enums.ItemMode.Update;
  9387.                                     item.Send(attacker.Owner);
  9388.                                     item.Mode = Enums.ItemMode.Default;
  9389.                                 }
  9390.                                 else if (item.Durability == 0)
  9391.                                 {
  9392.                                     MsgName str = new MsgName(true)
  9393.                                     {
  9394.                                         UID = attacker.UID,
  9395.                                         Action = MsgName.Effect,
  9396.                                         TextsCount = 1
  9397.                                     };
  9398.                                     str.Texts.Add("EquipBroken");
  9399.                                     attacker.Owner.Send(str.ToArray());
  9400.                                     attacker.Owner.Send(new MsgTalk(Database.ConquerItemInformation.BaseInformations[item.ID].Name + " is totaly damaged!", System.Drawing.Color.Red, 2012));
  9401.                                 }
  9402.                             }
  9403.                         }
  9404.                         if (i == 6) break;
  9405.                     }
  9406.                     if (!attacker.Owner.Equipment.Free(10))
  9407.                     {
  9408.                         var item = attacker.Owner.Equipment.TryGetItem(10);
  9409.                         if (Kernel.Rate(20, 100))
  9410.                         {
  9411.                             if (item.Durability != 0)
  9412.                             {
  9413.                                 if (item.ID == 1050002) return;
  9414.                                 item.Durability--;
  9415.                                 if (item.Durability == 0)
  9416.                                     Database.ConquerItemTable.UpdateDurabilityItem2(item, item.ID);
  9417.                                 Database.ConquerItemTable.UpdateDurabilityItem(item);
  9418.                                 item.Mode = Enums.ItemMode.Update;
  9419.                                 item.Send(attacker.Owner);
  9420.                                 item.Mode = Enums.ItemMode.Default;
  9421.                             }
  9422.                             else if (item.Durability == 0)
  9423.                             {
  9424.                                 MsgName str = new MsgName(true)
  9425.                                 {
  9426.                                     UID = attacker.UID,
  9427.                                     Action = MsgName.Effect,
  9428.                                     TextsCount = 1
  9429.                                 };
  9430.                                 str.Texts.Add("EquipBroken");
  9431.                                 attacker.Owner.Send(str.ToArray());
  9432.                                 attacker.Owner.Send(new MsgTalk(Database.ConquerItemInformation.BaseInformations[item.ID].Name + " is totaly damaged!", System.Drawing.Color.Red, 2012));
  9433.                             }
  9434.                         }
  9435.                     }
  9436.                 }
  9437.             #endregion
  9438.             #region Defence
  9439.             if (attacked != null && !attacker.Name.Contains("Guard1"))
  9440.                 if (attacked.PlayerFlag == PlayerFlag.Player)
  9441.                 {
  9442.                     for (byte i = 1; i <= 8; i++)
  9443.                     {
  9444.                         if (i == 4 || i == 6 || i == 7) continue;
  9445.                         if (!attacked.Owner.Equipment.Free(i))
  9446.                         {
  9447.                             var item = attacked.Owner.Equipment.TryGetItem(i);
  9448.                             if (i == 5)
  9449.                             {
  9450.                                 if (ItemHandler.ItemPosition(item.ID) != 5 && ItemHandler.IsArrow(item.ID))
  9451.                                 {
  9452.                                     continue;
  9453.                                 }
  9454.                             }
  9455.                             if (Kernel.Rate(30, 100))
  9456.                             {
  9457.                                 if (item.Durability != 0)
  9458.                                 {
  9459.                                     item.Durability--;
  9460.                                     if (item.Durability == 0)
  9461.                                         Database.ConquerItemTable.UpdateDurabilityItem2(item, item.ID);
  9462.                                     Database.ConquerItemTable.UpdateDurabilityItem(item);
  9463.                                     item.Mode = Enums.ItemMode.Update;
  9464.                                     item.Send(attacked.Owner);
  9465.                                     item.Mode = Enums.ItemMode.Default;
  9466.                                 }
  9467.                                 else if (item.Durability == 0)
  9468.                                 {
  9469.                                     MsgName str = new MsgName(true)
  9470.                                     {
  9471.                                         UID = attacked.UID,
  9472.                                         Action = MsgName.Effect,
  9473.                                         TextsCount = 1
  9474.                                     };
  9475.                                     str.Texts.Add("EquipBroken");
  9476.                                     attacked.Owner.Send(str.ToArray());
  9477.                                     attacked.Owner.Send(new MsgTalk(Database.ConquerItemInformation.BaseInformations[item.ID].Name + " is totaly damaged!", System.Drawing.Color.Red, 2012));
  9478.                                 }
  9479.                             }
  9480.                         }
  9481.                         if (i == 8)
  9482.                             break;
  9483.                     }
  9484.                     if (!attacked.Owner.Equipment.Free(11) && Kernel.Rate(30, 100))
  9485.                     {
  9486.                         var item = attacked.Owner.Equipment.TryGetItem(11);
  9487.                         if (Kernel.Rate(30, 100))
  9488.                         {
  9489.                             if (item.Durability != 0)
  9490.                             {
  9491.                                 item.Durability--;
  9492.                                 if (item.Durability == 0)
  9493.                                     Database.ConquerItemTable.UpdateDurabilityItem2(item, item.ID);
  9494.                                 Database.ConquerItemTable.UpdateDurabilityItem(item);
  9495.                                 item.Mode = Enums.ItemMode.Update;
  9496.                                 item.Send(attacked.Owner);
  9497.                                 item.Mode = Enums.ItemMode.Default;
  9498.                             }
  9499.                             else if (item.Durability == 0)
  9500.                             {
  9501.                                 MsgName str = new MsgName(true)
  9502.                                 {
  9503.                                     UID = attacked.UID,
  9504.                                     Action = MsgName.Effect,
  9505.                                     TextsCount = 1
  9506.                                 };
  9507.                                 str.Texts.Add("EquipBroken");
  9508.                                 attacked.Owner.Send(str.ToArray());
  9509.                                 attacked.Owner.Send(new MsgTalk(Database.ConquerItemInformation.BaseInformations[item.ID].Name + " is totaly damaged!", System.Drawing.Color.Red, 2012));
  9510.                             }
  9511.                         }
  9512.                     }
  9513.                 }
  9514.             #endregion
  9515.         }
  9516.     }
  9517. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement