From f05fab12f4757ec8ebd32ea80d7b4e1a99d485e4 Mon Sep 17 00:00:00 2001 From: Stankman Date: Mon, 26 Jun 2023 11:04:18 -0500 Subject: [PATCH] Fixed Wired Match Effect with new structure --- .../items/interactions/InteractionWired.java | 18 +++------ .../interactions/InteractionWiredEffect.java | 5 --- .../interactions/wired/WiredSettings.java | 9 +++++ .../WiredConditionMatchStatePosition.java | 33 ++++++++++----- .../wired/effects/WiredEffectMatchFurni.java | 40 +++++++++++++------ .../InteractionWiredMatchFurniSettings.java | 5 ++- .../incoming/wired/ApplySnapshotEvent.java | 2 +- .../incoming/wired/UpdateActionEvent.java | 2 +- .../incoming/wired/UpdateConditionEvent.java | 2 +- .../incoming/wired/UpdateTriggerEvent.java | 2 +- 10 files changed, 73 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java index fe8f321f..81964b85 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java @@ -57,17 +57,8 @@ public abstract class InteractionWired extends InteractionDefault implements IWi */ public void loadWiredSettings(ResultSet set) throws SQLException, JsonProcessingException { String wiredData = set.getString("wired_data"); - this.wiredSettings = new WiredSettings(); - - if(wiredData.startsWith("{")) { - //TODO CHECK IF WIRED_DATA IS MS4_DATA - this.wiredSettings = WiredHandler.getObjectMapper().readValue(wiredData, WiredSettings.class); - - //TODO CHECK IF WIRED_DATA IS MS3_DATA AND READ IT - } else { - //TODO READ MS1-MS2_DATA - } + this.wiredSettings = WiredHandler.getObjectMapper().readValue(wiredData, WiredSettings.class); } /** @@ -107,7 +98,7 @@ public abstract class InteractionWired extends InteractionDefault implements IWi * * @param packet */ - public void saveWiredSettings(ClientMessage packet) { + public void saveWiredSettings(ClientMessage packet, Room room) { int intParamCount = packet.readInt(); List integerParams = new ArrayList<>(); @@ -134,6 +125,8 @@ public abstract class InteractionWired extends InteractionDefault implements IWi } this.wiredSettings.setSelectionType(packet.readInt()); + + saveAdditionalData(room); } /** @@ -149,7 +142,7 @@ public abstract class InteractionWired extends InteractionDefault implements IWi //EXAMPLE: if StringParam should be number, throw error here, maybe activating a flag in wiredSettings that string params are numbers this.loadDefaultIntegerParams(); - String wiredData = ""; + String wiredData; try { wiredData = WiredHandler.getObjectMapper().writeValueAsString(this.wiredSettings); @@ -187,6 +180,7 @@ public abstract class InteractionWired extends InteractionDefault implements IWi } public void loadDefaultIntegerParams() {} + public void saveAdditionalData(Room room) {} public void activateBox(Room room) { this.activateBox(room, null, 0L); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java index b9bef234..5b027410 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java @@ -1,14 +1,9 @@ package com.eu.habbo.habbohotel.items.interactions; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredEffectInteraction; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; -import com.eu.habbo.messages.outgoing.wired.WiredEffectDataComposer; import gnu.trove.set.hash.THashSet; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredSettings.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredSettings.java index 7264bca5..e814e601 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredSettings.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredSettings.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions.wired; import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import gnu.trove.set.hash.THashSet; @@ -27,11 +28,17 @@ public class WiredSettings implements IWiredSettings { @Setter @JsonInclude(JsonInclude.Include.NON_EMPTY) private List itemIds; + @Getter @Setter @JsonInclude(JsonInclude.Include.NON_DEFAULT) private int delay; + @Getter + @Setter + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List matchParams; + @Getter @Setter @JsonIgnore @@ -42,6 +49,7 @@ public class WiredSettings implements IWiredSettings { this.integerParams = new ArrayList<>(); this.stringParam = ""; this.delay = 0; + this.matchParams = new ArrayList<>(); this.selectionType = 0; } @@ -71,6 +79,7 @@ public class WiredSettings implements IWiredSettings { this.itemIds.clear(); this.stringParam = ""; this.delay = 0; + this.matchParams.clear(); this.selectionType = 0; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java index 3fab95cf..08b983f8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java @@ -1,6 +1,5 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings; @@ -9,20 +8,19 @@ 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.WiredMatchFurniSetting; -import gnu.trove.set.hash.THashSet; import lombok.Getter; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { public final int PARAM_STATE = 0; public final int PARAM_ROTATION = 1; public final int PARAM_POSITION = 2; - @Getter - private THashSet matchFurniSettings; + private List matchSettings; public WiredConditionMatchStatePosition(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -34,33 +32,36 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if(this.getWiredSettings().getItemIds().isEmpty()) { + if(this.getWiredSettings().getItemIds().isEmpty() && this.getWiredSettings().getMatchParams().isEmpty()) { return true; } boolean state = this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1; boolean position = this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1; boolean rotation = this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1; + this.matchSettings = this.getWiredSettings().getMatchParams(); for(HabboItem item : this.getWiredSettings().getItems(room)) { - WiredMatchFurniSetting setting = new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY()); + WiredMatchFurniSetting furniSettings = this.matchSettings.stream().filter(settings -> settings.getItem_id() == item.getId()).findAny().orElse(null); - this.matchFurniSettings.add(setting); + if(furniSettings == null) { + continue; + } if(state) { - if(!item.getExtradata().equals(setting.getState())) { + if(!item.getExtradata().equals(furniSettings.getState())) { return false; } } if(position) { - if (!(setting.getX() == item.getX() && setting.getY() == item.getY())) { + if (!(furniSettings.getX() == item.getX() && furniSettings.getY() == item.getY())) { return false; } } if(rotation) { - if (setting.getRotation() != item.getRotation()) { + if (furniSettings.getRotation() != item.getRotation()) { return false; } } @@ -78,6 +79,18 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition } } + @Override + public void saveAdditionalData(Room room) { + List matchSettings = new ArrayList<>(); + + for (HabboItem item : this.getWiredSettings().getItems(room)) { + WiredMatchFurniSetting settings = new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY()); + matchSettings.add(settings); + } + + this.getWiredSettings().setMatchParams(matchSettings); + } + @Override public boolean shouldMatchState() { return this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java index 22031c46..598c4778 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java @@ -8,12 +8,13 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; -import gnu.trove.set.hash.THashSet; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; @Slf4j public class WiredEffectMatchFurni extends InteractionWiredEffect implements InteractionWiredMatchFurniSettings { @@ -22,7 +23,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int public final int PARAM_ROTATION = 1; public final int PARAM_POSITION = 2; @Getter - private THashSet matchFurniSettings; + private List matchSettings; public WiredEffectMatchFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -34,22 +35,25 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if(this.getWiredSettings().getItemIds().isEmpty()) { + if(this.getWiredSettings().getItemIds().isEmpty() && this.getWiredSettings().getMatchParams().isEmpty()) { return true; } boolean state = this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1; boolean position = this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1; boolean rotation = this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1; + this.matchSettings = this.getWiredSettings().getMatchParams(); for(HabboItem item : this.getWiredSettings().getItems(room)) { - WiredMatchFurniSetting setting = new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY()); + WiredMatchFurniSetting furniSettings = this.matchSettings.stream().filter(settings -> settings.getItem_id() == item.getId()).findAny().orElse(null); - this.matchFurniSettings.add(setting); + if(furniSettings == null) { + continue; + } if (state && (this.checkForWiredResetPermission && item.allowWiredResetState())) { - if (!setting.getState().equals(" ") && !item.getExtradata().equals(setting.getState())) { - item.setExtradata(setting.getState()); + if (!furniSettings.getState().equals(" ") && !item.getExtradata().equals(furniSettings.getState())) { + item.setExtradata(furniSettings.getState()); room.updateItemState(item); } } @@ -58,14 +62,14 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int double oldZ = item.getZ(); if(rotation && !position) { - if(item.getRotation() != setting.getRotation() && room.furnitureFitsAt(oldLocation, item, setting.getRotation(), false) == FurnitureMovementError.NONE) { - room.moveFurniTo(item, oldLocation, setting.getRotation(), null, true); + if(item.getRotation() != furniSettings.getRotation() && room.furnitureFitsAt(oldLocation, item, furniSettings.getRotation(), false) == FurnitureMovementError.NONE) { + room.moveFurniTo(item, oldLocation, furniSettings.getRotation(), null, true); } } else if(position) { - boolean slideAnimation = !rotation || item.getRotation() == setting.getRotation(); - RoomTile newLocation = room.getLayout().getTile((short) setting.getX(), (short) setting.getY()); - int newRotation = rotation ? setting.getRotation() : item.getRotation(); + boolean slideAnimation = !rotation || item.getRotation() == furniSettings.getRotation(); + RoomTile newLocation = room.getLayout().getTile((short) furniSettings.getX(), (short) furniSettings.getY()); + int newRotation = rotation ? furniSettings.getRotation() : item.getRotation(); if(newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && room.furnitureFitsAt(newLocation, item, newRotation, true) == FurnitureMovementError.NONE) { if(room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) { @@ -89,6 +93,18 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int } } + @Override + public void saveAdditionalData(Room room) { + List matchSettings = new ArrayList<>(); + + for (HabboItem item : this.getWiredSettings().getItems(room)) { + WiredMatchFurniSetting settings = new WiredMatchFurniSetting(item.getId(), this.checkForWiredResetPermission && item.allowWiredResetState() ? item.getExtradata() : " ", item.getRotation(), item.getX(), item.getY()); + matchSettings.add(settings); + } + + this.getWiredSettings().setMatchParams(matchSettings); + } + @Override public boolean shouldMatchState() { return this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java index 9f631c9d..c0cd89fa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java @@ -1,10 +1,11 @@ package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; -import gnu.trove.set.hash.THashSet; + +import java.util.List; public interface InteractionWiredMatchFurniSettings { - THashSet getMatchFurniSettings(); + List getMatchSettings(); boolean shouldMatchState(); boolean shouldMatchRotation(); boolean shouldMatchPosition(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/ApplySnapshotEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/ApplySnapshotEvent.java index 5f9aebd7..6971d6ca 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/ApplySnapshotEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/ApplySnapshotEvent.java @@ -61,7 +61,7 @@ public class ApplySnapshotEvent extends MessageHandler { if (wiredItem instanceof InteractionWiredMatchFurniSettings wired) { // Try to apply the set settings to each item - wired.getMatchFurniSettings().forEach(setting -> { + wired.getMatchSettings().forEach(setting -> { HabboItem matchItem = room.getHabboItem(setting.getItem_id()); // Match state diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateActionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateActionEvent.java index 2c86e59f..80c3d987 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateActionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateActionEvent.java @@ -26,7 +26,7 @@ public class UpdateActionEvent extends MessageHandler { throw new WiredSaveException(String.format("Wired effect with item id %s not found in room", itemId)); } - effect.saveWiredSettings(this.packet); + effect.saveWiredSettings(this.packet, room); this.client.sendResponse(new WiredSavedComposer()); effect.needsUpdate(true); Emulator.getThreading().run(effect); diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateConditionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateConditionEvent.java index 55f95f27..24ce1cb6 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateConditionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateConditionEvent.java @@ -24,7 +24,7 @@ public class UpdateConditionEvent extends MessageHandler { throw new WiredSaveException(String.format("Wired condition with item id %s not found in room", itemId)); } - condition.saveWiredSettings(this.packet); + condition.saveWiredSettings(this.packet, room); this.client.sendResponse(new WiredSavedComposer()); condition.needsUpdate(true); Emulator.getThreading().run(condition); diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateTriggerEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateTriggerEvent.java index b251c097..7f3d0ff7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateTriggerEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateTriggerEvent.java @@ -24,7 +24,7 @@ public class UpdateTriggerEvent extends MessageHandler { throw new WiredSaveException(String.format("Wired trigger with item id %s not found in room", itemId)); } - trigger.saveWiredSettings(this.packet); + trigger.saveWiredSettings(this.packet, room); this.client.sendResponse(new WiredSavedComposer()); trigger.needsUpdate(true); Emulator.getThreading().run(trigger);