From 40ab27002b32fd6cebc7fa5cb3a71ec74a1e05fb Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 08:59:01 +0100 Subject: [PATCH] Fixed a bunch of pathfinder bugs & improved performance --- .../interactions/InteractionTeleport.java | 3 + .../com/eu/habbo/habbohotel/pets/Pet.java | 21 +++ .../com/eu/habbo/habbohotel/rooms/Room.java | 125 +++++++----------- .../eu/habbo/habbohotel/rooms/RoomLayout.java | 26 ++-- .../habbo/habbohotel/rooms/RoomManager.java | 8 +- .../eu/habbo/habbohotel/rooms/RoomTile.java | 21 ++- .../eu/habbo/habbohotel/rooms/RoomUnit.java | 81 +++++++----- .../incoming/rooms/RequestRoomLoadEvent.java | 7 +- .../rooms/pets/CompostMonsterplantEvent.java | 7 +- .../incoming/rooms/pets/PetPickupEvent.java | 7 +- .../teleport/TeleportActionFive.java | 2 - .../teleport/TeleportActionThree.java | 2 +- 12 files changed, 155 insertions(+), 155 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java index 1dd5e11e..7f83c904 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java @@ -102,6 +102,7 @@ public class InteractionTeleport extends HabboItem walkable = this.getBaseItem().allowWalk(); room.updateTile(currentLocation); tryTeleport(client, room); + unit.removeOverrideTile(currentLocation); }); onFail.add(() -> { @@ -110,10 +111,12 @@ public class InteractionTeleport extends HabboItem this.setExtradata("0"); room.updateItem(this); this.roomUnitID = -1; + unit.removeOverrideTile(currentLocation); }); walkable = true; room.updateTile(currentLocation); + unit.addOverrideTile(currentLocation); unit.setGoalLocation(currentLocation); Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail)); } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java index 7688db9c..b28b91ab 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java @@ -11,6 +11,7 @@ import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.pets.PetLevelUpdatedComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetExperienceComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetRespectComposer; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUserRemoveComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTalkComposer; import com.eu.habbo.plugin.events.pets.PetTalkEvent; import gnu.trove.map.hash.THashMap; @@ -876,4 +877,24 @@ public class Pet implements ISerialize, Runnable { this.levelHunger = levelHunger; } + + public void removeFromRoom() { + removeFromRoom(false); + } + + public void removeFromRoom(boolean dontSendPackets) { + + if(this.roomUnit != null && this.roomUnit.getCurrentLocation() != null) { + this.roomUnit.getCurrentLocation().removeUnit(this.roomUnit); + } + + if(!dontSendPackets) { + room.sendComposer(new RoomUserRemoveComposer(this.roomUnit).compose()); + room.removePet(this.id); + } + + this.roomUnit = null; + this.room = null; + this.needsUpdate = true; + } } \ No newline at end of file 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 bc73cbcf..2fe6d52b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -701,59 +701,17 @@ public class Room implements Comparable, ISerialize, Runnable public boolean tileWalkable(short x, short y) { boolean walkable = this.layout.tileWalkable(x, y); + RoomTile tile = this.getLayout().getTile(x, y); - if (walkable) + if (walkable && tile != null) { - if (this.hasHabbosAt(x, y) && !this.allowWalkthrough) + if (tile.hasUnits() && !this.allowWalkthrough) { walkable = false; } } - return walkable; //&& (!this.allowWalkthrough && !this.hasHabbosAt(x, y))); - //if(this.layout.tileWalkable(x, y)) - - - - - -// - - - -// - - - -// - - - - - -// - - -// - - - - - - - - - - - - - -// - - -// - - + return walkable; } public void pickUpItem(HabboItem item, Habbo picker) @@ -849,7 +807,7 @@ public class Room implements Comparable, ISerialize, Runnable } else { - roomUnit.setZ(item.getZ() + item.getBaseItem().getHeight()); + roomUnit.setZ(item.getZ() + Item.getCurrentHeight(item)); } if (oldZ != roomUnit.getZ()) @@ -899,11 +857,11 @@ public class Room implements Comparable, ISerialize, Runnable } else { - habbo.getRoomUnit().setZ(item.getZ() + item.getBaseItem().getHeight()); + habbo.getRoomUnit().setZ(item.getZ() + Item.getCurrentHeight(item)); if (item.getBaseItem().allowLay()) { - habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + item.getBaseItem().getHeight()) + ""); + habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + Item.getCurrentHeight(item)) + ""); } } } @@ -938,10 +896,9 @@ public class Room implements Comparable, ISerialize, Runnable for(Pet pet : pets) { - pet.setRoom(null); - pet.needsUpdate = true; + pet.removeFromRoom(); + Emulator.getThreading().run(pet); habbo.getInventory().getPetsComponent().addPet(pet); - this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); habbo.getClient().sendResponse(new AddPetComposer(pet)); this.currentPets.remove(pet.getId()); } @@ -1596,7 +1553,7 @@ public class Room implements Comparable, ISerialize, Runnable for(HabboItem item : getItemsAt(rollerTile)) { - if(item.getZ() >= roller.getZ() + roller.getBaseItem().getHeight()) { + if(item.getZ() >= roller.getZ() + Item.getCurrentHeight(roller)) { itemsOnRoller.add(item); } } @@ -1689,7 +1646,7 @@ public class Room implements Comparable, ISerialize, Runnable } else { - zOffset = -roller.getBaseItem().getHeight() + tileInFront.getStackHeight() - rollerTile.z; + zOffset = -Item.getCurrentHeight(roller) + tileInFront.getStackHeight() - rollerTile.z; } if (allowUsers) @@ -1917,7 +1874,7 @@ public class Room implements Comparable, ISerialize, Runnable if (!unit.isWalking() && !unit.cmdSit) { - HabboItem topItem = this.getLowestChair(unit.getX(), unit.getY()); + HabboItem topItem = this.getLowestChair(this.getLayout().getTile(unit.getX(), unit.getY())); if (topItem == null || !topItem.getBaseItem().allowSit()) { @@ -1932,15 +1889,8 @@ public class Room implements Comparable, ISerialize, Runnable if (!unit.hasStatus(RoomUnitStatus.SIT) || unit.sitUpdate) { this.dance(unit, DanceType.NONE); - int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z; - if (topItem instanceof InteractionMultiHeight) - { - unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + ""); - } - else - { - unit.setStatus(RoomUnitStatus.SIT, (topItem.getBaseItem().getHeight() * 1.0D) + ""); - } + //int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z; + unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + ""); unit.setPreviousLocationZ(topItem.getZ()); unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]); unit.sitUpdate = false; @@ -1966,14 +1916,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (!unit.hasStatus(RoomUnitStatus.LAY)) { - if (topItem instanceof InteractionMultiHeight) - { - unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) * 1.0D + ""); - } - else - { - unit.setStatus(RoomUnitStatus.LAY, topItem.getBaseItem().getHeight() * 1.0D + ""); - } + unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) * 1.0D + ""); unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]); if (topItem.getRotation() == 0 || topItem.getRotation() == 4) @@ -2392,9 +2335,8 @@ public class Room implements Comparable, ISerialize, Runnable for (Pet pet : this.currentPets.valueCollection()) { try { if (pet.getUserId() != excludeUserId) { - pet.setRoom(null); - removedPets.add(pet); - this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); + + pet.removeFromRoom(); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); if (habbo != null) { @@ -3194,8 +3136,20 @@ public class Room implements Comparable, ISerialize, Runnable } } - public void removeHabbo(Habbo habbo) + public void removeHabbo(Habbo habbo) { + removeHabbo(habbo, false); + } + + public void removeHabbo(Habbo habbo, boolean sendRemovePacket) { + if(habbo.getRoomUnit() != null && habbo.getRoomUnit().getCurrentLocation() != null) { + habbo.getRoomUnit().getCurrentLocation().removeUnit(habbo.getRoomUnit()); + } + + if(sendRemovePacket && habbo.getRoomUnit() != null) { + this.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose()); + } + HabboItem item = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY()); if (item != null) @@ -3408,6 +3362,10 @@ public class Room implements Comparable, ISerialize, Runnable { if (this.currentBots.containsKey(bot.getId())) { + if(bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentLocation() != null) { + bot.getRoomUnit().getCurrentLocation().removeUnit(bot.getRoomUnit()); + } + this.currentBots.remove(bot.getId()); bot.getRoomUnit().setInRoom(false); bot.setRoom(null); @@ -3570,7 +3528,7 @@ public class Room implements Comparable, ISerialize, Runnable public void teleportHabboToItem(Habbo habbo, HabboItem item) { - this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + item.getBaseItem().getHeight()); + this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item)); } public void teleportHabboToLocation(Habbo habbo, short x, short y) @@ -3580,7 +3538,7 @@ public class Room implements Comparable, ISerialize, Runnable public void teleportRoomUnitToItem(RoomUnit roomUnit, HabboItem item) { - this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + item.getBaseItem().getHeight()); + this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item)); } public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y) @@ -4208,7 +4166,8 @@ public class Room implements Comparable, ISerialize, Runnable { item = habboItem; } - } else + } + else { if (habboItem.getBaseItem().getWidth() <= 1 && habboItem.getBaseItem().getLength() <= 1) { @@ -4240,7 +4199,7 @@ public class Room implements Comparable, ISerialize, Runnable HabboItem item = this.getTopItemAt(x, y); if(item != null) - return (item.getZ() + item.getBaseItem().getHeight()); + return (item.getZ() + Item.getCurrentHeight(item)); else return this.layout.getHeightAtSquare(x, y); } @@ -4319,6 +4278,12 @@ public class Room implements Comparable, ISerialize, Runnable canStack = item.getBaseItem().allowStack(); height = item.getZ() + Item.getCurrentHeight(item); } + + HabboItem lowestChair = this.getLowestChair(x, y); + if(lowestChair != null) { + canStack = true; + height = lowestChair.getZ() + Item.getCurrentHeight(lowestChair); + } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java index 7bd8f853..1bcbdf0b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -262,7 +262,7 @@ public class RoomLayout return this.heightmap.replace("\r\n", "\r"); } - public final Deque findPath(RoomTile oldTile, RoomTile newTile, RoomTile goalLocation) + public final Deque findPath(RoomTile oldTile, RoomTile newTile, RoomTile goalLocation, RoomUnit roomUnit) { LinkedList openList = new LinkedList<>(); try @@ -274,20 +274,6 @@ public class RoomLayout openList.add(oldTile.copy()); - List unitsAt = new ArrayList<>(); - - for(Bot b : this.room.getCurrentBots().valueCollection()) { - unitsAt.add(b.getRoomUnit().getCurrentLocation()); - } - - for(Habbo b : this.room.getCurrentHabbos().values()) { - unitsAt.add(b.getRoomUnit().getCurrentLocation()); - } - - for(Pet b : this.room.getCurrentPets().valueCollection()) { - unitsAt.add(b.getRoomUnit().getCurrentLocation()); - } - long startMillis = System.currentTimeMillis(); while (true) { @@ -310,6 +296,14 @@ public class RoomLayout { if (closedList.contains(currentAdj)) continue; + if(roomUnit.canOverrideTile(currentAdj) || (currentAdj.state != RoomTileState.BLOCKED && currentAdj.x == doorX && currentAdj.y == doorY)) { + currentAdj.setPrevious(current); + currentAdj.sethCosts(this.findTile(openList, newTile.x, newTile.y)); + currentAdj.setgCosts(current); + openList.add(currentAdj); + continue; + } + //If the tile is sitable or layable and its not our goal tile, we cannot walk over it. if (!currentAdj.equals(goalLocation) && (currentAdj.state == RoomTileState.BLOCKED || currentAdj.state == RoomTileState.SIT || currentAdj.state == RoomTileState.LAY)) { @@ -329,7 +323,7 @@ public class RoomLayout if (currentAdj.state == RoomTileState.OPEN && height > MAXIMUM_STEP_HEIGHT) continue; //Check if the tile has habbos. - if (unitsAt.contains(currentAdj) && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) + if (currentAdj.hasUnits() && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) { closedList.add(currentAdj); openList.remove(currentAdj); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index bb77a5e1..06cbd713 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -750,7 +750,8 @@ public class RoomManager if (habbo.getHabboInfo().getCurrentRoom() != room && habbo.getHabboInfo().getCurrentRoom() != null) { habbo.getHabboInfo().getCurrentRoom().removeHabbo(habbo); - } else if (!habbo.getHabboStats().blockFollowing && habbo.getHabboInfo().getCurrentRoom() == null) + } + else if (!habbo.getHabboStats().blockFollowing && habbo.getHabboInfo().getCurrentRoom() == null) { habbo.getMessenger().connectionChanged(habbo, true, true); } @@ -824,7 +825,6 @@ public class RoomManager if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting) { - RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY()); if (doorTile != null) @@ -836,6 +836,7 @@ public class RoomManager habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); } + habbo.getRoomUnit().setPathFinderRoom(room); habbo.getRoomUnit().resetIdleTimer(); @@ -1100,9 +1101,8 @@ public class RoomManager habbo.getRoomUnit().setPathFinderRoom(null); this.logExit(habbo); - room.removeHabbo(habbo); + room.removeHabbo(habbo, true); - room.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose()); if (redirectToHotelView) { habbo.getClient().sendResponse(new HotelViewComposer()); 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 a666d706..356af4ff 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 gnu.trove.set.hash.THashSet; + public class RoomTile { public final short x; @@ -10,12 +12,13 @@ public class RoomTile private double stackHeight; private boolean allowStack = true; - private RoomTile previous = null; private boolean diagonally; private short gCosts; private short hCosts; + private THashSet units; + public RoomTile(short x, short y, short z, RoomTileState state, boolean allowStack) { @@ -25,6 +28,7 @@ public class RoomTile this.stackHeight = z; this.state = state; this.setAllowStack(allowStack); + this.units = new THashSet<>(); } public RoomTile(RoomTile tile) @@ -43,6 +47,7 @@ public class RoomTile { this.allowStack = false; } + this.units = tile.units; } public double getStackHeight() @@ -199,4 +204,18 @@ public class RoomTile { return this.x == x && this.y == y; } + + public void addUnit(RoomUnit unit) { + if(!this.units.contains(unit)) { + this.units.add(unit); + } + } + + public void removeUnit(RoomUnit unit) { + this.units.remove(unit); + } + + public boolean hasUnits() { + return this.units.size() > 0; + } } \ No newline at end of file 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 161284a1..597afdab 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -21,7 +21,9 @@ import com.eu.habbo.threading.runnables.RoomUnitKick; import com.eu.habbo.util.pathfinding.Rotation; import gnu.trove.map.TMap; import gnu.trove.map.hash.THashMap; +import gnu.trove.set.hash.THashSet; +import java.awt.geom.RectangularShape; import java.util.Deque; import java.util.LinkedList; import java.util.Map; @@ -72,6 +74,7 @@ public class RoomUnit private int idleTimer; private Room room; private RoomRightLevels rightsLevel = RoomRightLevels.NONE; + private THashSet overridableTiles; public RoomUnit() { @@ -87,6 +90,7 @@ public class RoomUnit this.walkTimeOut = Emulator.getIntUnixTimestamp(); this.effectId = 0; this.isKicked = false; + this.overridableTiles = new THashSet<>(); } public void clearWalking() @@ -113,11 +117,6 @@ public class RoomUnit { try { - if (this.isTeleporting) - { - return false; - } - Habbo rider = null; if(this.getRoomUnitType() == RoomUnitType.PET) { Pet pet = room.getPet(this); @@ -179,25 +178,20 @@ public class RoomUnit canfastwalk = false; } - if (canfastwalk && this.fastWalk && this.path.size() >= 3) - { - this.path.poll(); - this.path.poll(); - } - RoomTile next = this.path.poll(); + boolean overrideChecks = next != null && this.canOverrideTile(next); if (this.path.isEmpty()) { this.sitUpdate = true; - if (next != null && room.hasHabbosAt(next.x, next.y)) + if (next != null && next.hasUnits() && !overrideChecks) { return false; } } - Deque peekPath = room.getLayout().findPath(this.currentLocation, this.path.peek(), this.goalLocation); + Deque peekPath = room.getLayout().findPath(this.currentLocation, this.path.peek(), this.goalLocation, this); if (peekPath.size() >= 3) { path.pop(); @@ -214,6 +208,13 @@ public class RoomUnit } } + if (canfastwalk && this.fastWalk) + { + if(this.path.size() > 1) { + next = this.path.poll(); + } + } + if (next == null) return true; @@ -252,7 +253,7 @@ public class RoomUnit //if(!(this.path.size() == 0 && canSitNextTile)) { - if (!room.tileWalkable(next.x, next.y)) + if (!room.tileWalkable(next.x, next.y) && !overrideChecks) { this.room = room; this.findPath(); @@ -281,7 +282,7 @@ public class RoomUnit item = lowestChair; } - if (next.equals(this.goalLocation) && next.state == RoomTileState.SIT) + if (next.equals(this.goalLocation) && next.state == RoomTileState.SIT && !overrideChecks) { if (item == null || item.getZ() - this.getZ() > RoomLayout.MAXIMUM_STEP_HEIGHT) { @@ -343,20 +344,7 @@ public class RoomUnit if (!item.getBaseItem().allowSit() && !item.getBaseItem().allowLay()) { - zHeight += item.getBaseItem().getHeight(); - - if (item instanceof InteractionMultiHeight) - { - if (item.getExtradata().length() == 0) - { - item.setExtradata("0"); - } - zHeight += Item.getCurrentHeight(item); - } - else if (item instanceof InteractionFreezeBlock) - { - zHeight -= item.getBaseItem().getHeight(); - } + zHeight += Item.getCurrentHeight(item); } } else @@ -574,8 +562,8 @@ public class RoomUnit if (location != null) { this.startLocation = location; - this.previousLocation = location; - this.currentLocation = location; + setPreviousLocation(location); + setCurrentLocation(location); this.goalLocation = location; } } @@ -584,7 +572,11 @@ public class RoomUnit { if (location != null) { - this.currentLocation = location; + if(this.currentLocation != null) { + this.currentLocation.removeUnit(this); + } + this.currentLocation = location; + location.addUnit(this); } } @@ -616,9 +608,9 @@ public class RoomUnit public void findPath() { - if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.x, this.goalLocation.y))) + if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.x, this.goalLocation.y) || this.canOverrideTile(this.goalLocation))) { - this.path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation); + this.path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation, this); } } @@ -811,4 +803,25 @@ public class RoomUnit public Room getRoom() { return room; } + + public boolean canOverrideTile(RoomTile tile) { + int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1; + return this.overridableTiles.contains(tileIndex); + } + + public void addOverrideTile(RoomTile tile) { + int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1; + if(!this.overridableTiles.contains(tileIndex)) { + this.overridableTiles.add(tileIndex); + } + } + + public void removeOverrideTile(RoomTile tile) { + int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1; + this.overridableTiles.remove(tileIndex); + } + + public void clearOverrideTiles() { + this.overridableTiles.clear(); + } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomLoadEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomLoadEvent.java index 992f7418..1fb051f2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomLoadEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomLoadEvent.java @@ -26,11 +26,8 @@ public class RequestRoomLoadEvent extends MessageHandler { Emulator.getGameEnvironment().getRoomManager().logExit(this.client.getHabbo()); - if (this.client.getHabbo().getRoomUnit() != null) - { - room.sendComposer(new RoomUserRemoveComposer(this.client.getHabbo().getRoomUnit()).compose()); - } - room.removeHabbo(this.client.getHabbo()); + room.removeHabbo(this.client.getHabbo(), true); + this.client.getHabbo().getHabboInfo().setCurrentRoom(null); } Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), roomId, password); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostMonsterplantEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostMonsterplantEvent.java index a93a4b1a..4b362122 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostMonsterplantEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostMonsterplantEvent.java @@ -45,12 +45,7 @@ public class CompostMonsterplantEvent extends MessageHandler room.sendComposer(new AddFloorItemComposer(compost, this.client.getHabbo().getHabboInfo().getUsername()).compose()); } - pet.setRoom(null); - pet.setUserId(0); - room.removePet(petId); - room.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); - pet.setRoomUnit(null); - + pet.removeFromRoom(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_pets WHERE id = ? LIMIT 1")) { statement.setInt(1, pet.getId()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java index 19f5a6ed..12c7e41c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java @@ -44,12 +44,7 @@ public class PetPickupEvent extends MessageHandler } } - room.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); - room.removePet(petId); - pet.setRoomUnit(null); - pet.setRoom(null); - pet.needsUpdate = true; - + pet.removeFromRoom(); Emulator.getThreading().run(pet); if (this.client.getHabbo().getHabboInfo().getId() == pet.getUserId()) diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java index fe8d268f..be318de4 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java @@ -35,8 +35,6 @@ class TeleportActionFive implements Runnable if (tile != null) { - this.client.getHabbo().getRoomUnit().setPreviousLocation(currentLocation); - this.client.getHabbo().getRoomUnit().setPreviousLocationZ(currentLocation.getStackHeight()); this.client.getHabbo().getRoomUnit().setGoalLocation(tile); this.client.getHabbo().getRoomUnit().statusUpdate(true); } diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java index 10f8cc5b..ba492e24 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java @@ -68,7 +68,7 @@ class TeleportActionThree implements Runnable if(targetRoom != this.room) { - this.room.sendComposer(new RoomUserRemoveComposer(this.client.getHabbo().getRoomUnit()).compose()); + this.room.removeHabbo(this.client.getHabbo(), true); Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation); }