2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.triggers;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.bots.Bot;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
|
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;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import gnu.trove.procedure.TObjectProcedure;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
2020-05-04 22:24:09 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2021-01-04 19:03:42 +01:00
|
|
|
import java.util.stream.Collectors;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
|
2020-05-04 22:24:09 +02:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(WiredTriggerBotReachedFurni.class);
|
|
|
|
|
2020-10-12 11:18:52 +02:00
|
|
|
public final static WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
private THashSet<HabboItem> items;
|
|
|
|
private String botName = "";
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredTriggerBotReachedFurni(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.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredTriggerBotReachedFurni(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.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredTriggerType 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-09-28 21:25:00 +02:00
|
|
|
THashSet<HabboItem> items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()) == 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 (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
|
|
|
|
items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (HabboItem item : items) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.items.remove(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
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(this.botName);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
2020-10-12 11:18:52 +02:00
|
|
|
message.appendInt(WiredTriggerType.BOT_REACHED_STF.code);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (!this.isTriggeredByRoomUnit()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
List<Integer> invalidTriggers = new ArrayList<>();
|
2019-05-26 20:14:53 +02:00
|
|
|
room.getRoomSpecialTypes().getEffects(this.getX(), this.getY()).forEach(new TObjectProcedure<InteractionWiredEffect>() {
|
2018-07-06 15:30:00 +02:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean execute(InteractionWiredEffect object) {
|
|
|
|
if (object.requiresTriggeringUser()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
invalidTriggers.add(object.getBaseItem().getSpriteId());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
message.appendInt(invalidTriggers.size());
|
2019-05-26 20:14:53 +02:00
|
|
|
for (Integer i : invalidTriggers) {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(i);
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-16 16:56:06 +01:00
|
|
|
public boolean saveData(WiredSettings settings) {
|
|
|
|
this.botName = settings.getStringParam();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
this.items.clear();
|
|
|
|
|
2022-11-16 16:56:06 +01:00
|
|
|
int count = settings.getFurniIds().length;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2022-11-16 16:56:06 +01:00
|
|
|
this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i]));
|
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) {
|
2020-10-12 11:18:52 +02:00
|
|
|
if (stuff.length >= 1) {
|
|
|
|
if (stuff[0] instanceof HabboItem) {
|
|
|
|
return this.items.contains(stuff[0]) && room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getWiredData() {
|
2021-01-04 14:14:51 +01:00
|
|
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
|
|
|
|
this.botName,
|
|
|
|
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 14:14:51 +01:00
|
|
|
String wiredData = set.getString("wired_data");
|
|
|
|
|
|
|
|
if (wiredData.startsWith("{")) {
|
|
|
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
|
|
|
this.botName = data.botName;
|
|
|
|
for (Integer 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 14:14:51 +01:00
|
|
|
if (data.length == 1) {
|
|
|
|
this.botName = data[0];
|
|
|
|
} else if (data.length == 2) {
|
|
|
|
this.botName = data[0];
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 14:14:51 +01:00
|
|
|
String[] items = data[1].split(";");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 19:03:42 +01:00
|
|
|
for (String id : items) {
|
2021-01-04 14:14:51 +01:00
|
|
|
try {
|
2021-01-04 19:03:42 +01:00
|
|
|
HabboItem item = room.getHabboItem(Integer.parseInt(id));
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2021-01-04 14:14:51 +01:00
|
|
|
if (item != null)
|
|
|
|
this.items.add(item);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.error("Caught exception", e);
|
|
|
|
}
|
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();
|
|
|
|
this.botName = "";
|
|
|
|
}
|
2021-01-04 14:14:51 +01:00
|
|
|
|
|
|
|
static class JsonData {
|
|
|
|
String botName;
|
|
|
|
List<Integer> itemIds;
|
|
|
|
|
|
|
|
public JsonData(String botName, List<Integer> itemIds) {
|
2021-01-04 14:20:37 +01:00
|
|
|
this.botName = botName;
|
|
|
|
this.itemIds = itemIds;
|
2021-01-04 14:14:51 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|