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;
|
2020-07-10 19:58:04 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomTileState;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
2020-07-10 19:58:04 +02:00
|
|
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.threading.runnables.RoomUnitTeleport;
|
2020-07-10 19:58:04 +02:00
|
|
|
import com.eu.habbo.threading.runnables.SendRoomUnitEffectComposer;
|
2018-07-06 15:30:00 +02:00
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2020-07-10 19:58:04 +02:00
|
|
|
import java.util.Collections;
|
2018-07-06 15:30:00 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredEffectBotTeleport extends InteractionWiredEffect {
|
2018-07-06 15:30:00 +02:00
|
|
|
public static final WiredEffectType type = WiredEffectType.BOT_TELEPORT;
|
|
|
|
|
|
|
|
private THashSet<HabboItem> items;
|
|
|
|
private String botName = "";
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectBotTeleport(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 WiredEffectBotTeleport(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
|
|
|
}
|
|
|
|
|
2020-07-10 19:58:04 +02:00
|
|
|
public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) {
|
|
|
|
if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Room room = roomUnit.getRoom();
|
|
|
|
|
|
|
|
if (room == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// makes a temporary effect
|
|
|
|
|
|
|
|
roomUnit.getRoom().unIdle(roomUnit.getRoom().getHabbo(roomUnit));
|
|
|
|
room.sendComposer(new RoomUserEffectComposer(roomUnit, 4).compose());
|
|
|
|
Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), WiredHandler.TELEPORT_DELAY + 1000);
|
|
|
|
|
|
|
|
if (tile == roomUnit.getCurrentLocation()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tile.state == RoomTileState.INVALID || tile.state == RoomTileState.BLOCKED) {
|
|
|
|
RoomTile alternativeTile = null;
|
|
|
|
List<RoomTile> optionalTiles = room.getLayout().getTilesAround(tile);
|
|
|
|
|
|
|
|
Collections.reverse(optionalTiles);
|
|
|
|
for (RoomTile optionalTile : optionalTiles) {
|
|
|
|
if (optionalTile.state != RoomTileState.INVALID && optionalTile.state != RoomTileState.BLOCKED) {
|
|
|
|
alternativeTile = optionalTile;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alternativeTile != null) {
|
|
|
|
tile = alternativeTile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
@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
|
|
|
for (HabboItem item : this.items) {
|
|
|
|
if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
|
2018-07-06 15:30:00 +02:00
|
|
|
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);
|
|
|
|
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.botName = packet.readString();
|
|
|
|
|
|
|
|
this.items.clear();
|
|
|
|
|
|
|
|
int count = packet.readInt();
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(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) {
|
|
|
|
if (this.items.isEmpty())
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
List<Bot> bots = room.getBots(this.botName);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (bots.isEmpty())
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
|
2020-07-10 17:26:16 +02:00
|
|
|
if (bots.size() > 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
for (Bot bot : bots) {
|
2018-07-06 15:30:00 +02:00
|
|
|
int i = Emulator.getRandom().nextInt(this.items.size()) + 1;
|
|
|
|
int j = 1;
|
2019-05-26 20:14:53 +02:00
|
|
|
for (HabboItem item : this.items) {
|
|
|
|
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
|
|
|
|
if (i == j) {
|
2020-07-10 19:58:04 +02:00
|
|
|
teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY()));
|
|
|
|
return true;
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getWiredData() {
|
2019-03-18 02:22:00 +01:00
|
|
|
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t" + this.botName + ";");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.items != null && !this.items.isEmpty()) {
|
|
|
|
for (HabboItem item : this.items) {
|
|
|
|
if (item.getRoomId() != 0) {
|
2019-03-18 02:22:00 +01:00
|
|
|
wiredData.append(item.getId()).append(";");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
return wiredData.toString();
|
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-09-28 21:25:00 +02:00
|
|
|
this.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
String[] wiredData = set.getString("wired_data").split("\t");
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (wiredData.length >= 2) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.setDelay(Integer.valueOf(wiredData[0]));
|
|
|
|
String[] data = wiredData[1].split(";");
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (data.length > 1) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.botName = data[0];
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (int i = 1; i < data.length; i++) {
|
2018-07-06 15:30:00 +02:00
|
|
|
HabboItem item = room.getHabboItem(Integer.valueOf(data[i]));
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
this.items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPickUp() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.botName = "";
|
|
|
|
this.items.clear();
|
|
|
|
this.setDelay(0);
|
|
|
|
}
|
|
|
|
}
|