Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java

154 lines
4.7 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
import com.eu.habbo.Emulator;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
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.wired.WiredEffectType;
2020-11-16 12:12:24 +01:00
import com.eu.habbo.habbohotel.wired.WiredHandler;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.regex.Pattern;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class WiredEffectBotClothes extends InteractionWiredEffect {
2018-07-06 15:30:00 +02:00
public static final WiredEffectType type = WiredEffectType.BOT_CLOTHES;
private String botName = "";
private String botLook = "";
2019-05-26 20:14:53 +02:00
public WiredEffectBotClothes(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 WiredEffectBotClothes(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 void serializeWiredData(ServerMessage message, Room room) {
2018-07-06 15:30:00 +02:00
message.appendBoolean(false);
message.appendInt(5);
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString(this.botName + ((char) 9) + "" + this.botLook);
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getType().code);
message.appendInt(this.getDelay());
message.appendInt(0);
}
@Override
2022-11-16 16:56:06 +01:00
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
String dataString = settings.getStringParam();
int delay = settings.getDelay();
2018-07-06 15:30:00 +02:00
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
2018-07-06 15:30:00 +02:00
String splitBy = "\t";
if(!dataString.contains(splitBy))
throw new WiredSaveException("Malformed data string");
2018-07-06 15:30:00 +02:00
String[] data = dataString.split(Pattern.quote(splitBy));
if (data.length != 2)
throw new WiredSaveException("Malformed data string. Invalid data length");
this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.botLook = data[1];
this.setDelay(delay);
2018-07-06 15:30:00 +02:00
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public WiredEffectType getType() {
2018-07-06 15:30:00 +02:00
return type;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
2018-07-06 15:30:00 +02:00
List<Bot> bots = room.getBots(this.botName);
2020-07-11 03:18:45 +02:00
if (bots.size() == 1) {
Bot bot = bots.get(0);
bot.setFigure(this.botLook);
2020-07-10 17:26:16 +02:00
}
2020-07-11 03:18:45 +02:00
2018-07-06 15:30:00 +02:00
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public String getWiredData() {
2020-11-16 12:12:24 +01:00
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.botLook, this.getDelay()));
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 {
2020-11-16 12:12:24 +01:00
String wiredData = set.getString("wired_data");
2018-07-06 15:30:00 +02:00
2020-11-16 12:12:24 +01:00
if(wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.botName = data.bot_name;
this.botLook = data.look;
}
else {
String[] data = wiredData.split(((char) 9) + "");
if (data.length >= 3) {
this.setDelay(Integer.valueOf(data[0]));
this.botName = data[1];
this.botLook = data[2];
}
this.needsUpdate(true);
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.botLook = "";
this.botName = "";
this.setDelay(0);
}
2019-05-26 20:14:53 +02:00
public String getBotName() {
2019-03-18 02:22:00 +01:00
return this.botName;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void setBotName(String botName) {
2018-07-06 15:30:00 +02:00
this.botName = botName;
}
2019-05-26 20:14:53 +02:00
public String getBotLook() {
2019-03-18 02:22:00 +01:00
return this.botLook;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void setBotLook(String botLook) {
2018-07-06 15:30:00 +02:00
this.botLook = botLook;
}
2020-11-16 12:12:24 +01:00
static class JsonData {
String bot_name;
String look;
int delay;
public JsonData(String bot_name, String look, int delay) {
this.bot_name = bot_name;
this.look = look;
this.delay = delay;
}
}
2018-07-06 15:30:00 +02:00
}