From 9554b969c636b79a9c1191f65b7e5a4a7a30b591 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Mon, 27 May 2019 12:12:36 +0300 Subject: [PATCH] Make user walk to correct tile on beds --- .../rooms/users/RoomUserWalkEvent.java | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserWalkEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserWalkEvent.java index a31b9b15..ea675a1c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserWalkEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserWalkEvent.java @@ -2,13 +2,16 @@ package com.eu.habbo.messages.incoming.rooms.users; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.users.RoomUnitOnRollerComposer; import com.eu.habbo.plugin.events.users.UserIdleEvent; +import gnu.trove.set.hash.THashSet; public class RoomUserWalkEvent extends MessageHandler { @Override @@ -37,6 +40,7 @@ public class RoomUserWalkEvent extends MessageHandler { } roomUnit = habbo.getRoomUnit(); + Room room = habbo.getHabboInfo().getCurrentRoom(); try { if (roomUnit != null && roomUnit.isInRoom() && roomUnit.canWalk()) { @@ -47,7 +51,7 @@ public class RoomUserWalkEvent extends MessageHandler { if (x == roomUnit.getX() && y == roomUnit.getY()) return; - if (habbo.getHabboInfo().getCurrentRoom() == null || habbo.getHabboInfo().getCurrentRoom().getLayout() == null) + if (room == null || room.getLayout() == null) return; if (roomUnit.isIdle()) { @@ -62,25 +66,47 @@ public class RoomUserWalkEvent extends MessageHandler { } } - RoomTile tile = habbo.getHabboInfo().getCurrentRoom().getLayout().getTile((short) x, (short) y); + RoomTile tile = room.getLayout().getTile((short) x, (short) y); if (tile == null) { return; } if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY)) { - if (habbo.getHabboInfo().getCurrentRoom().getLayout().getTilesInFront(habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getBodyRotation().getValue(), 2).contains(tile)) + if (room.getLayout().getTilesInFront(habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getBodyRotation().getValue(), 2).contains(tile)) return; } - if (tile.isWalkable() || habbo.getHabboInfo().getCurrentRoom().canSitOrLayAt(tile.x, tile.y)) { + if (room.canLayAt(tile.x, tile.y)) { + HabboItem bed = room.getTopItemAt(tile.x, tile.y); + + if (bed != null && bed.getBaseItem().allowLay()) { + RoomTile pillow = room.getLayout().getTile(bed.getX(), bed.getY()); + switch (bed.getRotation()) { + case 0: + case 4: + pillow = room.getLayout().getTile((short)x, bed.getY()); + break; + case 2: + case 8: + pillow = room.getLayout().getTile(bed.getX(), (short)y); + break; + } + + if (pillow != null && room.canLayAt(pillow.x, pillow.y)) { + roomUnit.setGoalLocation(pillow); + return; + } + } + } + if (tile.isWalkable() || room.canSitOrLayAt(tile.x, tile.y)) { roomUnit.setGoalLocation(tile); } } else { - RoomTile t = habbo.getHabboInfo().getCurrentRoom().getLayout().getTile((short) x, (short) y); - habbo.getHabboInfo().getCurrentRoom().sendComposer(new RoomUnitOnRollerComposer(roomUnit, t, habbo.getHabboInfo().getCurrentRoom()).compose()); + RoomTile t = room.getLayout().getTile((short) x, (short) y); + room.sendComposer(new RoomUnitOnRollerComposer(roomUnit, t, room).compose()); if (habbo.getHabboInfo().getRiding() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new RoomUnitOnRollerComposer(habbo.getHabboInfo().getRiding().getRoomUnit(), t, habbo.getHabboInfo().getCurrentRoom()).compose()); + room.sendComposer(new RoomUnitOnRollerComposer(habbo.getHabboInfo().getRiding().getRoomUnit(), t, room).compose()); } } }