Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. #region
  2.  
  3. using System.Collections.Concurrent;
  4. using System.Linq;
  5. using Quiron.Communication.Packets.Incoming;
  6. using Quiron.Communication.Packets.Outgoing.Rooms.Engine;
  7. using Quiron.HabboHotel.Rooms;
  8.  
  9. #endregion
  10.  
  11. namespace Quiron.HabboHotel.Items.Wired.Boxes.Effects
  12. {
  13. internal class MoveFurniToUserBox : IWiredItem, IWiredCycle
  14. {
  15. private int _delay;
  16. private double _next;
  17. private bool Requested;
  18.  
  19. public MoveFurniToUserBox(Room Instance, Item Item)
  20. {
  21. this.Instance = Instance;
  22. this.Item = Item;
  23. SetItems = new ConcurrentDictionary<int, Item>();
  24. TickCount = Delay;
  25. Requested = false;
  26. }
  27.  
  28. public int Delay
  29. {
  30. get { return _delay; }
  31. set
  32. {
  33. _delay = value;
  34. TickCount = value + 1;
  35. }
  36. }
  37.  
  38. public int TickCount { get; set; }
  39.  
  40. public bool OnCycle()
  41. {
  42. if (Instance == null || !Requested || _next < 1)
  43. return false;
  44. var time = QuironServer.GetUnixTimestamp();
  45. if (_next <= time)
  46. {
  47. foreach (
  48. var Item in
  49. SetItems.Values
  50. .Where(Item => Instance.GetRoomItemHandler().GetFloor.Contains(Item)))
  51. {
  52. Item toRemove;
  53.  
  54. if (Instance.GetWired().OtherBoxHasItem(this, Item.Id))
  55. SetItems.TryRemove(Item.Id, out toRemove);
  56.  
  57. var Point = Instance.GetGameMap().GetChaseMovement(Item);
  58.  
  59. Instance.GetWired().onUserFurniCollision(Instance, Item);
  60.  
  61. if (!Instance.GetGameMap().ItemCanMove(Item, Point))
  62. continue;
  63.  
  64. if (Instance.GetGameMap().CanRollItemHere(Point.X, Point.Y) &&
  65. !Instance.GetGameMap().SquareHasUsers(Point.X, Point.Y))
  66. {
  67. var NewZ = Instance.GetGameMap().SqAbsoluteHeight(Point.X, Point.Y);
  68. var CanBePlaced = true;
  69.  
  70. var Items = Instance.GetGameMap().GetCoordinatedItems(Point);
  71. foreach (var IItem in Items.Where(IItem => IItem != null && IItem.Id != Item.Id))
  72. {
  73. if (!IItem.GetBaseItem().Walkable)
  74. {
  75. _next = 0;
  76. CanBePlaced = false;
  77. break;
  78. }
  79.  
  80. if (CanBePlaced && !IItem.GetBaseItem().Stackable)
  81. CanBePlaced = false;
  82. }
  83.  
  84. if (CanBePlaced && Point != Item.Coordinate)
  85. {
  86. Instance.SendMessage(new SlideObjectBundleComposer(Item.GetX, Item.GetY, Item.GetZ, Point.X,
  87. Point.Y, NewZ, 0, 0, Item.Id));
  88. Instance.GetRoomItemHandler().SetFloorItem(Item, Point.X, Point.Y, NewZ);
  89. }
  90. }
  91. }
  92.  
  93. _next = 0;
  94. return true;
  95. }
  96. return false;
  97. }
  98.  
  99. public Room Instance { get; set; }
  100. public Item Item { get; set; }
  101.  
  102. public WiredBoxType Type => WiredBoxType.EffectMoveFurniToNearestUser;
  103.  
  104. public ConcurrentDictionary<int, Item> SetItems { get; set; }
  105. public string StringData { get; set; }
  106. public bool BoolData { get; set; }
  107. public string ItemsData { get; set; }
  108.  
  109. public void HandleSave(ClientPacket Packet)
  110. {
  111. var Unknown = Packet.PopInt();
  112. var Unknown2 = Packet.PopString();
  113.  
  114. SetItems.Clear();
  115.  
  116. var FurniCount = Packet.PopInt();
  117. for (var i = 0; i < FurniCount; i++)
  118. {
  119. var SelectedItem = Instance.GetRoomItemHandler().GetItem(Packet.PopInt());
  120.  
  121. if (SelectedItem != null && !Instance.GetWired().OtherBoxHasItem(this, SelectedItem.Id))
  122. SetItems.TryAdd(SelectedItem.Id, SelectedItem);
  123. }
  124.  
  125. var Delay = Packet.PopInt();
  126. this.Delay = Delay;
  127. }
  128.  
  129. public bool Execute(params object[] Params)
  130. {
  131. if (SetItems.Count == 0)
  132. return false;
  133.  
  134.  
  135. if (_next < 1 || _next < QuironServer.GetUnixTimestamp())
  136. _next = QuironServer.GetUnixTimestamp() + Delay;
  137. if (!Requested)
  138. {
  139. TickCount = Delay;
  140. Requested = true;
  141. }
  142. return true;
  143. }
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement