2018-07-06 15:30:00 +02:00
|
|
|
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.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.WiredHandler;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
|
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2021-01-04 22:28:17 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredConditionMatchStatePosition extends InteractionWiredCondition {
|
2018-07-06 15:30:00 +02:00
|
|
|
public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT;
|
|
|
|
|
|
|
|
private THashSet<WiredMatchFurniSetting> settings;
|
|
|
|
|
|
|
|
private boolean state;
|
|
|
|
private boolean position;
|
|
|
|
private boolean direction;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredConditionMatchStatePosition(ResultSet set, Item baseItem) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set, baseItem);
|
2018-09-28 21:25:00 +02:00
|
|
|
this.settings = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredConditionMatchStatePosition(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
2018-09-28 21:25:00 +02:00
|
|
|
this.settings = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredConditionType getType() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void serializeWiredData(ServerMessage message, Room room) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.refresh();
|
|
|
|
|
|
|
|
message.appendBoolean(false);
|
|
|
|
message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
|
|
|
|
message.appendInt(this.settings.size());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting item : this.settings)
|
2020-11-16 12:12:24 +01:00
|
|
|
message.appendInt(item.item_id);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
message.appendInt(this.getBaseItem().getSpriteId());
|
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString("");
|
|
|
|
message.appendInt(4);
|
2019-05-26 20:14:53 +02:00
|
|
|
message.appendInt(this.state ? 1 : 0);
|
|
|
|
message.appendInt(this.direction ? 1 : 0);
|
|
|
|
message.appendInt(this.position ? 1 : 0);
|
|
|
|
message.appendInt(10);
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean saveData(ClientMessage packet) {
|
2018-07-06 15:30:00 +02:00
|
|
|
int count;
|
|
|
|
packet.readInt();
|
|
|
|
|
|
|
|
this.state = packet.readInt() == 1;
|
|
|
|
this.direction = packet.readInt() == 1;
|
|
|
|
this.position = packet.readInt() == 1;
|
|
|
|
|
|
|
|
packet.readString();
|
|
|
|
|
|
|
|
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (room == null)
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
count = packet.readInt();
|
2020-09-15 19:38:31 +02:00
|
|
|
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
|
|
|
|
|
|
|
|
this.settings.clear();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2018-07-06 15:30:00 +02:00
|
|
|
int itemId = packet.readInt();
|
|
|
|
HabboItem item = room.getHabboItem(itemId);
|
|
|
|
|
|
|
|
if (item != null)
|
2018-12-22 11:39:00 +01:00
|
|
|
this.settings.add(new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY()));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
|
|
|
|
if (this.settings.isEmpty())
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
THashSet<WiredMatchFurniSetting> s = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting setting : this.settings) {
|
2020-11-16 12:12:24 +01:00
|
|
|
HabboItem item = room.getHabboItem(setting.item_id);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (item != null) {
|
|
|
|
if (this.state) {
|
|
|
|
if (!item.getExtradata().equals(setting.state))
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.position) {
|
|
|
|
if (!(setting.x == item.getX() && setting.y == item.getY()))
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.direction) {
|
|
|
|
if (setting.rotation != item.getRotation())
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
s.add(setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (!s.isEmpty()) {
|
|
|
|
for (WiredMatchFurniSetting setting : s) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.settings.remove(setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getWiredData() {
|
2021-01-04 22:28:17 +01:00
|
|
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
|
|
|
|
this.state,
|
|
|
|
this.position,
|
|
|
|
this.direction,
|
|
|
|
new ArrayList<>(this.settings)
|
|
|
|
));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
2021-01-04 22:28:17 +01:00
|
|
|
String wiredData = set.getString("wired_data");
|
|
|
|
|
|
|
|
if (wiredData.startsWith("{")) {
|
|
|
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
|
|
|
this.state = data.state;
|
|
|
|
this.position = data.position;
|
|
|
|
this.direction = data.direction;
|
|
|
|
this.settings.addAll(data.settings);
|
|
|
|
} else {
|
|
|
|
String[] data = wiredData.split(":");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 22:28:17 +01:00
|
|
|
int itemCount = Integer.parseInt(data[0]);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 22:28:17 +01:00
|
|
|
String[] items = data[1].split(";");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 22:28:17 +01:00
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
|
String[] stuff = items[i].split("-");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 22:28:17 +01:00
|
|
|
if (stuff.length >= 5)
|
|
|
|
this.settings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4])));
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 22:28:17 +01:00
|
|
|
this.state = data[2].equals("1");
|
|
|
|
this.direction = data[3].equals("1");
|
|
|
|
this.position = data[4].equals("1");
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPickUp() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.settings.clear();
|
|
|
|
this.direction = false;
|
|
|
|
this.position = false;
|
|
|
|
this.state = false;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
private void refresh() {
|
2018-07-06 15:30:00 +02:00
|
|
|
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (room != null) {
|
2018-09-28 21:25:00 +02:00
|
|
|
THashSet<WiredMatchFurniSetting> remove = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting setting : this.settings) {
|
2020-11-16 12:12:24 +01:00
|
|
|
HabboItem item = room.getHabboItem(setting.item_id);
|
2019-05-26 20:14:53 +02:00
|
|
|
if (item == null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
remove.add(setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting setting : remove) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.settings.remove(setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-04 22:28:17 +01:00
|
|
|
|
|
|
|
static class JsonData {
|
|
|
|
boolean state;
|
|
|
|
boolean position;
|
|
|
|
boolean direction;
|
|
|
|
List<WiredMatchFurniSetting> settings;
|
|
|
|
|
|
|
|
public JsonData(boolean state, boolean position, boolean direction, List<WiredMatchFurniSetting> settings) {
|
|
|
|
this.state = state;
|
|
|
|
this.position = position;
|
|
|
|
this.direction = direction;
|
|
|
|
this.settings = settings;
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|