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.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionRoller;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
2018-10-07 00:28:00 +02:00
|
|
|
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.habbohotel.wired.WiredMatchFurniSetting;
|
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredEffectMatchFurni extends InteractionWiredEffect {
|
2018-07-06 15:30:00 +02:00
|
|
|
private static final WiredEffectType type = WiredEffectType.MATCH_SSHOT;
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean checkForWiredResetPermission = true;
|
2018-07-06 15:30:00 +02:00
|
|
|
private THashSet<WiredMatchFurniSetting> settings;
|
|
|
|
private boolean state = false;
|
|
|
|
private boolean direction = false;
|
|
|
|
private boolean position = false;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectMatchFurni(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.settings = new THashSet<>(0);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectMatchFurni(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.settings = new THashSet<>(0);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
THashSet<RoomTile> tilesToUpdate = new THashSet<>(this.settings.size());
|
|
|
|
//this.refresh();
|
2018-11-17 14:28:00 +01:00
|
|
|
|
2020-02-22 23:40:12 +01:00
|
|
|
if(this.settings.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting setting : this.settings) {
|
2018-07-06 15:30:00 +02:00
|
|
|
HabboItem item = room.getHabboItem(setting.itemId);
|
2019-05-26 20:14:53 +02:00
|
|
|
if (item != null) {
|
|
|
|
if (this.state && (this.checkForWiredResetPermission && item.allowWiredResetState())) {
|
|
|
|
if (!setting.state.equals(" ")) {
|
2018-07-06 15:30:00 +02:00
|
|
|
item.setExtradata(setting.state);
|
2018-11-17 14:28:00 +01:00
|
|
|
tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int oldRotation = item.getRotation();
|
2019-03-18 02:22:00 +01:00
|
|
|
boolean slideAnimation = true;
|
2020-01-27 18:43:17 +01:00
|
|
|
double offsetZ = 0;
|
|
|
|
|
|
|
|
if (this.direction && item.getRotation() != setting.rotation) {
|
2018-07-06 15:30:00 +02:00
|
|
|
item.setRotation(setting.rotation);
|
2019-03-18 02:22:00 +01:00
|
|
|
slideAnimation = false;
|
2020-01-24 19:03:04 +01:00
|
|
|
|
|
|
|
room.scheduledTasks.add(() -> {
|
|
|
|
room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), oldRotation).forEach(t -> {
|
|
|
|
room.updateBotsAt(t.x, t.y);
|
|
|
|
room.updateHabbosAt(t.x, t.y);
|
|
|
|
});
|
|
|
|
room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), setting.rotation).forEach(t -> {
|
|
|
|
room.updateBotsAt(t.x, t.y);
|
|
|
|
room.updateHabbosAt(t.x, t.y);
|
|
|
|
});
|
|
|
|
});
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2020-02-01 12:13:21 +01:00
|
|
|
RoomTile t = null;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.position) {
|
2020-02-01 12:13:21 +01:00
|
|
|
t = room.getLayout().getTile((short) setting.x, (short) setting.y);
|
2019-03-18 02:22:00 +01:00
|
|
|
|
2020-02-01 12:13:21 +01:00
|
|
|
if (t != null && t.state != RoomTileState.INVALID) {
|
|
|
|
boolean canMove = true;
|
|
|
|
|
|
|
|
if (t.x == item.getX() && t.y == item.getY()) {
|
|
|
|
canMove = !(room.getTopItemAt(t.x, t.y) == item);
|
|
|
|
slideAnimation = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canMove && !room.hasHabbosAt(t.x, t.y)) {
|
|
|
|
THashSet<RoomTile> tiles = room.getLayout().getTilesAt(t, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), setting.rotation);
|
|
|
|
double highestZ = -1d;
|
|
|
|
for (RoomTile tile : tiles) {
|
|
|
|
if (tile.state == RoomTileState.INVALID) {
|
|
|
|
highestZ = -1d;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item instanceof InteractionRoller && room.hasItemsAt(tile.x, tile.y)) {
|
|
|
|
highestZ = -1d;
|
|
|
|
break;
|
|
|
|
}
|
2019-03-18 02:22:00 +01:00
|
|
|
|
2020-02-01 12:13:21 +01:00
|
|
|
double stackHeight = room.getStackHeight(tile.x, tile.y, false, item);
|
|
|
|
if (stackHeight > highestZ) {
|
|
|
|
highestZ = stackHeight;
|
2018-12-22 11:39:00 +01:00
|
|
|
}
|
2020-02-01 12:13:21 +01:00
|
|
|
}
|
2018-12-22 11:39:00 +01:00
|
|
|
|
2020-02-01 12:13:21 +01:00
|
|
|
if (highestZ != -1d) {
|
|
|
|
tilesToUpdate.addAll(tiles);
|
2018-12-22 11:39:00 +01:00
|
|
|
|
2020-02-01 12:13:21 +01:00
|
|
|
offsetZ = highestZ - item.getZ();
|
|
|
|
double totalHeight = item.getZ() + offsetZ;
|
|
|
|
if (totalHeight > 40) break;
|
|
|
|
tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), oldRotation));
|
2019-03-18 02:22:00 +01:00
|
|
|
|
2020-02-01 12:13:21 +01:00
|
|
|
if (!slideAnimation) {
|
|
|
|
item.setX(t.x);
|
|
|
|
item.setY(t.y);
|
2018-12-22 11:39:00 +01:00
|
|
|
}
|
|
|
|
}
|
2018-10-07 00:28:00 +02:00
|
|
|
}
|
2018-09-12 18:45:00 +02:00
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2020-01-27 18:43:17 +01:00
|
|
|
if (slideAnimation && t != null) {
|
|
|
|
room.sendComposer(new FloorItemOnRollerComposer(item, null, t, offsetZ, room).compose());
|
|
|
|
} else {
|
|
|
|
room.updateItem(item);
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
item.needsUpdate(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
room.updateTiles(tilesToUpdate);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getWiredData() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.refresh();
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
StringBuilder data = new StringBuilder(this.settings.size() + ":");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.settings.isEmpty()) {
|
2019-03-18 02:22:00 +01:00
|
|
|
data.append(";");
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting item : this.settings) {
|
2019-03-18 02:22:00 +01:00
|
|
|
HabboItem i;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (room != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
i = room.getHabboItem(item.itemId);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (i != null) {
|
2019-03-18 02:22:00 +01:00
|
|
|
data.append(item.toString(this.checkForWiredResetPermission && i.allowWiredResetState())).append(";");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
data.append(":").append(this.state ? 1 : 0).append(":").append(this.direction ? 1 : 0).append(":").append(this.position ? 1 : 0).append(":").append(this.getDelay());
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
return data.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-07-06 15:30:00 +02:00
|
|
|
String[] data = set.getString("wired_data").split(":");
|
|
|
|
|
|
|
|
int itemCount = Integer.valueOf(data[0]);
|
|
|
|
|
|
|
|
String[] items = data[1].split(";");
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (int i = 0; i < items.length; i++) {
|
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
String[] stuff = items[i].split("-");
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (stuff.length >= 5) {
|
2018-12-22 11:39:00 +01:00
|
|
|
this.settings.add(new WiredMatchFurniSetting(Integer.valueOf(stuff[0]), stuff[1], Integer.valueOf(stuff[2]), Integer.valueOf(stuff[3]), Integer.valueOf(stuff[4])));
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-03 01:46:07 +02:00
|
|
|
logger.error("Caught exception", e);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state = data[2].equals("1");
|
|
|
|
this.direction = data[3].equals("1");
|
|
|
|
this.position = data[4].equals("1");
|
|
|
|
this.setDelay(Integer.valueOf(data[5]));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPickUp() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.settings.clear();
|
|
|
|
this.state = false;
|
|
|
|
this.direction = false;
|
|
|
|
this.position = false;
|
|
|
|
this.setDelay(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 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.settings.size());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting item : this.settings)
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(item.itemId);
|
|
|
|
|
|
|
|
message.appendInt(this.getBaseItem().getSpriteId());
|
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString("");
|
|
|
|
message.appendInt(3);
|
2019-05-26 20:14:53 +02:00
|
|
|
message.appendInt(this.state ? 1 : 0);
|
|
|
|
message.appendInt(this.direction ? 1 : 0);
|
|
|
|
message.appendInt(this.position ? 1 : 0);
|
2018-07-06 15:30:00 +02:00
|
|
|
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
|
|
|
this.settings.clear();
|
|
|
|
|
|
|
|
//packet.readInt();
|
|
|
|
|
|
|
|
int count;
|
|
|
|
packet.readInt();
|
|
|
|
|
|
|
|
this.state = packet.readInt() == 1;
|
|
|
|
this.direction = packet.readInt() == 1;
|
|
|
|
this.position = packet.readInt() == 1;
|
|
|
|
|
|
|
|
packet.readString();
|
|
|
|
|
|
|
|
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
|
|
|
return true;
|
|
|
|
|
|
|
|
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
|
|
|
int itemId = packet.readInt();
|
|
|
|
HabboItem item = room.getHabboItem(itemId);
|
|
|
|
|
|
|
|
if (item != null)
|
2018-12-22 11:39:00 +01:00
|
|
|
this.settings.add(new WiredMatchFurniSetting(item.getId(), this.checkForWiredResetPermission && item.allowWiredResetState() ? item.getExtradata() : " ", item.getRotation(), item.getX(), item.getY()));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setDelay(packet.readInt());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
private void refresh() {
|
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 && room.isLoaded()) {
|
2018-09-28 21:25:00 +02:00
|
|
|
THashSet<WiredMatchFurniSetting> remove = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting setting : this.settings) {
|
2018-07-06 15:30:00 +02:00
|
|
|
HabboItem item = room.getHabboItem(setting.itemId);
|
2019-05-26 20:14:53 +02:00
|
|
|
if (item == null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
remove.add(setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredMatchFurniSetting setting : remove) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.settings.remove(setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|