Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 19.37 KB | None | 0 0
  1. public static void EquipItem(ItemUsage itemUsage, GameState client)
  2.         {
  3.             ConquerItem item = null;
  4.             if (itemUsage.dwParam == 17 || itemUsage.dwParam == 9)
  5.             {
  6.                 client.Entity.AttackPacket = null;
  7.                 if (client.WarDrobe.TryGetItem(itemUsage.UID, out item) && client.Booth == null)
  8.                 {
  9.                     uint original = (ushort)itemUsage.dwParam;
  10.                     if (item.Suspicious) return;
  11.                     Positions pos = GetPositionFromID(item.ID);
  12.                     if (itemUsage.dwParam > 20 && itemUsage.dwParam < 30 && (ushort)pos < 10)
  13.                     {
  14.                         pos += 20;
  15.  
  16.                     }
  17.                     if ((ushort)pos == 4 && original == 5 || (ushort)pos == 24 && original == 25 || (ushort)pos == 15 && original == 16)
  18.                     {
  19.                         pos += 1;
  20.                     }
  21.                     itemUsage.dwParam = (ushort)pos;
  22.                     if (pos == Positions.Inventory)
  23.                     {
  24.                         UseItem(item, client); return;
  25.                     }
  26.                     if (ItemPosition(item.ID) == ConquerItem.Garment)
  27.                         if (client.Entity.Tournament_Signed) return;
  28.  
  29.                     item.Position = (ushort)itemUsage.dwParam;
  30.                     if (client.Equipment.Free((byte)itemUsage.dwParam))
  31.                     {
  32.                         item.Position = (byte)itemUsage.dwParam;
  33.                         client.Equipment.Add(item);
  34.                         item.Mode = Game.Enums.ItemMode.Update;
  35.                     }
  36.                     else
  37.                     {
  38.                         client.Equipment.RemoveWrap((byte)itemUsage.dwParam);
  39.                         item.Position = (byte)itemUsage.dwParam;
  40.                         client.Equipment.Add(item);
  41.                     }
  42.                     client.CalculateStatBonus();
  43.                     client.CalculateHPBonus();
  44.                     client.LoadItemStats();
  45.                     ClientEquip equips = new ClientEquip();
  46.                     equips.DoEquips(client);
  47.                     client.Send(equips);
  48.                     Database.ConquerItemTable.UpdateLocation(item, client);
  49.                     client.Equipment.UpdateEntityPacket();
  50.                     WindowStats Stats = new WindowStats(client);
  51.                     client.Send(Stats.ToArray());
  52.                     if (client.Team != null)
  53.                     {
  54.                         client.Team.GetClanShareBp(client);
  55.                     }
  56.  
  57.                 }
  58.                 return;
  59.             }
  60.             else
  61.             {
  62.                 client.Entity.AttackPacket = null;
  63.                 if (client.Inventory.TryGetItem(itemUsage.UID, out item) || client.WarDrobe.TryGetItem(itemUsage.UID, out item) && client.Booth == null)
  64.                 {
  65.                     if (item.Suspicious) return;
  66.                     Positions pos = GetPositionFromID(item.ID);
  67.                     if (pos == Positions.Inventory)
  68.                     {
  69.                         UseItem(item, client); return;
  70.                     }
  71.                     if (ItemPosition(item.ID) == ConquerItem.Garment)
  72.                         if (client.Entity.Tournament_Signed) return;
  73.                     #region Sanity Checks
  74.                     bool can2hand = false;
  75.                     bool can2wpn = false;
  76.                     uint dwExtra = 0;
  77.                     if (itemUsage.dwParam > 20)
  78.                         dwExtra = 20;
  79.                     if (client.Entity.Class >= 10 && client.Entity.Class <= 85)
  80.                         can2hand = true;
  81.                     if (client.Entity.Class >= 10 && client.Entity.Class <= 15 ||
  82.                         client.Entity.Class >= 40 && client.Entity.Class <= 45 ||
  83.                         client.Entity.Class >= 50 && client.Entity.Class <= 55 ||
  84.                         client.Entity.Class >= 60 && client.Entity.Class <= 65 ||
  85.                         client.Entity.Class >= 70 && client.Entity.Class <= 75 ||
  86.                         client.Entity.Class >= 80 && client.Entity.Class <= 85)
  87.                         can2wpn = true;
  88.                     if (client.Entity.Class >= 70 && client.Entity.Class <= 75 ||
  89.                         client.Entity.Class >= 40 && client.Entity.Class <= 45)
  90.                         can2wpn = true;
  91.                     if (client.Entity.Class >= 100 && client.Entity.Class <= 145)
  92.                     {
  93.                         if (!client.Equipment.Free(4))
  94.                         {
  95.                             if (IsEpicBacksword(client.Equipment.TryGetItem(4).ID))
  96.                             {
  97.                                 if (IsEpicHossu(item.ID))
  98.                                 {
  99.                                     can2wpn = true;
  100.                                 }
  101.                             }
  102.                         }
  103.                     }
  104.                     if (client.Entity.Class >= 20 && client.Entity.Class <= 25)
  105.                     {
  106.                         can2hand = true;
  107.                         can2wpn = true;
  108.                     }
  109.                     if (client.Entity.Class >= 160 && client.Entity.Class <= 165)
  110.                     {
  111.                         can2hand = true;
  112.                         can2wpn = true;
  113.                     }
  114.                     if (!Equipable(item, client)) return;
  115.                     if (ItemPosition(item.ID) == 5)
  116.                     {
  117.                         itemUsage.dwParam = 5 + dwExtra;
  118.                         if (!can2hand && !can2wpn) return;
  119.                         if (client.Equipment.Free(4 + dwExtra) || (client.Equipment.TryGetItem(4 + dwExtra).ID / 1000 != 500 && IsArrow(item.ID)))
  120.                             return;
  121.                     }
  122.                     if (ItemPosition(item.ID) == 4)
  123.                     {
  124.                         if (itemUsage.dwParam == 5 + dwExtra)
  125.                             if (!can2hand || !can2wpn) return;
  126.                     }
  127.                     if (!((itemUsage.dwParam == 4 + dwExtra || itemUsage.dwParam == 5 + dwExtra) && (ItemPosition(item.ID) == 4 || ItemPosition(item.ID) == 5)))
  128.                     {
  129.                         if (!IsAccessory(item.ID))
  130.                             itemUsage.dwParam = ItemPosition(item.ID) + dwExtra;
  131.                     }
  132.                     bool twohand = IsTwoHand(item.ID);
  133.                     if (!twohand && itemUsage.dwParam == 4 + dwExtra)
  134.                     {
  135.                         if (!client.Equipment.Free((byte)(5 + dwExtra)))
  136.                         {
  137.                             if (client.Inventory.Count < 40)
  138.                             {
  139.                                 if (IsArrow(client.Equipment.TryGetItem((byte)(5 + dwExtra)).ID))
  140.                                     client.Equipment.Remove((byte)(5 + dwExtra));
  141.                                 else
  142.                                 {
  143.                                     if (client.Equipment.TryGetItem((byte)(4 + dwExtra)) != null)
  144.                                     {
  145.                                         if (IsTwoHand(client.Equipment.TryGetItem((byte)(4 + dwExtra)).ID))
  146.                                             client.Equipment.Remove((byte)(4 + dwExtra));
  147.                                     }
  148.                                 }
  149.                             }
  150.                         }
  151.                     }
  152.                     if ((itemUsage.dwParam - dwExtra) == 5)
  153.                     {
  154.                         if ((item.ID / 1000) == 421 || IsTwoHand(item.ID)) return;
  155.                         var rItem = client.Equipment.TryGetItem((byte)(4 + dwExtra));
  156.                         if (rItem != null)
  157.                         {
  158.                             if (rItem.IsTwoHander())
  159.                             {
  160.                                 if (IsArrow(item.ID))
  161.                                 {
  162.                                     if (rItem.ID / 1000 != 500) return;
  163.                                 }
  164.                                 else
  165.                                 {
  166.                                     if (IsShield(item.ID))
  167.                                     {
  168.                                         if ((rItem.ID / 1000) == 421) return;
  169.                                         if (!client.Spells.ContainsKey(10311) && client.Entity.FirstRebornClass == 25 && client.Entity.SecondRebornClass == 25)//Perseverance
  170.                                         {
  171.                                             client.Send(new Message("You need to know Perseverance (Warrior Pure skill) to be able to wear 2-handed weapon and shield.", System.Drawing.Color.Red, Message.Talk));
  172.                                             return;
  173.                                         }
  174.                                     }
  175.                                     else itemUsage.dwParam = 4 + dwExtra;
  176.                                 }
  177.                             }
  178.                         }
  179.                     }
  180.                     if (itemUsage.dwParam == 4 + dwExtra)
  181.                         if (client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly))
  182.                             if (item.ID / 1000 != 500)
  183.                                 return;
  184.  
  185.                     if (itemUsage.dwParam == 4 + dwExtra)
  186.                         if (client.Entity.ContainsFlag3((ulong)FlagsUpdate.Flags3.PathOfShadow))
  187.                             if (item.ID / 1000 != 613)
  188.                                 return;
  189.  
  190.                     if (!(client.Entity.Class >= 50 && client.Entity.Class <= 55))
  191.                         if ((item.ID / 1000) == 601)
  192.                             if ((itemUsage.dwParam - dwExtra) == 5)
  193.                                 return;
  194.                     #endregion
  195.  
  196.                     if (client.Map.ID == 1039)
  197.                         client.Entity.AttackPacket = null;
  198.  
  199.                     item.Position = (ushort)itemUsage.dwParam;
  200.                     if (ItemPosition(item.ID) == 5 && !IsArrow(item.ID))
  201.                     {
  202.                         if (IsTwoHand(client.Equipment.TryGetItem((byte)(4 + dwExtra)).ID))
  203.                         {
  204.                             if (!client.Spells.ContainsKey(10311))
  205.                             {
  206.                                 client.Send(new Message("You need to know Perseverance (Warrior Pure skill) to be able to wear 2-handed weapon and shield.", System.Drawing.Color.Red, Message.Talk));
  207.                                 return;
  208.                             }
  209.                         }
  210.                     }
  211.                     #region Checks itemType
  212.                     uint itemType = item.ID / 1000;
  213.                     if (itemType == 421)//Backsword
  214.                     {
  215.                         if (item.Position == 5 + dwExtra)
  216.                         {
  217.                             item.Position = 0; return;
  218.                         }
  219.                     }
  220.                     if (itemType == 900)
  221.                     {
  222.                         if (!(client.Entity.Class >= 20 && client.Entity.Class <= 25))
  223.                         {
  224.                             item.Position = 0; return;
  225.                         }
  226.                     }
  227.                     if (itemType == 613)//Knife
  228.                     {
  229.                         if ((client.Entity.Class >= 70 && client.Entity.Class <= 75) || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 50 && client.Entity.Class <= 55 || (client.Entity.Class >= 20 && client.Entity.Class <= 25 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135)))))))
  230.                         {
  231.                             item.Position = 0; return;
  232.                         }
  233.                     }
  234.                     if (itemType == 511)//Scythe
  235.                     {
  236.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 70 && client.Entity.Class <= 75 || (client.Entity.Class >= 20 && client.Entity.Class <= 25 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135)))))))
  237.                         {
  238.                             item.Position = 0; return;
  239.                         }
  240.                     }
  241.                     if (itemType == 601)//Katana
  242.                     {
  243.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 70 && client.Entity.Class <= 75 || (client.Entity.Class >= 20 && client.Entity.Class <= 25 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135)))))))
  244.                         {
  245.                             item.Position = 0; return;
  246.                         }
  247.                     }
  248.                     if (itemType == 614)//CrossSaber
  249.                     {
  250.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 70 && client.Entity.Class <= 75 || (client.Entity.Class >= 20 && client.Entity.Class <= 25 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135))))))
  251.                         {
  252.                             item.Position = 0; return;
  253.                         }
  254.                     }
  255.                     if (itemType == 611)//Rapier
  256.                     {
  257.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 50 && client.Entity.Class <= 55 || (client.Entity.Class >= 20 && client.Entity.Class <= 25 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135)))))))
  258.                         {
  259.                             item.Position = 0; return;
  260.                         }
  261.                     }
  262.                     if (itemType == 612)//Pistol
  263.                     {
  264.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 50 && client.Entity.Class <= 55 || (client.Entity.Class >= 20 && client.Entity.Class <= 25 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135)))))))
  265.                         {
  266.                             item.Position = 0; return;
  267.                         }
  268.                     }
  269.                     if (itemType == 421)//Backsword
  270.                     {
  271.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 50 && client.Entity.Class <= 55 || (client.Entity.Class >= 20 && client.Entity.Class <= 25 || (client.Entity.Class >= 70 && client.Entity.Class <= 75))))))
  272.                         {
  273.                             item.Position = 0; return;
  274.                         }
  275.                     }
  276.                     if (itemType == 610) // Beads
  277.                     {
  278.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 70 && client.Entity.Class <= 75 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 50 && client.Entity.Class <= 55 || (client.Entity.Class >= 20 && client.Entity.Class <= 25 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135)))))))
  279.                         {
  280.                             item.Position = 0; return;
  281.                         }
  282.                     }
  283.                     if (itemType == 131)//warrior armor
  284.                     {
  285.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 70 && client.Entity.Class <= 75 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135))))))
  286.                         {
  287.                             item.Position = 0; return;
  288.                         }
  289.                     }
  290.                     if (itemType == 111)//WarriorHelmet
  291.                     {
  292.                         if ((client.Entity.Class >= 40 && client.Entity.Class <= 45) || (client.Entity.Class >= 70 && client.Entity.Class <= 75 || (client.Entity.Class >= 10 && client.Entity.Class <= 15 || (client.Entity.Class >= 60 && client.Entity.Class <= 65 || (client.Entity.Class >= 142 && client.Entity.Class <= 145 || (client.Entity.Class >= 132 && client.Entity.Class <= 135))))))
  293.                         {
  294.                             item.Position = 0; return;
  295.                         }
  296.                     }
  297.                     #endregion
  298.                     client.Inventory.Remove(item, Game.Enums.ItemUse.Move, true);
  299.                     if (client.Equipment.Free((byte)itemUsage.dwParam))
  300.                     {
  301.                         if (twohand)
  302.                             client.Equipment.Remove((byte)(5 + dwExtra));
  303.                         item.Position = (byte)itemUsage.dwParam;
  304.                         client.Equipment.Add(item);
  305.                         item.Mode = Game.Enums.ItemMode.Update;
  306.                         item.Send(client);
  307.                     }
  308.                     else
  309.                     {
  310.                         if (twohand)
  311.                             client.Equipment.Remove((byte)(5 + dwExtra));
  312.                         client.Equipment.Remove((byte)itemUsage.dwParam);
  313.                         item.Position = (byte)itemUsage.dwParam;
  314.                         client.Equipment.Add(item);
  315.                     }
  316.                     client.CalculateStatBonus();
  317.                     client.CalculateHPBonus();
  318.                     client.LoadItemStats();
  319.                     ClientEquip equips = new ClientEquip();
  320.                     equips.DoEquips(client);
  321.                     client.Send(equips);
  322.                     Database.ConquerItemTable.UpdateLocation(item, client);
  323.                     client.Equipment.UpdateEntityPacket();
  324.                     WindowStats Stats = new WindowStats(client);
  325.                     client.Send(Stats.ToArray());
  326.                     if (item != null)
  327.                     {
  328.                         if (Database.PerfectionTable.PerfectItems.ContainsKey(item.UID))
  329.                         {
  330.                             Database.PerfectionTable.PerfectItems[item.UID].Position = item.Position;
  331.                         }
  332.                     }
  333.                     if (client.Team != null)
  334.                     {
  335.                         client.Team.GetClanShareBp(client);
  336.                     }
  337.                 }
  338.             }
  339.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement