2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
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;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredEffectBotTalk extends InteractionWiredEffect {
|
2018-07-06 15:30:00 +02:00
|
|
|
public static final WiredEffectType type = WiredEffectType.BOT_TALK;
|
|
|
|
|
|
|
|
private int mode;
|
|
|
|
private String botName = "";
|
|
|
|
private String message = "";
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectBotTalk(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 WiredEffectBotTalk(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.message);
|
|
|
|
message.appendInt(1);
|
|
|
|
message.appendInt(this.mode);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(this.getDelay());
|
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean saveData(ClientMessage packet, GameClient gameClient) {
|
2018-07-06 15:30:00 +02:00
|
|
|
packet.readInt();
|
|
|
|
|
|
|
|
this.mode = packet.readInt();
|
|
|
|
|
|
|
|
String[] data = packet.readString().split(((char) 9) + "");
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (data.length == 2) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.botName = data[0];
|
2020-09-17 08:11:06 +02:00
|
|
|
|
|
|
|
if (data[1].length() > 64) return false;
|
2018-07-06 15:30:00 +02:00
|
|
|
this.message = data[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
packet.readInt();
|
|
|
|
this.setDelay(packet.readInt());
|
|
|
|
|
|
|
|
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
|
|
|
String message = this.message;
|
|
|
|
|
|
|
|
Habbo habbo = room.getHabbo(roomUnit);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (habbo != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
message = message.replace(Emulator.getTexts().getValue("wired.variable.username"), habbo.getHabboInfo().getUsername())
|
|
|
|
.replace(Emulator.getTexts().getValue("wired.variable.credits"), habbo.getHabboInfo().getCredits() + "")
|
|
|
|
.replace(Emulator.getTexts().getValue("wired.variable.pixels"), habbo.getHabboInfo().getPixels() + "")
|
|
|
|
.replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "");
|
|
|
|
}
|
2020-07-11 03:18:45 +02:00
|
|
|
|
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) {
|
2020-07-10 17:26:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-11 03:18:45 +02:00
|
|
|
|
|
|
|
Bot bot = bots.get(0);
|
|
|
|
|
|
|
|
if (this.mode == 1) {
|
|
|
|
bot.shout(message);
|
|
|
|
} else {
|
|
|
|
bot.talk(message);
|
2018-07-06 15:30:00 +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() {
|
|
|
|
return this.getDelay() + "" + ((char) 9) + "" + this.mode + "" + ((char) 9) + "" + this.botName + "" + ((char) 9) + "" + this.message;
|
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
|
|
|
String d = set.getString("wired_data");
|
2019-05-26 20:14:53 +02:00
|
|
|
String[] data = d.split(((char) 9) + "");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (data.length == 4) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.setDelay(Integer.valueOf(data[0]));
|
|
|
|
this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0;
|
|
|
|
this.botName = data[2];
|
|
|
|
this.message = data[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPickUp() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.mode = 0;
|
|
|
|
this.botName = "";
|
|
|
|
this.message = "";
|
|
|
|
this.setDelay(0);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getMode() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.mode;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setMode(int mode) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.mode = mode;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getBotName() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.botName;
|
|
|
|
}
|
|
|
|
|
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 getMessage() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.message;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setMessage(String message) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.message = message;
|
|
|
|
}
|
2019-03-18 02:22:00 +01:00
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
protected long requiredCooldown() {
|
2019-04-30 04:07:01 +02:00
|
|
|
return 500;
|
2019-03-18 02:22:00 +01:00
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|