Advertisement
XConquer

Calculate - Familiar

Dec 1st, 2018
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 94.89 KB | None | 0 0
  1. using System;
  2. using Conquer_Online_Server.Network.GamePackets;
  3. using Conquer_Online_Server.Game;
  4. // Calculate Codificado Por Jose Carlos Pezzi, para mi queridito primito pezzi tomas
  5. namespace Conquer_Online_Server.Game.Attacking
  6. {
  7.     public class Calculate
  8.     {
  9.         public static Boolean ChanceSuccess(Double Chance, Double offset = 0)
  10.         {
  11.             Random Rand = new Random();
  12.             if (Chance <= 0) return false;
  13.             else if (Chance >= 100) return true;
  14.             return ((float)Rand.Next(1, 1000000) / 10000d >= (100d + offset) - Chance);
  15.         }
  16.  
  17.         public static uint Melee(Entity attacker, Entity attacked)
  18.         {
  19.             int Damage = 0;
  20.  
  21.             #region Nobility Damage
  22.             if ((byte)attacker.NobilityRank == 12 && (byte)attacked.NobilityRank == 12)
  23.             {
  24.                 Damage = (int)(Damage * 1.5);
  25.             }
  26.             else
  27.             {
  28.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  29.                 {
  30.                     Damage = (int)(Damage * 4 * attacker.PhysicalDamageIncrease);
  31.                 }
  32.             }
  33.             if ((byte)attacker.NobilityRank == 12 && (byte)attacked.NobilityRank == 9)
  34.             {
  35.                 Damage = (int)(Damage * 2);
  36.             }
  37.             else
  38.             {
  39.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  40.                 {
  41.                     Damage = (int)(Damage * 3.3 * attacker.PhysicalDamageIncrease);
  42.                 }
  43.             }
  44.             if ((byte)attacker.NobilityRank == 12 && (byte)attacked.NobilityRank == 7)
  45.             {
  46.                 Damage = (int)(Damage * 2.3);
  47.             }
  48.             else
  49.             {
  50.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  51.                 {
  52.                     Damage = (int)(Damage * 3.5 * attacker.PhysicalDamageIncrease);
  53.                 }
  54.             }
  55.             if ((byte)attacker.NobilityRank == 12 && (byte)attacked.NobilityRank <= 5)
  56.             {
  57.                 Damage = (int)(Damage * 3);
  58.             }
  59.             else
  60.             {
  61.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  62.                 {
  63.                     Damage = (int)(Damage * 3.8 * attacker.PhysicalDamageIncrease);
  64.                 }
  65.             }
  66.             if ((byte)attacker.NobilityRank == 9 && (byte)attacked.NobilityRank == 12)
  67.             {
  68.                 Damage = (int)(Damage * 1.2);
  69.             }
  70.             else
  71.             {
  72.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  73.                 {
  74.                     Damage = (int)(Damage * 2.5 * attacker.PhysicalDamageIncrease);
  75.                 }
  76.             }
  77.             if ((byte)attacker.NobilityRank == 9 && (byte)attacked.NobilityRank == 9)
  78.             {
  79.                 Damage = (int)(Damage * 2);
  80.             }
  81.             else
  82.             {
  83.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  84.                 {
  85.                     Damage = (int)(Damage * 2.5 * attacker.PhysicalDamageIncrease);
  86.                 }
  87.             }
  88.             if ((byte)attacker.NobilityRank == 9 && (byte)attacked.NobilityRank == 7)
  89.             {
  90.                 Damage = (int)(Damage * 2);
  91.             }
  92.             else
  93.             {
  94.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  95.                 {
  96.                     Damage = (int)(Damage * 3 * attacker.PhysicalDamageIncrease);
  97.                 }
  98.             }
  99.             if ((byte)attacker.NobilityRank == 9 && (byte)attacked.NobilityRank <= 5)
  100.             {
  101.                 Damage = (int)(Damage * 2.7);
  102.             }
  103.             else
  104.             {
  105.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  106.                 {
  107.                     Damage = (int)(Damage * 3.3 * attacker.PhysicalDamageIncrease);
  108.                 }
  109.             }
  110.             if ((byte)attacker.NobilityRank == 7 && (byte)attacked.NobilityRank == 12)
  111.             {
  112.                 Damage = (int)(Damage * 1.3);
  113.             }
  114.             else
  115.             {
  116.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  117.                 {
  118.                     Damage = (int)(Damage * 1.6 * attacker.PhysicalDamageIncrease);
  119.                 }
  120.             }
  121.             if ((byte)attacker.NobilityRank == 7 && (byte)attacked.NobilityRank == 9)
  122.             {
  123.                 Damage = (int)(Damage * 1.8);
  124.             }
  125.             else
  126.             {
  127.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  128.                 {
  129.                     Damage = (int)(Damage * 2 * attacker.PhysicalDamageIncrease);
  130.                 }
  131.             }
  132.             if ((byte)attacker.NobilityRank == 7 && (byte)attacked.NobilityRank == 7)
  133.             {
  134.                 Damage = (int)(Damage * 1.5);
  135.             }
  136.             else
  137.             {
  138.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  139.                 {
  140.                     Damage = (int)(Damage * 2 * attacker.PhysicalDamageIncrease);
  141.                 }
  142.             }
  143.             if ((byte)attacker.NobilityRank == 7 && (byte)attacked.NobilityRank <= 5)
  144.             {
  145.                 Damage = (int)(Damage * 2);
  146.             }
  147.             else
  148.             {
  149.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  150.                 {
  151.                     Damage = (int)(Damage * 2.5 * attacker.PhysicalDamageIncrease);
  152.                 }
  153.             }
  154.             if ((byte)attacker.NobilityRank <= 5 && (byte)attacked.NobilityRank == 12)
  155.             {
  156.                 Damage = (int)(Damage * 1.3);
  157.             }
  158.             else
  159.             {
  160.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  161.                 {
  162.                     Damage = (int)(Damage * 1.5 * attacker.PhysicalDamageIncrease);
  163.                 }
  164.             }
  165.             if ((byte)attacker.NobilityRank <= 5 && (byte)attacked.NobilityRank == 9)
  166.             {
  167.                 Damage = (int)(Damage * 1.5);
  168.             }
  169.             else
  170.             {
  171.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  172.                 {
  173.                     Damage = (int)(Damage * 1.7 * attacker.PhysicalDamageIncrease);
  174.                 }
  175.             }
  176.             if ((byte)attacker.NobilityRank <= 5 && (byte)attacked.NobilityRank == 7)
  177.             {
  178.                 Damage = (int)(Damage * 2);
  179.             }
  180.             else
  181.             {
  182.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  183.                 {
  184.                     Damage = (int)(Damage * 2.3 * attacker.PhysicalDamageIncrease);
  185.                 }
  186.             }
  187.             if ((byte)attacker.NobilityRank <= 5 && (byte)attacked.NobilityRank <= 5)
  188.             {
  189.                 Damage = (int)(Damage * 2);
  190.             }
  191.             else
  192.             {
  193.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  194.                 {
  195.                     Damage = (int)(Damage * 2.5 * attacker.PhysicalDamageIncrease);
  196.                 }
  197.             }
  198.             #endregion
  199.             #region Base Calculate
  200.             if (attacker.EntityFlag == EntityFlag.Monster)
  201.                 if (attacked.EntityFlag == EntityFlag.Player)
  202.                     if (ServerBase.Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  203.                         return 0;
  204.  
  205.             Durability(attacker, attacked, null);
  206.  
  207.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  208.                 return 1;
  209.             if (!attacker.Transformed)
  210.                 Damage = ServerBase.Kernel.Random.Next(Math.Min((int)attacker.MinAttack, (int)attacker.MaxAttack), Math.Max((int)attacker.MinAttack, (int)attacker.MaxAttack) + 1);
  211.             else
  212.                 Damage = ServerBase.Kernel.Random.Next((int)attacker.TransformationMinAttack, (int)attacker.TransformationMaxAttack + 1);
  213.  
  214.             if (attacker.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  215.                 if (!attacker.Transformed)
  216.                     Damage = (int)(Damage * attacker.StigmaIncrease);
  217.             #region Breakthrough
  218.             int rateBreakthrough = (attacker.Breaktrough - attacked.Counteraction) / 100;
  219.             if (attacker.BattlePower < attacked.BattlePower)
  220.             {
  221.                 if (ServerBase.Kernel.Rate(rateBreakthrough))
  222.                 {
  223.                     Damage = (int)(Damage * 0.7); attacker.Owner.Send(new Message("Breakthrough Has a chance to exceed Max Attack when the enemy has a higher BP.", System.Drawing.Color.Red, Message.TopLeft));
  224.                 }
  225.             }
  226.             #endregion
  227.  
  228.             if (attacked.EntityFlag == EntityFlag.Monster)
  229.             {
  230.                 if (attacked.MapID < 1351 || attacked.MapID > 1354)
  231.                     Damage = (int)(Damage * (1 + (GetLevelBonus(attacker.Level, attacked.Level) * 0.08)));
  232.             }
  233.             if (attacker.EntityFlag == EntityFlag.Player)
  234.             {
  235.                 if (attacked.EntityFlag == EntityFlag.Monster)
  236.                 {
  237.                     if (attacked.MapID < 1351 || attacked.MapID > 1354)
  238.                         if (!attacker.Owner.Equipment.Free(4) && !attacker.Owner.Equipment.Free(5))
  239.                             Damage = (int)(Damage * 1.5);
  240.                 }
  241.                 if (attacked.EntityFlag == EntityFlag.Monster)
  242.                     if (attacked.MapID < 1351 || attacked.MapID > 1354)
  243.                         Damage = (int)(Damage * AttackMultiplier(attacker, attacked));
  244.                 try
  245.                 {
  246.                     if (attacker.OnSuperman() && !attacked.MonsterInfo.Boss)
  247.                         if (attacked.EntityFlag == EntityFlag.Monster)
  248.                             Damage *= 10;
  249.                 }
  250.                 catch { }
  251.  
  252.                 if (attacker.ContainsFlag(Update.Flags2.Oblivion))
  253.                     if (attacked.EntityFlag == EntityFlag.Monster)
  254.                         Damage *= 2;
  255.  
  256.                 try
  257.                 {
  258.                     if (attacker.OnFatalStrike() && !attacked.MonsterInfo.Boss)
  259.                         if (attacked.EntityFlag == EntityFlag.Monster)
  260.                             Damage *= 5;
  261.                 }
  262.                 catch { }
  263.             }
  264.             #endregion
  265.             #region Penetration
  266.             uint _B = attacker.Penetration;
  267.             if (!ServerBase.Kernel.Rate(_B /= 20))
  268.             {
  269.                 if (!attacked.Transformed)
  270.                 {
  271.                     if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.MagicShield))
  272.                     {
  273.                         if (attacked.ShieldTime > 0)
  274.                             Damage -= (ushort)(attacked.Defence * attacked.ShieldIncrease);
  275.                         else
  276.                             Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  277.                     }
  278.                     else
  279.                     {
  280.                         Damage -= attacked.Defence;
  281.                     }
  282.                 }
  283.                 else
  284.                     Damage -= attacked.TransformationDefence;
  285.  
  286.                 Damage = BattlePowerCalculation(Damage, attacker.BattlePower - attacked.BattlePower);
  287.             }
  288.             else
  289.             {
  290.                 _String str = new _String(true);
  291.                 str.UID = attacker.UID;
  292.                 str.TextsCount = 1;
  293.                 str.Type = _String.Effect;
  294.                 str.Texts.Add("zf2-e295");
  295.                 attacker.Owner.SendScreen(str, true);
  296.             }
  297.             #endregion
  298.             #region LuckTime
  299.             if (ServerBase.Kernel.Rate(5))
  300.             {
  301.                 if (attacker.EntityFlag == EntityFlag.Player)
  302.                 {
  303.                     if (attacker.Owner.BlessTime > 0)
  304.                     {
  305.                         Damage *= 2;
  306.                         _String str = new _String(true);
  307.                         str.UID = attacker.UID;
  308.                         str.TextsCount = 1;
  309.                         str.Type = _String.Effect;
  310.                         str.Texts.Add("LuckyGuy");
  311.                         attacker.Owner.SendScreen(str, true);
  312.                     }
  313.                 }
  314.             }
  315.             if (ServerBase.Kernel.Rate(5))
  316.             {
  317.                 if (attacked.EntityFlag == EntityFlag.Player)
  318.                 {
  319.                     if (attacked.Owner.BlessTime > 0)
  320.                     {
  321.                         Damage = 1;
  322.                         _String str = new _String(true);
  323.                         str.UID = attacker.UID;
  324.                         str.TextsCount = 1;
  325.                         str.Type = _String.Effect;
  326.                         str.Texts.Add("LuckyGuy");
  327.                         attacked.Owner.SendScreen(str, true);
  328.                     }
  329.                 }
  330.             }
  331.             #endregion
  332.             #region RemoveExcess
  333.             Damage = RemoveExcessDamage(Damage, attacker, attacked);
  334.  
  335.             Damage += attacker.PhysicalDamageIncrease;
  336.             Damage -= attacked.PhysicalDamageDecrease;
  337.  
  338.             if (attacked.EntityFlag == EntityFlag.Monster)
  339.             {
  340.                 if (Damage >= 700 * attacked.MaxHitpoints)
  341.                     Damage = (int)(700 * attacked.MaxHitpoints);
  342.             }
  343.             if (Damage <= 0)
  344.                 Damage = 1;
  345.  
  346.             AutoRespone(attacker, attacked, ref Damage);
  347.             #endregion
  348.             #region AzureShield
  349.             if (attacked.ContainsFlag2(Update.Flags2.AzureShield))
  350.             {
  351.                 if (Damage >= attacked.AzureDamage)
  352.                 {
  353.                     Damage -= attacked.AzureDamage;
  354.                     attacked.AzureDamage = 0;
  355.                 }
  356.                 else
  357.                 {
  358.                     attacked.AzureDamage -= Damage;
  359.                     Damage = 1;
  360.                 }
  361.  
  362.                 _String str = new _String(true);
  363.                 str.UID = attacked.UID;
  364.                 str.TextsCount = 1;
  365.                 str.Type = _String.Effect;
  366.                 str.Texts.Add("ShieldBlock");
  367.                 if (attacked.EntityFlag == EntityFlag.Player)
  368.                     attacked.Owner.SendScreen(str, true);
  369.             }
  370.             #endregion
  371.             #region Block
  372.             if (attacked.Block >= 0)
  373.             {
  374.                 uint _bb = attacked.Block;
  375.                 try
  376.                 {
  377.                     if (ServerBase.Kernel.Rate(_bb /= 170))
  378.                     {
  379.                         Damage = Damage /= 2;
  380.                         _String str = new _String(true);
  381.                         str.UID = attacked.UID;
  382.                         str.TextsCount = 1;
  383.                         str.Type = _String.Effect;
  384.                         str.Texts.Add("ShieldBlock");
  385.                         if (attacked.EntityFlag == EntityFlag.Player)
  386.                             attacked.Owner.SendScreen(str, true);
  387.                     }
  388.                 }
  389.                 catch (Exception E)
  390.                 {
  391.                     Console.WriteLine(E);
  392.                 }
  393.  
  394.             }
  395.             #endregion
  396.             #region Elements
  397.             try
  398.             {
  399.                 if (attacked.EntityFlag == EntityFlag.Player)
  400.                 {
  401.                     int mr = (int)attacked.MetalResistance * 2;
  402.                     int wr = (int)attacked.WaterResistance * 2;
  403.                     int wd = (int)attacked.WoodResistance * 2;
  404.                     int fr = (int)attacked.FireResistance * 2;
  405.                     int er = (int)attacked.EarthResistance * 2;
  406.  
  407.                     Damage -= mr;
  408.                     Damage -= fr;
  409.                     Damage -= wd;
  410.                     Damage -= er;
  411.                     Damage -= wr;
  412.  
  413.                 }
  414.                 if (Damage <= 0)
  415.                     Damage = 1;
  416.             }
  417.             catch (Exception E)
  418.             {
  419.                 Console.WriteLine(E);
  420.             }
  421.             #endregion
  422.             #region Tortoise
  423.             if (attacked.EntityFlag == EntityFlag.Player)
  424.             {
  425.                 uint _ddmg = (uint)(Damage / 20) * (attacked.Owner.Tortoise);
  426.                 Damage -= (int)_ddmg;
  427.             }
  428.             #endregion
  429.             #region Guard
  430.             if (attacker.Name.Contains("AdventureGuard1") && attacker.EntityFlag == EntityFlag.Monster)
  431.                 return 700000;
  432.             if (attacked.Name.Contains("AdventureGuard1") && attacked.EntityFlag == EntityFlag.Monster)
  433.                 return 1;
  434.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  435.                 return 1;
  436.             #endregion
  437.             #region Kratos
  438.             if (attacked.Name.Contains("Kratos") && attacked.EntityFlag == EntityFlag.Monster)
  439.                 return 1;
  440.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  441.                 return 1;
  442.             #endregion
  443.             #region Immunity
  444.             if (attacked.Immunity >= 0)
  445.             {
  446.                 uint _bb = attacked.Immunity;
  447.                 try
  448.                 {
  449.                     if (ServerBase.Kernel.Rate(_bb /= 210))
  450.                     {
  451.                         Damage = 1;
  452.                         _String str = new _String(true);
  453.                         str.UID = attacked.UID;
  454.                         str.TextsCount = 1;
  455.                         str.Type = _String.Effect;
  456.                         str.Texts.Add("bossimmunity");
  457.  
  458.                         if (attacked.EntityFlag == EntityFlag.Player)
  459.                             attacked.Owner.SendScreen(str, true);
  460.                     }
  461.                 }
  462.                 catch (Exception E)
  463.                 {
  464.                     Console.WriteLine(E);
  465.                 }
  466.             }
  467.             #endregion
  468.             #region Carlos.P[TQ]
  469.             if (attacked.Name.Contains("Carlos.P[TQ]"))
  470.                 return 1;
  471.             #endregion
  472.  
  473.             return (uint)Damage;
  474.         }
  475.         public static uint Melee(Entity attacker, Entity attacked, Database.SpellInformation spell)
  476.         {
  477.             int Damage = 0;
  478.  
  479.             #region Base Calculate
  480.             if (attacker.EntityFlag == EntityFlag.Monster)
  481.                 if (attacked.EntityFlag == EntityFlag.Player)
  482.                     if (ServerBase.Kernel.Rate(Math.Min(60, attacked.Dodge + 30)))
  483.                         return 0;
  484.  
  485.             Durability(attacker, attacked, null);
  486.  
  487.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  488.                 return 1;
  489.             if (!attacker.Transformed)
  490.                 Damage = ServerBase.Kernel.Random.Next(Math.Min((int)attacker.MinAttack, (int)attacker.MaxAttack), Math.Max((int)attacker.MinAttack, (int)attacker.MaxAttack) + 1);
  491.             else
  492.                 Damage = ServerBase.Kernel.Random.Next((int)attacker.TransformationMinAttack, (int)attacker.TransformationMaxAttack + 1);
  493.  
  494.             if (attacker.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  495.                 if (!attacker.Transformed)
  496.                     Damage = (int)(Damage * attacker.StigmaIncrease);
  497.             #region Breakthrough
  498.             int rateBreakthrough = (attacker.Breaktrough - attacked.Counteraction) / 100;
  499.             if (attacker.BattlePower < attacked.BattlePower)
  500.             {
  501.                 if (ServerBase.Kernel.Rate(rateBreakthrough))
  502.                 {
  503.                     Damage = (int)(Damage * 0.7); attacker.Owner.Send(new Message("Breakthrough Has a chance to exceed Max Attack when the enemy has a higher BP.", System.Drawing.Color.Red, Message.TopLeft));
  504.                 }
  505.             }
  506.             #endregion
  507.  
  508.             if (attacked.EntityFlag == EntityFlag.Monster)
  509.             {
  510.                 if (attacked.MapID < 1351 || attacked.MapID > 1354)
  511.                     Damage = (int)(Damage * (1 + (GetLevelBonus(attacker.Level, attacked.Level) * 0.08)));
  512.             }
  513.             if (attacker.EntityFlag == EntityFlag.Player)
  514.             {
  515.                 if (attacked.EntityFlag == EntityFlag.Monster)
  516.                 {
  517.                     if (attacked.MapID < 1351 || attacked.MapID > 1354)
  518.                         if (!attacker.Owner.Equipment.Free(4) && !attacker.Owner.Equipment.Free(5))
  519.                             Damage = (int)(Damage * 1.5);
  520.                 }
  521.                 if (attacked.EntityFlag == EntityFlag.Monster)
  522.                     if (attacked.MapID < 1351 || attacked.MapID > 1354)
  523.                         Damage = (int)(Damage * AttackMultiplier(attacker, attacked));
  524.  
  525.                 try
  526.                 {
  527.                     if (attacker.OnSuperman() && !attacked.MonsterInfo.Boss)
  528.                         if (attacked.EntityFlag == EntityFlag.Monster)
  529.                             Damage *= 10;
  530.                 }
  531.                 catch { }
  532.  
  533.                 if (attacker.ContainsFlag(Update.Flags2.Oblivion))
  534.                     if (attacked.EntityFlag == EntityFlag.Monster)
  535.                         Damage *= 2;
  536.  
  537.                 try
  538.                 {
  539.  
  540.                     if (attacker.OnFatalStrike() && !attacked.MonsterInfo.Boss)
  541.                         if (attacked.EntityFlag == EntityFlag.Monster)
  542.                             Damage *= 5;
  543.                 }
  544.                 catch { }
  545.             }
  546.             #endregion
  547.             #region Breaktrough
  548.             uint _B = attacker.Breaktrough;
  549.             if (!ServerBase.Kernel.Rate(_B /= 20))
  550.             {
  551.                 if (!attacked.Transformed)
  552.                 {
  553.                     if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.MagicShield))
  554.                     {
  555.                         if (attacked.ShieldTime > 0)
  556.                             Damage -= (ushort)(attacked.Defence * attacked.ShieldIncrease);
  557.                         else
  558.                             Damage -= (ushort)(attacked.Defence * attacked.MagicShieldIncrease);
  559.                     }
  560.                     else
  561.                     {
  562.                         Damage -= attacked.Defence;
  563.                     }
  564.                 }
  565.                 else
  566.                     Damage -= attacked.TransformationDefence;
  567.                 Damage = BattlePowerCalculation(Damage, attacker.BattlePower - attacked.BattlePower);
  568.             }
  569.             else
  570.             {
  571.                 _String str = new _String(true);
  572.                 str.UID = attacker.UID;
  573.                 str.TextsCount = 1;
  574.                 str.Type = _String.Effect;
  575.                 str.Texts.Add("partbehithead");
  576.                 attacker.Owner.SendScreen(str, true);
  577.             }
  578.             #endregion
  579.             #region LuckTime
  580.             if (ServerBase.Kernel.Rate(5))
  581.             {
  582.                 if (attacker.EntityFlag == EntityFlag.Player)
  583.                 {
  584.                     if (attacker.Owner.BlessTime > 0)
  585.                     {
  586.                         Damage *= 2;
  587.                         _String str = new _String(true);
  588.                         str.UID = attacker.UID;
  589.                         str.TextsCount = 1;
  590.                         str.Type = _String.Effect;
  591.                         str.Texts.Add("LuckyGuy");
  592.                         attacker.Owner.SendScreen(str, true);
  593.                     }
  594.                 }
  595.             }
  596.             if (ServerBase.Kernel.Rate(5))
  597.             {
  598.                 if (attacked.EntityFlag == EntityFlag.Player)
  599.                 {
  600.                     if (attacked.Owner.BlessTime > 0)
  601.                     {
  602.                         Damage = 1;
  603.                         _String str = new _String(true);
  604.                         str.UID = attacker.UID;
  605.                         str.TextsCount = 1;
  606.                         str.Type = _String.Effect;
  607.                         str.Texts.Add("LuckyGuy");
  608.                         attacked.Owner.SendScreen(str, true);
  609.                     }
  610.                 }
  611.             }
  612.             #endregion
  613.             #region Remove Excess
  614.             if (spell.ID == 6000 && attacked.EntityFlag == EntityFlag.Monster)
  615.             {
  616.                 if (spell.PowerPercent != 0)
  617.                     Damage = (int)(Damage * spell.PowerPercent);
  618.             }
  619.             else if (spell.ID != 6000)
  620.             {
  621.                 if (spell.PowerPercent != 0)
  622.                     Damage = (int)(Damage * spell.PowerPercent);
  623.             }
  624.             Damage = RemoveExcessDamage(Damage, attacker, attacked);
  625.  
  626.             Damage += attacker.PhysicalDamageIncrease;
  627.             Damage -= attacked.PhysicalDamageDecrease;
  628.  
  629.             if (attacked.EntityFlag == EntityFlag.Monster)
  630.             {
  631.                 if (Damage >= 700 * attacked.MaxHitpoints)
  632.                     Damage = (int)(700 * attacked.MaxHitpoints);
  633.             }
  634.             if (Damage <= 0)
  635.                 Damage = 1;
  636.  
  637.             AutoRespone(attacker, attacked, ref Damage);
  638.  
  639.             try
  640.             {
  641.                 if (attacker.OnSuperman() && !attacked.MonsterInfo.Boss)
  642.                     if (attacked.EntityFlag == EntityFlag.Monster)
  643.                         Damage *= 10;
  644.             }
  645.             catch { }
  646.             if (attacker.NobilityRank != attacked.NobilityRank)
  647.             {
  648.                 int addnobility_damage = 0;
  649.                 if ((byte)attacker.NobilityRank == 12)
  650.                     addnobility_damage = (Damage * ((byte)attacker.NobilityRank + 45)) / 100;
  651.                 else
  652.                     if ((byte)attacker.NobilityRank > 5)
  653.                         addnobility_damage = (Damage * ((byte)attacker.NobilityRank + 25)) / 100;
  654.                 if ((byte)attacked.NobilityRank > 5)
  655.                 {
  656.                     if ((addnobility_damage - (uint)((Damage * ((byte)attacked.NobilityRank + 8)) / 100)) > 0)
  657.                     {
  658.                         addnobility_damage -= (int)((Damage * ((byte)attacked.NobilityRank + 8)) / 100);
  659.                     }
  660.                     else
  661.                     {
  662.                         if (Damage > (uint)((Damage * ((byte)attacked.NobilityRank + 8)) / 100))
  663.                         {
  664.                             Damage -= (int)((Damage * ((byte)attacked.NobilityRank + 8)) / 100);
  665.                         }
  666.                         else
  667.                             Damage = 1;
  668.                     }
  669.                 }
  670.                 if (Damage != 1)
  671.                 {
  672.                     Damage += addnobility_damage;
  673.                 }
  674.             }
  675.             #endregion
  676.             #region AzureShield
  677.             if (attacked.ContainsFlag2(Update.Flags2.AzureShield))
  678.             {
  679.                 if (Damage >= attacked.AzureDamage)
  680.                 {
  681.                     Damage -= attacked.AzureDamage;
  682.                     attacked.AzureDamage = 0;
  683.                 }
  684.                 else
  685.                 {
  686.                     attacked.AzureDamage -= Damage;
  687.                     Damage = 1;
  688.                 }
  689.  
  690.                 _String str = new _String(true);
  691.                 str.UID = attacked.UID;
  692.                 str.TextsCount = 1;
  693.                 str.Type = _String.Effect;
  694.                 str.Texts.Add("ShieldBlock");
  695.                 if (attacked.EntityFlag == EntityFlag.Player)
  696.                     attacked.Owner.SendScreen(str, true);
  697.             }
  698.             #endregion
  699.             #region Block
  700.             if (attacked.Block >= 0)
  701.             {
  702.                 uint _bb = attacked.Block;
  703.                 try
  704.                 {
  705.                     if (ServerBase.Kernel.Rate(_bb /= 170))
  706.                     {
  707.                         Damage = Damage /= 2;
  708.                         _String str = new _String(true);
  709.                         str.UID = attacked.UID;
  710.                         str.TextsCount = 1;
  711.                         str.Type = _String.Effect;
  712.                         str.Texts.Add("ShieldBlock");
  713.                         if (attacked.EntityFlag == EntityFlag.Player)
  714.                             attacked.Owner.SendScreen(str, true);
  715.                     }
  716.                 }
  717.                 catch (Exception E)
  718.                 {
  719.                     Console.WriteLine(E);
  720.                 }
  721.  
  722.             }
  723.             #endregion
  724.             #region Elements
  725.             try
  726.             {
  727.                 if (attacked.EntityFlag == EntityFlag.Player)
  728.                 {
  729.                     int mr = (int)attacked.MetalResistance * 2;
  730.                     int wr = (int)attacked.WaterResistance * 2;
  731.                     int wd = (int)attacked.WoodResistance * 2;
  732.                     int fr = (int)attacked.FireResistance * 2;
  733.                     int er = (int)attacked.EarthResistance * 2;
  734.  
  735.                     Damage -= mr;
  736.                     Damage -= fr;
  737.                     Damage -= wd;
  738.                     Damage -= er;
  739.                     Damage -= wr;
  740.  
  741.                 }
  742.                 if (Damage <= 0)
  743.                     Damage = 1;
  744.             }
  745.             catch (Exception E)
  746.             {
  747.                 Console.WriteLine(E);
  748.             }
  749.             #endregion
  750.             #region Tortoise
  751.             if (attacked.EntityFlag == EntityFlag.Player)
  752.             {
  753.                 uint _ddmg = (uint)(Damage / 20) * (attacked.Owner.Tortoise);
  754.                 Damage -= (int)_ddmg;
  755.             }
  756.             #endregion
  757.             #region Nobility Damage
  758.             if ((byte)attacker.NobilityRank == 12 && (byte)attacked.NobilityRank == 12)
  759.             {
  760.                 Damage = (int)(Damage * 1.5);
  761.             }
  762.             else
  763.             {
  764.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  765.                 {
  766.                     Damage = (int)(Damage * 4 * attacker.PhysicalDamageIncrease);
  767.                 }
  768.             }
  769.             if ((byte)attacker.NobilityRank == 12 && (byte)attacked.NobilityRank == 9)
  770.             {
  771.                 Damage = (int)(Damage * 2);
  772.             }
  773.             else
  774.             {
  775.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  776.                 {
  777.                     Damage = (int)(Damage * 3.3 * attacker.PhysicalDamageIncrease);
  778.                 }
  779.             }
  780.             if ((byte)attacker.NobilityRank == 12 && (byte)attacked.NobilityRank == 7)
  781.             {
  782.                 Damage = (int)(Damage * 2.3);
  783.             }
  784.             else
  785.             {
  786.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  787.                 {
  788.                     Damage = (int)(Damage * 3.5 * attacker.PhysicalDamageIncrease);
  789.                 }
  790.             }
  791.             if ((byte)attacker.NobilityRank == 12 && (byte)attacked.NobilityRank <= 5)
  792.             {
  793.                 Damage = (int)(Damage * 3);
  794.             }
  795.             else
  796.             {
  797.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  798.                 {
  799.                     Damage = (int)(Damage * 3.8 * attacker.PhysicalDamageIncrease);
  800.                 }
  801.             }
  802.             if ((byte)attacker.NobilityRank == 9 && (byte)attacked.NobilityRank == 12)
  803.             {
  804.                 Damage = (int)(Damage * 1.2);
  805.             }
  806.             else
  807.             {
  808.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  809.                 {
  810.                     Damage = (int)(Damage * 2.5 * attacker.PhysicalDamageIncrease);
  811.                 }
  812.             }
  813.             if ((byte)attacker.NobilityRank == 9 && (byte)attacked.NobilityRank == 9)
  814.             {
  815.                 Damage = (int)(Damage * 2);
  816.             }
  817.             else
  818.             {
  819.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  820.                 {
  821.                     Damage = (int)(Damage * 2.5 * attacker.PhysicalDamageIncrease);
  822.                 }
  823.             }
  824.             if ((byte)attacker.NobilityRank == 9 && (byte)attacked.NobilityRank == 7)
  825.             {
  826.                 Damage = (int)(Damage * 2);
  827.             }
  828.             else
  829.             {
  830.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  831.                 {
  832.                     Damage = (int)(Damage * 3 * attacker.PhysicalDamageIncrease);
  833.                 }
  834.             }
  835.             if ((byte)attacker.NobilityRank == 9 && (byte)attacked.NobilityRank <= 5)
  836.             {
  837.                 Damage = (int)(Damage * 2.7);
  838.             }
  839.             else
  840.             {
  841.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  842.                 {
  843.                     Damage = (int)(Damage * 3.3 * attacker.PhysicalDamageIncrease);
  844.                 }
  845.             }
  846.             if ((byte)attacker.NobilityRank == 7 && (byte)attacked.NobilityRank == 12)
  847.             {
  848.                 Damage = (int)(Damage * 1.3);
  849.             }
  850.             else
  851.             {
  852.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  853.                 {
  854.                     Damage = (int)(Damage * 1.6 * attacker.PhysicalDamageIncrease);
  855.                 }
  856.             }
  857.             if ((byte)attacker.NobilityRank == 7 && (byte)attacked.NobilityRank == 9)
  858.             {
  859.                 Damage = (int)(Damage * 1.8);
  860.             }
  861.             else
  862.             {
  863.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  864.                 {
  865.                     Damage = (int)(Damage * 2 * attacker.PhysicalDamageIncrease);
  866.                 }
  867.             }
  868.             if ((byte)attacker.NobilityRank == 7 && (byte)attacked.NobilityRank == 7)
  869.             {
  870.                 Damage = (int)(Damage * 1.5);
  871.             }
  872.             else
  873.             {
  874.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  875.                 {
  876.                     Damage = (int)(Damage * 2 * attacker.PhysicalDamageIncrease);
  877.                 }
  878.             }
  879.             if ((byte)attacker.NobilityRank == 7 && (byte)attacked.NobilityRank <= 5)
  880.             {
  881.                 Damage = (int)(Damage * 2);
  882.             }
  883.             else
  884.             {
  885.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  886.                 {
  887.                     Damage = (int)(Damage * 2.5 * attacker.PhysicalDamageIncrease);
  888.                 }
  889.             }
  890.             if ((byte)attacker.NobilityRank <= 5 && (byte)attacked.NobilityRank == 12)
  891.             {
  892.                 Damage = (int)(Damage * 1.3);
  893.             }
  894.             else
  895.             {
  896.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  897.                 {
  898.                     Damage = (int)(Damage * 1.5 * attacker.PhysicalDamageIncrease);
  899.                 }
  900.             }
  901.             if ((byte)attacker.NobilityRank <= 5 && (byte)attacked.NobilityRank == 9)
  902.             {
  903.                 Damage = (int)(Damage * 1.5);
  904.             }
  905.             else
  906.             {
  907.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  908.                 {
  909.                     Damage = (int)(Damage * 1.7 * attacker.PhysicalDamageIncrease);
  910.                 }
  911.             }
  912.             if ((byte)attacker.NobilityRank <= 5 && (byte)attacked.NobilityRank == 7)
  913.             {
  914.                 Damage = (int)(Damage * 2);
  915.             }
  916.             else
  917.             {
  918.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  919.                 {
  920.                     Damage = (int)(Damage * 2.3 * attacker.PhysicalDamageIncrease);
  921.                 }
  922.             }
  923.             if ((byte)attacker.NobilityRank <= 5 && (byte)attacked.NobilityRank <= 5)
  924.             {
  925.                 Damage = (int)(Damage * 2);
  926.             }
  927.             else
  928.             {
  929.                 if ((byte)attacker.Class == 65 && (byte)attacked.Class >= 10 && (byte)attacked.Class <= 15 && (byte)attacked.Class >= 50 && (byte)attacked.Class <= 55)
  930.                 {
  931.                     Damage = (int)(Damage * 2.5 * attacker.PhysicalDamageIncrease);
  932.                 }
  933.             }
  934.             #endregion
  935.             #region Guard
  936.             if (attacker.Name.Contains("AdventureGuard1") && attacker.EntityFlag == EntityFlag.Monster)
  937.                 return 700000;
  938.             if (attacked.Name.Contains("AdventureGuard1") && attacked.EntityFlag == EntityFlag.Monster)
  939.                 return 1;
  940.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  941.                 return 1;
  942.             #endregion
  943.             #region Kratos
  944.             if (attacked.Name.Contains("Kratos") && attacked.EntityFlag == EntityFlag.Monster)
  945.                 return 1;
  946.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  947.                 return 1;
  948.             #endregion
  949.             #region Immunity
  950.             if (attacked.Immunity >= 0)
  951.             {
  952.                 uint _bb = attacked.Immunity;
  953.                 try
  954.                 {
  955.                     if (ServerBase.Kernel.Rate(_bb /= 210))
  956.                     {
  957.                         Damage = 1;
  958.                         _String str = new _String(true);
  959.                         str.UID = attacked.UID;
  960.                         str.TextsCount = 1;
  961.                         str.Type = _String.Effect;
  962.                         str.Texts.Add("bossimmunity");
  963.                         if (attacked.EntityFlag == EntityFlag.Player)
  964.                             attacked.Owner.SendScreen(str, true);
  965.                     }
  966.                 }
  967.                 catch (Exception E)
  968.                 {
  969.                     Console.WriteLine(E);
  970.                 }
  971.             }
  972.             #endregion
  973.             #region Carlos.P[TQ]
  974.             if (attacked.Name.Contains("Carlos.P[TQ]"))
  975.                 return 1;
  976.             #endregion
  977.  
  978.             return (uint)Damage;
  979.         }
  980.         public static uint Melee(Entity attacker, SobNpcSpawn attacked)
  981.         {
  982.             int Damage = 0;
  983.  
  984.             #region Base Calculate
  985.             try
  986.             {
  987.                 if (attacked.UID == 810 && attacker.Owner.Guild != null)
  988.                 {
  989.                     if (Game.ConquerStructures.Society.GuildWar.PoleKeeper == attacker.Owner.Guild)
  990.                     {
  991.                         return 0;
  992.                     }
  993.                 }
  994.                 Durability(attacker, null, null);
  995.                 if (attacker.MinAttack > attacker.MaxAttack)
  996.                 {
  997.                     uint _ma = attacker.MinAttack;
  998.                     uint ma = attacker.MaxAttack;
  999.                     attacker.MinAttack = ma;
  1000.                     attacker.MaxAttack = _ma;
  1001.                 }
  1002.                 if (!attacker.Transformed)
  1003.                     Damage = ServerBase.Kernel.Random.Next((int)attacker.MinAttack, (int)attacker.MaxAttack + 1);
  1004.                 else
  1005.                     Damage = ServerBase.Kernel.Random.Next(Math.Min((int)attacker.MinAttack, (int)attacker.MaxAttack), Math.Max((int)attacker.MinAttack, (int)attacker.MaxAttack) + 1);
  1006.                 if (attacker.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  1007.                     if (!attacker.Transformed)
  1008.                         Damage = (int)(Damage * attacker.StigmaIncrease);
  1009.                 Damage += attacker.PhysicalDamageIncrease;
  1010.  
  1011.             #endregion
  1012.                 #region LuckTime
  1013.                 if (ServerBase.Kernel.Rate(5))
  1014.                 {
  1015.                     if (attacker.EntityFlag == EntityFlag.Player)
  1016.                     {
  1017.                         if (attacker.Owner.BlessTime > 0)
  1018.                         {
  1019.                             Damage *= 2;
  1020.                             _String str = new _String(true);
  1021.                             str.UID = attacker.UID;
  1022.                             str.TextsCount = 1;
  1023.                             str.Type = _String.Effect;
  1024.                             str.Texts.Add("LuckyGuy");
  1025.                             attacker.Owner.SendScreen(str, true);
  1026.                         }
  1027.                     }
  1028.                 }
  1029.             }
  1030.             catch (Exception E)
  1031.             {
  1032.                 Console.WriteLine(E);
  1033.             }
  1034.             if (Damage <= 0)
  1035.                 Damage = 1;
  1036.                 #endregion
  1037.  
  1038.             return (uint)Damage;
  1039.         }
  1040.         public static bool Miss(int Percent)
  1041.         {
  1042.             if (Percent >= 100)
  1043.                 return false;
  1044.  
  1045.             return ChanceSuccess(Percent, 100);
  1046.         }
  1047.         public static uint Magic(Entity attacker, Entity attacked, Database.SpellInformation spell)
  1048.         {
  1049.             #region Base Calculate
  1050.             if (!ServerBase.Kernel.Rate(spell.Percent))
  1051.                 return 0;
  1052.             Durability(attacker, attacked, spell);
  1053.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1054.                 return 1;
  1055.             if (attacker.Transformed)
  1056.                 return 0;
  1057.  
  1058.             int Damage = 0;
  1059.             Damage = (int)attacker.MagicAttack;
  1060.             Damage += spell.Power;
  1061.             #endregion
  1062.             #region Breakthrough
  1063.             if (!attacked.Transformed)
  1064.             {
  1065.                 //(uint)((double)damage * (100 - Attacked.Entity.ItemBless) / 95);
  1066.                 // Damage -= (int)((uint)(attacked.MagicDefencePercent * Damage / 100));
  1067.                 if (attacked.ItemBless > 60)
  1068.                     attacked.ItemBless = 58;
  1069.                 Damage = (int)((uint)((double)Damage * (100 - attacked.ItemBless) / 340));
  1070.                 Damage -= attacked.MagicDefence;
  1071.  
  1072.  
  1073.             }
  1074.             else
  1075.                 Damage = (int)(((Damage * 0.75) * (1 - (0 * 0.01))) - attacked.TransformationMagicDefence);
  1076.             #region Breakthrough
  1077.             int rateBreakthrough = (attacker.Breaktrough - attacked.Counteraction) / 100;
  1078.             if (attacker.BattlePower < attacked.BattlePower)
  1079.             {
  1080.                 if (attacker.Breaktrough > 0)
  1081.                 {
  1082.                     if (ServerBase.Kernel.Rate(rateBreakthrough))
  1083.                     {
  1084.                         Attack attack = new Attack(true);
  1085.                         attack.Attacker = attacker.UID;
  1086.                         attack.Attacked = attacked.UID;
  1087.                         attack.AttackType = 2;
  1088.                         attack.X = attacked.X;
  1089.                         attack.Y = attacked.Y;
  1090.                         attack.Effect1 = Attack.AttackEffects1.Penetration;
  1091.                         attacker.Owner.SendScreen(attack, true);
  1092.                         Damage = (int)(Damage * 0.9); attacker.Owner.Send(new Message("Breakthrough Has a chance to exceed Max Attack when the enemy has a higher BP.", System.Drawing.Color.Red, Message.TopLeft));
  1093.                     }
  1094.                 }
  1095.             }
  1096.             #endregion
  1097.             #endregion
  1098.             #region Other Calculate
  1099.             if (attacked.EntityFlag == EntityFlag.Monster)
  1100.                 if (attacked.MapID < 1351 || attacked.MapID > 1354)
  1101.                     Damage = (int)(Damage * AttackMultiplier(attacker, attacked) / 2);
  1102.  
  1103.             if (attacked.EntityFlag == EntityFlag.Monster)
  1104.             {
  1105.                 Damage = (int)(Damage * 6.6);
  1106.                 if (attacked.MapID < 1351 || attacked.MapID > 1354)
  1107.                     Damage = (int)(Damage * (1 + (GetLevelBonus(attacker.Level, attacked.Level) * 0.08)));
  1108.             }
  1109.  
  1110.             Damage = BattlePowerCalculation(Damage, attacker.BattlePower - attacked.BattlePower);
  1111.  
  1112.             //  Damage = RemoveExcessDamage(Damage, attacker, attacked);
  1113.             //   Console.WriteLine("[3]" + Damage);
  1114.             #endregion
  1115.             #region LuckTime
  1116.             if (ServerBase.Kernel.Rate(5))
  1117.             {
  1118.                 if (attacker.EntityFlag == EntityFlag.Player)
  1119.                 {
  1120.                     Damage *= 2;
  1121.                     _String str = new _String(true);
  1122.                     str.UID = attacker.UID;
  1123.                     str.TextsCount = 1;
  1124.                     str.Type = _String.Effect;
  1125.                     str.Texts.Add("LuckyGuy");
  1126.                     attacker.Owner.SendScreen(str, true);
  1127.                 }
  1128.             }
  1129.             if (ServerBase.Kernel.Rate(5))
  1130.             {
  1131.                 if (attacked.EntityFlag == EntityFlag.Player)
  1132.                 {
  1133.                     if (attacked.Owner.BlessTime > 0)
  1134.                     {
  1135.                         Damage = 1;
  1136.                         _String str = new _String(true);
  1137.                         str.UID = attacker.UID;
  1138.                         str.TextsCount = 1;
  1139.                         str.Type = _String.Effect;
  1140.                         str.Texts.Add("LuckyGuy");
  1141.                         attacked.Owner.SendScreen(str, true);
  1142.                     }
  1143.                 }
  1144.             }
  1145.             #endregion
  1146.             #region Remove Excess
  1147.             Damage += attacker.MagicDamageIncrease;
  1148.             Damage -= attacked.MagicDamageDecrease;
  1149.  
  1150.             if (Damage <= 0)
  1151.                 Damage = 1;
  1152.  
  1153.             if (attacked.EntityFlag == EntityFlag.Monster)
  1154.             {
  1155.                 if (Damage >= 700 * attacked.MaxHitpoints)
  1156.                     Damage = (int)(700 * attacked.MaxHitpoints);
  1157.             }
  1158.             else
  1159.             {
  1160.                 if (attacker.EntityFlag == EntityFlag.Monster)
  1161.                 {
  1162.                     if (attacker.Name.Contains("AdventureGuard1") && attacker.EntityFlag == EntityFlag.Monster)
  1163.                         Damage = (int)attacked.MaxHitpoints + 1;
  1164.                 }
  1165.             }
  1166.  
  1167.             AutoRespone(attacker, attacked, ref Damage);
  1168.             #endregion
  1169.             #region AzureShield
  1170.             if (attacked.ContainsFlag2(Update.Flags2.AzureShield))
  1171.             {
  1172.                 if (Damage >= attacked.AzureDamage)
  1173.                 {
  1174.                     Damage -= attacked.AzureDamage;
  1175.                     attacked.AzureDamage = 0;
  1176.                 }
  1177.                 else
  1178.                 {
  1179.                     attacked.AzureDamage -= Damage;
  1180.                     Damage = 1;
  1181.                 }
  1182.  
  1183.                 _String str = new _String(true);
  1184.                 str.UID = attacked.UID;
  1185.                 str.TextsCount = 1;
  1186.                 str.Type = _String.Effect;
  1187.                 str.Texts.Add("ShieldBlock");
  1188.                 if (attacked.EntityFlag == EntityFlag.Player)
  1189.                     attacked.Owner.SendScreen(str, true);
  1190.             }
  1191.             #endregion
  1192.             #region Block
  1193.             if (attacked.Block >= 0)
  1194.             {
  1195.                 uint _bb = attacked.Block;
  1196.                 try
  1197.                 {
  1198.                     if (ServerBase.Kernel.Rate(_bb /= 170))
  1199.                     {
  1200.                         Damage = Damage /= 2;
  1201.                         _String str = new _String(true);
  1202.                         str.UID = attacked.UID;
  1203.                         str.TextsCount = 1;
  1204.                         str.Type = _String.Effect;
  1205.                         str.Texts.Add("ShieldBlock");
  1206.                         if (attacked.EntityFlag == EntityFlag.Player)
  1207.                             attacked.Owner.SendScreen(str, true);
  1208.                     }
  1209.                 }
  1210.                 catch (Exception E)
  1211.                 {
  1212.                     Console.WriteLine(E);
  1213.                 }
  1214.  
  1215.             }
  1216.             #endregion
  1217.             #region Elements
  1218.             try
  1219.             {
  1220.                 if (attacked.EntityFlag == EntityFlag.Player)
  1221.                 {
  1222.                     int mr = (int)attacked.MetalResistance * 2;
  1223.                     int wr = (int)attacked.WaterResistance * 2;
  1224.                     int wd = (int)attacked.WoodResistance * 2;
  1225.                     int fr = (int)attacked.FireResistance * 2;
  1226.                     int er = (int)attacked.EarthResistance * 2;
  1227.  
  1228.                     Damage -= mr;
  1229.                     Damage -= fr;
  1230.                     Damage -= wd;
  1231.                     Damage -= er;
  1232.                     Damage -= wr;
  1233.  
  1234.                 }
  1235.                 if (Damage <= 0)
  1236.                     Damage = 1;
  1237.             }
  1238.             catch (Exception E)
  1239.             {
  1240.                 Console.WriteLine(E);
  1241.             }
  1242.             #endregion
  1243.             #region Tortoise
  1244.             if (attacked.EntityFlag == EntityFlag.Player)
  1245.             {
  1246.                 uint _ddmg = (uint)(Damage / 20) * (attacked.Owner.Tortoise);
  1247.                 Damage -= (int)_ddmg;
  1248.             }
  1249.             #endregion
  1250.             #region Nobility Damge
  1251.             if (attacker.NobilityRank != attacked.NobilityRank)
  1252.             {
  1253.                 int addnobility_damage = 0;
  1254.                 if ((byte)attacker.NobilityRank == 12)
  1255.                     addnobility_damage = (Damage * ((byte)attacker.NobilityRank + 45)) / 100;
  1256.                 else
  1257.                     if ((byte)attacker.NobilityRank > 5)
  1258.                         addnobility_damage = (Damage * ((byte)attacker.NobilityRank + 25)) / 100;
  1259.                 if ((byte)attacked.NobilityRank > 5)
  1260.                 {
  1261.                     if ((addnobility_damage - (uint)((Damage * ((byte)attacked.NobilityRank + 8)) / 100)) > 0)
  1262.                     {
  1263.                         addnobility_damage -= (int)((Damage * ((byte)attacked.NobilityRank + 8)) / 100);
  1264.                     }
  1265.                     else
  1266.                     {
  1267.                         if (Damage > (uint)((Damage * ((byte)attacked.NobilityRank + 8)) / 100))
  1268.                         {
  1269.                             Damage -= (int)((Damage * ((byte)attacked.NobilityRank + 8)) / 100);
  1270.                         }
  1271.                         else
  1272.                             Damage = 1;
  1273.                     }
  1274.                 }
  1275.                 if (Damage != 1)
  1276.                 {
  1277.                     Damage += addnobility_damage;
  1278.                 }
  1279.  
  1280.             }
  1281.             #endregion
  1282.             #region Guard
  1283.             if (attacker.Name.Contains("AdventureGuard1") && attacker.EntityFlag == EntityFlag.Monster)
  1284.                 return 700000;
  1285.             if (attacked.Name.Contains("AdventureGuard1") && attacked.EntityFlag == EntityFlag.Monster)
  1286.                 return 1;
  1287.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1288.                 return 1;
  1289.             #endregion
  1290.             #region Kratos
  1291.             if (attacked.Name.Contains("Kratos") && attacked.EntityFlag == EntityFlag.Monster)
  1292.                 return 1;
  1293.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1294.                 return 1;
  1295.             #endregion
  1296.             #region Immunity
  1297.             if (attacked.Immunity >= 0)
  1298.             {
  1299.                 uint _bb = attacked.Immunity;
  1300.                 try
  1301.                 {
  1302.                     if (ServerBase.Kernel.Rate(_bb /= 210))
  1303.                     {
  1304.                         Damage = 1;
  1305.                         _String str = new _String(true);
  1306.                         str.UID = attacked.UID;
  1307.                         str.TextsCount = 1;
  1308.                         str.Type = _String.Effect;
  1309.                         str.Texts.Add("bossimmunity");
  1310.                         if (attacked.EntityFlag == EntityFlag.Player)
  1311.                             attacked.Owner.SendScreen(str, true);
  1312.                     }
  1313.                 }
  1314.                 catch (Exception E)
  1315.                 {
  1316.                     Console.WriteLine(E);
  1317.                 }
  1318.             }
  1319.             #endregion
  1320.             #region Carlos.P[TQ]
  1321.             if (attacked.Name.Contains("Carlos.P[TQ]"))
  1322.                 return 1;
  1323.             #endregion
  1324.             Damage += attacker.MagicDamageIncrease;
  1325.             Damage -= attacked.MagicDamageDecrease;
  1326.  
  1327.             if (Damage <= 0)
  1328.                 Damage = 1;
  1329.  
  1330.             if (attacked.EntityFlag == EntityFlag.Monster)
  1331.             {
  1332.                 if (Damage >= 700 * attacked.MaxHitpoints)
  1333.                     Damage = (int)(700 * attacked.MaxHitpoints);
  1334.             }
  1335.             else
  1336.             {
  1337.                 if (attacker.EntityFlag == EntityFlag.Monster)
  1338.                 {
  1339.                     if (attacker.Name.Contains("AdventureGuard1") && attacker.EntityFlag == EntityFlag.Monster)
  1340.                         Damage = (int)attacked.MaxHitpoints + 1;
  1341.                 }
  1342.             }
  1343.  
  1344.             return (uint)Damage;
  1345.         }
  1346.         public static uint Magic(Entity attacker, Entity attacked, ushort spellID, byte spellLevel)
  1347.         {
  1348.             Database.SpellInformation spell = Database.SpellTable.SpellInformations[spellID][spellLevel];
  1349.             return Magic(attacker, attacked, spell);
  1350.         }
  1351.         public static uint Magic(Entity attacker, SobNpcSpawn attacked, Database.SpellInformation spell)
  1352.         {
  1353.             #region Base Calculate
  1354.             if (!ServerBase.Kernel.Rate(spell.Percent))
  1355.                 return 0;
  1356.             if (attacked.UID == 810 && attacker.Owner.Guild != null)
  1357.             {
  1358.                 if (Game.ConquerStructures.Society.GuildWar.PoleKeeper == attacker.Owner.Guild)
  1359.                 {
  1360.                     return 0;
  1361.                 }
  1362.             }
  1363.             Durability(attacker, null, spell);
  1364.             if (attacker.Transformed)
  1365.                 return 0;
  1366.  
  1367.             int Damage = 0;
  1368.             Damage = (int)attacker.MagicAttack;
  1369.             Damage += spell.Power;
  1370.             #region LuckTime
  1371.             if (ServerBase.Kernel.Rate(5))
  1372.             {
  1373.                 if (attacker.EntityFlag == EntityFlag.Player)
  1374.                 {
  1375.                     if (attacker.Owner.BlessTime > 0)
  1376.                     {
  1377.                         Damage *= 2;
  1378.                         _String str = new _String(true);
  1379.                         str.UID = attacker.UID;
  1380.                         str.TextsCount = 1;
  1381.                         str.Type = _String.Effect;
  1382.                         str.Texts.Add("LuckyGuy");
  1383.                         attacker.Owner.SendScreen(str, true);
  1384.                     }
  1385.                 }
  1386.             }
  1387.             #endregion
  1388.  
  1389.  
  1390.             Damage += attacker.MagicDamageIncrease;
  1391.  
  1392.             if (Damage <= 0)
  1393.                 Damage = 1;
  1394.             #endregion
  1395.  
  1396.             return (uint)Damage;
  1397.         }
  1398.  
  1399.         public static uint Ranged(Entity attacker, Entity attacked)
  1400.         {
  1401.             #region Base Calculate
  1402.             int Damage = 0;
  1403.             Durability(attacker, attacked, null);
  1404.  
  1405.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1406.                 return 1;
  1407.             if (attacker.Transformed)
  1408.                 return 0;
  1409.  
  1410.             Damage = ServerBase.Kernel.Random.Next(Math.Min((int)attacker.MinAttack, (int)attacker.MaxAttack), Math.Max((int)attacker.MinAttack, (int)attacker.MaxAttack) + 1);
  1411.  
  1412.  
  1413.             try
  1414.             {
  1415.                 if (attacker.OnSuperman() && !attacked.MonsterInfo.Boss)
  1416.                     if (attacked.EntityFlag == EntityFlag.Monster)
  1417.                         Damage *= 10;
  1418.             }
  1419.             catch { }
  1420.  
  1421.             if (attacker.ContainsFlag(Update.Flags2.Oblivion))
  1422.                 if (attacked.EntityFlag == EntityFlag.Monster)
  1423.                     Damage *= 2;
  1424.  
  1425.             try
  1426.             {
  1427.                 if (attacker.OnFatalStrike() && !attacked.MonsterInfo.Boss)
  1428.                     if (attacked.EntityFlag == EntityFlag.Monster)
  1429.                         Damage *= 5;
  1430.             }
  1431.             catch { }
  1432.  
  1433.             #region Penetration
  1434.             uint _B = attacker.Penetration;
  1435.             if (!ServerBase.Kernel.Rate(_B /= 20))
  1436.             {
  1437.                 if (!attacked.Transformed)
  1438.                     Damage -= attacked.Defence;
  1439.                 else
  1440.                     Damage -= attacked.TransformationDefence;
  1441.             }
  1442.             else
  1443.             {
  1444.                 _String str = new _String(true);
  1445.                 str.UID = attacker.UID;
  1446.                 str.TextsCount = 1;
  1447.                 str.Type = _String.Effect;
  1448.                 str.Texts.Add("zf2-e295");
  1449.                 attacker.Owner.SendScreen(str, true);
  1450.             }
  1451.             #endregion
  1452.             Damage -= Damage * attacked.ItemBless / 100;
  1453.             #region Breakthrough
  1454.             int rateBreakthrough = (attacker.Breaktrough - attacked.Counteraction) / 100;
  1455.             if (attacker.BattlePower < attacked.BattlePower)
  1456.             {
  1457.                 if (ServerBase.Kernel.Rate(rateBreakthrough))
  1458.                 {
  1459.                     Damage = (int)(Damage * 0.7); attacker.Owner.Send(new Message("Breakthrough Has a chance to exceed Max Attack when the enemy has a higher BP.", System.Drawing.Color.Red, Message.TopLeft));
  1460.                 }
  1461.             }
  1462.             #endregion
  1463.             byte dodge = attacked.Dodge;
  1464.             if (dodge > 100)
  1465.                 dodge = 99;
  1466.             if (!attacked.Transformed)
  1467.                 Damage -= Damage * dodge / 100;
  1468.             else
  1469.                 Damage -= Damage * attacked.TransformationDodge / 100;
  1470.  
  1471.             if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  1472.             {
  1473.                 Damage *= 2;
  1474.                 attacker.OnIntensify = false;
  1475.             }
  1476.  
  1477.             if (attacker.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  1478.                 if (!attacker.Transformed)
  1479.                     Damage = (int)(Damage * attacker.StigmaIncrease);
  1480.  
  1481.             if (attacked.EntityFlag == EntityFlag.Monster)
  1482.             {
  1483.                 if (attacked.MapID < 1351 || attacked.MapID > 1354)
  1484.                     Damage = (int)(Damage * (1 + (GetLevelBonus(attacker.Level, attacked.Level) * 0.08)));
  1485.  
  1486.                 if (attacked.MapID < 1351 || attacked.MapID > 1354)
  1487.                     Damage = (int)(Damage * AttackMultiplier(attacker, attacked));
  1488.             }
  1489.             Damage = BattlePowerCalculation(Damage, attacker.BattlePower - attacked.BattlePower);
  1490.             #endregion
  1491.             #region LuckTime
  1492.             if (ServerBase.Kernel.Rate(5))
  1493.             {
  1494.                 if (attacker.EntityFlag == EntityFlag.Player)
  1495.                 {
  1496.                     if (attacker.Owner.BlessTime > 0)
  1497.                     {
  1498.                         Damage *= 2;
  1499.                         _String str = new _String(true);
  1500.                         str.UID = attacker.UID;
  1501.                         str.TextsCount = 1;
  1502.                         str.Type = _String.Effect;
  1503.                         str.Texts.Add("LuckyGuy");
  1504.                         attacker.Owner.SendScreen(str, true);
  1505.                     }
  1506.                 }
  1507.             }
  1508.             if (ServerBase.Kernel.Rate(5))
  1509.             {
  1510.                 if (attacked.EntityFlag == EntityFlag.Player)
  1511.                 {
  1512.                     if (attacked.Owner.BlessTime > 0)
  1513.                     {
  1514.                         Damage = 1;
  1515.                         _String str = new _String(true);
  1516.                         str.UID = attacker.UID;
  1517.                         str.TextsCount = 1;
  1518.                         str.Type = _String.Effect;
  1519.                         str.Texts.Add("LuckyGuy");
  1520.                         attacked.Owner.SendScreen(str, true);
  1521.                     }
  1522.                 }
  1523.             }
  1524.             #endregion
  1525.             #region Remove Excess
  1526.             if (attacked.EntityFlag == EntityFlag.Monster)
  1527.             {
  1528.                 if (Damage >= 700 * attacked.MaxHitpoints)
  1529.                     Damage = (int)(700 * attacked.MaxHitpoints);
  1530.             }
  1531.  
  1532.             Damage += attacker.PhysicalDamageIncrease;
  1533.             Damage -= attacked.PhysicalDamageDecrease;
  1534.  
  1535.             if (Damage <= 0)
  1536.                 Damage = 1;
  1537.             AutoRespone(attacker, attacked, ref Damage);
  1538.             #endregion
  1539.             #region AzureShield
  1540.             if (attacked.ContainsFlag2(Update.Flags2.AzureShield))
  1541.             {
  1542.                 if (Damage >= attacked.AzureDamage)
  1543.                 {
  1544.                     Damage -= attacked.AzureDamage;
  1545.                     attacked.AzureDamage = 0;
  1546.                 }
  1547.                 else
  1548.                 {
  1549.                     attacked.AzureDamage -= Damage;
  1550.                     Damage = 1;
  1551.                 }
  1552.  
  1553.                 _String str = new _String(true);
  1554.                 str.UID = attacked.UID;
  1555.                 str.TextsCount = 1;
  1556.                 str.Type = _String.Effect;
  1557.                 str.Texts.Add("ShieldBlock");
  1558.                 if (attacked.EntityFlag == EntityFlag.Player)
  1559.                     attacked.Owner.SendScreen(str, true);
  1560.             }
  1561.             #endregion
  1562.             #region Block
  1563.             if (attacked.Block >= 0)
  1564.             {
  1565.                 uint _bb = attacked.Block;
  1566.                 try
  1567.                 {
  1568.                     if (ServerBase.Kernel.Rate(_bb /= 170))
  1569.                     {
  1570.                         Damage = Damage /= 2;
  1571.                         _String str = new _String(true);
  1572.                         str.UID = attacked.UID;
  1573.                         str.TextsCount = 1;
  1574.                         str.Type = _String.Effect;
  1575.                         str.Texts.Add("ShieldBlock");
  1576.                         if (attacked.EntityFlag == EntityFlag.Player)
  1577.                             attacked.Owner.SendScreen(str, true);
  1578.                     }
  1579.                 }
  1580.                 catch (Exception E)
  1581.                 {
  1582.                     Console.WriteLine(E);
  1583.                 }
  1584.  
  1585.             }
  1586.             #endregion
  1587.             #region Elements
  1588.             try
  1589.             {
  1590.                 if (attacked.EntityFlag == EntityFlag.Player)
  1591.                 {
  1592.                     int mr = (int)attacked.MetalResistance * 2;
  1593.                     int wr = (int)attacked.WaterResistance * 2;
  1594.                     int wd = (int)attacked.WoodResistance * 2;
  1595.                     int fr = (int)attacked.FireResistance * 2;
  1596.                     int er = (int)attacked.EarthResistance * 2;
  1597.  
  1598.                     Damage -= mr;
  1599.                     Damage -= fr;
  1600.                     Damage -= wd;
  1601.                     Damage -= er;
  1602.                     Damage -= wr;
  1603.  
  1604.                 }
  1605.                 if (Damage <= 0)
  1606.                     Damage = 1;
  1607.             }
  1608.             catch (Exception E)
  1609.             {
  1610.                 Console.WriteLine(E);
  1611.             }
  1612.             #endregion
  1613.             #region Immunity
  1614.             if (attacked.Immunity >= 0)
  1615.             {
  1616.                 uint _bb = attacked.Immunity;
  1617.                 try
  1618.                 {
  1619.                     if (ServerBase.Kernel.Rate(_bb /= 210))
  1620.                     {
  1621.                         Damage = 1;
  1622.                         _String str = new _String(true);
  1623.                         str.UID = attacked.UID;
  1624.                         str.TextsCount = 1;
  1625.                         str.Type = _String.Effect;
  1626.                         str.Texts.Add("bossimmunity");
  1627.                         if (attacked.EntityFlag == EntityFlag.Player)
  1628.                             attacked.Owner.SendScreen(str, true);
  1629.                     }
  1630.                 }
  1631.                 catch (Exception E)
  1632.                 {
  1633.                     Console.WriteLine(E);
  1634.                 }
  1635.             }
  1636.             #endregion
  1637.             #region Tortoise
  1638.             if (attacked.EntityFlag == EntityFlag.Player)
  1639.             {
  1640.                 uint _ddmg = (uint)(Damage / 20) * (attacked.Owner.Tortoise);
  1641.                 Damage -= (int)_ddmg;
  1642.             }
  1643.             #endregion
  1644.             #region Nobility Damge
  1645.             if (attacker.NobilityRank != attacked.NobilityRank)
  1646.             {
  1647.                 int addnobility_damage = 0;
  1648.                 if ((byte)attacker.NobilityRank == 12)
  1649.                     addnobility_damage = (Damage * ((byte)attacker.NobilityRank + 45)) / 100;
  1650.                 else
  1651.                     if ((byte)attacker.NobilityRank > 5)
  1652.                         addnobility_damage = (Damage * ((byte)attacker.NobilityRank + 25)) / 100;
  1653.                 if ((byte)attacked.NobilityRank > 5)
  1654.                 {
  1655.                     if ((addnobility_damage - (uint)((Damage * ((byte)attacked.NobilityRank + 8)) / 100)) > 0)
  1656.                     {
  1657.                         addnobility_damage -= (int)((Damage * ((byte)attacked.NobilityRank + 8)) / 100);
  1658.                     }
  1659.                     else
  1660.                     {
  1661.                         if (Damage > (uint)((Damage * ((byte)attacked.NobilityRank + 8)) / 100))
  1662.                         {
  1663.                             Damage -= (int)((Damage * ((byte)attacked.NobilityRank + 8)) / 100);
  1664.                         }
  1665.                         else
  1666.                             Damage = 1;
  1667.                     }
  1668.                 }
  1669.                 if (Damage != 1)
  1670.                 {
  1671.                     Damage += addnobility_damage;
  1672.                 }
  1673.  
  1674.             }
  1675.             #endregion
  1676.             #region Guard
  1677.             if (attacker.Name.Contains("AdventureGuard1") && attacker.EntityFlag == EntityFlag.Monster)
  1678.                 return 700000;
  1679.             if (attacked.Name.Contains("AdventureGuard1") && attacked.EntityFlag == EntityFlag.Monster)
  1680.                 return 1;
  1681.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1682.                 return 1;
  1683.             #endregion
  1684.             #region Kratos
  1685.             if (attacked.Name.Contains("Kratos") && attacked.EntityFlag == EntityFlag.Monster)
  1686.                 return 1;
  1687.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1688.                 return 1;
  1689.             #endregion
  1690.             #region Carlos.P[TQ]
  1691.             if (attacked.Name.Contains("Carlos.P[TQ]"))
  1692.                 return 1;
  1693.             #endregion
  1694.  
  1695.             return (uint)Damage;
  1696.         }
  1697.         public static uint Ranged(Entity attacker, Entity attacked, Database.SpellInformation spell)
  1698.         {
  1699.             #region Base Calculate
  1700.             int Damage = 0;
  1701.             Durability(attacker, attacked, null);
  1702.  
  1703.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1704.                 return 1;
  1705.             if (attacker.Transformed)
  1706.                 return 0;
  1707.  
  1708.             Damage = ServerBase.Kernel.Random.Next(Math.Min((int)attacker.MinAttack, (int)attacker.MaxAttack), Math.Max((int)attacker.MinAttack, (int)attacker.MaxAttack) + 1);
  1709.             #region Breakthrough
  1710.             int rateBreakthrough = (attacker.Breaktrough - attacked.Counteraction) / 100;
  1711.             if (attacker.BattlePower < attacked.BattlePower)
  1712.             {
  1713.                 if (ServerBase.Kernel.Rate(rateBreakthrough))
  1714.                 {
  1715.                     Damage = (int)(Damage * 0.7); attacker.Owner.Send(new Message("Breakthrough Has a chance to exceed Max Attack when the enemy has a higher BP.", System.Drawing.Color.Red, Message.TopLeft));
  1716.                 }
  1717.             }
  1718.             #endregion
  1719.             if (attacker.OnSuperman() && !attacked.MonsterInfo.Boss)
  1720.                 if (attacked.EntityFlag == EntityFlag.Monster)
  1721.                     Damage *= 10;
  1722.                 else
  1723.                     Damage *= 2;
  1724.  
  1725.             try
  1726.             {
  1727.                 if (attacker.OnFatalStrike() && !attacked.MonsterInfo.Boss)
  1728.                     if (attacked.EntityFlag == EntityFlag.Monster)
  1729.                         Damage *= 5;
  1730.             }
  1731.             catch { }
  1732.  
  1733.             uint _B = attacker.Breaktrough;
  1734.             if (!ServerBase.Kernel.Rate(_B /= 20))
  1735.             {
  1736.                 if (!attacked.Transformed)
  1737.                     Damage -= attacked.Defence;
  1738.                 else
  1739.                     Damage -= attacked.TransformationDefence;
  1740.             }
  1741.             else
  1742.             {
  1743.                 _String str = new _String(true);
  1744.                 str.UID = attacker.UID;
  1745.                 str.TextsCount = 1;
  1746.                 str.Type = _String.Effect;
  1747.                 str.Texts.Add("partbehithead");
  1748.                 attacker.Owner.SendScreen(str, true);
  1749.             }
  1750.  
  1751.             Damage -= Damage * attacked.ItemBless / 100;
  1752.  
  1753.             byte dodge = attacked.Dodge;
  1754.             if (dodge > 100)
  1755.                 dodge = 99;
  1756.             if (!attacked.Transformed)
  1757.                 Damage -= Damage * dodge / 100;
  1758.             else
  1759.                 Damage -= Damage * attacked.TransformationDodge / 100;
  1760.  
  1761.             if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  1762.             {
  1763.                 Damage *= 2;
  1764.                 attacker.OnIntensify = false;
  1765.             }
  1766.  
  1767.             if (attacker.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  1768.                 if (!attacker.Transformed)
  1769.                     Damage = (int)(Damage * attacker.StigmaIncrease);
  1770.  
  1771.             if (attacked.EntityFlag == EntityFlag.Monster)
  1772.             {
  1773.                 if (attacked.MapID < 1351 || attacked.MapID > 1354)
  1774.                     Damage = (int)(Damage * (1 + (GetLevelBonus(attacker.Level, attacked.Level) * 0.08)));
  1775.  
  1776.                 if (attacked.MapID < 1351 || attacked.MapID > 1354)
  1777.                     Damage = (int)(Damage * AttackMultiplier(attacker, attacked));
  1778.             }
  1779.             Damage = BattlePowerCalculation(Damage, attacker.BattlePower - attacked.BattlePower);
  1780.             #region LuckTime
  1781.             if (ServerBase.Kernel.Rate(5))
  1782.             {
  1783.                 if (attacker.EntityFlag == EntityFlag.Player)
  1784.                 {
  1785.                     if (attacker.Owner.BlessTime > 0)
  1786.                     {
  1787.                         Damage *= 2;
  1788.                         _String str = new _String(true);
  1789.                         str.UID = attacker.UID;
  1790.                         str.TextsCount = 1;
  1791.                         str.Type = _String.Effect;
  1792.                         str.Texts.Add("LuckyGuy");
  1793.                         attacker.Owner.SendScreen(str, true);
  1794.                     }
  1795.                 }
  1796.             }
  1797.             if (ServerBase.Kernel.Rate(5))
  1798.             {
  1799.                 if (attacked.EntityFlag == EntityFlag.Player)
  1800.                 {
  1801.                     if (attacked.Owner.BlessTime > 0)
  1802.                     {
  1803.                         Damage = 1;
  1804.                         _String str = new _String(true);
  1805.                         str.UID = attacker.UID;
  1806.                         str.TextsCount = 1;
  1807.                         str.Type = _String.Effect;
  1808.                         str.Texts.Add("LuckyGuy");
  1809.                         attacked.Owner.SendScreen(str, true);
  1810.                     }
  1811.                 }
  1812.             }
  1813.             #endregion
  1814.             if (attacked.EntityFlag == EntityFlag.Monster)
  1815.             {
  1816.                 if (Damage >= 700 * attacked.MaxHitpoints)
  1817.                     Damage = (int)(700 * attacked.MaxHitpoints);
  1818.             }
  1819.  
  1820.             if (spell.PowerPercent != 0)
  1821.                 Damage = (int)(Damage * spell.PowerPercent);
  1822.  
  1823.             Damage += attacker.PhysicalDamageIncrease;
  1824.             Damage -= attacked.PhysicalDamageDecrease;
  1825.  
  1826.             if (Damage <= 0)
  1827.                 Damage = 1;
  1828.             AutoRespone(attacker, attacked, ref Damage);
  1829.             #endregion
  1830.             #region AzureShield
  1831.             if (attacked.ContainsFlag2(Update.Flags2.AzureShield))
  1832.             {
  1833.                 if (Damage >= attacked.AzureDamage)
  1834.                 {
  1835.                     Damage -= attacked.AzureDamage;
  1836.                     attacked.AzureDamage = 0;
  1837.                 }
  1838.                 else
  1839.                 {
  1840.                     attacked.AzureDamage -= Damage;
  1841.                     Damage = 1;
  1842.                 }
  1843.  
  1844.                 _String str = new _String(true);
  1845.                 str.UID = attacked.UID;
  1846.                 str.TextsCount = 1;
  1847.                 str.Type = _String.Effect;
  1848.                 str.Texts.Add("ShieldBlock");
  1849.                 if (attacked.EntityFlag == EntityFlag.Player)
  1850.                     attacked.Owner.SendScreen(str, true);
  1851.             }
  1852.             #endregion
  1853.             #region Block
  1854.             if (attacked.Block >= 0)
  1855.             {
  1856.                 uint _bb = attacked.Block;
  1857.                 try
  1858.                 {
  1859.                     if (ServerBase.Kernel.Rate(_bb /= 170))
  1860.                     {
  1861.                         Damage = Damage /= 2;
  1862.                         _String str = new _String(true);
  1863.                         str.UID = attacked.UID;
  1864.                         str.TextsCount = 1;
  1865.                         str.Type = _String.Effect;
  1866.                         str.Texts.Add("ShieldBlock");
  1867.                         if (attacked.EntityFlag == EntityFlag.Player)
  1868.                             attacked.Owner.SendScreen(str, true);
  1869.                     }
  1870.                 }
  1871.                 catch (Exception E)
  1872.                 {
  1873.                     Console.WriteLine(E);
  1874.                 }
  1875.  
  1876.             }
  1877.             #endregion
  1878.             #region Immunity
  1879.             if (attacked.Immunity >= 0)
  1880.             {
  1881.                 uint _bb = attacked.Immunity;
  1882.                 try
  1883.                 {
  1884.                     if (ServerBase.Kernel.Rate(_bb /= 210))
  1885.                     {
  1886.                         Damage = 1;
  1887.                         _String str = new _String(true);
  1888.                         str.UID = attacked.UID;
  1889.                         str.TextsCount = 1;
  1890.                         str.Type = _String.Effect;
  1891.                         str.Texts.Add("bossimmunity");
  1892.                         if (attacked.EntityFlag == EntityFlag.Player)
  1893.                             attacked.Owner.SendScreen(str, true);
  1894.                     }
  1895.                 }
  1896.                 catch (Exception E)
  1897.                 {
  1898.                     Console.WriteLine(E);
  1899.                 }
  1900.             }
  1901.             #endregion
  1902.             #region Elements
  1903.             try
  1904.             {
  1905.                 if (attacked.EntityFlag == EntityFlag.Player)
  1906.                 {
  1907.                     int mr = (int)attacked.MetalResistance * 2;
  1908.                     int wr = (int)attacked.WaterResistance * 2;
  1909.                     int wd = (int)attacked.WoodResistance * 2;
  1910.                     int fr = (int)attacked.FireResistance * 2;
  1911.                     int er = (int)attacked.EarthResistance * 2;
  1912.  
  1913.                     Damage -= mr;
  1914.                     Damage -= fr;
  1915.                     Damage -= wd;
  1916.                     Damage -= er;
  1917.                     Damage -= wr;
  1918.  
  1919.                 }
  1920.                 if (Damage <= 0)
  1921.                     Damage = 1;
  1922.             }
  1923.             catch (Exception E)
  1924.             {
  1925.                 Console.WriteLine(E);
  1926.             }
  1927.             #endregion
  1928.             #region Tortoise
  1929.             if (attacked.EntityFlag == EntityFlag.Player)
  1930.             {
  1931.                 uint _ddmg = (uint)(Damage / 20) * (attacked.Owner.Tortoise);
  1932.                 Damage -= (int)_ddmg;
  1933.             }
  1934.             #endregion
  1935.             #region Nobility Damge
  1936.             if (attacker.NobilityRank != attacked.NobilityRank)
  1937.             {
  1938.                 int addnobility_damage = 0;
  1939.                 if ((byte)attacker.NobilityRank == 12)
  1940.                     addnobility_damage = (Damage * ((byte)attacker.NobilityRank + 45)) / 100;
  1941.                 else
  1942.                     if ((byte)attacker.NobilityRank > 5)
  1943.                         addnobility_damage = (Damage * ((byte)attacker.NobilityRank + 25)) / 100;
  1944.                 if ((byte)attacked.NobilityRank > 5)
  1945.                 {
  1946.                     if ((addnobility_damage - (uint)((Damage * ((byte)attacked.NobilityRank + 8)) / 100)) > 0)
  1947.                     {
  1948.                         addnobility_damage -= (int)((Damage * ((byte)attacked.NobilityRank + 8)) / 100);
  1949.                     }
  1950.                     else
  1951.                     {
  1952.                         if (Damage > (uint)((Damage * ((byte)attacked.NobilityRank + 8)) / 100))
  1953.                         {
  1954.                             Damage -= (int)((Damage * ((byte)attacked.NobilityRank + 8)) / 100);
  1955.                         }
  1956.                         else
  1957.                             Damage = 1;
  1958.                     }
  1959.                 }
  1960.                 if (Damage != 1)
  1961.                 {
  1962.                     Damage += addnobility_damage;
  1963.                 }
  1964.  
  1965.             }
  1966.             #endregion
  1967.             #region Guard
  1968.             if (attacker.Name.Contains("AdventureGuard1") && attacker.EntityFlag == EntityFlag.Monster)
  1969.                 return 700000;
  1970.             if (attacked.Name.Contains("AdventureGuard1") && attacked.EntityFlag == EntityFlag.Monster)
  1971.                 return 1;
  1972.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1973.                 return 1;
  1974.             #endregion
  1975.             #region Kratos
  1976.             if (attacked.Name.Contains("Kratos") && attacked.EntityFlag == EntityFlag.Monster)
  1977.                 return 1;
  1978.             if (attacked.ContainsFlag(Network.GamePackets.Update.Flags.ShurikenVortex))
  1979.                 return 1;
  1980.             #endregion
  1981.             #region Carlos.P[TQ]
  1982.             if (attacked.Name.Contains("Carlos.P[TQ]"))
  1983.                 return 1;
  1984.             #endregion
  1985.  
  1986.             return (uint)Damage;
  1987.         }
  1988.         public static uint Ranged(Entity attacker, SobNpcSpawn attacked)
  1989.         {
  1990.             #region Base Calculate
  1991.             int Damage = 0;
  1992.             Durability(attacker, null, null);
  1993.             if (attacker.Transformed)
  1994.                 return 0;
  1995.             if (attacked.UID == 810 && attacker.Owner.Guild != null)
  1996.             {
  1997.                 if (Game.ConquerStructures.Society.GuildWar.PoleKeeper == attacker.Owner.Guild)
  1998.                 {
  1999.                     return 0;
  2000.                 }
  2001.             }
  2002.             Damage = ServerBase.Kernel.Random.Next(Math.Min((int)attacker.MinAttack, (int)attacker.MaxAttack), Math.Max((int)attacker.MinAttack, (int)attacker.MaxAttack) + 1);
  2003.  
  2004.             if (attacker.OnIntensify && Time32.Now >= attacker.IntensifyStamp.AddSeconds(4))
  2005.             {
  2006.                 Damage *= 2;
  2007.  
  2008.                 attacker.OnIntensify = false;
  2009.             }
  2010.             #region LuckTime
  2011.             if (ServerBase.Kernel.Rate(5))
  2012.             {
  2013.                 if (attacker.EntityFlag == EntityFlag.Player)
  2014.                 {
  2015.                     if (attacker.Owner.BlessTime > 0)
  2016.                     {
  2017.                         Damage *= 2;
  2018.                         _String str = new _String(true);
  2019.                         str.UID = attacker.UID;
  2020.                         str.TextsCount = 1;
  2021.                         str.Type = _String.Effect;
  2022.                         str.Texts.Add("LuckyGuy");
  2023.                         attacker.Owner.SendScreen(str, true);
  2024.                     }
  2025.                 }
  2026.             }
  2027.             #endregion
  2028.             if (attacker.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  2029.                 if (!attacker.Transformed)
  2030.                     Damage = (int)(Damage * attacker.StigmaIncrease);
  2031.  
  2032.             Damage += attacker.PhysicalDamageIncrease;
  2033.             if (Damage <= 0)
  2034.                 Damage = 1;
  2035.             #endregion
  2036.  
  2037.             return (uint)Damage;
  2038.         }
  2039.  
  2040.         public static int RemoveExcessDamage(int CurrentDamage, Entity Attacker, Entity Opponent)
  2041.         {
  2042.             if (Opponent.EntityFlag != EntityFlag.Player)
  2043.                 return CurrentDamage;
  2044.             if (Opponent.Reborn == 1)
  2045.                 CurrentDamage = (int)Math.Round((double)(CurrentDamage * 0.7));
  2046.             else if (Opponent.Reborn == 2)
  2047.                 CurrentDamage = (int)Math.Round((double)(CurrentDamage * 0.5));
  2048.             CurrentDamage = (int)Math.Round((double)(CurrentDamage * (1.00 - (Opponent.ItemBless * 0.01))));
  2049.  
  2050.             return CurrentDamage;
  2051.         }
  2052.  
  2053.         public static bool ChanceSuccess(int c, int inchance)
  2054.         {
  2055.             Random rand = new Random();
  2056.             int e = rand.Next(inchance);
  2057.  
  2058.             if (e != 0)
  2059.                 if (e <= c)
  2060.                     return true;
  2061.  
  2062.             return false;
  2063.         }
  2064.  
  2065.         public static int BattlePowerCalculation(int damage, int battlepowerExcess)
  2066.         {
  2067.             if (battlepowerExcess == 0)
  2068.                 return damage;
  2069.  
  2070.             if (battlepowerExcess < -50)
  2071.                 battlepowerExcess = -50;
  2072.  
  2073.             if (battlepowerExcess > 50)
  2074.                 battlepowerExcess = 50;
  2075.  
  2076.             return damage + (damage * battlepowerExcess / 100);
  2077.         }
  2078.  
  2079.         public static uint Percent(Entity attacked, float percent)
  2080.         {
  2081.             return (uint)(attacked.Hitpoints * percent);
  2082.         }
  2083.  
  2084.         public static uint Percent(SobNpcSpawn attacked, float percent)
  2085.         {
  2086.             return (uint)(attacked.Hitpoints * percent);
  2087.         }
  2088.  
  2089.         public static uint Percent(int target, float percent)
  2090.         {
  2091.             return (uint)(target * percent);
  2092.         }
  2093.  
  2094.         private static void Durability(Entity attacker, Entity attacked, Database.SpellInformation spell)
  2095.         {
  2096.  
  2097.             if (spell != null)
  2098.                 if (!spell.CanKill)
  2099.                     return;
  2100.             if (attacker.EntityFlag == EntityFlag.Player)
  2101.                 if (attacker.Owner.Map.ID == 1039)
  2102.                     return;
  2103.             #region Attack
  2104.             if (attacker != null)
  2105.                 if (attacker.EntityFlag == EntityFlag.Player)
  2106.                 {
  2107.                     for (byte i = 4; i <= 6; i++)
  2108.                     {
  2109.                         if (!attacker.Owner.Equipment.Free(i))
  2110.                         {
  2111.                             var item = attacker.Owner.Equipment.TryGetItem(i);
  2112.                             if (i == 5)
  2113.                             {
  2114.                                 if (Network.PacketHandler.IsArrow(item.ID))
  2115.                                 {
  2116.                                     continue;
  2117.                                 }
  2118.                             }
  2119.                             if (ServerBase.Kernel.Rate(20, 100))
  2120.                             {
  2121.                                 if (item.Durability != 0)
  2122.                                 {
  2123.                                     item.Durability--;
  2124.                                     if (item.Durability == 0)
  2125.                                         attacker.Owner.UnloadItemStats(item, true);
  2126.                                     Database.ConquerItemTable.UpdateDurabilityItem(item);
  2127.                                     item.Mode = Enums.ItemMode.Update;
  2128.                                     item.Send(attacker.Owner);
  2129.                                     item.Mode = Enums.ItemMode.Default;
  2130.                                 }
  2131.                             }
  2132.                         }
  2133.                         if (i == 6)
  2134.                             break;
  2135.                     }
  2136.                     if (!attacker.Owner.Equipment.Free(10))
  2137.                     {
  2138.                         var item = attacker.Owner.Equipment.TryGetItem(10);
  2139.                         if (ServerBase.Kernel.Rate(20, 100))
  2140.                         {
  2141.                             if (item.Durability != 0)
  2142.                             {
  2143.                                 item.Durability--;
  2144.                                 if (item.Durability == 0)
  2145.                                     attacker.Owner.UnloadItemStats(item, true);
  2146.                                 Database.ConquerItemTable.UpdateDurabilityItem(item);
  2147.                                 item.Mode = Enums.ItemMode.Update;
  2148.                                 item.Send(attacker.Owner);
  2149.                                 item.Mode = Enums.ItemMode.Default;
  2150.                             }
  2151.                         }
  2152.                     }
  2153.                 }
  2154.             #endregion
  2155.             #region Defence
  2156.             if (attacked != null)
  2157.                 if (attacked.EntityFlag == EntityFlag.Player)
  2158.                 {
  2159.                     for (byte i = 1; i <= 8; i++)
  2160.                     {
  2161.                         if (i == 4 || i == 6 || i == 7)
  2162.                             continue;
  2163.                         if (!attacked.Owner.Equipment.Free(i))
  2164.                         {
  2165.                             var item = attacked.Owner.Equipment.TryGetItem(i);
  2166.                             if (i == 5)
  2167.                             {
  2168.                                 if (Network.PacketHandler.ItemPosition(item.ID) != 5 && Network.PacketHandler.IsArrow(item.ID))
  2169.                                 {
  2170.                                     continue;
  2171.                                 }
  2172.                             }
  2173.                             if (ServerBase.Kernel.Rate(30, 100))
  2174.                             {
  2175.                                 if (item.Durability != 0)
  2176.                                 {
  2177.                                     item.Durability--;
  2178.                                     if (item.Durability == 0)
  2179.                                         attacked.Owner.UnloadItemStats(item, true);
  2180.                                     Database.ConquerItemTable.UpdateDurabilityItem(item);
  2181.  
  2182.                                     item.Mode = Enums.ItemMode.Update;
  2183.                                     item.Send(attacked.Owner);
  2184.                                     item.Mode = Enums.ItemMode.Default;
  2185.                                 }
  2186.                             }
  2187.                         }
  2188.                         if (i == 8)
  2189.                             break;
  2190.                     }
  2191.                     if (!attacked.Owner.Equipment.Free(11) && ServerBase.Kernel.Rate(30, 100))
  2192.                     {
  2193.                         var item = attacked.Owner.Equipment.TryGetItem(11);
  2194.                         if (ServerBase.Kernel.Rate(30, 100))
  2195.                         {
  2196.                             if (item.Durability != 0)
  2197.                             {
  2198.                                 item.Durability--;
  2199.                                 if (item.Durability == 0)
  2200.                                     attacked.Owner.UnloadItemStats(item, true);
  2201.                                 Database.ConquerItemTable.UpdateDurabilityItem(item);
  2202.                                 item.Mode = Enums.ItemMode.Update;
  2203.                                 item.Send(attacked.Owner);
  2204.                                 item.Mode = Enums.ItemMode.Default;
  2205.                             }
  2206.                         }
  2207.                     }
  2208.                 }
  2209.  
  2210.             #endregion
  2211.         }
  2212.  
  2213.         private static void AutoRespone(Entity attacker, Entity attacked, ref int Damage)
  2214.         {
  2215.             try
  2216.             {
  2217.                 if (attacked.EntityFlag == EntityFlag.Player)
  2218.                 {
  2219.                     if (attacked.CounterKillSwitch && ServerBase.Kernel.Rate(10) && !attacked.ContainsFlag(Update.Flags.Fly) && Time32.Now > attacker.CounterKillStamp.AddSeconds(15))
  2220.                     {
  2221.                         attacker.CounterKillStamp = Time32.Now;
  2222.                         uint damage = Melee(attacked, attacker);
  2223.                         Database.SpellInformation information = Database.SpellTable.SpellInformations[6003][attacked.Owner.Spells[6003].Level];
  2224.                         damage = (uint)(Percent((int)damage, information.Percent) / 100);
  2225.                         Network.GamePackets.Attack attack = new Conquer_Online_Server.Network.GamePackets.Attack(true);
  2226.                         attack.Attacked = attacker.UID;
  2227.                         attack.Attacker = attacked.UID;
  2228.                         attack.AttackType = Network.GamePackets.Attack.Scapegoat;
  2229.                         attack.Damage = 0;
  2230.                         attack.ResponseDamage = damage;
  2231.                         attack.X = attacked.X;
  2232.                         attack.Y = attacked.Y;
  2233.  
  2234.                         if (attacker.Hitpoints <= damage)
  2235.                         {
  2236.                             if (attacker.EntityFlag == EntityFlag.Player)
  2237.                             {
  2238.                                 if (attacked.Owner.QualifierGroup != null)
  2239.                                     attacked.Owner.QualifierGroup.UpdateDamage(attacked.Owner, attacker.Hitpoints);
  2240.                                 attacker.Owner.SendScreen(attack, true);
  2241.                                 attacked.AttackPacket = null;
  2242.                             }
  2243.                             else
  2244.                             {
  2245.                                 attacker.MonsterInfo.SendScreen(attack);
  2246.                             }
  2247.                             attacker.Die(attacked);
  2248.                         }
  2249.                         else
  2250.                         {
  2251.                             attacker.Hitpoints -= damage;
  2252.                             if (attacker.EntityFlag == EntityFlag.Player)
  2253.                             {
  2254.                                 if (attacked.Owner.QualifierGroup != null)
  2255.                                     attacked.Owner.QualifierGroup.UpdateDamage(attacked.Owner, damage);
  2256.                                 attacker.Owner.SendScreen(attack, true);
  2257.                             }
  2258.                             else
  2259.                             {
  2260.                                 attacker.MonsterInfo.SendScreen(attack);
  2261.                             }
  2262.                         }
  2263.                         Damage = 0;
  2264.                     }
  2265.                     else if (attacked.Owner.Spells.ContainsKey(3060) && ServerBase.Kernel.Rate(10))
  2266.                     {
  2267.                         uint damage = (uint)(Damage / 10);
  2268.                         if (damage <= 0)
  2269.                             damage = 1;
  2270.                         Network.GamePackets.Attack attack = new Conquer_Online_Server.Network.GamePackets.Attack(true);
  2271.                         attack.Attacked = attacker.UID;
  2272.                         attack.Attacker = attacked.UID;
  2273.                         attack.AttackType = Network.GamePackets.Attack.Reflect;
  2274.                         attack.Damage = damage;
  2275.                         attack.ResponseDamage = damage;
  2276.                         attack.X = attacked.X;
  2277.                         attack.Y = attacked.Y;
  2278.  
  2279.                         if (attacker.Hitpoints <= damage)
  2280.                         {
  2281.                             if (attacker.EntityFlag == EntityFlag.Player)
  2282.                             {
  2283.                                 if (attacked.Owner.QualifierGroup != null)
  2284.                                     attacked.Owner.QualifierGroup.UpdateDamage(attacked.Owner, attacker.Hitpoints);
  2285.                                 attacker.Owner.SendScreen(attack, true);
  2286.                                 attacked.AttackPacket = null;
  2287.                             }
  2288.                             else
  2289.                             {
  2290.                                 attacker.MonsterInfo.SendScreen(attack);
  2291.                             }
  2292.                             attacker.Die(attacked);
  2293.                         }
  2294.                         else
  2295.                         {
  2296.                             attacker.Hitpoints -= damage;
  2297.                             if (attacker.EntityFlag == EntityFlag.Player)
  2298.                             {
  2299.                                 if (attacked.Owner.QualifierGroup != null)
  2300.                                     attacked.Owner.QualifierGroup.UpdateDamage(attacked.Owner, damage);
  2301.                                 attacker.Owner.SendScreen(attack, true);
  2302.                             }
  2303.                             else
  2304.                             {
  2305.                                 attacker.MonsterInfo.SendScreen(attack);
  2306.                             }
  2307.                         }
  2308.                         Damage = 0;
  2309.                     }
  2310.                 }
  2311.             }
  2312.             catch { }
  2313.         }
  2314.  
  2315.         public static int GetLevelBonus(int l1, int l2)
  2316.         {
  2317.             int num = l1 - l2;
  2318.             int bonus = 0;
  2319.             if (num >= 3)
  2320.             {
  2321.                 num -= 3;
  2322.                 bonus = 1 + (num / 5);
  2323.             }
  2324.             return bonus;
  2325.         }
  2326.  
  2327.         private static double AttackMultiplier(Entity attacker, Entity attacked)
  2328.         {
  2329.             if (attacked.Level > attacker.Level)
  2330.                 return 1;
  2331.             return ((double)(attacker.Level - attacked.Level)) / 10 + 1;
  2332.         }
  2333.  
  2334.         public static ulong CalculateExpBonus(ushort Level, ushort MonsterLevel, ulong Experience)
  2335.         {
  2336.             int leveldiff = (2 + Level - MonsterLevel);
  2337.             if (leveldiff < -5)
  2338.                 Experience = (ulong)(Experience * 1.3);
  2339.             else if (leveldiff < -1)
  2340.                 Experience = (ulong)(Experience * 1.2);
  2341.             else if (leveldiff == 4)
  2342.                 Experience = (ulong)(Experience * 0.8);
  2343.             else if (leveldiff == 5)
  2344.                 Experience = (ulong)(Experience * 0.3);
  2345.             else if (leveldiff > 5)
  2346.                 Experience = (ulong)(Experience * 0.1);
  2347.             return Experience;
  2348.         }
  2349.  
  2350.         #region Point Distance
  2351.         public static int PointDistance(double x1, double y1, double x2, double y2)
  2352.         {
  2353.             return (int)Math.Sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
  2354.         }
  2355.         #endregion
  2356.     }
  2357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement