Advertisement
Guest User

Untitled

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