Guest User

www.criahabbos.ga

a guest
Jan 2nd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Collections.Generic;
  5. using System.Collections.Concurrent;
  6. using Plus.Communication.Packets.Outgoing.Handshake;
  7.  
  8. using Plus.Communication.Packets.Incoming;
  9. using Plus.HabboHotel.Rooms;
  10. using Plus.HabboHotel.Users;
  11. using Plus.Communication.Packets.Outgoing.Rooms.Chat;
  12. using Plus.Communication.Packets.Outgoing.Inventory.Furni;
  13. using Plus.Communication.Packets.Outgoing.Catalog;
  14.  
  15. namespace Plus.HabboHotel.Items.Wired.Boxes.Effects
  16. {
  17. class GiveRewardBox : IWiredItem
  18. {
  19. public Room Instance { get; set; }
  20. public Item Item { get; set; }
  21. public WiredBoxType Type { get { return WiredBoxType.EffectGiveReward; } }
  22. public ConcurrentDictionary<int, Item> SetItems { get; set; }
  23. public string StringData { get; set; }
  24. public bool BoolData { get; set; }
  25. public string ItemsData { get; set; }
  26.  
  27. public GiveRewardBox(Room Instance, Item Item)
  28. {
  29. this.Instance = Instance;
  30. this.Item = Item;
  31. this.SetItems = new ConcurrentDictionary<int, Item>();
  32. }
  33.  
  34. public void HandleSave(ClientPacket Packet)
  35. {
  36. int Unknown = Packet.PopInt();
  37. int Often = Packet.PopInt();
  38. bool Unique = (Packet.PopInt() == 1);
  39. int Limit = Packet.PopInt();
  40. int Often_No = Packet.PopInt();
  41. string Reward = Packet.PopString();
  42.  
  43. this.BoolData = Unique;
  44. this.StringData = Reward + "-" + Often + "-" + Limit;
  45. }
  46.  
  47. public bool Execute(params object[] Params)
  48. {
  49. if (Params == null || Params.Length == 0)
  50. return false;
  51.  
  52. Habbo Owner = PlusEnvironment.GetHabboById(Item.UserID);
  53. if (Owner == null || !Owner.GetPermissions().HasRight("room_item_wired_rewards"))
  54. return false;
  55.  
  56. Habbo Player = (Habbo)Params[0];
  57. if (Player == null || Player.GetClient() == null)
  58. return false;
  59.  
  60. RoomUser User = Player.CurrentRoom.GetRoomUserManager().GetRoomUserByHabbo(Player.Username);
  61. if (User == null)
  62. return false;
  63.  
  64. if (String.IsNullOrEmpty(StringData))
  65. return false;
  66.  
  67. int amountLeft = int.Parse(this.StringData.Split('-')[2]);
  68. int often = int.Parse(this.StringData.Split('-')[1]);
  69. bool unique = this.BoolData;
  70.  
  71. bool premied = false;
  72.  
  73. if (amountLeft == 1)
  74. {
  75. Player.GetClient().SendNotification("Os prêmios acabaram, volte mais tarde.");
  76. return true;
  77. }
  78.  
  79. foreach (var dataStr in (this.StringData.Split('-')[0]).Split(';'))
  80. {
  81. var dataArray = dataStr.Split(',');
  82.  
  83. var isbadge = dataArray[0] == "0";
  84. var code = dataArray[1];
  85. var percentage = int.Parse(dataArray[2]);
  86.  
  87. var random = PlusEnvironment.GetRandomNumber(0, 100);
  88.  
  89. if (!unique && percentage < random)
  90.  
  91. continue;
  92.  
  93. premied = true;
  94.  
  95.  
  96. if (isbadge)
  97. {
  98.  
  99. if (Player.GetBadgeComponent().HasBadge(code))
  100. Player.GetClient().SendMessage(new WhisperComposer(User.VirtualId, "Oops, parece que você já tem este emblema.", 0, User.LastBubble));
  101.  
  102. else
  103. {
  104. Player.GetBadgeComponent().GiveBadge(code, true, Player.GetClient());
  105. Player.GetClient().SendNotification("Você recebeu um emblema!");
  106. }
  107. }
  108. else
  109. {
  110. ItemData ItemData = null;
  111.  
  112. if (!PlusEnvironment.GetGame().GetItemManager().GetItem(int.Parse(code), out ItemData))
  113. {
  114. Player.GetClient().SendMessage(new WhisperComposer(User.VirtualId, "ITEM ID não existe: " + code, 0, User.LastBubble));
  115. return false;
  116. }
  117.  
  118. Item Itemc = ItemFactory.CreateSingleItemNullable(ItemData, Player.GetClient().GetHabbo(), "", "", 0, 0, 0);
  119.  
  120.  
  121. if (Itemc != null)
  122. {
  123. Player.GetClient().GetHabbo().GetInventoryComponent().TryAddItem(Itemc);
  124. Player.GetClient().SendMessage(new FurniListNotificationComposer(Itemc.Id, 1));
  125. Player.GetClient().SendMessage(new PurchaseOKComposer());
  126. Player.GetClient().SendMessage(new FurniListAddComposer(Itemc));
  127. Player.GetClient().SendMessage(new FurniListUpdateComposer());
  128. Player.GetClient().SendNotification("Você acaba de receber um mobi, confira o seu inventário.");
  129. }
  130. }
  131. }
  132.  
  133. if (!premied)
  134. {
  135. Player.GetClient().SendNotification("Sorte da próxima vez. :(");
  136. }
  137. else if (amountLeft > 1)
  138. {
  139. amountLeft--;
  140. this.StringData.Split('-')[2] = amountLeft.ToString();
  141. }
  142.  
  143. return true;
  144. }
  145. }
  146. }
Add Comment
Please, Sign In to add comment