Advertisement
MrPoP

ItemHandlerScript

Aug 24th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1. public class ItemHandlerScript
  2.     {
  3.         public static void Handle(MsgItemInfo UseItem, GameState client)
  4.         {
  5.             using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("itemscript").Where("useitemid", UseItem.ID))
  6.             using (var rdr = new MySqlReader(cmd))
  7.             {
  8.                 if (rdr.Read())
  9.                 {
  10.                     if (!client.Inventory.Contains(UseItem.ID, rdr.ReadByte("removecount")))
  11.                         return;
  12.                     if (rdr.ReadUInt32("giveitemid") > 0)
  13.                     {
  14.                         Database.ConquerItemInformation infos = new Database.ConquerItemInformation(rdr.ReadUInt32("giveitemid"), 0);
  15.                         if (infos == null)
  16.                             return;
  17.                         if (infos.BaseInformation.StackSize > 0)
  18.                         {
  19.                             if (client.Inventory.Count <= 39)
  20.                             {
  21.                                 if (rdr.ReadUInt32("chance") > 0)
  22.                                 {
  23.                                     if (Kernel.ChanceSuccess((int)rdr.ReadUInt32("chance")))
  24.                                     {
  25.                                         client.Inventory.Add(infos.BaseInformation.ID, rdr.ReadByte("giveitemplus"), rdr.ReadByte("givecount"));
  26.                                     }
  27.                                 }
  28.                                 else
  29.                                 {
  30.                                     client.Inventory.Add(infos.BaseInformation.ID, rdr.ReadByte("giveitemplus"), rdr.ReadByte("givecount"));
  31.                                 }
  32.                             }
  33.                             else
  34.                             {
  35.                                 client.Send(Constants.FullInventory);
  36.                                 return;
  37.                             }
  38.                         }
  39.                         else if (infos.BaseInformation.StackSize == 0)
  40.                         {
  41.                             if (client.Inventory.Count <= (40 - rdr.ReadByte("givecount")))
  42.                             {
  43.                                 if (rdr.ReadUInt32("chance") > 0)
  44.                                 {
  45.                                     if (Kernel.ChanceSuccess((int)rdr.ReadUInt32("chance")))
  46.                                     {
  47.                                         client.Inventory.Add(infos.BaseInformation.ID, rdr.ReadByte("giveitemplus"), rdr.ReadByte("givecount"));
  48.                                     }
  49.                                 }
  50.                                 else
  51.                                 {
  52.                                     client.Inventory.Add(infos.BaseInformation.ID, rdr.ReadByte("giveitemplus"), rdr.ReadByte("givecount"));
  53.                                 }
  54.                             }
  55.                             else
  56.                             {
  57.                                 client.Send(Constants.FullInventory);
  58.                                 return;
  59.                             }
  60.                         }
  61.                         infos = null;
  62.                     }
  63.                     else if (rdr.ReadUInt16("actionid") > 0)
  64.                     {
  65.                         client.Send(MsgAction.Custom(rdr.ReadUInt16("actionid"), client.Player.UID));
  66.                     }
  67.                     if (rdr.ReadBoolean("removeused"))
  68.                     {
  69.                         client.Inventory.Remove(UseItem.ID, rdr.ReadByte("removecount"));
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement