From 76f5bd1810b6e960d36c762be5d346aa49dfa5ca Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 18:32:13 +0300 Subject: [PATCH] Trigger onWalkOff when moving a furni from under a RoomUnit --- .../interactions/InteractionDefault.java | 17 ++++++++++++++ .../items/interactions/InteractionWater.java | 2 ++ .../com/eu/habbo/habbohotel/rooms/Room.java | 22 +++++++++++++++++++ .../eu/habbo/habbohotel/rooms/RoomTile.java | 6 +++++ 4 files changed, 47 insertions(+) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java index bf5f5093..928ca2d9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java @@ -50,6 +50,23 @@ public class InteractionDefault extends HabboItem return true; } + @Override + public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) + { + super.onMove(room, oldLocation, newLocation); + + for (RoomUnit unit : room.getRoomUnits()) { + if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // If the unit was previously on the furni... + if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // but is not anymore... + + try { + this.onWalkOff(unit, room, new Object[]{}); // the unit walked off! + } catch (Exception ignored) { + + } + } + } + @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java index 00f988c4..971e4b61 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java @@ -34,6 +34,8 @@ public class InteractionWater extends InteractionDefault @Override public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + super.onMove(room, oldLocation, newLocation); + this.recalculate(room); } 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 b800d9a7..8bccab0a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -5696,5 +5696,27 @@ public class Room implements Comparable, ISerialize, Runnable return FurnitureMovementError.NONE; } + public THashSet getRoomUnits() { + THashSet units = new THashSet<>(); + for (Habbo habbo : this.currentHabbos.values()) { + if (habbo != null && habbo.getRoomUnit() != null && habbo.getRoomUnit().getRoom().getId() == this.getId()) { + units.add(habbo.getRoomUnit()); + } + } + + for (Pet pet : this.currentPets.valueCollection()) { + if (pet != null && pet.getRoomUnit() != null && pet.getRoomUnit().getRoom().getId() == this.getId()) { + units.add(pet.getRoomUnit()); + } + } + + for (Bot bot : this.currentBots.valueCollection()) { + if (bot != null && bot.getRoomUnit() != null && bot.getRoomUnit().getRoom().getId() == this.getId()) { + units.add(bot.getRoomUnit()); + } + } + + return units; + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java index c284d37a..177db674 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java @@ -1,5 +1,7 @@ package com.eu.habbo.habbohotel.rooms; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboItem; import gnu.trove.set.hash.THashSet; import java.util.ArrayList; @@ -233,4 +235,8 @@ public class RoomTile return this.units.size() > 0; } } + + public boolean unitIsOnFurniOnTile(RoomUnit unit, Item item) { + return (unit.getX() >= this.x && unit.getX() < this.x + item.getLength()) && (unit.getY() >= this.y && unit.getY() < this.y + item.getWidth()); + } } \ No newline at end of file