public void EnqueueCycle(IWiredItem item) { if (!_cycleItems.Contains(item)) { _cycleItems.Enqueue(item); } }
public void RemoveWired(RoomItem item) { foreach (IWiredItem current in _wiredItems) { if (current?.Item == null || current.Item.Id != item.Id) { continue; } Queue queue = new Queue(); lock (_cycleItems.SyncRoot) { while (_cycleItems.Count > 0) { IWiredItem wiredItem = (IWiredItem)_cycleItems.Dequeue(); if (wiredItem.Item.Id != item.Id) { queue.Enqueue(wiredItem); } } } _cycleItems = queue; _wiredItems.Remove(current); break; } }
public static List <int> ContainsBlockedTrigger(IWiredItem Box, ICollection <IWiredItem> Triggers) { List <int> BlockedItems = new List <int>(); if (Box.Type != WiredBoxType.EffectShowMessage && Box.Type != WiredBoxType.EffectMuteTriggerer && Box.Type != WiredBoxType.EffectTeleportToFurni && Box.Type != WiredBoxType.EffectKickUser && Box.Type != WiredBoxType.ConditionTriggererOnFurni) { return(BlockedItems); } foreach (IWiredItem Item in Triggers) { if (Item.Type == WiredBoxType.TriggerRepeat) { if (!BlockedItems.Contains(Item.Item.GetBaseItem().SpriteId)) { BlockedItems.Add(Item.Item.GetBaseItem().SpriteId); } else { continue; } } else { continue; } } return(BlockedItems); }
public bool Execute(params object[] Params) { ICollection <IWiredItem> Effects = Instance.GetWired().GetEffects(this); ICollection <IWiredItem> Conditions = Instance.GetWired().GetConditions(this); foreach (IWiredItem Condition in Conditions) { if (!Condition.Execute(Condition.Item)) { return(false); } Instance.GetWired().OnEvent(Condition.Item); } //Check the ICollection to find the random addon effect. bool HasRandomEffectAddon = Effects.Where(x => x.Type == WiredBoxType.AddonRandomEffect).ToList().Count() > 0; if (HasRandomEffectAddon) { //Okay, so we have a random addon effect, now lets get the IWiredItem and attempt to execute it. IWiredItem RandomBox = Effects.FirstOrDefault(x => x.Type == WiredBoxType.AddonRandomEffect); if (!RandomBox.Execute()) { return(false); } //Success! Let's get our selected box and continue. IWiredItem SelectedBox = Instance.GetWired().GetRandomEffect(Effects.ToList()); if (!SelectedBox.Execute()) { return(false); } //Woo! Almost there captain, now lets broadcast the update to the room instance. if (Instance != null) { Instance.GetWired().OnEvent(RandomBox.Item); Instance.GetWired().OnEvent(SelectedBox.Item); } } else { foreach (IWiredItem Effect in Effects) { foreach (RoomUser User in Instance.GetRoomUserManager().GetRoomUsers().ToList()) { if (User == null || User.GetClient() == null || User.GetClient().GetHabbo() == null) { continue; } Effect.Execute(User.GetClient().GetHabbo()); } Instance.GetWired().OnEvent(Effect.Item); } } return(true); }
public static void SaveWired(IWiredItem fItem) { if (fItem?.Item == null) { return; } using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { string text = string.Empty; int num = 0; if (fItem.Items != null) { foreach (RoomItem current in fItem.Items) { if (current == null) { continue; } if (num != 0) { text += ";"; } text += current.Id; num++; } } if (fItem.OtherString == null) { fItem.OtherString = string.Empty; } if (fItem.OtherExtraString == null) { fItem.OtherExtraString = string.Empty; } if (fItem.OtherExtraString2 == null) { fItem.OtherExtraString2 = string.Empty; } queryReactor.SetQuery("REPLACE INTO items_wireds VALUES (@id, @items, @delay, @string, @bool, @extrastring, @extrastring2)"); queryReactor.AddParameter("id", fItem.Item.Id); queryReactor.AddParameter("items", text); queryReactor.AddParameter("delay", fItem.Delay); queryReactor.AddParameter("string", fItem.OtherString); queryReactor.AddParameter("bool", Yupi.BoolToEnum(fItem.OtherBool)); queryReactor.AddParameter("extrastring", fItem.OtherExtraString); queryReactor.AddParameter("extrastring2", fItem.OtherExtraString2); queryReactor.RunQuery(); } }
public static List<int> ContainsBlockedEffect(IWiredItem Box, ICollection<IWiredItem> Effects) { List<int> BlockedItems = new List<int>(); if (Box.Type != WiredBoxType.TriggerRepeat) return BlockedItems; bool HasMoveRotate = Effects.Where(x => x.Type == WiredBoxType.EffectMoveAndRotate).ToList().Count > 0; bool HasMoveNear = Effects.Where(x => x.Type == WiredBoxType.EffectMoveFurniToNearestUser).ToList().Count > 0; foreach (IWiredItem Item in Effects) { if (Item.Type == WiredBoxType.EffectKickUser || Item.Type == WiredBoxType.EffectMuteTriggerer || Item.Type == WiredBoxType.EffectShowMessage || Item.Type == WiredBoxType.EffectTeleportToFurni || Item.Type == WiredBoxType.EffectBotFollowsUserBox) { if (!BlockedItems.Contains(Item.Item.GetBaseItem().SpriteId)) BlockedItems.Add(Item.Item.GetBaseItem().SpriteId); else continue; } else if((Item.Type == WiredBoxType.EffectMoveFurniToNearestUser && HasMoveRotate) || (Item.Type == WiredBoxType.EffectMoveAndRotate && HasMoveNear)) { if (!BlockedItems.Contains(Item.Item.GetBaseItem().SpriteId)) BlockedItems.Add(Item.Item.GetBaseItem().SpriteId); else continue; } } return BlockedItems; }
public static void OnEvent(IWiredItem item) { if (item.Item.ExtraData == "1") return; item.Item.ExtraData = "1"; item.Item.UpdateState(false, true); item.Item.ReqUpdate(1, true); }
public WiredTriggerConfigComposer(IWiredItem Box, List<int> BlockedItems) : base(ServerPacketHeader.WiredTriggerConfigMessageComposer) { base.WriteBoolean(false); base.WriteInteger(5); base.WriteInteger(Box.SetItems.Count); foreach (Item Item in Box.SetItems.Values.ToList()) { base.WriteInteger(Item.Id); } base.WriteInteger(Box.Item.GetBaseItem().SpriteId); base.WriteInteger(Box.Item.Id); base.WriteString(Box.StringData); base.WriteInteger(Box is IWiredCycle ? 1 : 0); if (Box is IWiredCycle) { IWiredCycle Cycle = (IWiredCycle)Box; base.WriteInteger(Cycle.Delay); } base.WriteInteger(0); base.WriteInteger(WiredBoxTypeUtility.GetWiredId(Box.Type)); base.WriteInteger(BlockedItems.Count()); if(BlockedItems.Count() > 0) { foreach (int Id in BlockedItems.ToList()) base.WriteInteger(Id); } }
public WiredTriggerConfigComposer(IWiredItem Box, List <int> BlockedItems) : base(ServerPacketHeader.WiredTriggerConfigMessageComposer) { base.WriteBoolean(false); base.WriteInteger(5); base.WriteInteger(Box.SetItems.Count); foreach (Item Item in Box.SetItems.Values.ToList()) { base.WriteInteger(Item.Id); } base.WriteInteger(Box.Item.GetBaseItem().SpriteId); base.WriteInteger(Box.Item.Id); base.WriteString(Box.StringData); base.WriteInteger(Box is IWiredCycle ? 1 : 0); if (Box is IWiredCycle) { IWiredCycle Cycle = (IWiredCycle)Box; base.WriteInteger(Cycle.Delay); } base.WriteInteger(0); base.WriteInteger(WiredBoxTypeUtility.GetWiredId(Box.Type)); base.WriteInteger(BlockedItems.Count()); if (BlockedItems.Count() > 0) { foreach (int Id in BlockedItems.ToList()) { base.WriteInteger(Id); } } }
public WiredConditionConfigComposer(IWiredItem box) : base(ServerPacketHeader.WiredConditionConfigMessageComposer) { WriteBoolean(false); WriteInteger(5); WriteInteger(box.SetItems.Count); foreach (var item in box.SetItems.Values.ToList()) { WriteInteger(item.Id); } WriteInteger(box.Item.GetBaseItem().SpriteId); WriteInteger(box.Item.Id); WriteString(box.StringData); if (box.Type == WiredBoxType.ConditionMatchStateAndPosition || box.Type == WiredBoxType.ConditionDontMatchStateAndPosition) { if (string.IsNullOrEmpty(box.StringData)) { box.StringData = "0;0;0"; } WriteInteger(3); //Loop WriteInteger(box.StringData != null ? int.Parse(box.StringData.Split(';')[0]) : 0); WriteInteger(box.StringData != null ? int.Parse(box.StringData.Split(';')[1]) : 0); WriteInteger(box.StringData != null ? int.Parse(box.StringData.Split(';')[2]) : 0); } else if (box.Type == WiredBoxType.ConditionUserCountInRoom || box.Type == WiredBoxType.ConditionUserCountDoesntInRoom) { if (string.IsNullOrEmpty(box.StringData)) { box.StringData = "0;0"; } WriteInteger(2); //Loop WriteInteger(box.StringData != null ? int.Parse(box.StringData.Split(';')[0]) : 1); WriteInteger(box.StringData != null ? int.Parse(box.StringData.Split(';')[1]) : 50); } if (box.Type == WiredBoxType.ConditionFurniHasNoFurni) { WriteInteger(1); } if (box.Type != WiredBoxType.ConditionUserCountInRoom && box.Type != WiredBoxType.ConditionUserCountDoesntInRoom && box.Type != WiredBoxType.ConditionFurniHasNoFurni) { WriteInteger(0); } else if (box.Type == WiredBoxType.ConditionFurniHasNoFurni) { if (string.IsNullOrEmpty(box.StringData)) { box.StringData = "0"; } WriteInteger(box.StringData != null ? int.Parse(box.StringData.Split(';')[0]) : 50); } WriteInteger(0); WriteInteger(WiredBoxTypeUtility.GetWiredId(box.Type)); }
public bool OtherBoxHasItem(IWiredItem Box, int ItemId) { if (Box == null) { return(false); } ICollection <IWiredItem> Items = GetEffects(Box).Where(x => x.Item.Id != Box.Item.Id).ToList(); if (Items != null && Items.Count > 0) { foreach (var Item in Items) { if (Item.Type != WiredBoxType.EffectMoveAndRotate && Item.Type != WiredBoxType.EffectMoveFurniFromNearestUser && Item.Type != WiredBoxType.EffectMoveFurniToNearestUser) { continue; } if (Item.SetItems == null || Item.SetItems.Count == 0) { continue; } if (Item.SetItems.ContainsKey(ItemId)) { return(true); } } } return(false); }
public static void SaveWired(IWiredItem fItem) { if (fItem == null) return; using (var queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor()) { var text = string.Empty; var num = 0; foreach (var current in fItem.Items) { if (num != 0) text += ";"; text += current.Id; num++; } if (fItem.OtherString == null) fItem.OtherString = string.Empty; if (fItem.OtherExtraString == null) fItem.OtherExtraString = string.Empty; if (fItem.OtherExtraString2 == null) fItem.OtherExtraString2 = string.Empty; queryReactor.SetQuery( "REPLACE INTO items_wireds VALUES (@id, @items, @delay, @string, @bool, @extrastring, @extrastring2)"); queryReactor.AddParameter("id", fItem.Item.Id); queryReactor.AddParameter("items", text); queryReactor.AddParameter("delay", fItem.Delay); queryReactor.AddParameter("string", fItem.OtherString); queryReactor.AddParameter("bool", AzureEmulator.BoolToEnum(fItem.OtherBool)); queryReactor.AddParameter("extrastring", fItem.OtherExtraString); queryReactor.AddParameter("extrastring2", fItem.OtherExtraString2); queryReactor.RunQuery(); } }
public static List <int> ContainsBlockedTrigger(IWiredItem box, ICollection <IWiredItem> triggers) { var blockedItems = new List <int>(); if (box.Type != WiredBoxType.EffectShowMessage && box.Type != WiredBoxType.EffectMuteTriggerer && box.Type != WiredBoxType.EffectTeleportToFurni && box.Type != WiredBoxType.EffectKickUser && box.Type != WiredBoxType.ConditionTriggererOnFurni) { return(blockedItems); } foreach (var item in triggers) { if (item.Type != WiredBoxType.TriggerRepeat) { continue; } if (!blockedItems.Contains(item.Item.GetBaseItem().SpriteId)) { blockedItems.Add(item.Item.GetBaseItem().SpriteId); } } return(blockedItems); }
public WiredTriggerConfigComposer(IWiredItem box, List <int> blockedItems) : base(ServerPacketHeader.WiredTriggerConfigMessageComposer) { WriteBoolean(false); WriteInteger(5); WriteInteger(box.SetItems.Count); foreach (var item in box.SetItems.Values.ToList()) { WriteInteger(item.Id); } WriteInteger(box.Item.GetBaseItem().SpriteId); WriteInteger(box.Item.Id); WriteString(box.StringData); WriteInteger(box is IWiredCycle ? 1 : 0); if (box is IWiredCycle) { var cycle = (IWiredCycle)box; WriteInteger(cycle.Delay); } WriteInteger(0); WriteInteger(WiredBoxTypeUtility.GetWiredId(box.Type)); WriteInteger(blockedItems.Count()); if (blockedItems.Any()) { foreach (var id in blockedItems.ToList()) { WriteInteger(id); } } }
public static List <int> ContainsBlockedEffect(IWiredItem box, ICollection <IWiredItem> effects) { var blockedItems = new List <int>(); if (box.Type != WiredBoxType.TriggerRepeat) { return(blockedItems); } var hasMoveRotate = effects.Where(x => x.Type == WiredBoxType.EffectMoveAndRotate).ToList().Count > 0; var hasMoveNear = effects.Where(x => x.Type == WiredBoxType.EffectMoveFurniToNearestUser).ToList().Count > 0; foreach (var item in effects) { if (item.Type == WiredBoxType.EffectKickUser || item.Type == WiredBoxType.EffectMuteTriggerer || item.Type == WiredBoxType.EffectShowMessage || item.Type == WiredBoxType.EffectTeleportToFurni || item.Type == WiredBoxType.EffectBotFollowsUserBox) { if (!blockedItems.Contains(item.Item.GetBaseItem().SpriteId)) { blockedItems.Add(item.Item.GetBaseItem().SpriteId); } } else if (item.Type == WiredBoxType.EffectMoveFurniToNearestUser && hasMoveRotate || item.Type == WiredBoxType.EffectMoveAndRotate && hasMoveNear) { if (!blockedItems.Contains(item.Item.GetBaseItem().SpriteId)) { blockedItems.Add(item.Item.GetBaseItem().SpriteId); } } } return(blockedItems); }
public void AddWired(IWiredItem item) { if (_wiredItems.Contains(item)) { _wiredItems.Remove(item); } _wiredItems.Add(item); }
public void RemoveWired(IWiredItem item) { if (!_wiredItems.Contains(item)) { _wiredItems.Remove(item); } _wiredItems.Remove(item); }
public List <IWiredItem> GetEffects(IWiredItem item) { return (_wiredItems.Where( current => current != null && IsEffect(current.Type) && current.Item.X == item.Item.X && current.Item.Y == item.Item.Y) .ToList()); }
public List <IWiredItem> GetConditions(IWiredItem item) { return (_wiredItems.Where( current => current != null && IsCondition(current.Type) && current.Item.X == item.Item.X && current.Item.Y == item.Item.Y) .ToList()); }
public IWiredItem LoadWired(IWiredItem fItem) { if (fItem?.Item == null) { if (_wiredItems.Contains(fItem)) { _wiredItems.Remove(fItem); } return(null); } using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery("SELECT * FROM items_wireds WHERE id=@id LIMIT 1"); queryReactor.AddParameter("id", fItem.Item.Id); DataRow row = queryReactor.GetRow(); if (row == null) { IWiredItem wiredItem = GenerateNewItem(fItem.Item); AddWired(wiredItem); SaveWired(wiredItem); return(wiredItem); } fItem.OtherString = row["string"].ToString(); fItem.OtherBool = row["bool"].ToString() == "1"; fItem.Delay = (int)row["delay"]; fItem.OtherExtraString = row["extra_string"].ToString(); fItem.OtherExtraString2 = row["extra_string_2"].ToString(); string[] array = row["items"].ToString().Split(';'); foreach (string s in array) { int value; if (!int.TryParse(s, out value)) { continue; } RoomItem item = _room.GetRoomItemHandler().GetItem(Convert.ToUInt32(value)); fItem.Items.Add(item); } AddWired(fItem); } return(fItem); }
public static void OnEvent(IWiredItem item) { if (item.Item.ExtraData == "1") { return; } item.Item.ExtraData = "1"; item.Item.UpdateState(false, true); item.Item.ReqUpdate(1, true); }
public void MoveWired(RoomItem item) { IWiredItem wired = GetWired(item); if (wired == null) { return; } wired.Item = item; RemoveWired(item); AddWired(wired); }
public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet) { if (Session == null || Session.GetHabbo() == null) { return; } if (!Session.GetHabbo().InRoom) { return; } int ItemId = Packet.PopInt(); Session.SendMessage(new HideWiredConfigComposer()); Room Room = Session.GetHabbo().CurrentRoom; if (Room == null) { return; } if (!Room.CheckRights(Session, false) && !Room.CheckRights(Session, true)) { return; } Item SelectedItem = Room.GetRoomItemHandler().GetItem(ItemId); if (SelectedItem == null) { return; } IWiredItem Box = null; if (!Session.GetHabbo().CurrentRoom.GetWired().TryGet(ItemId, out Box)) { return; } if (Box.Type == WiredBoxType.EffectGiveUserBadge && !Session.GetHabbo().GetPermissions().HasRight("room_item_wired_rewards")) { Session.SendNotification("You don't have the correct permissions to do this."); return; } Box.HandleSave(Packet); Session.GetHabbo().CurrentRoom.GetWired().SaveBox(Box); }
public IWiredItem LoadWired(IWiredItem fItem) { if (fItem?.Item == null) { if (_wiredItems.Contains(fItem)) _wiredItems.Remove(fItem); return null; } using (IQueryAdapter commitableQueryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { commitableQueryReactor.SetQuery("SELECT * FROM items_wireds WHERE id=@id LIMIT 1"); commitableQueryReactor.AddParameter("id", fItem.Item.Id); DataRow row = commitableQueryReactor.GetRow(); if (row == null) { IWiredItem wiredItem = GenerateNewItem(fItem.Item); AddWired(wiredItem); SaveWired(wiredItem); return wiredItem; } fItem.OtherString = row["string"].ToString(); fItem.OtherBool = row["bool"].ToString() == "1"; fItem.Delay = (int) row["delay"]; fItem.OtherExtraString = row["extra_string"].ToString(); fItem.OtherExtraString2 = row["extra_string_2"].ToString(); string[] array = row["items"].ToString().Split(';'); foreach (string s in array) { int value; if (!int.TryParse(s, out value)) continue; RoomItem item = _room.GetRoomItemHandler().GetItem(Convert.ToUInt32(value)); fItem.Items.Add(item); } AddWired(fItem); } return fItem; }
public ICollection <IWiredItem> GetTriggers(IWiredItem Item) { List <IWiredItem> Items = new List <IWiredItem>(); foreach (IWiredItem I in _wiredItems.Values) { if (IsTrigger(I.Item) && I.Item.GetX == Item.Item.GetX && I.Item.GetY == Item.Item.GetY) { Items.Add(I); } } return(Items); }
public ICollection <IWiredItem> GetEffects(IWiredItem Item) { var Items = new List <IWiredItem>(); foreach (var I in _wiredItems.Values) { if (IsEffect(I.Item) && I.Item.GetX == Item.Item.GetX && I.Item.GetY == Item.Item.GetY) { Items.Add(I); } } return(Items.OrderBy(x => x.Item.GetZ).ToList()); }
public WiredConditionConfigComposer(IWiredItem Box) : base(ServerPacketHeader.WiredConditionConfigMessageComposer) { base.WriteBoolean(false); base.WriteInteger(5); base.WriteInteger(Box.SetItems.Count); foreach (Item Item in Box.SetItems.Values.ToList()) { base.WriteInteger(Item.Id); } base.WriteInteger(Box.Item.GetBaseItem().SpriteId); base.WriteInteger(Box.Item.Id); base.WriteString(Box.StringData); if (Box.Type == WiredBoxType.ConditionMatchStateAndPosition || Box.Type == WiredBoxType.ConditionDontMatchStateAndPosition) { if (String.IsNullOrEmpty(Box.StringData)) Box.StringData = "0;0;0"; base.WriteInteger(3);//Loop base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[0]) : 0); base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[1]) : 0); base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[2]) : 0); } else if (Box.Type == WiredBoxType.ConditionUserCountInRoom || Box.Type == WiredBoxType.ConditionUserCountDoesntInRoom) { if (String.IsNullOrEmpty(Box.StringData)) Box.StringData = "0;0"; base.WriteInteger(2);//Loop base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[0]) : 1); base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[1]) : 50); } if (Box.Type == WiredBoxType.ConditionFurniHasNoFurni) base.WriteInteger(1); if (Box.Type != WiredBoxType.ConditionUserCountInRoom && Box.Type != WiredBoxType.ConditionUserCountDoesntInRoom && Box.Type != WiredBoxType.ConditionFurniHasNoFurni) base.WriteInteger(0); else if (Box.Type == WiredBoxType.ConditionFurniHasNoFurni) { if (String.IsNullOrEmpty(Box.StringData)) Box.StringData = "0"; base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[0]) : 50); } base.WriteInteger(0); base.WriteInteger(WiredBoxTypeUtility.GetWiredId(Box.Type)); }
public ICollection <IWiredItem> GetConditions(IWiredItem Item) { var Items = new List <IWiredItem>(); foreach (var I in _wiredItems.Values) { if (IsCondition(I.Item) && I.Item.GetX == Item.Item.GetX && I.Item.GetY == Item.Item.GetY) { Items.Add(I); } } return(Items); }
public void OnTrigger(GameClient Session, Item Item, int Request, bool HasRights) { bool flag = Session == null || Item == null; if (!flag) { bool flag2 = !HasRights; if (!flag2) { IWiredItem wiredItem = null; bool flag3 = !Item.GetRoom().GetWired().TryGet(Item.Id, out wiredItem); if (!flag3) { Item.ExtraData = "1"; Item.UpdateState(false, true); Item.RequestUpdate(2, true); bool flag4 = Item.GetBaseItem().WiredType == WiredBoxType.AddonRandomEffect; if (!flag4) { bool flag5 = Item.GetRoom().GetWired().IsTrigger(Item); if (flag5) { List <int> blockedItems = WiredBoxTypeUtility.ContainsBlockedEffect(wiredItem, Item.GetRoom().GetWired().GetEffects(wiredItem)); Session.SendMessage(new WiredTriggerConfigComposer(wiredItem, blockedItems)); } else { bool flag6 = Item.GetRoom().GetWired().IsEffect(Item); if (flag6) { List <int> blockedItems2 = WiredBoxTypeUtility.ContainsBlockedTrigger(wiredItem, Item.GetRoom().GetWired().GetTriggers(wiredItem)); Session.SendMessage(new WiredEffectConfigComposer(wiredItem, blockedItems2)); } else { bool flag7 = Item.GetRoom().GetWired().IsCondition(Item); if (flag7) { Session.SendMessage(new WiredConditionConfigComposer(wiredItem)); } } } } } } } }
public void Parse(GameClient session, ClientPacket packet) { if (session?.GetHabbo() == null) { return; } if (!session.GetHabbo().InRoom) { return; } var room = session.GetHabbo().CurrentRoom; if (room == null || !room.CheckRights(session, false, true)) { return; } var itemId = packet.PopInt(); session.SendPacket(new HideWiredConfigComposer()); var selectedItem = room.GetRoomItemHandler().GetItem(itemId); if (selectedItem == null) { return; } IWiredItem box = null; if (!session.GetHabbo().CurrentRoom.GetWired().TryGet(itemId, out box)) { return; } if (box.Type == WiredBoxType.EffectGiveUserBadge && !session.GetHabbo().GetPermissions().HasRight("room_item_wired_rewards")) { session.SendNotification("You don't have the correct permissions to do this."); return; } box.HandleSave(packet); session.GetHabbo().CurrentRoom.GetWired().SaveBox(box); }
public void SaveBox(IWiredItem item) { var items = ""; IWiredCycle cycle = null; if (item is IWiredCycle) { cycle = (IWiredCycle)item; } foreach (var I in item.SetItems.Values) { var selectedItem = _room.GetRoomItemHandler().GetItem(Convert.ToInt32(I.Id)); if (selectedItem == null) { continue; } if (item.Type == WiredBoxType.EffectMatchPosition || item.Type == WiredBoxType.ConditionMatchStateAndPosition || item.Type == WiredBoxType.ConditionDontMatchStateAndPosition) { items += I.Id + ":" + I.GetX + "," + I.GetY + "," + I.GetZ + "," + I.Rotation + "," + I.ExtraData + ";"; } else { items += I.Id + ";"; } } if (item.Type == WiredBoxType.EffectMatchPosition || item.Type == WiredBoxType.ConditionMatchStateAndPosition || item.Type == WiredBoxType.ConditionDontMatchStateAndPosition) { item.ItemsData = items; } using (var dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("REPLACE INTO `wired_items` VALUES (@id, @items, @delay, @string, @bool)"); dbClient.AddParameter("id", item.Item.Id); dbClient.AddParameter("items", items); dbClient.AddParameter("delay", item is IWiredCycle ? cycle.Delay : 0); dbClient.AddParameter("string", item.StringData); dbClient.AddParameter("bool", item.BoolData ? "1" : "0"); dbClient.RunQuery(); } }
public void SaveBox(IWiredItem Item) { string Items = ""; IWiredCycle Cycle = null; if (Item is IWiredCycle) { Cycle = (IWiredCycle)Item; } foreach (Item I in Item.SetItems.Values) { Item SelectedItem = _room.GetRoomItemHandler().GetItem(Convert.ToInt32(I.Id)); if (SelectedItem == null) { continue; } if (Item.Type == WiredBoxType.EffectMatchPosition || Item.Type == WiredBoxType.ConditionMatchStateAndPosition || Item.Type == WiredBoxType.ConditionDontMatchStateAndPosition) { Items += I.Id + ":" + I.GetX + "," + I.GetY + "," + I.GetZ + "," + I.Rotation + "," + I.ExtraData + ";"; } else { Items += I.Id + ";"; } } if (Item.Type == WiredBoxType.EffectMatchPosition || Item.Type == WiredBoxType.ConditionMatchStateAndPosition || Item.Type == WiredBoxType.ConditionDontMatchStateAndPosition) { Item.ItemsData = Items; } using (IQueryAdapter dbClient = BiosEmuThiago.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("REPLACE INTO `wired_items` VALUES (@id, @items, @delay, @string, @bool)"); dbClient.AddParameter("id", Item.Item.Id); dbClient.AddParameter("items", Items); dbClient.AddParameter("delay", (Item is IWiredCycle) ? Cycle.Delay : 0); dbClient.AddParameter("string", Item.StringData); dbClient.AddParameter("bool", Item.BoolData ? "1" : "0"); dbClient.RunQuery(); } }
public void OnTrigger(Player Session, Item Item, int Request, bool HasRights) { if (Session == null || Item == null) { return; } if (!HasRights) { return; } IWiredItem Box = null; if (!Item.GetRoom().GetWired().TryGet(Item.Id, out Box)) { return; } Item.ExtraData = "1"; Item.UpdateState(false, true); Item.RequestUpdate(2, true); if (Item.GetBaseItem().WiredType == WiredBoxType.AddonRandomEffect) { return; } if (Item.GetRoom().GetWired().IsTrigger(Item)) { var BlockedItems = WiredBoxTypeUtility.ContainsBlockedEffect(Box, Item.GetRoom().GetWired().GetEffects(Box)); Session.SendPacket(new WiredTriggeRconfigComposer(Box, BlockedItems)); } else if (Item.GetRoom().GetWired().IsEffect(Item)) { var BlockedItems = WiredBoxTypeUtility.ContainsBlockedTrigger(Box, Item.GetRoom().GetWired().GetTriggers(Box)); Session.SendPacket(new WiredEffectConfigComposer(Box, BlockedItems)); } else if (Item.GetRoom().GetWired().IsCondition(Item)) { Session.SendPacket(new WiredConditionConfigComposer(Box)); } }
public static List<int> ContainsBlockedTrigger(IWiredItem Box, ICollection<IWiredItem> Triggers) { List<int> BlockedItems = new List<int>(); if (Box.Type != WiredBoxType.EffectShowMessage && Box.Type != WiredBoxType.EffectMuteTriggerer && Box.Type != WiredBoxType.EffectTeleportToFurni && Box.Type != WiredBoxType.EffectKickUser && Box.Type != WiredBoxType.ConditionTriggererOnFurni) return BlockedItems; foreach (IWiredItem Item in Triggers) { if (Item.Type == WiredBoxType.TriggerRepeat) { if (!BlockedItems.Contains(Item.Item.GetBaseItem().SpriteId)) BlockedItems.Add(Item.Item.GetBaseItem().SpriteId); else continue; } else continue; } return BlockedItems; }
public bool Execute(params object[] stuff) { //var roomUser = (RoomUser)stuff[0]; //var item = (InteractionType)stuff[1]; foreach (RoomItem aitem in this.Items) { switch (aitem.GetBaseItem().InteractionType) { case Interaction.TriggerRepeater: case Interaction.TriggerTimer: IWiredItem trigger = this.Room.GetWiredHandler().GetWired(aitem); trigger.Delay = 5000; this.Room.GetWiredHandler().ReloadWired(trigger); break; } } return(true); }
public static List <int> ContainsBlockedEffect(IWiredItem Box, ICollection <IWiredItem> Effects) { List <int> BlockedItems = new List <int>(); if (Box.Type != WiredBoxType.TriggerRepeat || Box.Type != WiredBoxType.TriggerLongRepeat) { return(BlockedItems); } bool HasMoveRotate = Effects.Where(x => x.Type == WiredBoxType.EffectMoveAndRotate).ToList().Count > 0; bool HasMoveNear = Effects.Where(x => x.Type == WiredBoxType.EffectMoveFurniToNearestUser).ToList().Count > 0; bool HasMoveToDir = Effects.Where(x => x.Type == WiredBoxType.EffectMoveToDir).ToList().Count > 0; foreach (IWiredItem Item in Effects) { if (Item.Type == WiredBoxType.EffectKickUser || Item.Type == WiredBoxType.EffectMuteTriggerer || Item.Type == WiredBoxType.EffectShowMessage || Item.Type == WiredBoxType.SendCustomMessageBox || Item.Type == WiredBoxType.EffectProgressUserAchievement || Item.Type == WiredBoxType.EffectTeleportToFurni || Item.Type == WiredBoxType.EffectBotFollowsUserBox) { if (!BlockedItems.Contains(Item.Item.GetBaseItem().SpriteId)) { BlockedItems.Add(Item.Item.GetBaseItem().SpriteId); } else { continue; } } else if ((Item.Type == WiredBoxType.EffectMoveFurniToNearestUser && HasMoveRotate) || (Item.Type == WiredBoxType.EffectMoveAndRotate && HasMoveNear) || (Item.Type == WiredBoxType.EffectMoveToDir && (HasMoveNear || HasMoveRotate))) { if (!BlockedItems.Contains(Item.Item.GetBaseItem().SpriteId)) { BlockedItems.Add(Item.Item.GetBaseItem().SpriteId); } else { continue; } } } return(BlockedItems); }
public void OnTrigger(GameClient session, Item item, int request, bool hasRights) { if (session == null || item == null) { return; } if (!hasRights) { return; } IWiredItem box = null; if (!item.GetRoom().GetWired().TryGet(item.Id, out box)) { return; } item.ExtraData = "1"; item.UpdateState(false, true); item.RequestUpdate(2, true); if (item.GetBaseItem().WiredType == WiredBoxType.AddonRandomEffect) { return; } if (item.GetRoom().GetWired().IsTrigger(item)) { var blockedItems = WiredBoxTypeUtility.ContainsBlockedEffect(box, item.GetRoom().GetWired().GetEffects(box)); session.SendPacket(new WiredTriggerConfigComposer(box, blockedItems)); } else if (item.GetRoom().GetWired().IsEffect(item)) { var blockedItems = WiredBoxTypeUtility.ContainsBlockedTrigger(box, item.GetRoom().GetWired().GetTriggers(box)); session.SendPacket(new WiredEffectConfigComposer(box, blockedItems)); } else if (item.GetRoom().GetWired().IsCondition(item)) { session.SendPacket(new WiredConditionConfigComposer(box)); } }
public List<IWiredItem> GetEffects(IWiredItem item) { return _wiredItems.Where( current => current != null && IsEffect(current.Type) && current.Item.X == item.Item.X && current.Item.Y == item.Item.Y) .ToList(); }
public bool IsCycleQueued(IWiredItem item) => _cycleItems.Contains(item);
public static void SaveWired(IWiredItem fItem) { if (fItem?.Item == null) return; using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { string text = string.Empty; int num = 0; if (fItem.Items != null) { foreach (RoomItem current in fItem.Items) { if (current == null) continue; if (num != 0) text += ";"; text += current.Id; num++; } } if (fItem.OtherString == null) fItem.OtherString = string.Empty; if (fItem.OtherExtraString == null) fItem.OtherExtraString = string.Empty; if (fItem.OtherExtraString2 == null) fItem.OtherExtraString2 = string.Empty; queryReactor.SetQuery("REPLACE INTO items_wireds VALUES (@id, @items, @delay, @string, @bool, @extrastring, @extrastring2)"); queryReactor.AddParameter("id", fItem.Item.Id); queryReactor.AddParameter("items", text); queryReactor.AddParameter("delay", fItem.Delay); queryReactor.AddParameter("string", fItem.OtherString); queryReactor.AddParameter("bool", Yupi.BoolToEnum(fItem.OtherBool)); queryReactor.AddParameter("extrastring", fItem.OtherExtraString); queryReactor.AddParameter("extrastring2", fItem.OtherExtraString2); queryReactor.RunQuery(); } }
public bool IsCycleQueued(IWiredItem item) { return _cycleItems.Contains(item); }
public List<IWiredItem> GetConditions(IWiredItem item) { return _wiredItems.Where( current => current != null && IsCondition(current.Type) && current.Item.X == item.Item.X && current.Item.Y == item.Item.Y) .ToList(); }
public void RemoveWired(IWiredItem item) { if (!_wiredItems.Contains(item)) _wiredItems.Remove(item); _wiredItems.Remove(item); }
public void ReloadWired(IWiredItem item) { SaveWired(item); RemoveWired(item); AddWired(item); }
public WiredEffectConfigComposer(IWiredItem Box, List<int> BlockedItems) : base(ServerPacketHeader.WiredEffectConfigMessageComposer) { base.WriteBoolean(false); base.WriteInteger(15); base.WriteInteger(Box.SetItems.Count); foreach (Item Item in Box.SetItems.Values.ToList()) { base.WriteInteger(Item.Id); } base.WriteInteger(Box.Item.GetBaseItem().SpriteId); base.WriteInteger(Box.Item.Id); if(Box.Type == WiredBoxType.EffectBotGivesHanditemBox) { if (String.IsNullOrEmpty(Box.StringData)) Box.StringData = "Bot name;0"; base.WriteString(Box.StringData != null ? (Box.StringData.Split(';')[0]) : ""); } else if (Box.Type == WiredBoxType.EffectBotFollowsUserBox) { if (String.IsNullOrEmpty(Box.StringData)) Box.StringData = "0;Bot name"; base.WriteString(Box.StringData != null ? (Box.StringData.Split(';')[1]) : ""); } else { base.WriteString(Box.StringData); } if (Box.Type != WiredBoxType.EffectMatchPosition && Box.Type != WiredBoxType.EffectMoveAndRotate && Box.Type != WiredBoxType.EffectMuteTriggerer && Box.Type != WiredBoxType.EffectBotFollowsUserBox) base.WriteInteger(0); // Loop else if (Box.Type == WiredBoxType.EffectMatchPosition) { if (String.IsNullOrEmpty(Box.StringData)) Box.StringData = "0;0;0"; base.WriteInteger(3); base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[0]) : 0); base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[1]) : 0); base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[2]) : 0); } else if (Box.Type == WiredBoxType.EffectMoveAndRotate) { if (String.IsNullOrEmpty(Box.StringData)) Box.StringData = "0;0"; base.WriteInteger(2); base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[0]) : 0); base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[1]) : 0); } else if (Box.Type == WiredBoxType.EffectMuteTriggerer) { if (String.IsNullOrEmpty(Box.StringData)) Box.StringData = "0;Message"; base.WriteInteger(1);//Count, for the time. base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[0]) : 0); } else if (Box.Type == WiredBoxType.EffectBotFollowsUserBox) { base.WriteInteger(1);//Count, for the time. base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[0]) : 0); } else if(Box.Type == WiredBoxType.EffectBotGivesHanditemBox) { base.WriteInteger(Box.StringData != null ? int.Parse(Box.StringData.Split(';')[1]) : 0); } if (Box is IWiredCycle && Box.Type != WiredBoxType.EffectKickUser && Box.Type != WiredBoxType.EffectMatchPosition && Box.Type != WiredBoxType.EffectMoveAndRotate && Box.Type != WiredBoxType.EffectSetRollerSpeed) { IWiredCycle Cycle = (IWiredCycle)Box; base.WriteInteger(WiredBoxTypeUtility.GetWiredId(Box.Type)); base.WriteInteger(0); base.WriteInteger(Cycle.Delay); } else if (Box.Type == WiredBoxType.EffectMatchPosition || Box.Type == WiredBoxType.EffectMoveAndRotate) { IWiredCycle Cycle = (IWiredCycle)Box; base.WriteInteger(0); base.WriteInteger(WiredBoxTypeUtility.GetWiredId(Box.Type)); base.WriteInteger(Cycle.Delay); } else { base.WriteInteger(0); base.WriteInteger(WiredBoxTypeUtility.GetWiredId(Box.Type)); base.WriteInteger(0); } base.WriteInteger(BlockedItems.Count()); // Incompatable items loop if (BlockedItems.Count() > 0) { foreach (int ItemId in BlockedItems.ToList()) base.WriteInteger(ItemId); } }
public void AddWired(IWiredItem item) { if (_wiredItems.Contains(item)) _wiredItems.Remove(item); _wiredItems.Add(item); }
public ICollection<IWiredItem> GetEffects(IWiredItem Item) { List<IWiredItem> Items = new List<IWiredItem>(); foreach (IWiredItem I in _wiredItems.Values) { if (this.IsEffect(I.Item) && I.Item.GetX == Item.Item.GetX && I.Item.GetY == Item.Item.GetY) { Items.Add(I); } } return Items.OrderBy(x => x.Item.GetZ).ToList(); }
public void EnqueueCycle(IWiredItem item) { if (!_cycleItems.Contains(item)) _cycleItems.Enqueue(item); }
public ICollection<IWiredItem> GetTriggers(IWiredItem Item) { List<IWiredItem> Items = new List<IWiredItem>(); foreach (IWiredItem I in _wiredItems.Values) { if (this.IsTrigger(I.Item) && I.Item.GetX == Item.Item.GetX && I.Item.GetY == Item.Item.GetY) { Items.Add(I); } } return Items; }
public bool OtherBoxHasItem(IWiredItem Box, int ItemId) { if (Box == null) return false; ICollection<IWiredItem> Items = GetEffects(Box).Where(x => x.Item.Id != Box.Item.Id).ToList(); if (Items != null && Items.Count > 0) { foreach (IWiredItem Item in Items) { if (Item.Type != WiredBoxType.EffectMoveAndRotate && Item.Type != WiredBoxType.EffectMoveFurniFromNearestUser && Item.Type != WiredBoxType.EffectMoveFurniToNearestUser) continue; if (Item.SetItems == null || Item.SetItems.Count == 0) continue; if (Item.SetItems.ContainsKey(ItemId)) return true; else continue; } } return false; }
public bool TryGet(int id, out IWiredItem Item) { return this._wiredItems.TryGetValue(id, out Item); }
public void SaveBox(IWiredItem Item) { string Items = ""; IWiredCycle Cycle = null; if (Item is IWiredCycle) { Cycle = (IWiredCycle)Item; } foreach (Item I in Item.SetItems.Values) { Item SelectedItem = _room.GetRoomItemHandler().GetItem(Convert.ToInt32(I.Id)); if (SelectedItem == null) continue; if (Item.Type == WiredBoxType.EffectMatchPosition || Item.Type == WiredBoxType.ConditionMatchStateAndPosition || Item.Type == WiredBoxType.ConditionDontMatchStateAndPosition) Items += I.Id + ":" + I.GetX + "," + I.GetY + "," + I.GetZ + "," + I.Rotation + "," + I.ExtraData + ";"; else Items += I.Id + ";"; } if (Item.Type == WiredBoxType.EffectMatchPosition || Item.Type == WiredBoxType.ConditionMatchStateAndPosition || Item.Type == WiredBoxType.ConditionDontMatchStateAndPosition) Item.ItemsData = Items; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("REPLACE INTO `wired_items` VALUES (@id, @items, @delay, @string, @bool)"); dbClient.AddParameter("id", Item.Item.Id); dbClient.AddParameter("items", Items); dbClient.AddParameter("delay", (Item is IWiredCycle) ? Cycle.Delay : 0); dbClient.AddParameter("string", Item.StringData); dbClient.AddParameter("bool", Item.BoolData ? "1" : "0"); dbClient.RunQuery(); } }
public bool AddBox(IWiredItem Item) { return this._wiredItems.TryAdd(Item.Item.Id, Item); }