Fixed Wired Match Effect with new structure

This commit is contained in:
Stankman 2023-06-26 11:04:18 -05:00
parent 9ed3bfc37a
commit f05fab12f4
10 changed files with 73 additions and 45 deletions

View File

@ -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
}
}
/**
@ -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<Integer> 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);

View File

@ -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;

View File

@ -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<Integer> itemIds;
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
private int delay;
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<WiredMatchFurniSetting> 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;
}
}

View File

@ -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<WiredMatchFurniSetting> matchFurniSettings;
private List<WiredMatchFurniSetting> 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<WiredMatchFurniSetting> 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;

View File

@ -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<WiredMatchFurniSetting> matchFurniSettings;
private List<WiredMatchFurniSetting> 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<WiredMatchFurniSetting> 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;

View File

@ -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<WiredMatchFurniSetting> getMatchFurniSettings();
List<WiredMatchFurniSetting> getMatchSettings();
boolean shouldMatchState();
boolean shouldMatchRotation();
boolean shouldMatchPosition();

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);