Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. #region
  2.  
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Quiron.Communication.Packets.Incoming;
  7. using Quiron.HabboHotel.Rooms;
  8.  
  9. #endregion
  10.  
  11. namespace Quiron.HabboHotel.Items.Wired.Boxes.Triggers
  12. {
  13. internal class RepeaterBox : IWiredItem, IWiredCycle
  14. {
  15. private int _delay;
  16.  
  17. public RepeaterBox(Room Instance, Item Item)
  18. {
  19. this.Instance = Instance;
  20. this.Item = Item;
  21. SetItems = new ConcurrentDictionary<int, Item>();
  22. }
  23.  
  24. public int Delay
  25. {
  26. get { return _delay; }
  27. set
  28. {
  29. _delay = value;
  30. TickCount = value;
  31. }
  32. }
  33.  
  34. public int TickCount { get; set; }
  35.  
  36. public bool OnCycle()
  37. {
  38. var Success = false;
  39. ICollection<RoomUser> Avatars = Instance.GetRoomUserManager().GetRoomUsers();
  40. var Effects = Instance.GetWired().GetEffects(this);
  41. var Conditions = Instance.GetWired().GetConditions(this);
  42.  
  43. foreach (var Condition in Conditions)
  44. {
  45. foreach (var Avatar in Avatars)
  46. {
  47. if (Avatar?.GetClient() == null || Avatar.GetClient().GetHabbo() == null ||
  48. !Condition.Execute(Avatar.GetClient().GetHabbo()))
  49. continue;
  50.  
  51. Success = true;
  52. }
  53.  
  54. if (!Success)
  55. return false;
  56.  
  57. Success = false;
  58. Instance.GetWired().OnEvent(Condition.Item);
  59. }
  60.  
  61.  
  62. //Check the ICollection to find the random addon effect.
  63. var HasRandomEffectAddon = Effects.Any(x => x.Type == WiredBoxType.AddonRandomEffect);
  64. if (HasRandomEffectAddon)
  65. {
  66. //Okay, so we have a random addon effect, now lets get the IWiredItem and attempt to execute it.
  67. var RandomBox = Effects.FirstOrDefault(x => x.Type == WiredBoxType.AddonRandomEffect);
  68. if (!RandomBox.Execute())
  69. return false;
  70.  
  71. //Success! Let's get our selected box and continue.
  72. var SelectedBox = Instance.GetWired().GetRandomEffect(Effects);
  73. if (!SelectedBox.Execute())
  74. return false;
  75.  
  76. //Woo! Almost there captain, now lets broadcast the update to the room instance.
  77. Instance?.GetWired().OnEvent(RandomBox.Item);
  78. Instance?.GetWired().OnEvent(SelectedBox.Item);
  79. }
  80. else
  81. {
  82. foreach (var Effect in Effects.Where(Effect => Effect.Execute()))
  83. Instance?.GetWired().OnEvent(Effect.Item);
  84. }
  85.  
  86. if(Delay == 1)
  87. TickCount = 0;
  88. else
  89. TickCount = Delay;
  90.  
  91. return true;
  92. }
  93.  
  94. public Room Instance { get; set; }
  95. public Item Item { get; set; }
  96.  
  97. public WiredBoxType Type => WiredBoxType.TriggerRepeat;
  98.  
  99. public ConcurrentDictionary<int, Item> SetItems { get; set; }
  100. public string StringData { get; set; }
  101. public bool BoolData { get; set; }
  102. public string ItemsData { get; set; }
  103.  
  104. public void HandleSave(ClientPacket Packet)
  105. {
  106. var Unknown = Packet.PopInt();
  107. var Delay = Packet.PopInt();
  108.  
  109. this.Delay = Delay;
  110. TickCount = Delay;
  111. }
  112.  
  113. public bool Execute(params object[] Params) => true;
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement