From 6bf80cdee58351870975ebc0bdb500f9f548c2e6 Mon Sep 17 00:00:00 2001 From: ArpyAge Date: Wed, 25 Sep 2024 03:21:30 +0200 Subject: [PATCH] New item Tile Walk Magic and stack helper move on top of unstackable furniture fix --- .../habbo/habbohotel/items/ItemManager.java | 1 + .../InteractionTileWalkMagic.java | 48 ++++++++++++ .../com/eu/habbo/habbohotel/rooms/Room.java | 74 ++++++++++++++++++- .../eu/habbo/habbohotel/rooms/RoomUnit.java | 4 + .../items/SetStackHelperHeightEvent.java | 12 ++- 5 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileWalkMagic.java diff --git a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java index a126296f..7fa15684 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -189,6 +189,7 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("crackable_subscription_box", InteractionRedeemableSubscriptionBox.class)); this.interactionsList.add(new ItemInteraction("random_state", InteractionRandomState.class)); this.interactionsList.add(new ItemInteraction("vendingmachine_no_sides", InteractionNoSidesVendingMachine.class)); + this.interactionsList.add(new ItemInteraction("tile_walkmagic", InteractionTileWalkMagic.class)); this.interactionsList.add(new ItemInteraction("game_timer", InteractionGameTimer.class)); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileWalkMagic.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileWalkMagic.java new file mode 100644 index 00000000..beb74e63 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileWalkMagic.java @@ -0,0 +1,48 @@ +package com.eu.habbo.habbohotel.items.interactions; + +import com.eu.habbo.habbohotel.items.Item; +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.messages.ServerMessage; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class InteractionTileWalkMagic extends HabboItem { + public InteractionTileWalkMagic(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public InteractionTileWalkMagic(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, userId, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { + return false; + } + + @Override + public boolean isWalkable() { + return false; + } + + @Override + public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { + + } + + @Override + public void serializeExtradata(ServerMessage serverMessage) { + serverMessage.appendInt((this.isLimited() ? 256 : 0)); + serverMessage.appendString(this.getExtradata()); + + super.serializeExtradata(serverMessage); + } + + @Override + public boolean isUsable() { + return true; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index e98dd691..03a2f242 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -640,6 +640,10 @@ public class Room implements Comparable, ISerialize, Runnable { result = overriddenState; } + if (this.getItemsAt(tile).stream().anyMatch(i -> i instanceof InteractionTileWalkMagic)) { + result = RoomTileState.OPEN; + } + return result; } @@ -830,6 +834,37 @@ public class Room implements Comparable, ISerialize, Runnable { } } + public void updatePetsAt(short x, short y) { + HabboItem topItem = this.getTopItemAt(x, y); + + THashSet roomUnits = new THashSet<>(); + + for (Pet pet : this.getPetsAt(this.layout.getTile(x, y))) { + if (topItem != null) { + if (topItem.getBaseItem().allowSit()) { + pet.getRoomUnit().setZ(topItem.getZ()); + pet.getRoomUnit().setPreviousLocationZ(topItem.getZ()); + pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(topItem.getRotation())); + } else { + pet.getRoomUnit().setZ(topItem.getZ() + Item.getCurrentHeight(topItem)); + + if (topItem.getBaseItem().allowLay()) { + pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, (topItem.getZ() + topItem.getBaseItem().getHeight()) + ""); + } + } + } else { + pet.getRoomUnit().setZ(pet.getRoomUnit().getCurrentLocation().getStackHeight()); + pet.getRoomUnit().setPreviousLocationZ(pet.getRoomUnit().getCurrentLocation().getStackHeight()); + } + + roomUnits.add(pet.getRoomUnit()); + } + + if (!roomUnits.isEmpty()) { + this.sendComposer(new RoomUserStatusComposer(roomUnits, true).compose()); + } + } + public void pickupPetsForHabbo(Habbo habbo) { THashSet pets = new THashSet<>(); @@ -2943,6 +2978,27 @@ public class Room implements Comparable, ISerialize, Runnable { return bots; } + public THashSet getPetsAt(RoomTile tile) { + THashSet pets = new THashSet<>(); + synchronized (this.currentPets) { + TIntObjectIterator petIterator = this.currentPets.iterator(); + + for (int i = this.currentPets.size(); i-- > 0; ) { + try { + petIterator.advance(); + + if (petIterator.value().getRoomUnit().getCurrentLocation().equals(tile)) { + pets.add(petIterator.value()); + } + } catch (Exception e) { + break; + } + } + } + + return pets; + } + public THashSet getHabbosAt(short x, short y) { return this.getHabbosAt(this.layout.getTile(x, y)); } @@ -3653,6 +3709,7 @@ public class Room implements Comparable, ISerialize, Runnable { boolean canStack = true; THashSet stackHelpers = this.getItemsAt(InteractionStackHelper.class, x, y); + stackHelpers.addAll(this.getItemsAt(InteractionTileWalkMagic.class, x, y)); if(stackHelpers.size() > 0) { for(HabboItem item : stackHelpers) { @@ -4511,7 +4568,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (!this.layout.fitsOnMap(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation)) return FurnitureMovementError.INVALID_MOVE; - if (item instanceof InteractionStackHelper) return FurnitureMovementError.NONE; + if (item instanceof InteractionStackHelper || item instanceof InteractionTileWalkMagic) return FurnitureMovementError.NONE; THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); for (RoomTile t : occupiedTiles) { @@ -4646,7 +4703,7 @@ public class Room implements Comparable, ISerialize, Runnable { pluginHelper = event.hasPluginHelper(); } - boolean magicTile = item instanceof InteractionStackHelper; + boolean magicTile = item instanceof InteractionStackHelper || item instanceof InteractionTileWalkMagic; Optional stackHelper = this.getItemsAt(tile).stream().filter(i -> i instanceof InteractionStackHelper).findAny(); @@ -4715,6 +4772,19 @@ public class Room implements Comparable, ISerialize, Runnable { height = stackHelper.get().getExtradata().isEmpty() ? Double.parseDouble("0.0") : (Double.parseDouble(stackHelper.get().getExtradata()) / 100); } else if (item == topItem) { height = item.getZ(); + } else if(magicTile) { + if(topItem == null) { + height = this.getStackHeight(tile.x, tile.y, false, item); + for(RoomTile til : occupiedTiles) { + double sHeight = this.getStackHeight(til.x, til.y, false, item); + if(sHeight > height) { + height = sHeight; + } + } + } + else { + height = topItem.getZ() + topItem.getBaseItem().getHeight(); + } } else { height = this.getStackHeight(tile.x, tile.y, false, item); for(RoomTile til : occupiedTiles) { diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java index 972030b8..9e1ad74e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -325,6 +325,10 @@ public class RoomUnit { zHeight += room.getLayout().getHeightAtSquare(next.x, next.y); } + Optional stackHelper = this.room.getItemsAt(next).stream().filter(i -> i instanceof InteractionTileWalkMagic).findAny(); + if (stackHelper.isPresent()) { + zHeight = stackHelper.get().getZ(); + } this.setPreviousLocation(this.getCurrentLocation()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java index dce31447..edc29cc2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionStackHelper; +import com.eu.habbo.habbohotel.items.interactions.InteractionTileWalkMagic; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.HabboItem; @@ -20,7 +21,7 @@ public class SetStackHelperHeightEvent extends MessageHandler { if (this.client.getHabbo().getHabboInfo().getId() == this.client.getHabbo().getHabboInfo().getCurrentRoom().getOwnerId() || this.client.getHabbo().getHabboInfo().getCurrentRoom().hasRights(this.client.getHabbo())) { HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); - if (item instanceof InteractionStackHelper) { + if (item instanceof InteractionStackHelper || item instanceof InteractionTileWalkMagic) { Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); RoomTile itemTile = room.getLayout().getTile(item.getX(), item.getY()); double stackerHeight = this.packet.readInt(); @@ -49,6 +50,15 @@ public class SetStackHelperHeightEvent extends MessageHandler { item.setZ(height); item.setExtradata((int) (height * 100) + ""); item.needsUpdate(true); + + if (item instanceof InteractionTileWalkMagic) { + for (RoomTile t : tiles) { + this.client.getHabbo().getHabboInfo().getCurrentRoom().updateHabbosAt(t.x, t.y); + this.client.getHabbo().getHabboInfo().getCurrentRoom().updateBotsAt(t.x, t.y); + this.client.getHabbo().getHabboInfo().getCurrentRoom().updatePetsAt(t.x, t.y); + } + } + this.client.getHabbo().getHabboInfo().getCurrentRoom().updateItem(item); this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(tiles); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightComposer(room, tiles).compose());