From 777c1d2aa1e0bde82c0a0826012c2cbe1341bf15 Mon Sep 17 00:00:00 2001 From: Lorenzune Date: Sun, 15 Mar 2026 19:01:54 +0100 Subject: [PATCH] wired: add source selection to conditions/effects --- .../WiredConditionFurniHaveFurni.java | 39 +++++++---- .../WiredConditionFurniHaveHabbo.java | 36 +++++++--- .../WiredConditionFurniTypeMatch.java | 40 +++++++---- .../conditions/WiredConditionGroupMember.java | 35 ++++++++-- .../conditions/WiredConditionHabboCount.java | 21 ++++-- .../WiredConditionHabboHasEffect.java | 29 ++++++-- .../WiredConditionHabboHasHandItem.java | 29 ++++++-- .../WiredConditionHabboWearsBadge.java | 35 +++++++--- .../WiredConditionMatchStatePosition.java | 69 ++++++++++++++---- .../WiredConditionNotFurniHaveFurni.java | 39 +++++++---- .../WiredConditionNotFurniHaveHabbo.java | 36 +++++++--- .../WiredConditionNotFurniTypeMatch.java | 40 +++++++---- .../WiredConditionNotHabboCount.java | 21 ++++-- .../WiredConditionNotHabboHasEffect.java | 31 ++++++-- .../WiredConditionNotHabboWearsBadge.java | 37 ++++++---- .../conditions/WiredConditionNotInGroup.java | 35 ++++++++-- .../conditions/WiredConditionNotInTeam.java | 33 ++++++--- .../WiredConditionNotTriggerOnFurni.java | 16 +++-- .../conditions/WiredConditionTeamMember.java | 33 ++++++--- .../WiredConditionTriggerOnFurni.java | 70 ++++++++++++++----- .../wired/effects/WiredEffectAlert.java | 2 +- .../effects/WiredEffectBotFollowHabbo.java | 24 +++++-- .../effects/WiredEffectBotGiveHandItem.java | 24 +++++-- .../effects/WiredEffectBotTalkToHabbo.java | 21 ++++-- .../wired/effects/WiredEffectBotTeleport.java | 42 +++++++---- .../effects/WiredEffectBotWalkToFurni.java | 47 ++++++++----- .../WiredEffectChangeFurniDirection.java | 52 ++++++++------ .../wired/effects/WiredEffectGiveEffect.java | 2 +- .../effects/WiredEffectGiveHandItem.java | 2 +- ...redEffectGiveHotelviewBonusRarePoints.java | 26 ++++--- .../WiredEffectGiveHotelviewHofPoints.java | 27 ++++--- .../wired/effects/WiredEffectGiveRespect.java | 21 ++++-- .../wired/effects/WiredEffectGiveReward.java | 21 ++++-- .../wired/effects/WiredEffectGiveScore.java | 21 ++++-- .../wired/effects/WiredEffectJoinTeam.java | 21 ++++-- .../wired/effects/WiredEffectKickHabbo.java | 20 ++++-- .../wired/effects/WiredEffectLeaveTeam.java | 24 +++++-- .../wired/effects/WiredEffectMatchFurni.java | 68 +++++++++++------- .../effects/WiredEffectMoveFurniAway.java | 58 +++++++++------ .../wired/effects/WiredEffectMoveFurniTo.java | 45 +++++++----- .../effects/WiredEffectMoveFurniTowards.java | 58 +++++++++------ .../effects/WiredEffectMoveRotateFurni.java | 45 +++++++----- .../wired/effects/WiredEffectMuteHabbo.java | 21 ++++-- .../wired/effects/WiredEffectTeleport.java | 61 +++++++++++----- .../wired/effects/WiredEffectToggleFurni.java | 47 ++++++++----- .../effects/WiredEffectToggleRandom.java | 46 ++++++++---- .../effects/WiredEffectTriggerStacks.java | 44 ++++++++---- .../wired/effects/WiredEffectWhisper.java | 24 +++++-- .../habbohotel/wired/core/WiredEngine.java | 49 +++++++++---- .../wired/core/WiredSourceUtil.java | 63 +++++++++++++++++ 50 files changed, 1246 insertions(+), 504 deletions(-) create mode 100644 Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredSourceUtil.java diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java index 546e9152..1e96dfc3 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java @@ -11,6 +11,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -24,6 +25,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { private boolean all; private THashSet items; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -41,14 +43,15 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { this.refresh(); - if(this.items.isEmpty()) + List targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if(targets.isEmpty()) return true; if (room.getLayout() == null) return false; if(this.all) { - return this.items.stream().allMatch(item -> { + return targets.stream().allMatch(item -> { if (item == null) return false; RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); if (baseTile == null) return false; @@ -59,7 +62,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { }); } else { - return this.items.stream().anyMatch(item -> { + return targets.stream().anyMatch(item -> { if (item == null) return false; RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); if (baseTile == null) return false; @@ -82,7 +85,8 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { this.refresh(); return WiredManager.getGson().toJson(new JsonData( this.all, - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -93,6 +97,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.all = data.all; + this.furniSource = data.furniSource; for(int id : data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -119,6 +124,10 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { } } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; } } @@ -126,6 +135,7 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { public void onPickUp() { this.items.clear(); this.all = false; + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -147,8 +157,9 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.all ? 1 : 0); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -159,26 +170,28 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { public boolean saveData(WiredSettings settings) { if(settings.getIntParams().length < 1) return false; - this.all = settings.getIntParams()[0] == 1; + int[] params = settings.getIntParams(); + this.all = params[0] == 1; + this.furniSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; int count = settings.getFurniIds().length; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; this.items.clear(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + + if (room == null) return false; - if (room != null) { for (int i = 0; i < count; i++) { HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); if (item != null) this.items.add(item); } - - return true; } - return false; + return true; } private void refresh() { @@ -202,10 +215,12 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { static class JsonData { boolean all; List itemIds; + int furniSource; - public JsonData(boolean all, List itemIds) { + public JsonData(boolean all, List itemIds, int furniSource) { this.all = all; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java index 7b6bd83a..1863c07c 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java @@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -26,6 +27,7 @@ import java.util.stream.Collectors; public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.FURNI_HAVE_HABBO; protected THashSet items; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -40,6 +42,7 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -48,7 +51,8 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { this.refresh(); - if (this.items.isEmpty()) + List targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (targets.isEmpty()) return true; if (room.getLayout() == null) @@ -58,7 +62,7 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { Collection bots = room.getCurrentBots().valueCollection(); Collection pets = room.getCurrentPets().valueCollection(); - return this.items.stream().filter(item -> item != null).allMatch(item -> { + return targets.stream().filter(item -> item != null).allMatch(item -> { RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); if (baseTile == null) return false; @@ -79,7 +83,8 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { public String getWiredData() { this.refresh(); return WiredManager.getGson().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -90,6 +95,7 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); + this.furniSource = data.furniSource; for(int id : data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -112,6 +118,10 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { this.items.add(item); } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; } } @@ -134,7 +144,8 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -147,22 +158,25 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.items.clear(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + + if (room == null) return false; - if (room != null) { for (int i = 0; i < count; i++) { HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); if (item != null) this.items.add(item); } - - return true; } - return false; + return true; } private void refresh() { @@ -185,9 +199,11 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { static class JsonData { List itemIds; + int furniSource; - public JsonData(List itemIds) { + public JsonData(List itemIds, int furniSource) { this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java index be2fcb8c..72552354 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java @@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -22,6 +23,7 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.STUFF_IS; private THashSet items = new THashSet<>(); + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -34,6 +36,7 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -43,12 +46,9 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { if(items.isEmpty()) return false; - HabboItem triggeringItem = ctx.sourceItem().orElse(null); - if (triggeringItem != null) { - return this.items.stream().anyMatch(item -> item == triggeringItem); - } - - return false; + List targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (targets.isEmpty()) return false; + return targets.stream().anyMatch(this.items::contains); } @Deprecated @@ -61,7 +61,8 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { public String getWiredData() { this.refresh(); return WiredManager.getGson().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -72,6 +73,7 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); + this.furniSource = data.furniSource; for(int id : data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -90,6 +92,10 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { this.items.add(item); } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; } } @@ -112,7 +118,8 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -124,13 +131,18 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { int count = settings.getFurniIds().length; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.items.clear(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room != null) { - for (int i = 0; i < count; i++) { - this.items.add(room.getHabboItem(settings.getFurniIds()[i])); + if (room != null) { + for (int i = 0; i < count; i++) { + this.items.add(room.getHabboItem(settings.getFurniIds()[i])); + } } } @@ -157,9 +169,11 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { static class JsonData { List itemIds; + int furniSource; - public JsonData(List itemIds) { + public JsonData(List itemIds, int furniSource) { this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java index 0364abce..aa9631b5 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java @@ -8,13 +8,16 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionGroupMember extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.ACTOR_IN_GROUP; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionGroupMember(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -26,14 +29,20 @@ public class WiredConditionGroupMember extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); Room room = ctx.room(); if (room.getGuildId() == 0) return false; - Habbo habbo = room.getHabbo(roomUnit); + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return false; - return habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId()); + for (RoomUnit roomUnit : targets) { + Habbo habbo = room.getHabbo(roomUnit); + if (habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId())) { + return true; + } + } + return false; } @Deprecated @@ -44,17 +53,26 @@ public class WiredConditionGroupMember extends InteractionWiredCondition { @Override public String getWiredData() { - return ""; + return String.valueOf(this.userSource); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - + String wiredData = set.getString("wired_data"); + if (wiredData != null && !wiredData.isEmpty()) { + try { + this.userSource = Integer.parseInt(wiredData); + } catch (NumberFormatException ignored) { + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; + } + } else { + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; + } } @Override public void onPickUp() { - + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -70,7 +88,8 @@ public class WiredConditionGroupMember extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -79,6 +98,8 @@ public class WiredConditionGroupMember extends InteractionWiredCondition { @Override public boolean saveData(WiredSettings settings) { + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; return true; } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java index 7747d9e0..6cd6e951 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java @@ -8,6 +8,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; @@ -18,6 +19,7 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { private int lowerLimit = 0; private int upperLimit = 50; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionHabboCount(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -29,7 +31,9 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - int count = ctx.room().getUserCount(); + int count = (this.userSource == WiredSourceUtil.SOURCE_TRIGGER) + ? ctx.room().getUserCount() + : WiredSourceUtil.resolveUsers(ctx, this.userSource).size(); return count >= this.lowerLimit && count <= this.upperLimit; } @@ -44,7 +48,8 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( this.lowerLimit, - this.upperLimit + this.upperLimit, + this.userSource )); } @@ -56,11 +61,13 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.lowerLimit = data.lowerLimit; this.upperLimit = data.upperLimit; + this.userSource = data.userSource; } else { String[] data = wiredData.split(":"); this.lowerLimit = Integer.parseInt(data[0]); this.upperLimit = Integer.parseInt(data[1]); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @@ -68,6 +75,7 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { public void onPickUp() { this.lowerLimit = 0; this.upperLimit = 50; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -83,9 +91,10 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(2); + message.appendInt(3); message.appendInt(this.lowerLimit); message.appendInt(this.upperLimit); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -97,6 +106,8 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { if(settings.getIntParams().length < 2) return false; this.lowerLimit = settings.getIntParams()[0]; this.upperLimit = settings.getIntParams()[1]; + int[] params = settings.getIntParams(); + this.userSource = (params.length > 2) ? params[2] : WiredSourceUtil.SOURCE_TRIGGER; return true; } @@ -104,10 +115,12 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { static class JsonData { int lowerLimit; int upperLimit; + int userSource; - public JsonData(int lowerLimit, int upperLimit) { + public JsonData(int lowerLimit, int upperLimit, int userSource) { this.lowerLimit = lowerLimit; this.upperLimit = upperLimit; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java index 5247e5c2..a184beaf 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java @@ -8,15 +8,18 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionHabboHasEffect extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_EFFECT; protected int effectId = 0; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionHabboHasEffect(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -28,9 +31,14 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); - if (roomUnit == null) return false; - return roomUnit.getEffectId() == this.effectId; + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return false; + for (RoomUnit roomUnit : targets) { + if (roomUnit != null && roomUnit.getEffectId() == this.effectId) { + return true; + } + } + return false; } @Deprecated @@ -42,7 +50,8 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition { @Override public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( - this.effectId + this.effectId, + this.userSource )); } @@ -53,14 +62,17 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.effectId = data.effectId; + this.userSource = data.userSource; } else { this.effectId = Integer.parseInt(wiredData); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.effectId = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -76,8 +88,9 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.effectId); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -88,15 +101,19 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition { public boolean saveData(WiredSettings settings) { if(settings.getIntParams().length < 1) return false; this.effectId = settings.getIntParams()[0]; + int[] params = settings.getIntParams(); + this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; return true; } static class JsonData { int effectId; + int userSource; - public JsonData(int effectId) { + public JsonData(int effectId, int userSource) { this.effectId = effectId; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java index 0175aadf..1a064793 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java @@ -8,12 +8,14 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { private static final Logger LOGGER = LoggerFactory.getLogger(WiredConditionHabboHasHandItem.class); @@ -21,6 +23,7 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.ACTOR_HAS_HANDITEM; private int handItem; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionHabboHasHandItem(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -43,8 +46,9 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.handItem); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -55,15 +59,22 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { public boolean saveData(WiredSettings settings) { if(settings.getIntParams().length < 1) return false; this.handItem = settings.getIntParams()[0]; + int[] params = settings.getIntParams(); + this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; return true; } @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); - if (roomUnit == null) return false; - return roomUnit.getHandItem() == this.handItem; + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return false; + for (RoomUnit roomUnit : targets) { + if (roomUnit != null && roomUnit.getHandItem() == this.handItem) { + return true; + } + } + return false; } @Deprecated @@ -75,7 +86,8 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { @Override public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( - this.handItem + this.handItem, + this.userSource )); } @@ -87,8 +99,10 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.handItem = data.handItemId; + this.userSource = data.userSource; } else { this.handItem = Integer.parseInt(wiredData); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } catch (Exception e) { LOGGER.error("Caught exception", e); @@ -98,13 +112,16 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { @Override public void onPickUp() { this.handItem = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { int handItemId; + int userSource; - public JsonData(int handItemId) { + public JsonData(int handItemId, int userSource) { this.handItemId = handItemId; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java index 7cb6f29f..844ef89c 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java @@ -10,15 +10,18 @@ import com.eu.habbo.habbohotel.users.HabboBadge; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_BADGE; protected String badge = ""; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -30,15 +33,18 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); Room room = ctx.room(); - Habbo habbo = room.getHabbo(roomUnit); + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return false; - if (habbo != null) { - synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { - for (HabboBadge badge : habbo.getInventory().getBadgesComponent().getWearingBadges()) { - if (badge.getCode().equalsIgnoreCase(this.badge)) { - return true; + for (RoomUnit roomUnit : targets) { + Habbo habbo = room.getHabbo(roomUnit); + if (habbo != null) { + synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { + for (HabboBadge badge : habbo.getInventory().getBadgesComponent().getWearingBadges()) { + if (badge.getCode().equalsIgnoreCase(this.badge)) { + return true; + } } } } @@ -55,7 +61,8 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { @Override public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( - this.badge + this.badge, + this.userSource )); } @@ -66,14 +73,17 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.badge = data.badge; + this.userSource = data.userSource; } else { this.badge = wiredData; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.badge = ""; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -89,7 +99,8 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.badge); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -99,15 +110,19 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { @Override public boolean saveData(WiredSettings settings) { this.badge = settings.getStringParam(); + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; return true; } static class JsonData { String badge; + int userSource; - public JsonData(String badge) { + public JsonData(String badge, int userSource) { this.badge = badge; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java index 82f745c4..bc965875 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java @@ -12,13 +12,16 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT; @@ -28,6 +31,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition private boolean state; private boolean position; private boolean direction; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionMatchStatePosition(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -62,7 +66,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition message.appendInt(this.state ? 1 : 0); message.appendInt(this.direction ? 1 : 0); message.appendInt(this.position ? 1 : 0); - message.appendInt(10); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -72,9 +76,11 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition @Override public boolean saveData(WiredSettings settings) { if(settings.getIntParams().length < 3) return false; - this.state = settings.getIntParams()[0] == 1; - this.direction = settings.getIntParams()[1] == 1; - this.position = settings.getIntParams()[2] == 1; + int[] params = settings.getIntParams(); + this.state = params[0] == 1; + this.direction = params[1] == 1; + this.position = params[2] == 1; + this.furniSource = (params.length > 3) ? params[3] : WiredSourceUtil.SOURCE_TRIGGER; Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); @@ -86,12 +92,14 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition this.settings.clear(); - for (int i = 0; i < count; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem item = room.getHabboItem(itemId); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < count; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem item = room.getHabboItem(itemId); - if (item != null) - this.settings.add(new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY())); + if (item != null) + this.settings.add(new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY())); + } } return true; @@ -103,12 +111,30 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition if (this.settings.isEmpty()) return true; - THashSet s = new THashSet<>(); + List targets = null; + Set targetIds = null; + + if (this.furniSource != WiredSourceUtil.SOURCE_SELECTED) { + targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, null); + if (targets.isEmpty()) return false; + targetIds = new HashSet<>(); + for (HabboItem item : targets) { + if (item != null) targetIds.add(item.getId()); + } + if (targetIds.isEmpty()) return false; + } + + THashSet toRemove = new THashSet<>(); + Set settingsIds = new HashSet<>(); for (WiredMatchFurniSetting setting : this.settings) { + if (targetIds != null && !targetIds.contains(setting.item_id)) { + continue; + } HabboItem item = room.getHabboItem(setting.item_id); if (item != null) { + settingsIds.add(setting.item_id); if (this.state) { if (!item.getExtradata().equals(setting.state)) return false; @@ -124,12 +150,16 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition return false; } } else { - s.add(setting); + toRemove.add(setting); } } - if (!s.isEmpty()) { - for (WiredMatchFurniSetting setting : s) { + if (targetIds != null && !settingsIds.containsAll(targetIds)) { + return false; + } + + if (!toRemove.isEmpty()) { + for (WiredMatchFurniSetting setting : toRemove) { this.settings.remove(setting); } } @@ -149,7 +179,8 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition this.state, this.position, this.direction, - new ArrayList<>(this.settings) + new ArrayList<>(this.settings), + this.furniSource )); } @@ -163,6 +194,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition this.position = data.position; this.direction = data.direction; this.settings.addAll(data.settings); + this.furniSource = data.furniSource; } else { String[] data = wiredData.split(":"); @@ -180,6 +212,10 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition this.state = data[2].equals("1"); this.direction = data[3].equals("1"); this.position = data[4].equals("1"); + this.furniSource = this.settings.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.settings.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; } } @@ -189,6 +225,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition this.direction = false; this.position = false; this.state = false; + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } private void refresh() { @@ -235,12 +272,14 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition boolean position; boolean direction; List settings; + int furniSource; - public JsonData(boolean state, boolean position, boolean direction, List settings) { + public JsonData(boolean state, boolean position, boolean direction, List settings, int furniSource) { this.state = state; this.position = position; this.direction = direction; this.settings = settings; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java index 629a2702..c4540b26 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java @@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.wired.WiredConditionOperator; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -25,6 +26,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { private boolean all; private THashSet items; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionNotFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -42,14 +44,15 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { this.refresh(); - if (this.items.isEmpty()) + List targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (targets.isEmpty()) return true; if (room.getLayout() == null) return true; if(this.all) { - return this.items.stream().allMatch(item -> { + return targets.stream().allMatch(item -> { if (item == null) return true; RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); if (baseTile == null) return true; @@ -60,7 +63,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { }); } else { - return this.items.stream().anyMatch(item -> { + return targets.stream().anyMatch(item -> { if (item == null) return true; RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); if (baseTile == null) return true; @@ -83,7 +86,8 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { this.refresh(); return WiredManager.getGson().toJson(new JsonData( this.all, - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -95,6 +99,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.all = data.all; + this.furniSource = data.furniSource; for (int id : data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -120,6 +125,10 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { } } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; } } @@ -127,6 +136,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { public void onPickUp() { this.all = false; this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -148,8 +158,9 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.all ? 1 : 0); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -159,26 +170,28 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { @Override public boolean saveData(WiredSettings settings) { if(settings.getIntParams().length < 1) return false; - this.all = settings.getIntParams()[0] == 1; + int[] params = settings.getIntParams(); + this.all = params[0] == 1; + this.furniSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; int count = settings.getFurniIds().length; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; this.items.clear(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + + if (room == null) return false; - if (room != null) { for (int i = 0; i < count; i++) { HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); if (item != null) this.items.add(item); } - - return true; } - return false; + return true; } private void refresh() { @@ -209,10 +222,12 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { static class JsonData { boolean all; List itemIds; + int furniSource; - public JsonData(boolean all, List itemIds) { + public JsonData(boolean all, List itemIds, int furniSource) { this.all = all; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java index 02324a60..dff23b8a 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java @@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -27,6 +28,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO; protected THashSet items; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionNotFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -41,6 +43,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -49,7 +52,8 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { this.refresh(); - if (this.items.isEmpty()) + List targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (targets.isEmpty()) return true; if (room.getLayout() == null) @@ -59,7 +63,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { Collection bots = room.getCurrentBots().valueCollection(); Collection pets = room.getCurrentPets().valueCollection(); - return this.items.stream().filter(item -> item != null).noneMatch(item -> { + return targets.stream().filter(item -> item != null).noneMatch(item -> { RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY()); if (baseTile == null) return false; @@ -80,7 +84,8 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { public String getWiredData() { this.refresh(); return WiredManager.getGson().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -91,6 +96,7 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { if (wiredData.startsWith("{")) { WiredConditionFurniHaveHabbo.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class); + this.furniSource = data.furniSource; for(int id : data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -112,6 +118,10 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { this.items.add(item); } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; } } @@ -134,7 +144,8 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -146,22 +157,25 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { int count = settings.getFurniIds().length; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.items.clear(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + + if (room == null) return false; - if (room != null) { for (int i = 0; i < count; i++) { HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); if (item != null) this.items.add(item); } - - return true; } - return false; + return true; } private void refresh() { @@ -184,9 +198,11 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { static class JsonData { List itemIds; + int furniSource; - public JsonData(List itemIds) { + public JsonData(List itemIds, int furniSource) { this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java index 19e841aa..b9aaf539 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java @@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -22,6 +23,7 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_STUFF_IS; private THashSet items = new THashSet<>(); + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionNotFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -38,12 +40,9 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { if(items.isEmpty()) return true; - HabboItem triggeringItem = ctx.sourceItem().orElse(null); - if (triggeringItem != null) { - return this.items.stream().noneMatch(item -> item == triggeringItem); - } - - return true; + List targets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (targets.isEmpty()) return true; + return targets.stream().noneMatch(this.items::contains); } @Deprecated @@ -56,7 +55,8 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { public String getWiredData() { this.refresh(); return WiredManager.getGson().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -67,6 +67,7 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { if (wiredData.startsWith("{")) { WiredConditionFurniTypeMatch.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class); + this.furniSource = data.furniSource; for(int id : data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -85,12 +86,17 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { this.items.add(item); } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; } } @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -112,7 +118,8 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -124,13 +131,18 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { int count = settings.getFurniIds().length; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.items.clear(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room != null) { - for (int i = 0; i < count; i++) { - this.items.add(room.getHabboItem(settings.getFurniIds()[i])); + if (room != null) { + for (int i = 0; i < count; i++) { + this.items.add(room.getHabboItem(settings.getFurniIds()[i])); + } } } @@ -157,9 +169,11 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { static class JsonData { List itemIds; + int furniSource; - public JsonData(List itemIds) { + public JsonData(List itemIds, int furniSource) { this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java index cbdbb7b4..a2bb7056 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java @@ -8,6 +8,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; @@ -18,6 +19,7 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { private int lowerLimit = 10; private int upperLimit = 20; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionNotHabboCount(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -29,7 +31,9 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - int count = ctx.room().getUserCount(); + int count = (this.userSource == WiredSourceUtil.SOURCE_TRIGGER) + ? ctx.room().getUserCount() + : WiredSourceUtil.resolveUsers(ctx, this.userSource).size(); return count < this.lowerLimit || count > this.upperLimit; } @@ -44,7 +48,8 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( this.lowerLimit, - this.upperLimit + this.upperLimit, + this.userSource )); } @@ -56,10 +61,12 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { WiredConditionHabboCount.JsonData data = WiredManager.getGson().fromJson(wiredData, WiredConditionHabboCount.JsonData.class); this.lowerLimit = data.lowerLimit; this.upperLimit = data.upperLimit; + this.userSource = data.userSource; } else { String[] data = wiredData.split(":"); this.lowerLimit = Integer.parseInt(data[0]); this.upperLimit = Integer.parseInt(data[1]); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @@ -67,6 +74,7 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { public void onPickUp() { this.upperLimit = 0; this.lowerLimit = 20; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -82,9 +90,10 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(2); + message.appendInt(3); message.appendInt(this.lowerLimit); message.appendInt(this.upperLimit); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -96,6 +105,8 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { if(settings.getIntParams().length < 2) return false; this.lowerLimit = settings.getIntParams()[0]; this.upperLimit = settings.getIntParams()[1]; + int[] params = settings.getIntParams(); + this.userSource = (params.length > 2) ? params[2] : WiredSourceUtil.SOURCE_TRIGGER; return true; } @@ -103,10 +114,12 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { static class JsonData { int lowerLimit; int upperLimit; + int userSource; - public JsonData(int lowerLimit, int upperLimit) { + public JsonData(int lowerLimit, int upperLimit, int userSource) { this.lowerLimit = lowerLimit; this.upperLimit = upperLimit; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java index 1a622641..d061c0a8 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java @@ -8,15 +8,18 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { private static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_EFFECT; protected int effectId; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionNotHabboHasEffect(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -28,9 +31,15 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); - if (roomUnit == null) return false; - return roomUnit.getEffectId() != this.effectId; + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return false; + for (RoomUnit roomUnit : targets) { + if (roomUnit == null) return false; + if (roomUnit.getEffectId() == this.effectId) { + return false; + } + } + return true; } @Deprecated @@ -42,7 +51,8 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { @Override public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( - this.effectId + this.effectId, + this.userSource )); } @@ -53,14 +63,17 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.effectId = data.effectId; + this.userSource = data.userSource; } else { this.effectId = Integer.parseInt(wiredData); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.effectId = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -76,7 +89,9 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.effectId + ""); - message.appendInt(0); + message.appendInt(2); + message.appendInt(this.effectId); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -87,15 +102,19 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { public boolean saveData(WiredSettings settings) { if(settings.getIntParams().length < 1) return false; this.effectId = settings.getIntParams()[0]; + int[] params = settings.getIntParams(); + this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; return true; } static class JsonData { int effectId; + int userSource; - public JsonData(int effectId) { + public JsonData(int effectId, int userSource) { this.effectId = effectId; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java index 81bc279b..5521d5d8 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java @@ -10,15 +10,18 @@ import com.eu.habbo.habbohotel.users.HabboBadge; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_BADGE; protected String badge = ""; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionNotHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -30,20 +33,21 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); Room room = ctx.room(); - Habbo habbo = room.getHabbo(roomUnit); + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return true; - if (habbo != null) { - synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { - for (HabboBadge b : habbo.getInventory().getBadgesComponent().getWearingBadges()) { - if (b.getCode().equalsIgnoreCase(this.badge)) - return false; + for (RoomUnit roomUnit : targets) { + Habbo habbo = room.getHabbo(roomUnit); + if (habbo != null) { + synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { + for (HabboBadge b : habbo.getInventory().getBadgesComponent().getWearingBadges()) { + if (b.getCode().equalsIgnoreCase(this.badge)) + return false; + } } } - return true; } - return true; } @@ -56,7 +60,8 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition @Override public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( - this.badge + this.badge, + this.userSource )); } @@ -67,14 +72,17 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.badge = data.badge; + this.userSource = data.userSource; } else { this.badge = wiredData; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.badge = ""; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -90,7 +98,8 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.badge); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -100,15 +109,19 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition @Override public boolean saveData(WiredSettings settings) { this.badge = settings.getStringParam(); + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; return true; } static class JsonData { String badge; + int userSource; - public JsonData(String badge) { + public JsonData(String badge, int userSource) { this.badge = badge; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java index 4670912e..237be63d 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java @@ -8,13 +8,16 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionNotInGroup extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_GROUP; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionNotInGroup(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -26,14 +29,20 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); Room room = ctx.room(); if (room.getGuildId() == 0) return false; - Habbo habbo = room.getHabbo(roomUnit); + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return true; - return habbo == null || !habbo.getHabboStats().hasGuild(room.getGuildId()); + for (RoomUnit roomUnit : targets) { + Habbo habbo = room.getHabbo(roomUnit); + if (habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId())) { + return false; + } + } + return true; } @Deprecated @@ -44,17 +53,26 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition { @Override public String getWiredData() { - return ""; + return String.valueOf(this.userSource); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - + String wiredData = set.getString("wired_data"); + if (wiredData != null && !wiredData.isEmpty()) { + try { + this.userSource = Integer.parseInt(wiredData); + } catch (NumberFormatException ignored) { + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; + } + } else { + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; + } } @Override public void onPickUp() { - + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -70,7 +88,8 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -79,6 +98,8 @@ public class WiredConditionNotInGroup extends InteractionWiredCondition { @Override public boolean saveData(WiredSettings settings) { + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; return true; } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java index 7ae8bb03..9eead216 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java @@ -10,15 +10,18 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionNotInTeam extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_TEAM; private GameTeamColors teamColor = GameTeamColors.RED; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionNotInTeam(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -30,14 +33,18 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); Room room = ctx.room(); - Habbo habbo = room.getHabbo(roomUnit); + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return true; - if (habbo != null) { - return habbo.getHabboInfo().getGamePlayer() == null || !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); // user is not part of any team + for (RoomUnit roomUnit : targets) { + Habbo habbo = room.getHabbo(roomUnit); + if (habbo != null && habbo.getHabboInfo().getGamePlayer() != null) { + if (habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor)) { + return false; + } + } } - return true; } @@ -50,7 +57,8 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition { @Override public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( - this.teamColor + this.teamColor, + this.userSource )); } @@ -62,18 +70,22 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.teamColor = data.teamColor; + this.userSource = data.userSource; } else { if (!wiredData.equals("")) this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)]; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } catch (Exception e) { this.teamColor = GameTeamColors.RED; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.teamColor = GameTeamColors.RED; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -89,8 +101,9 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.teamColor.type); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -101,15 +114,19 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition { public boolean saveData(WiredSettings settings) { if(settings.getIntParams().length < 1) return false; this.teamColor = GameTeamColors.values()[settings.getIntParams()[0]]; + int[] params = settings.getIntParams(); + this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; return true; } static class JsonData { GameTeamColors teamColor; + int userSource; - public JsonData(GameTeamColors teamColor) { + public JsonData(GameTeamColors teamColor, int userSource) { this.teamColor = teamColor; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java index 88558789..4fe1d474 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java @@ -3,11 +3,14 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurni { public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_ON_FURNI; @@ -22,18 +25,19 @@ public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurn @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); Room room = ctx.room(); - if (roomUnit == null) - return false; - this.refresh(); - if (this.items.isEmpty()) + List userTargets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (userTargets.isEmpty()) + return false; + + List itemTargets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (itemTargets.isEmpty()) return true; - return !triggerOnFurni(roomUnit, room); + return !isAnyUserOnFurni(userTargets, itemTargets, room); } @Deprecated diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java index 5f1ac3a6..658f8b7d 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java @@ -10,15 +10,18 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; public class WiredConditionTeamMember extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.ACTOR_IN_TEAM; private GameTeamColors teamColor = GameTeamColors.RED; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionTeamMember(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -30,16 +33,18 @@ public class WiredConditionTeamMember extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); Room room = ctx.room(); - Habbo habbo = room.getHabbo(roomUnit); + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return false; - if (habbo != null) { - if (habbo.getHabboInfo().getGamePlayer() != null) { - return habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); + for (RoomUnit roomUnit : targets) { + Habbo habbo = room.getHabbo(roomUnit); + if (habbo != null && habbo.getHabboInfo().getGamePlayer() != null) { + if (habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor)) { + return true; + } } } - return false; } @@ -52,7 +57,8 @@ public class WiredConditionTeamMember extends InteractionWiredCondition { @Override public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( - this.teamColor + this.teamColor, + this.userSource )); } @@ -64,18 +70,22 @@ public class WiredConditionTeamMember extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.teamColor = data.teamColor; + this.userSource = data.userSource; } else { if (!wiredData.equals("")) this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)]; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } catch (Exception e) { this.teamColor = GameTeamColors.RED; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.teamColor = GameTeamColors.RED; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -91,8 +101,9 @@ public class WiredConditionTeamMember extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.teamColor.type); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -103,15 +114,19 @@ public class WiredConditionTeamMember extends InteractionWiredCondition { public boolean saveData(WiredSettings settings) { if(settings.getIntParams().length < 1) return false; this.teamColor = GameTeamColors.values()[settings.getIntParams()[0]]; + int[] params = settings.getIntParams(); + this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; return true; } static class JsonData { GameTeamColors teamColor; + int userSource; - public JsonData(GameTeamColors teamColor) { + public JsonData(GameTeamColors teamColor, int userSource) { this.teamColor = teamColor; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java index 3ced00ba..560ac2d8 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java @@ -11,11 +11,13 @@ import com.eu.habbo.habbohotel.wired.WiredConditionOperator; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -23,6 +25,8 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI; protected THashSet items = new THashSet<>(); + protected int furniSource = WiredSourceUtil.SOURCE_TRIGGER; + protected int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -34,18 +38,19 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { @Override public boolean evaluate(WiredContext ctx) { - RoomUnit roomUnit = ctx.actor().orElse(null); Room room = ctx.room(); - if (roomUnit == null) - return false; - this.refresh(); - if (this.items.isEmpty()) + List userTargets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (userTargets.isEmpty()) return false; - return triggerOnFurni(roomUnit, room); + List itemTargets = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (itemTargets.isEmpty()) + return false; + + return isAnyUserOnFurni(userTargets, itemTargets, room); } @Deprecated @@ -54,16 +59,24 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { return false; } - protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) { - THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); - return this.items.stream().anyMatch(itemsAtUser::contains); + protected boolean isAnyUserOnFurni(Collection users, Collection items, Room room) { + for (RoomUnit roomUnit : users) { + if (roomUnit == null) continue; + THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); + if (items.stream().anyMatch(itemsAtUser::contains)) { + return true; + } + } + return false; } @Override public String getWiredData() { this.refresh(); return WiredManager.getGson().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource, + this.userSource )); } @@ -74,6 +87,8 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); + this.furniSource = data.furniSource; + this.userSource = data.userSource; for(int id : data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -92,12 +107,19 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { this.items.add(item); } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; + } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; } } @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -119,7 +141,9 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(2); + message.appendInt(this.furniSource); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(0); @@ -131,16 +155,22 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { int count = settings.getFurniIds().length; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; + this.items.clear(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room != null) { - for (int i = 0; i < count; i++) { - HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); + if (room != null) { + for (int i = 0; i < count; i++) { + HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); - if (item != null) { - this.items.add(item); + if (item != null) { + this.items.add(item); + } } } } @@ -171,9 +201,13 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { static class JsonData { List itemIds; + int furniSource; + int userSource; - public JsonData(List itemIds) { + public JsonData(List itemIds, int furniSource, int userSource) { this.itemIds = itemIds; + this.furniSource = furniSource; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java index 40bd2d3d..ee4520c2 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java @@ -22,7 +22,7 @@ public class WiredEffectAlert extends WiredEffectWhisper { public void execute(WiredContext ctx) { Room room = ctx.room(); - for (com.eu.habbo.habbohotel.rooms.RoomUnit unit : ctx.targets().users()) { + for (com.eu.habbo.habbohotel.rooms.RoomUnit unit : resolveUsers(ctx)) { Habbo habbo = room.getHabbo(unit); if (habbo == null) continue; diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java index 28ba0c3a..6bdb028d 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java @@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; @@ -27,6 +28,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { private String botName = ""; private int mode = 0; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectBotFollowHabbo(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -44,8 +46,9 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.botName); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.mode); + message.appendInt(this.userSource); message.appendInt(1); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -72,9 +75,10 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("Mode is invalid"); + if(settings.getIntParams().length < 2) throw new WiredSaveException("Mode is invalid"); int mode = settings.getIntParams()[0]; + this.userSource = settings.getIntParams()[1]; if(mode != 0 && mode != 1) throw new WiredSaveException("Mode is invalid"); @@ -102,8 +106,9 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { @Override public void execute(WiredContext ctx) { Room room = ctx.room(); - RoomUnit roomUnit = ctx.actor().orElse(null); - if (roomUnit == null) return; + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return; + RoomUnit roomUnit = targets.get(0); Habbo habbo = room.getHabbo(roomUnit); List bots = room.getBots(this.botName); @@ -127,7 +132,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.getDelay(), this.userSource)); } @Override @@ -139,6 +144,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { this.setDelay(data.delay); this.mode = data.mode; this.botName = data.bot_name; + this.userSource = data.userSource; } else { String[] data = wiredData.split(((char) 9) + ""); @@ -150,6 +156,7 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @@ -157,23 +164,26 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { public void onPickUp() { this.botName = ""; this.mode = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { String bot_name; int mode; int delay; + int userSource; - public JsonData(String bot_name, int mode, int delay) { + public JsonData(String bot_name, int mode, int delay, int userSource) { this.bot_name = bot_name; this.mode = mode; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java index d39d1044..c5350555 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java @@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; @@ -30,6 +31,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { private String botName = ""; private int itemId; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectBotGiveHandItem(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -47,8 +49,9 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.botName); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.itemId); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -75,9 +78,10 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("Missing item id"); + if(settings.getIntParams().length < 2) throw new WiredSaveException("Missing item id"); int itemId = settings.getIntParams()[0]; + this.userSource = settings.getIntParams()[1]; if(itemId < 0) itemId = 0; @@ -104,8 +108,9 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { @Override public void execute(WiredContext ctx) { Room room = ctx.room(); - RoomUnit roomUnit = ctx.actor().orElse(null); - if (roomUnit == null) return; + List targets = WiredSourceUtil.resolveUsers(ctx, this.userSource); + if (targets.isEmpty()) return; + RoomUnit roomUnit = targets.get(0); Habbo habbo = room.getHabbo(roomUnit); List bots = room.getBots(this.botName); @@ -141,7 +146,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.botName, this.itemId, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.botName, this.itemId, this.getDelay(), this.userSource)); } @Override @@ -153,6 +158,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { this.setDelay(data.delay); this.itemId = data.item_id; this.botName = data.bot_name; + this.userSource = data.userSource; } else { String[] data = wiredData.split(((char) 9) + ""); @@ -164,6 +170,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @@ -171,23 +178,26 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { public void onPickUp() { this.botName = ""; this.itemId = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { String bot_name; int item_id; int delay; + int userSource; - public JsonData(String bot_name, int item_id, int delay) { + public JsonData(String bot_name, int item_id, int delay, int userSource) { this.bot_name = bot_name; this.item_id = item_id; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java index c765b2ba..c7dc2eb5 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java @@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; @@ -29,6 +30,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { private int mode; private String botName = ""; private String message = ""; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectBotTalkToHabbo(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -46,8 +48,9 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.botName + "" + ((char) 9) + "" + this.message); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.mode); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -74,8 +77,9 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("Missing mode"); + if(settings.getIntParams().length < 2) throw new WiredSaveException("Missing mode"); int mode = settings.getIntParams()[0]; + this.userSource = settings.getIntParams()[1]; if(mode != 0 && mode != 1) throw new WiredSaveException("Mode is invalid"); @@ -116,7 +120,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { if (bots.size() != 1) return; Bot bot = bots.get(0); - for (RoomUnit roomUnit : ctx.targets().users()) { + for (RoomUnit roomUnit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { Habbo habbo = room.getHabbo(roomUnit); if (habbo == null) continue; @@ -149,7 +153,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay(), this.userSource)); } @Override @@ -162,6 +166,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { this.mode = data.mode; this.botName = data.bot_name; this.message = data.message; + this.userSource = data.userSource; } else { String[] data = wiredData.split(((char) 9) + ""); @@ -174,6 +179,7 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @@ -182,12 +188,13 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { this.botName = ""; this.message = ""; this.mode = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @Override public boolean requiresTriggeringUser() { - return false; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { @@ -195,12 +202,14 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { int mode; String message; int delay; + int userSource; - public JsonData(String bot_name, int mode, String message, int delay) { + public JsonData(String bot_name, int mode, String message, int delay, int userSource) { this.bot_name = bot_name; this.mode = mode; this.message = message; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java index a24b850b..650877d7 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java @@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer; @@ -32,6 +33,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { private THashSet items; private String botName = ""; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectBotTeleport(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -108,7 +110,8 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.botName); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -118,6 +121,8 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { String botName = settings.getStringParam(); + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; int itemsCount = settings.getFurniIds().length; if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { @@ -126,14 +131,16 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { List newItems = new ArrayList<>(); - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); - newItems.add(it); + newItems.add(it); + } } int delay = settings.getDelay(); @@ -142,7 +149,9 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.addAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.addAll(newItems); + } this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); this.setDelay(delay); @@ -158,10 +167,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - // Use selector targets if a selector has modified them, otherwise use manually picked items - Iterable effectiveItems = ctx.targets().isItemsModifiedBySelector() - ? ctx.targets().items() - : new ArrayList<>(this.items); + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); List validItems = new ArrayList<>(); for (HabboItem item : effectiveItems) { @@ -208,7 +214,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { } } - return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay(), this.furniSource)); } @Override @@ -221,6 +227,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); this.botName = data.bot_name; + this.furniSource = data.furniSource; for(int itemId : data.items) { HabboItem item = room.getHabboItem(itemId); @@ -228,6 +235,9 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { if (item != null) this.items.add(item); } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] wiredDataSplit = set.getString("wired_data").split("\t"); @@ -249,6 +259,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { } this.needsUpdate(true); + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @@ -256,6 +267,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { public void onPickUp() { this.botName = ""; this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -263,11 +275,13 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { String bot_name; List items; int delay; + int furniSource; - public JsonData(String bot_name, List items, int delay) { + public JsonData(String bot_name, List items, int delay, int furniSource) { this.bot_name = bot_name; this.items = items; this.delay = delay; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java index 9084e4ac..b8a2f059 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java @@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.set.hash.THashSet; @@ -27,6 +28,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { private List items; private String botName = ""; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectBotWalkToFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -60,7 +62,8 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.botName); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -70,6 +73,8 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { String botName = settings.getStringParam(); + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; int itemsCount = settings.getFurniIds().length; if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { @@ -78,14 +83,16 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { List newItems = new ArrayList<>(); - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); - newItems.add(it); + newItems.add(it); + } } int delay = settings.getDelay(); @@ -94,7 +101,9 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.addAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.addAll(newItems); + } this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); this.setDelay(delay); @@ -111,15 +120,9 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { Room room = ctx.room(); List bots = room.getBots(this.botName); - // Use selector targets if a selector has modified them, otherwise use manually picked items - boolean useSelector = ctx.targets().isItemsModifiedBySelector(); - List effectiveItems; - - if (useSelector) { - effectiveItems = new ArrayList<>(ctx.targets().items()); - } else { + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); - effectiveItems = this.items; } if (effectiveItems.isEmpty() || bots.size() != 1) { @@ -163,7 +166,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { } } - return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.botName, itemIds, this.getDelay(), this.furniSource)); } @Override @@ -176,6 +179,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); this.botName = data.bot_name; + this.furniSource = data.furniSource; for(int itemId : data.items) { HabboItem item = room.getHabboItem(itemId); @@ -183,6 +187,9 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { if (item != null) this.items.add(item); } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] wiredDataSplit = set.getString("wired_data").split("\t"); @@ -204,6 +211,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { } this.needsUpdate(true); + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @@ -211,6 +219,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { public void onPickUp() { this.items.clear(); this.botName = ""; + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -218,11 +227,13 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { String bot_name; List items; int delay; + int furniSource; - public JsonData(String bot_name, List items, int delay) { + public JsonData(String bot_name, List items, int delay, int furniSource) { this.bot_name = bot_name; this.items = items; this.delay = delay; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java index e9ffcef0..529f206b 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java @@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.*; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; @@ -36,6 +37,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { private final THashMap items = new THashMap<>(0); private RoomUserRotation startRotation = RoomUserRotation.NORTH; private int blockedAction = 0; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -50,23 +52,10 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { Room room = ctx.room(); if (room == null || room.getLayout() == null) return; - // Use selector targets if a selector has modified them, otherwise use manually picked items - boolean useSelector = ctx.targets().isItemsModifiedBySelector(); + List resolvedItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items.keySet()); THashMap effectiveItems; - if (useSelector) { - effectiveItems = new THashMap<>(); - for (HabboItem item : ctx.targets().items()) { - if (item != null) { - // Check if we already have settings for this item, otherwise create defaults - WiredChangeDirectionSetting setting = this.items.get(item); - if (setting == null) { - setting = new WiredChangeDirectionSetting(item.getId(), item.getRotation(), this.startRotation); - } - effectiveItems.put(item, setting); - } - } - } else { + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { THashSet toRemove = new THashSet<>(); for (HabboItem item : this.items.keySet()) { if (item == null || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) @@ -76,6 +65,17 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { this.items.remove(item); } effectiveItems = this.items; + } else { + effectiveItems = new THashMap<>(); + for (HabboItem item : resolvedItems) { + if (item != null) { + WiredChangeDirectionSetting setting = this.items.get(item); + if (setting == null) { + setting = new WiredChangeDirectionSetting(item.getId(), item.getRotation(), this.startRotation); + } + effectiveItems.put(item, setting); + } + } } if (effectiveItems.isEmpty()) return; @@ -157,7 +157,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { @Override public String getWiredData() { ArrayList settings = new ArrayList<>(this.items.values()); - return WiredManager.getGson().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay(), this.furniSource)); } @Override @@ -172,6 +172,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { this.setDelay(data.delay); this.startRotation = data.start_direction; this.blockedAction = data.blocked_action; + this.furniSource = data.furniSource; for(WiredChangeDirectionSetting setting : data.items) { HabboItem item = room.getHabboItem(setting.item_id); @@ -180,6 +181,9 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { this.items.put(item, setting); } } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] data = wiredData.split("\t"); @@ -212,6 +216,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; this.needsUpdate(true); } } @@ -222,6 +227,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { this.items.clear(); this.blockedAction = 0; this.startRotation = RoomUserRotation.NORTH; + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -240,9 +246,10 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(2); + message.appendInt(3); message.appendInt(this.startRotation != null ? this.startRotation.getValue() : 0); message.appendInt(this.blockedAction); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -251,7 +258,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 2) throw new WiredSaveException("Invalid data"); + if(settings.getIntParams().length < 3) throw new WiredSaveException("Invalid data"); int startDirectionInt = settings.getIntParams()[0]; @@ -262,6 +269,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { RoomUserRotation startDirection = RoomUserRotation.fromValue(startDirectionInt); int blockedActionInt = settings.getIntParams()[1]; + this.furniSource = settings.getIntParams()[2]; if(blockedActionInt < 0 || blockedActionInt > 6) { throw new WiredSaveException("Blocked action is invalid"); @@ -291,7 +299,9 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.putAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.putAll(newItems); + } this.startRotation = startDirection; this.blockedAction = blockedActionInt; this.setDelay(delay); @@ -329,12 +339,14 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { int blocked_action; List items; int delay; + int furniSource; - public JsonData(RoomUserRotation start_direction, int blocked_action, List items, int delay) { + public JsonData(RoomUserRotation start_direction, int blocked_action, List items, int delay, int furniSource) { this.start_direction = start_direction; this.blocked_action = blocked_action; this.items = items; this.delay = delay; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java index 1c7a976b..cd46edcf 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java @@ -30,7 +30,7 @@ public class WiredEffectGiveEffect extends WiredEffectWhisper { Room room = ctx.room(); if (effectId >= 0) { - for (RoomUnit roomUnit : ctx.targets().users()) { + for (RoomUnit roomUnit : resolveUsers(ctx)) { room.giveEffect(roomUnit, effectId, Integer.MAX_VALUE); } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java index 637c02c4..b8d1ceaa 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java @@ -24,7 +24,7 @@ public class WiredEffectGiveHandItem extends WiredEffectWhisper { Room room = ctx.room(); - for (com.eu.habbo.habbohotel.rooms.RoomUnit unit : ctx.targets().users()) { + for (com.eu.habbo.habbohotel.rooms.RoomUnit unit : resolveUsers(ctx)) { Habbo habbo = room.getHabbo(unit); if (habbo != null) { room.giveHandItem(habbo, itemId); diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java index 0834f54d..f33d591a 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java @@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.hotelview.BonusRareComposer; import gnu.trove.procedure.TObjectProcedure; @@ -25,6 +26,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; private int amount = 0; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectGiveHotelviewBonusRarePoints(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -42,7 +44,8 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.amount + ""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(type.code); message.appendInt(this.getDelay()); @@ -75,6 +78,9 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff return false; } + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.setDelay(settings.getDelay()); return true; @@ -87,12 +93,12 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff @Override public void execute(WiredContext ctx) { - Habbo habbo = ctx.actor().map(unit -> ctx.room().getHabbo(unit)).orElse(null); + if (this.amount <= 0) return; - if (habbo == null) - return; + for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { + Habbo habbo = ctx.room().getHabbo(unit); + if (habbo == null) continue; - if (this.amount > 0) { habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), this.amount); habbo.getClient().sendResponse(new BonusRareComposer(habbo)); } @@ -106,7 +112,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.getDelay(), this.amount)); + return WiredManager.getGson().toJson(new JsonData(this.getDelay(), this.amount, this.userSource)); } @Override @@ -118,6 +124,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); this.amount = data.amount; + this.userSource = data.userSource; } else { if (wiredData.split("\t").length >= 2) { super.setDelay(Integer.parseInt(wiredData.split("\t")[0])); @@ -133,21 +140,24 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff @Override public void onPickUp() { this.amount = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { int delay; int amount; + int userSource; - public JsonData(int delay, int amount) { + public JsonData(int delay, int amount, int userSource) { this.delay = delay; this.amount = amount; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java index 56d1cf94..6229acbf 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java @@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.procedure.TObjectProcedure; @@ -24,6 +25,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; private int amount = 0; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectGiveHotelviewHofPoints(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -41,7 +43,8 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.amount + ""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(type.code); message.appendInt(this.getDelay()); @@ -74,6 +77,9 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { return false; } + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.setDelay(settings.getDelay()); return true; @@ -86,12 +92,12 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { @Override public void execute(WiredContext ctx) { - Habbo habbo = ctx.actor().map(unit -> ctx.room().getHabbo(unit)).orElse(null); + if (this.amount <= 0) return; - if (habbo == null) - return; + for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { + Habbo habbo = ctx.room().getHabbo(unit); + if (habbo == null) continue; - if (this.amount > 0) { habbo.getHabboStats().hofPoints += this.amount; Emulator.getThreading().run(habbo.getHabboStats()); } @@ -105,7 +111,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.amount, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.amount, this.getDelay(), this.userSource)); } @Override @@ -116,6 +122,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.amount = data.amount; this.setDelay(data.delay); + this.userSource = data.userSource; } else { this.amount = 0; @@ -130,27 +137,31 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.amount = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { int amount; int delay; + int userSource; - public JsonData(int amount, int delay) { + public JsonData(int amount, int delay, int userSource) { this.amount = amount; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java index a83e9a31..335792d6 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java @@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import gnu.trove.procedure.TObjectProcedure; @@ -25,6 +26,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; private int respects = 0; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectGiveRespect(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -42,7 +44,8 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.respects + ""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(type.code); message.appendInt(this.getDelay()); @@ -75,6 +78,9 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { return false; } + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.setDelay(settings.getDelay()); return true; @@ -89,7 +95,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - for (RoomUnit unit : ctx.targets().users()) { + for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { Habbo habbo = room.getHabbo(unit); if (habbo == null) continue; @@ -106,7 +112,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.respects, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.respects, this.getDelay(), this.userSource)); } @Override @@ -117,6 +123,7 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.respects = data.amount; this.setDelay(data.delay); + this.userSource = data.userSource; } else { String[] data = wiredData.split("\t"); @@ -132,27 +139,31 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.respects = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { int amount; int delay; + int userSource; - public JsonData(int amount, int delay) { + public JsonData(int amount, int delay, int userSource) { this.amount = amount; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java index 21d8e10e..a2df0c12 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java @@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredGiveRewardItem; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.generic.alerts.UpdateFailedComposer; @@ -40,6 +41,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { public int rewardTime; public boolean uniqueRewards; public THashSet rewardItems = new THashSet<>(); + public int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectGiveReward(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -53,7 +55,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - for (RoomUnit roomUnit : ctx.targets().users()) { + for (RoomUnit roomUnit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { Habbo habbo = room.getHabbo(roomUnit); if (habbo != null) { WiredManager.getReward(habbo, this); @@ -71,7 +73,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { public String getWiredData() { ArrayList rewards = new ArrayList<>(this.rewardItems); - return WiredManager.getGson().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay(), this.userSource)); } @Override @@ -88,6 +90,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { this.limitationInterval = data.limit_interval; this.rewardItems.clear(); this.rewardItems.addAll(data.rewards); + this.userSource = data.userSource; } else { String[] data = wiredData.split(":"); @@ -115,6 +118,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } } @@ -127,6 +131,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { this.rewardTime = 0; this.uniqueRewards = false; this.rewardItems.clear(); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -157,11 +162,12 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { s.append(item.wiredString()).append(";"); } message.appendString(s.toString()); - message.appendInt(4); + message.appendInt(5); message.appendInt(this.rewardTime); message.appendInt(this.uniqueRewards); message.appendInt(this.limit); message.appendInt(this.limitationInterval); + message.appendInt(this.userSource); message.appendInt(this.limit > 0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -189,11 +195,12 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { if (gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) { - if(settings.getIntParams().length < 4) throw new WiredSaveException("Invalid data"); + if(settings.getIntParams().length < 5) throw new WiredSaveException("Invalid data"); this.rewardTime = settings.getIntParams()[0]; this.uniqueRewards = settings.getIntParams()[1] == 1; this.limit = settings.getIntParams()[2]; this.limitationInterval = settings.getIntParams()[3]; + this.userSource = settings.getIntParams()[4]; this.given = 0; String data = settings.getStringParam(); @@ -229,7 +236,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -245,8 +252,9 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { int limit_interval; List rewards; int delay; + int userSource; - public JsonData(int limit, int given, int reward_time, boolean unique_rewards, int limit_interval, List rewards, int delay) { + public JsonData(int limit, int given, int reward_time, boolean unique_rewards, int limit_interval, List rewards, int delay, int userSource) { this.limit = limit; this.given = given; this.reward_time = reward_time; @@ -254,6 +262,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { this.limit_interval = limit_interval; this.rewards = rewards; this.delay = delay; + this.userSource = userSource; } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java index 416a5e18..b2b07b4d 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java @@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.iterator.TObjectIntIterator; @@ -32,6 +33,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { private int score; private int count; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; private TObjectIntMap> data = new TObjectIntHashMap<>(); @@ -47,7 +49,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - for (RoomUnit unit : ctx.targets().users()) { + for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { Habbo habbo = room.getHabbo(unit); if (habbo == null || habbo.getHabboInfo().getCurrentGame() == null) continue; @@ -107,7 +109,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.score, this.count, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.score, this.count, this.getDelay(), this.userSource)); } @Override @@ -119,6 +121,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { this.score = data.score; this.count = data.count; this.setDelay(data.delay); + this.userSource = data.userSource; } else { String[] data = wiredData.split(";"); @@ -130,6 +133,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @@ -138,6 +142,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { this.score = 0; this.count = 0; this.setDelay(0); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -153,9 +158,10 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(2); + message.appendInt(3); message.appendInt(this.score); message.appendInt(this.count); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -182,7 +188,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 2) throw new WiredSaveException("Invalid data"); + if(settings.getIntParams().length < 3) throw new WiredSaveException("Invalid data"); int score = settings.getIntParams()[0]; @@ -194,6 +200,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { if(timesPerGame < 1 || timesPerGame > 10) throw new WiredSaveException("Times per game is invalid"); + this.userSource = settings.getIntParams()[2]; int delay = settings.getDelay(); if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) @@ -208,18 +215,20 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { int score; int count; int delay; + int userSource; - public JsonData(int score, int count, int delay) { + public JsonData(int score, int count, int delay, int userSource) { this.score = score; this.count = count; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java index 6a548fa1..82b94846 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java @@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; @@ -28,6 +29,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.JOIN_TEAM; private GameTeamColors teamColor = GameTeamColors.RED; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectJoinTeam(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -41,7 +43,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - for (RoomUnit unit : ctx.targets().users()) { + for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { Habbo habbo = room.getHabbo(unit); if (habbo == null) continue; @@ -67,7 +69,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.teamColor, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.teamColor, this.getDelay(), this.userSource)); } @Override @@ -78,6 +80,7 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); this.teamColor = data.team; + this.userSource = data.userSource; } else { String[] data = set.getString("wired_data").split("\t"); @@ -91,12 +94,14 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.teamColor = GameTeamColors.RED; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -113,8 +118,9 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.teamColor.type); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -141,9 +147,10 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("invalid data"); + if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data"); int team = settings.getIntParams()[0]; + this.userSource = settings.getIntParams()[1]; if(team < 1 || team > 4) throw new WiredSaveException("Team is invalid"); @@ -161,16 +168,18 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { GameTeamColors team; int delay; + int userSource; - public JsonData(GameTeamColors team, int delay) { + public JsonData(GameTeamColors team, int delay, int userSource) { this.team = team; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java index 27e85f05..5df7a21f 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java @@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; @@ -34,6 +35,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.KICK_USER; private String message = ""; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectKickHabbo(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -50,7 +52,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { LOGGER.debug("[KickHabbo] targets.users().size={} usersModifiedBySelector={}", ctx.targets().users().size(), ctx.targets().isUsersModifiedBySelector()); - for (RoomUnit unit : ctx.targets().users()) { + for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { Habbo habbo = room.getHabbo(unit); LOGGER.debug("[KickHabbo] RoomUnit id={} type={} -> Habbo={}", unit.getId(), unit.getRoomUnitType(), habbo != null ? habbo.getHabboInfo().getUsername() : "null"); @@ -83,7 +85,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay(), this.userSource)); } @Override @@ -94,6 +96,7 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); this.message = data.message; + this.userSource = data.userSource; } else { try { @@ -112,12 +115,14 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { } this.needsUpdate(true); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.message = ""; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -134,7 +139,8 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.message); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -162,6 +168,8 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { String message = settings.getStringParam(); + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; int delay = settings.getDelay(); if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) @@ -175,16 +183,18 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { String message; int delay; + int userSource; - public JsonData(String message, int delay) { + public JsonData(String message, int delay, int userSource) { this.message = message; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java index e294ac51..76a0d84b 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java @@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; @@ -25,6 +26,7 @@ import java.util.List; public class WiredEffectLeaveTeam extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.LEAVE_TEAM; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectLeaveTeam(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -38,7 +40,7 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - for (RoomUnit unit : ctx.targets().users()) { + for (RoomUnit unit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { Habbo habbo = room.getHabbo(unit); if (habbo == null) continue; @@ -64,7 +66,7 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.getDelay(), this.userSource)); } @Override @@ -74,15 +76,18 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { if(wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); + this.userSource = data.userSource; } else { this.setDelay(Integer.parseInt(wiredData)); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.setDelay(0); + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -98,7 +103,8 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -125,6 +131,9 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + int delay = settings.getDelay(); if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) @@ -134,11 +143,18 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { return true; } + @Override + public boolean requiresTriggeringUser() { + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; + } + static class JsonData { int delay; + int userSource; - public JsonData(int delay) { + public JsonData(int delay, int userSource) { this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java index cfbd8459..bab1896a 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java @@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; @@ -34,6 +35,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int private boolean state = false; private boolean direction = false; private boolean position = false; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectMatchFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -55,18 +57,21 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int if (room.getLayout() == null) return; - // When a selector provides items, only apply matching to items in both the selector targets and settings - boolean useSelector = ctx.targets().isItemsModifiedBySelector(); - java.util.Set selectorItemIds = null; - if (useSelector) { - selectorItemIds = new java.util.HashSet<>(); - for (HabboItem si : ctx.targets().items()) { - selectorItemIds.add(si.getId()); + java.util.Set allowedItemIds = null; + if (this.furniSource != WiredSourceUtil.SOURCE_SELECTED) { + allowedItemIds = new java.util.HashSet<>(); + for (HabboItem si : WiredSourceUtil.resolveItems(ctx, this.furniSource, null)) { + if (si != null) { + allowedItemIds.add(si.getId()); + } + } + if (allowedItemIds.isEmpty()) { + return; } } for (WiredMatchFurniSetting setting : this.settings) { - if (useSelector && !selectorItemIds.contains(setting.item_id)) continue; + if (allowedItemIds != null && !allowedItemIds.contains(setting.item_id)) continue; HabboItem item = room.getHabboItem(setting.item_id); if (item != null) { @@ -113,7 +118,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int @Override public String getWiredData() { this.refresh(); - return WiredManager.getGson().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList(this.settings), this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList(this.settings), this.getDelay(), this.furniSource)); } @Override @@ -128,6 +133,10 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int this.position = data.position; this.settings.clear(); this.settings.addAll(data.items); + this.furniSource = data.furniSource; + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.settings.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] data = set.getString("wired_data").split(":"); @@ -154,6 +163,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int this.direction = data[3].equals("1"); this.position = data[4].equals("1"); this.setDelay(Integer.parseInt(data[5])); + this.furniSource = this.settings.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; this.needsUpdate(true); } } @@ -164,6 +174,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int this.state = false; this.direction = false; this.position = false; + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -186,10 +197,11 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(3); + message.appendInt(4); message.appendInt(this.state ? 1 : 0); message.appendInt(this.direction ? 1 : 0); message.appendInt(this.position ? 1 : 0); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -198,32 +210,34 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 3) throw new WiredSaveException("Invalid data"); + if(settings.getIntParams().length < 4) throw new WiredSaveException("Invalid data"); boolean setState = settings.getIntParams()[0] == 1; boolean setDirection = settings.getIntParams()[1] == 1; boolean setPosition = settings.getIntParams()[2] == 1; + this.furniSource = settings.getIntParams()[3]; Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (room == null) throw new WiredSaveException("Trying to save wired in unloaded room"); - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - List newSettings = new ArrayList<>(); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + int itemsCount = settings.getFurniIds().length; - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = room.getHabboItem(itemId); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); + } - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = room.getHabboItem(itemId); - newSettings.add(new WiredMatchFurniSetting(it.getId(), this.checkForWiredResetPermission && it.allowWiredResetState() ? it.getExtradata() : " ", it.getRotation(), it.getX(), it.getY())); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newSettings.add(new WiredMatchFurniSetting(it.getId(), this.checkForWiredResetPermission && it.allowWiredResetState() ? it.getExtradata() : " ", it.getRotation(), it.getX(), it.getY())); + } } int delay = settings.getDelay(); @@ -235,7 +249,9 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int this.direction = setDirection; this.position = setPosition; this.settings.clear(); - this.settings.addAll(newSettings); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.settings.addAll(newSettings); + } this.setDelay(delay); return true; @@ -276,13 +292,15 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int boolean position; List items; int delay; + int furniSource; - public JsonData(boolean state, boolean direction, boolean position, List items, int delay) { + public JsonData(boolean state, boolean direction, boolean position, List items, int delay, int furniSource) { this.state = state; this.direction = direction; this.position = position; this.items = items; this.delay = delay; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java index a36379e6..3cd56464 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java @@ -11,6 +11,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredSimulation; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; @@ -28,6 +29,7 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.FLEE; private THashSet items = new THashSet<>(); + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectMoveFurniAway(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -42,21 +44,15 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { Room room = ctx.room(); if (room.getLayout() == null) return; - // Use selector targets if a selector has modified them, otherwise use manually picked items - boolean useSelector = ctx.targets().isItemsModifiedBySelector(); - Iterable effectiveItems; - - if (useSelector) { - effectiveItems = ctx.targets().items(); - } else { + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { THashSet toRemove = new THashSet<>(); - List itemsSnapshot = new ArrayList<>(this.items); - for (HabboItem item : itemsSnapshot) { - if (item.getRoomId() == 0) + for (HabboItem item : effectiveItems) { + if (item != null && item.getRoomId() == 0) { toRemove.add(item); + } } this.items.removeAll(toRemove); - effectiveItems = new ArrayList<>(this.items); } for (HabboItem item : effectiveItems) { @@ -124,7 +120,8 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { Room room = ctx.room(); if (room.getLayout() == null) return true; - for (HabboItem item : new ArrayList<>(this.items)) { + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + for (HabboItem item : effectiveItems) { if (item == null) continue; WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item); @@ -170,7 +167,8 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { List itemsSnapshot = new ArrayList<>(this.items); return WiredManager.getGson().toJson(new JsonData( this.getDelay(), - itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) + itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -182,12 +180,16 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); + this.furniSource = data.furniSource; for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); if (item != null) { this.items.add(item); } } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] wiredDataOld = wiredData.split("\t"); @@ -204,12 +206,14 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { } } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -241,7 +245,8 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -250,6 +255,9 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + int itemsCount = settings.getFurniIds().length; if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { @@ -258,14 +266,16 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { List newItems = new ArrayList<>(); - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); - newItems.add(it); + newItems.add(it); + } } int delay = settings.getDelay(); @@ -274,7 +284,9 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.addAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.addAll(newItems); + } this.setDelay(delay); return true; @@ -288,10 +300,12 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { static class JsonData { int delay; List itemIds; + int furniSource; - public JsonData(int delay, List itemIds) { + public JsonData(int delay, List itemIds, int furniSource) { this.delay = delay; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java index 5bdfd634..d2087c9f 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java @@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredSimulation; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; @@ -32,6 +33,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { private int direction; private int spacing = 1; private Map indexOffset = new LinkedHashMap<>(); + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectMoveFurniTo(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -51,13 +53,16 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { this.items.clear(); this.indexOffset.clear(); - if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data"); + if(settings.getIntParams().length < 3) throw new WiredSaveException("invalid data"); this.direction = settings.getIntParams()[0]; this.spacing = settings.getIntParams()[1]; + this.furniSource = settings.getIntParams()[2]; int count = settings.getFurniIds().length; - for (int i = 0; i < count; i++) { - this.items.add(room.getHabboItem(settings.getFurniIds()[i])); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < count; i++) { + this.items.add(room.getHabboItem(settings.getFurniIds()[i])); + } } this.setDelay(settings.getDelay()); @@ -75,23 +80,16 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { Room room = ctx.room(); if (room == null || room.getLayout() == null) return; - // Use selector targets if a selector has modified them, otherwise use manually picked items - boolean useSelector = ctx.targets().isItemsModifiedBySelector(); - List effectiveItems; - - if (useSelector) { - effectiveItems = new ArrayList<>(ctx.targets().items()); - } else { + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { List toRemove = new ArrayList<>(); - List itemsSnapshot = new ArrayList<>(this.items); - for (HabboItem item : itemsSnapshot) { + for (HabboItem item : effectiveItems) { if (item == null || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) toRemove.add(item); } for (HabboItem item : toRemove) { this.items.remove(item); } - effectiveItems = new ArrayList<>(this.items); } if (effectiveItems.isEmpty()) @@ -158,12 +156,13 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { Object[] stuff = ctx.legacySettings(); if (stuff == null || stuff.length == 0) return true; + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); for (Object object : stuff) { if (object instanceof HabboItem) { HabboItem item = (HabboItem) object; - if (this.items.isEmpty()) continue; - HabboItem targetItem = this.items.get(0); + if (effectiveItems.isEmpty()) continue; + HabboItem targetItem = effectiveItems.get(0); if (targetItem == null) continue; WiredSimulation.SimulatedPosition targetPos = simulation.getItemPosition(targetItem); @@ -205,7 +204,8 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { this.direction, this.spacing, this.getDelay(), - itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) + itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -232,9 +232,10 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(2); + message.appendInt(3); message.appendInt(this.direction); message.appendInt(this.spacing); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -251,6 +252,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { this.direction = data.direction; this.spacing = data.spacing; this.setDelay(data.delay); + this.furniSource = data.furniSource; for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -258,6 +260,9 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { this.items.add(item); } } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] data = wiredData.split("\t"); @@ -276,6 +281,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { this.items.add(item); } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @@ -286,6 +292,7 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { this.direction = 0; this.spacing = 0; this.indexOffset.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -298,12 +305,14 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { int spacing; int delay; List itemIds; + int furniSource; - public JsonData(int direction, int spacing, int delay, List itemIds) { + public JsonData(int direction, int spacing, int delay, List itemIds, int furniSource) { this.direction = direction; this.spacing = spacing; this.delay = delay; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java index 73ecd97c..d01a9fc5 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java @@ -11,6 +11,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredSimulation; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; @@ -37,6 +38,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { private THashSet items; private THashMap lastDirections; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectMoveFurniTowards(ResultSet set, Item baseItem) throws SQLException { @@ -90,23 +92,17 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - // Use selector targets if a selector has modified them, otherwise use manually picked items - boolean useSelector = ctx.targets().isItemsModifiedBySelector(); - Iterable effectiveItems; - - if (useSelector) { - effectiveItems = ctx.targets().items(); - } else { + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { THashSet toRemove = new THashSet<>(); - List itemsSnapshot = new ArrayList<>(this.items); - for (HabboItem item : itemsSnapshot) { - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) + for (HabboItem item : effectiveItems) { + if (item != null && Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) { toRemove.add(item); + } } for (HabboItem item : toRemove) { this.items.remove(item); } - effectiveItems = new ArrayList<>(this.items); } for (HabboItem item : effectiveItems) { @@ -257,7 +253,8 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { RoomLayout layout = room.getLayout(); if (layout == null) return true; - for (HabboItem item : new ArrayList<>(this.items)) { + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + for (HabboItem item : effectiveItems) { if (item == null) continue; WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item); @@ -322,7 +319,8 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { List itemsSnapshot = new ArrayList<>(this.items); return WiredManager.getGson().toJson(new JsonData( this.getDelay(), - itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) + itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -334,6 +332,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); + this.furniSource = data.furniSource; for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -341,6 +340,9 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { this.items.add(item); } } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] wiredDataOld = wiredData.split("\t"); @@ -357,12 +359,14 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { } } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -394,7 +398,8 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -403,6 +408,9 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + int itemsCount = settings.getFurniIds().length; if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { @@ -411,14 +419,16 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { List newItems = new ArrayList<>(); - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); - newItems.add(it); + newItems.add(it); + } } int delay = settings.getDelay(); @@ -427,7 +437,9 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.addAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.addAll(newItems); + } this.setDelay(delay); return true; @@ -441,10 +453,12 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { static class JsonData { int delay; List itemIds; + int furniSource; - public JsonData(int delay, List itemIds) { + public JsonData(int delay, List itemIds, int furniSource) { this.delay = delay; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java index b5dfb505..0b4cbb55 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java @@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredSimulation; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; @@ -30,6 +31,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement private final Set items = new LinkedHashSet<>(WiredManager.MAXIMUM_FURNI_SELECTION / 2); private int direction; private int rotation; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; // Use thread-safe set for cooldowns since execute() can be called from async threads private final Set itemCooldowns = ConcurrentHashMap.newKeySet(); // Pre-selected directions from simulation (itemId -> direction) @@ -47,16 +49,9 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement public void execute(WiredContext ctx) { Room room = ctx.room(); - // Use selector targets if a selector has modified them, otherwise use manually picked items - boolean useSelector = ctx.targets().isItemsModifiedBySelector(); - Iterable effectiveItems; - - if (useSelector) { - effectiveItems = ctx.targets().items(); - } else { - // remove items that are no longer in the room + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); - effectiveItems = this.items; } for (HabboItem item : effectiveItems) { @@ -99,7 +94,8 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement // Clear any previous pre-selected directions this.preSelectedDirections.clear(); - for (HabboItem item : this.items) { + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + for (HabboItem item : effectiveItems) { if (item == null) continue; WiredSimulation.SimulatedPosition currentPos = simulation.getItemPosition(item); @@ -156,7 +152,8 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement this.direction, this.rotation, this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -170,12 +167,16 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement this.setDelay(data.delay); this.direction = data.direction; this.rotation = data.rotation; + this.furniSource = data.furniSource; for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); if (item != null) { this.items.add(item); } } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] data = wiredData.split("\t"); @@ -195,6 +196,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement this.items.add(item); } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @@ -203,6 +205,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement this.direction = 0; this.rotation = 0; this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -232,9 +235,10 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(2); + message.appendInt(3); message.appendInt(this.direction); message.appendInt(this.rotation); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -248,19 +252,22 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement if (room == null) return false; - if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data"); + if(settings.getIntParams().length < 3) throw new WiredSaveException("invalid data"); this.direction = settings.getIntParams()[0]; this.rotation = settings.getIntParams()[1]; + this.furniSource = settings.getIntParams()[2]; int count = settings.getFurniIds().length; if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count", 5)) return false; this.items.clear(); - for (int i = 0; i < count; i++) { - HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); - if (item != null) { - this.items.add(item); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < count; i++) { + HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); + if (item != null) { + this.items.add(item); + } } } @@ -384,12 +391,14 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement int rotation; int delay; List itemIds; + int furniSource; - public JsonData(int direction, int rotation, int delay, List itemIds) { + public JsonData(int direction, int rotation, int delay, List itemIds, int furniSource) { this.direction = direction; this.rotation = rotation; this.delay = delay; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java index a476d224..41acb60e 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java @@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; @@ -25,6 +26,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { private int length = 5; private String message = ""; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectMuteHabbo(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -42,8 +44,9 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.message); - message.appendInt(1); + message.appendInt(2); message.appendInt(this.length); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -52,9 +55,10 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("invalid data"); + if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data"); this.length = settings.getIntParams()[0]; + this.userSource = settings.getIntParams()[1]; this.message = settings.getStringParam(); this.setDelay(settings.getDelay()); @@ -66,7 +70,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - for (RoomUnit roomUnit : ctx.targets().users()) { + for (RoomUnit roomUnit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { Habbo habbo = room.getHabbo(roomUnit); if (habbo == null) continue; @@ -89,7 +93,8 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { return WiredManager.getGson().toJson(new JsonData( this.getDelay(), this.length, - this.message + this.message, + this.userSource )); } @@ -102,6 +107,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { this.setDelay(data.delay); this.length = data.length; this.message = data.message; + this.userSource = data.userSource; } else { String[] data = wiredData.split("\t"); @@ -121,6 +127,7 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { this.setDelay(0); this.message = ""; this.length = 0; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -130,18 +137,20 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { int delay; int length; String message; + int userSource; - public JsonData(int delay, int length, String message) { + public JsonData(int delay, int length, String message, int userSource) { this.delay = delay; this.length = length; this.message = message; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java index ffae7301..03ecbf13 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java @@ -18,6 +18,7 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer; @@ -38,6 +39,8 @@ public class WiredEffectTeleport extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.TELEPORT; protected List items; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; + private int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectTeleport(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -134,7 +137,9 @@ public class WiredEffectTeleport extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(2); + message.appendInt(this.furniSource); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -160,6 +165,10 @@ public class WiredEffectTeleport extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + this.userSource = (params.length > 1) ? params[1] : WiredSourceUtil.SOURCE_TRIGGER; + int itemsCount = settings.getFurniIds().length; if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { @@ -168,14 +177,16 @@ public class WiredEffectTeleport extends InteractionWiredEffect { List newItems = new ArrayList<>(); - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); - newItems.add(it); + newItems.add(it); + } } int delay = settings.getDelay(); @@ -184,7 +195,9 @@ public class WiredEffectTeleport extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.addAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.addAll(newItems); + } this.setDelay(delay); return true; @@ -198,20 +211,15 @@ public class WiredEffectTeleport extends InteractionWiredEffect { return; } - // Use selector targets if a selector has modified them, otherwise use manually picked items - List effectiveItems; - - if (ctx.targets().isItemsModifiedBySelector()) { - effectiveItems = new ArrayList<>(ctx.targets().items()); - } else { + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); - effectiveItems = new ArrayList<>(this.items); } if (effectiveItems.isEmpty()) return; - for (RoomUnit roomUnit : ctx.targets().users()) { + for (RoomUnit roomUnit : WiredSourceUtil.resolveUsers(ctx, this.userSource)) { int i = Emulator.getRandom().nextInt(effectiveItems.size()); HabboItem item = effectiveItems.get(i); @@ -235,7 +243,9 @@ public class WiredEffectTeleport extends InteractionWiredEffect { List itemsSnapshot = new ArrayList<>(this.items); return WiredManager.getGson().toJson(new JsonData( this.getDelay(), - itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) + itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource, + this.userSource )); } @@ -247,12 +257,17 @@ public class WiredEffectTeleport extends InteractionWiredEffect { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); + this.furniSource = data.furniSource; + this.userSource = data.userSource; for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); if (item != null) { this.items.add(item); } } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] wiredDataOld = wiredData.split("\t"); @@ -269,12 +284,16 @@ public class WiredEffectTeleport extends InteractionWiredEffect { } } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; } } @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -285,7 +304,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect { @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } @Override @@ -296,10 +315,14 @@ public class WiredEffectTeleport extends InteractionWiredEffect { static class JsonData { int delay; List itemIds; + int furniSource; + int userSource; - public JsonData(int delay, List itemIds) { + public JsonData(int delay, List itemIds, int furniSource, int userSource) { this.delay = delay; this.itemIds = itemIds; + this.furniSource = furniSource; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java index 34c771bc..09a14d67 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java @@ -23,6 +23,7 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; @@ -42,6 +43,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.TOGGLE_STATE; private final THashSet items; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; private static final List> FORBIDDEN_TYPES = new ArrayList>() { { @@ -120,7 +122,8 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -147,6 +150,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + int itemsCount = settings.getFurniIds().length; if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { @@ -154,15 +160,16 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { } List newItems = new ArrayList<>(); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); + newItems.add(it); + } } int delay = settings.getDelay(); @@ -171,7 +178,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.addAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.addAll(newItems); + } this.setDelay(delay); return true; @@ -182,12 +191,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { Room room = ctx.room(); Habbo habbo = ctx.actor().map(unit -> room.getHabbo(unit)).orElse(null); - // Use selector targets if a selector has modified them, otherwise use manually picked items. // Snapshot this.items into a new list to avoid undefined behavior from concurrent // THashSet access (serializeWiredData can modify items from the network thread). - Iterable effectiveItems = ctx.targets().isItemsModifiedBySelector() - ? ctx.targets().items() - : new ArrayList<>(this.items); + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); THashSet itemsToRemove = new THashSet<>(); for (HabboItem item : effectiveItems) { @@ -213,7 +219,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { } } - if (!ctx.targets().isItemsModifiedBySelector()) { + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { this.items.removeAll(itemsToRemove); } } @@ -228,7 +234,8 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { public String getWiredData() { return WiredManager.getGson().toJson(new JsonData( this.getDelay(), - new ArrayList<>(this.items).stream().map(HabboItem::getId).collect(Collectors.toList()) + new ArrayList<>(this.items).stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -240,6 +247,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); + this.furniSource = data.furniSource; for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -251,6 +259,9 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { this.items.add(item); } } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] wiredDataOld = wiredData.split("\t"); @@ -270,12 +281,14 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { } } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -287,10 +300,12 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { static class JsonData { int delay; List itemIds; + int furniSource; - public JsonData(int delay, List itemIds) { + public JsonData(int delay, List itemIds, int furniSource) { this.delay = delay; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java index 0f3dba28..370655af 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java @@ -22,6 +22,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; @@ -41,6 +42,7 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.TOGGLE_RANDOM; private final THashSet items = new THashSet<>(); + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; private static final List> FORBIDDEN_TYPES = new ArrayList>() { { @@ -114,7 +116,8 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -141,6 +144,9 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + int itemsCount = settings.getFurniIds().length; if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { @@ -149,14 +155,16 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { List newItems = new ArrayList<>(); - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); - newItems.add(it); + newItems.add(it); + } } int delay = settings.getDelay(); @@ -165,7 +173,9 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.addAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.addAll(newItems); + } this.setDelay(delay); return true; @@ -175,14 +185,11 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { public void execute(WiredContext ctx) { Room room = ctx.room(); - // Use selector targets if a selector has modified them, otherwise use manually picked items - Iterable effectiveItems = ctx.targets().isItemsModifiedBySelector() - ? ctx.targets().items() - : new ArrayList<>(this.items); + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); for (HabboItem item : effectiveItems) { if (item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) { - if (!ctx.targets().isItemsModifiedBySelector()) { + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { this.items.remove(item); } continue; @@ -208,7 +215,8 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { List itemsSnapshot = new ArrayList<>(this.items); return WiredManager.getGson().toJson(new JsonData( this.getDelay(), - itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) + itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -220,6 +228,7 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); + this.furniSource = data.furniSource; for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); @@ -229,6 +238,9 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { if (item != null) this.items.add(item); } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] wiredDataOld = wiredData.split("\t"); @@ -248,12 +260,14 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { } } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -265,10 +279,12 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { static class JsonData { int delay; List itemIds; + int furniSource; - public JsonData(int delay, List itemIds) { + public JsonData(int delay, List itemIds, int furniSource) { this.delay = delay; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java index e3c94187..7c07f009 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java @@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.wired.core.WiredContext; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; @@ -28,6 +29,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.CALL_STACKS; private THashSet items; + private int furniSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectTriggerStacks(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -62,7 +64,8 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(""); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.furniSource); message.appendInt(0); message.appendInt(this.getType().code); message.appendInt(this.getDelay()); @@ -89,6 +92,9 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { + int[] params = settings.getIntParams(); + this.furniSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; + int itemsCount = settings.getFurniIds().length; if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { @@ -97,14 +103,16 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { List newItems = new ArrayList<>(); - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + for (int i = 0; i < itemsCount; i++) { + int itemId = settings.getFurniIds()[i]; + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); - newItems.add(it); + newItems.add(it); + } } int delay = settings.getDelay(); @@ -113,7 +121,9 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { throw new WiredSaveException("Delay too long"); this.items.clear(); - this.items.addAll(newItems); + if (this.furniSource == WiredSourceUtil.SOURCE_SELECTED) { + this.items.addAll(newItems); + } this.setDelay(delay); return true; @@ -137,10 +147,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { return; } - // Use selector targets if a selector has modified them, otherwise use manually picked items - Iterable effectiveItems = ctx.targets().isItemsModifiedBySelector() - ? ctx.targets().items() - : new ArrayList<>(this.items); + List effectiveItems = WiredSourceUtil.resolveItems(ctx, this.furniSource, this.items); THashSet usedTiles = new THashSet<>(); @@ -179,7 +186,8 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { List itemsSnapshot = new ArrayList<>(this.items); return WiredManager.getGson().toJson(new JsonData( this.getDelay(), - itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()) + itemsSnapshot.stream().map(HabboItem::getId).collect(Collectors.toList()), + this.furniSource )); } @@ -191,12 +199,16 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { if (wiredData.startsWith("{")) { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); + this.furniSource = data.furniSource; for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); if (item != null) { this.items.add(item); } } + if (this.furniSource == WiredSourceUtil.SOURCE_TRIGGER && !this.items.isEmpty()) { + this.furniSource = WiredSourceUtil.SOURCE_SELECTED; + } } else { String[] wiredDataOld = wiredData.split("\t"); @@ -213,12 +225,14 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { } } } + this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED; } } @Override public void onPickUp() { this.items.clear(); + this.furniSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -235,10 +249,12 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { static class JsonData { int delay; List itemIds; + int furniSource; - public JsonData(int delay, List itemIds) { + public JsonData(int delay, List itemIds, int furniSource) { this.delay = delay; this.itemIds = itemIds; + this.furniSource = furniSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java index 0a928d64..9ac89433 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java @@ -12,6 +12,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.core.WiredManager; import com.eu.habbo.habbohotel.wired.core.WiredContext; +import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; @@ -26,6 +27,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; protected String message = ""; + protected int userSource = WiredSourceUtil.SOURCE_TRIGGER; public WiredEffectWhisper(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -43,7 +45,8 @@ public class WiredEffectWhisper extends InteractionWiredEffect { message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); message.appendString(this.message); - message.appendInt(0); + message.appendInt(1); + message.appendInt(this.userSource); message.appendInt(0); message.appendInt(type.code); message.appendInt(this.getDelay()); @@ -71,6 +74,8 @@ public class WiredEffectWhisper extends InteractionWiredEffect { @Override public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { String message = settings.getStringParam(); + int[] params = settings.getIntParams(); + this.userSource = (params.length > 0) ? params[0] : WiredSourceUtil.SOURCE_TRIGGER; if(gameClient.getHabbo() == null || !gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) { message = Emulator.getGameEnvironment().getWordFilter().filter(message, null); @@ -87,11 +92,15 @@ public class WiredEffectWhisper extends InteractionWiredEffect { return true; } + protected List resolveUsers(WiredContext ctx) { + return WiredSourceUtil.resolveUsers(ctx, this.userSource); + } + @Override public void execute(WiredContext ctx) { Room room = ctx.room(); if (this.message.length() > 0) { - for (RoomUnit roomUnit : ctx.targets().users()) { + for (RoomUnit roomUnit : resolveUsers(ctx)) { Habbo habbo = room.getHabbo(roomUnit); if (habbo == null) continue; @@ -113,7 +122,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect { @Override public String getWiredData() { - return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay())); + return WiredManager.getGson().toJson(new JsonData(this.message, this.getDelay(), this.userSource)); } @Override @@ -124,6 +133,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect { JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class); this.setDelay(data.delay); this.message = data.message; + this.userSource = data.userSource; } else { this.message = ""; @@ -133,6 +143,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect { this.message = wiredData.split("\t")[1]; } + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.needsUpdate(true); } } @@ -140,6 +151,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect { @Override public void onPickUp() { this.message = ""; + this.userSource = WiredSourceUtil.SOURCE_TRIGGER; this.setDelay(0); } @@ -150,16 +162,18 @@ public class WiredEffectWhisper extends InteractionWiredEffect { @Override public boolean requiresTriggeringUser() { - return true; + return this.userSource == WiredSourceUtil.SOURCE_TRIGGER; } static class JsonData { String message; int delay; + int userSource; - public JsonData(String message, int delay) { + public JsonData(String message, int delay, int userSource) { this.message = message; this.delay = delay; + this.userSource = userSource; } } } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredEngine.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredEngine.java index e47698c2..28300ca6 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredEngine.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredEngine.java @@ -229,6 +229,11 @@ public final class WiredEngine { // Activate extras (for their animation) activateExtras(room, stack.triggerItem(), event.getActor().orElse(null), currentTime); + // Run selectors before conditions so targets are available + if (stack.hasEffects()) { + executeSelectors(stack, ctx, currentTime); + } + // Evaluate conditions if (stack.hasConditions()) { debug(room, "Evaluating {} conditions...", stack.conditions().size()); @@ -347,15 +352,11 @@ public final class WiredEngine { if (effects.isEmpty()) { return; } - - // Separate selectors from regular effects. - // Selectors must always run first so ctx.targets() is populated before - // regular effects consume it. - List selectors = new ArrayList<>(); + + // Selectors already executed before conditions; only run regular effects here List regulars = new ArrayList<>(); for (IWiredEffect e : effects) { - if (e.isSelector()) selectors.add(e); - else regulars.add(e); + if (!e.isSelector()) regulars.add(e); } // Determine which (regular) effects to execute @@ -385,12 +386,6 @@ public final class WiredEngine { Collections.shuffle(toExecute); } - // Selectors always run first (in their natural tile order), then regular effects - List ordered = new ArrayList<>(selectors.size() + toExecute.size()); - ordered.addAll(selectors); - ordered.addAll(toExecute); - toExecute = ordered; - // Execute selected effects for (IWiredEffect effect : toExecute) { // Check if effect requires actor @@ -421,6 +416,34 @@ public final class WiredEngine { } } } + + /** + * Execute selector effects before conditions so ctx.targets() is populated. + */ + private void executeSelectors(WiredStack stack, WiredContext ctx, long currentTime) { + List effects = stack.effects(); + if (effects.isEmpty()) return; + + for (IWiredEffect effect : effects) { + if (!effect.isSelector()) continue; + if (effect.requiresActor() && !ctx.hasActor()) { + continue; + } + + ctx.state().step(); + try { + effect.execute(ctx); + + if (effect instanceof InteractionWiredEffect) { + InteractionWiredEffect wiredEffect = (InteractionWiredEffect) effect; + wiredEffect.setCooldown(currentTime); + wiredEffect.activateBox(ctx.room(), ctx.actor().orElse(null), currentTime); + } + } catch (Exception e) { + LOGGER.warn("Error executing selector: {}", e.getMessage()); + } + } + } /** * Schedule a delayed effect execution. diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredSourceUtil.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredSourceUtil.java new file mode 100644 index 00000000..ed65404a --- /dev/null +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/wired/core/WiredSourceUtil.java @@ -0,0 +1,63 @@ +package com.eu.habbo.habbohotel.wired.core; + +import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboItem; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public final class WiredSourceUtil { + public static final int SOURCE_TRIGGER = 0; + public static final int SOURCE_SELECTED = 100; + public static final int SOURCE_SELECTOR = 200; + public static final int SOURCE_SIGNAL = 201; + + private WiredSourceUtil() { + } + + public static List resolveItems(WiredContext ctx, int sourceType, Collection selectedItems) { + switch (sourceType) { + case SOURCE_TRIGGER: + return ctx.sourceItem().map(Collections::singletonList).orElse(Collections.emptyList()); + case SOURCE_SELECTED: + return (selectedItems != null) ? new ArrayList<>(selectedItems) : Collections.emptyList(); + case SOURCE_SELECTOR: + return ctx.targets().isItemsModifiedBySelector() + ? new ArrayList<>(ctx.targets().items()) + : Collections.emptyList(); + case SOURCE_SIGNAL: + if (ctx.eventType() == WiredEvent.Type.SIGNAL_RECEIVED) { + return ctx.sourceItem().map(Collections::singletonList).orElse(Collections.emptyList()); + } + return Collections.emptyList(); + default: + return ctx.sourceItem().map(Collections::singletonList).orElse(Collections.emptyList()); + } + } + + public static List resolveUsers(WiredContext ctx, int sourceType) { + return resolveUsers(ctx, sourceType, null); + } + + public static List resolveUsers(WiredContext ctx, int sourceType, Collection selectedUsers) { + switch (sourceType) { + case SOURCE_TRIGGER: + return ctx.actor().map(Collections::singletonList).orElse(Collections.emptyList()); + case SOURCE_SELECTED: + return (selectedUsers != null) ? new ArrayList<>(selectedUsers) : Collections.emptyList(); + case SOURCE_SELECTOR: + return ctx.targets().isUsersModifiedBySelector() + ? new ArrayList<>(ctx.targets().users()) + : Collections.emptyList(); + case SOURCE_SIGNAL: + if (ctx.eventType() == WiredEvent.Type.SIGNAL_RECEIVED) { + return ctx.actor().map(Collections::singletonList).orElse(Collections.emptyList()); + } + return Collections.emptyList(); + default: + return ctx.actor().map(Collections::singletonList).orElse(Collections.emptyList()); + } + } +}