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;
|
2022-11-16 16:56:06 +01:00
|
|
|
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
2020-10-12 11:18:52 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.wired.WiredConditionType;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
|
|
|
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 23:15:01 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
|
2018-07-06 15:30:00 +02:00
|
|
|
public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI;
|
|
|
|
|
2021-02-01 19:09:11 +01:00
|
|
|
protected THashSet<HabboItem> items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set, baseItem);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredConditionTriggerOnFurni(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
|
2020-11-18 18:47:26 +01:00
|
|
|
if (roomUnit == null)
|
|
|
|
return false;
|
2019-03-18 02:22:00 +01:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
this.refresh();
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.items.isEmpty())
|
2020-10-12 11:18:52 +02:00
|
|
|
return false;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-02-01 19:09:11 +01:00
|
|
|
return triggerOnFurni(roomUnit, room);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) {
|
2021-09-02 01:41:33 +02:00
|
|
|
THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation());
|
|
|
|
return this.items.stream().anyMatch(itemsAtUser::contains);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getWiredData() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.refresh();
|
2021-01-04 23:15:01 +01:00
|
|
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
|
|
|
|
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
|
|
|
|
));
|
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 {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.items.clear();
|
2021-01-04 23:15:01 +01:00
|
|
|
String wiredData = set.getString("wired_data");
|
|
|
|
|
|
|
|
if (wiredData.startsWith("{")) {
|
|
|
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 23:15:01 +01:00
|
|
|
for(int id : data.itemIds) {
|
|
|
|
HabboItem item = room.getHabboItem(id);
|
|
|
|
|
|
|
|
if (item != null) {
|
|
|
|
this.items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String[] data = wiredData.split(";");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 23:15:01 +01:00
|
|
|
for (String s : data) {
|
|
|
|
HabboItem item = room.getHabboItem(Integer.parseInt(s));
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 23:15:01 +01:00
|
|
|
if (item != null) {
|
|
|
|
this.items.add(item);
|
|
|
|
}
|
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.items.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@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.items.size());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (HabboItem item : this.items)
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(item.getId());
|
|
|
|
|
|
|
|
message.appendInt(this.getBaseItem().getSpriteId());
|
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString("");
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-16 16:56:06 +01:00
|
|
|
public boolean saveData(WiredSettings settings) {
|
|
|
|
int count = settings.getFurniIds().length;
|
2020-09-15 19:38:31 +02:00
|
|
|
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
|
|
|
|
|
|
|
|
this.items.clear();
|
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) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
2022-11-16 16:56:06 +01:00
|
|
|
HabboItem item = room.getHabboItem(settings.getFurniIds()[i]);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (item != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-01 19:09:11 +01:00
|
|
|
protected void refresh() {
|
2018-09-28 21:25:00 +02:00
|
|
|
THashSet<HabboItem> items = new THashSet<>();
|
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-07-06 15:30:00 +02:00
|
|
|
items.addAll(this.items);
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
|
|
|
for (HabboItem item : this.items) {
|
2018-07-06 15:30:00 +02:00
|
|
|
if (item.getRoomId() != room.getId())
|
|
|
|
items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items.removeAll(items);
|
|
|
|
}
|
2018-12-22 11:39:00 +01:00
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredConditionOperator operator() {
|
2020-10-12 11:18:52 +02:00
|
|
|
return WiredConditionOperator.AND;
|
2018-12-22 11:39:00 +01:00
|
|
|
}
|
2021-01-04 23:15:01 +01:00
|
|
|
|
|
|
|
static class JsonData {
|
|
|
|
List<Integer> itemIds;
|
|
|
|
|
|
|
|
public JsonData(List<Integer> itemIds) {
|
|
|
|
this.itemIds = itemIds;
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|