From 6eccf01f6ee3c03cfb0af783f9bfb8fb41949d70 Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Sun, 9 Jun 2019 00:13:23 +0100 Subject: [PATCH] Fixed Pathfinder. Credits to Quadral. Note this is a test. --- src/main/java/com/eu/habbo/Emulator.java | 12 -- .../eu/habbo/habbohotel/rooms/RoomLayout.java | 110 ++++++------------ .../eu/habbo/habbohotel/rooms/RoomTile.java | 14 +++ .../eu/habbo/habbohotel/rooms/RoomUnit.java | 26 +++-- .../rooms/users/RoomUserWalkEvent.java | 41 +++++-- 5 files changed, 100 insertions(+), 103 deletions(-) diff --git a/src/main/java/com/eu/habbo/Emulator.java b/src/main/java/com/eu/habbo/Emulator.java index af521b00..506b10c4 100644 --- a/src/main/java/com/eu/habbo/Emulator.java +++ b/src/main/java/com/eu/habbo/Emulator.java @@ -97,12 +97,6 @@ public final class Emulator { Emulator.runtime = Runtime.getRuntime(); Emulator.config = new ConfigurationManager("config.ini"); - - if (Emulator.getConfig().getValue("username").isEmpty()) { - Emulator.getLogging().logErrorLine("Please make sure you enter your forum login details!"); - Thread.sleep(2000); - } - Emulator.database = new Database(Emulator.getConfig()); Emulator.config.loaded = true; Emulator.config.loadFromDatabase(); @@ -123,12 +117,6 @@ public final class Emulator { Emulator.rconServer.initializePipeline(); Emulator.rconServer.connect(); Emulator.badgeImager = new BadgeImager(); - // Removed Wesleys Camera Server lol. - /* if (Emulator.getConfig().getBoolean("camera.enabled")) - { - Emulator.getThreading().run(new CameraClientAutoReconnect()); - } - */ Emulator.getLogging().logStart("Habbo Hotel Emulator has succesfully loaded."); Emulator.getLogging().logStart("You're running: " + Emulator.version); Emulator.getLogging().logStart("System launched in: " + (System.nanoTime() - startTime) / 1e6 + "ms. Using: " + (Runtime.getRuntime().availableProcessors() * 2) + " threads!"); 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 7da2e518..258d023b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -253,42 +253,29 @@ public class RoomLayout { return this.roomTiles[x][y].state == RoomTileState.INVALID; } - public RoomTileState getStateAt(short x, short y) { - return this.roomTiles[x][y].state; - } - public String getRelativeMap() { return this.heightmap.replace("\r\n", "\r"); - } + }//re + /// Pathfinder Reworked By Quadral, thanks buddy!! You Saved Morningstar <3 public final Deque findPath(RoomTile oldTile, RoomTile newTile, RoomTile goalLocation, RoomUnit roomUnit) { + if (this.room == null || !this.room.isLoaded() || oldTile == null || newTile == null || oldTile.equals(newTile) || newTile.state == RoomTileState.INVALID) + return new LinkedList<>(); LinkedList openList = new LinkedList<>(); - try { - if (this.room == null || !this.room.isLoaded() || oldTile == null || newTile == null || oldTile.equals(newTile) || newTile.state == RoomTileState.INVALID) - return openList; - - List closedList = new LinkedList<>(); - - openList.add(oldTile.copy()); - - long startMillis = System.currentTimeMillis(); - while (true) { - if (System.currentTimeMillis() - startMillis > 50) { - return new LinkedList<>(); - } - - RoomTile current = this.lowestFInOpen(openList); - openList.remove(current); - - if ((current.x == newTile.x) && (current.y == newTile.y)) { - return this.calcPath(this.findTile(openList, oldTile.x, oldTile.y), current); - } - - List adjacentNodes = this.getAdjacent(openList, current, newTile); - - for (RoomTile currentAdj : adjacentNodes) { - if (closedList.contains(currentAdj)) continue; + List closedList = new LinkedList<>(); + RoomTile current; + openList.add(oldTile.copy()); + while (!openList.isEmpty()) { + current = this.lowestFInOpen(openList); + if ((current.x == newTile.x) && (current.y == newTile.y)) { + return this.calcPath(this.findTile(openList, oldTile.x, oldTile.y), current); + } + closedList.add(current); + openList.remove(current); + List adjacentNodes = this.getAdjacent(openList, current, newTile); + for (RoomTile currentAdj : adjacentNodes) { + 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)); @@ -296,50 +283,31 @@ public class RoomLayout { 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)) { - closedList.add(currentAdj); - openList.remove(currentAdj); - continue; - } - ////if (!room.getLayout().tileWalkable((short) currentAdj.x, (short) currentAdj.y)) continue; - - //Height difference. - double height = currentAdj.getStackHeight() - current.getStackHeight(); - - //If we are not allowed to fall and the height difference is bigger than the maximum stepheight, continue. - if (!ALLOW_FALLING && height < -MAXIMUM_STEP_HEIGHT) continue; - - //If the step difference is bigger than the maximum step height, continue. - if (currentAdj.state == RoomTileState.OPEN && height > MAXIMUM_STEP_HEIGHT) continue; - - //Check if the tile has habbos. - if (currentAdj.hasUnits() && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) { - closedList.add(currentAdj); - openList.remove(currentAdj); - continue; - } - - //if (room.hasPetsAt(currentAdj.x, currentAdj.y)) continue; - - if (!openList.contains(currentAdj)) { - currentAdj.setPrevious(current); - currentAdj.sethCosts(this.findTile(openList, newTile.x, newTile.y)); - currentAdj.setgCosts(current); - openList.add(currentAdj); - } else if (currentAdj.getgCosts() > currentAdj.calculategCosts(current)) { - currentAdj.setPrevious(current); - currentAdj.setgCosts(current); - } + if ((currentAdj.state == RoomTileState.BLOCKED) || ((currentAdj.state == RoomTileState.SIT || currentAdj.state == RoomTileState.LAY) && !currentAdj.equals(goalLocation))) { + closedList.add(currentAdj); + openList.remove(currentAdj); + continue; } - if (openList.isEmpty()) { - return new LinkedList<>(); + double height = currentAdj.getStackHeight() - current.getStackHeight(); + if (!ALLOW_FALLING && height < -MAXIMUM_STEP_HEIGHT) continue; + if (currentAdj.state == RoomTileState.OPEN && height > MAXIMUM_STEP_HEIGHT) continue; + if (currentAdj.hasUnits() && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) { + closedList.add(currentAdj); + openList.remove(currentAdj); + continue; + } + if (!openList.contains(currentAdj)) { + currentAdj.setPrevious(current); + currentAdj.sethCosts(this.findTile(openList, newTile.x, newTile.y)); + currentAdj.setgCosts(current); + openList.add(currentAdj); + } else if (currentAdj.getgCosts() > currentAdj.calculategCosts(current)) { + currentAdj.setPrevious(current); + currentAdj.setgCosts(current); } } - } catch (Exception e) { - Emulator.getLogging().logErrorLine(e); } + // System.out.println("Invalid Path."); return new LinkedList<>(); } @@ -605,8 +573,6 @@ public class RoomLayout { } public boolean fitsOnMap(RoomTile tile, int width, int length, int rotation) { - THashSet pointList = new THashSet<>(width * length, 0.1f); - if (tile != null) { if (rotation == 0 || rotation == 4) { for (short i = tile.x; i <= (tile.x + (width - 1)); i++) { 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 61d1db47..d3978d8d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java @@ -47,6 +47,20 @@ public class RoomTile { this.units = tile.units; } + public RoomTile() + { + x = 0; + y = 0; + z = 0; + this.stackHeight = 0; + this.state = RoomTileState.INVALID; + this.allowStack = false; + this.diagonally = false; + this.gCosts = 0; + this.hCosts = 0; + this.units = null; + } + public double getStackHeight() { return this.stackHeight; } 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 d369d23a..07809406 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -227,17 +227,15 @@ public class RoomUnit { //if(!(this.path.size() == 0 && canSitNextTile)) { - if (!room.tileWalkable(next.x, next.y) && !overrideChecks) { + if (!room.tileWalkable(next)) { this.room = room; this.findPath(); - if (!this.path.isEmpty()) { - next = this.path.pop(); - item = room.getTopItemAt(next.x, next.y); - } else { + if (this.path.isEmpty()) { this.status.remove(RoomUnitStatus.MOVE); return false; } + next = (RoomTile)this.path.pop(); } } @@ -465,14 +463,15 @@ public class RoomUnit { public void setGoalLocation(RoomTile goalLocation) { if (goalLocation != null) { - if (goalLocation.state != RoomTileState.INVALID) { + // if (goalLocation.state != RoomTileState.INVALID) { this.setGoalLocation(goalLocation, false); } - } + //} } public void setGoalLocation(RoomTile goalLocation, boolean noReset) { - if (Emulator.getPluginManager().isRegistered(RoomUnitSetGoalEvent.class, false)) { + if (Emulator.getPluginManager().isRegistered(RoomUnitSetGoalEvent.class, false)) + { Event event = new RoomUnitSetGoalEvent(this.room, this, goalLocation); Emulator.getPluginManager().fireEvent(event); @@ -480,16 +479,18 @@ public class RoomUnit { return; } + /// Set start location this.startLocation = this.currentLocation; if (goalLocation != null && !noReset) { this.goalLocation = goalLocation; - this.findPath(); + this.findPath(); ///< Quadral: this is where we start formulating a path if (!this.path.isEmpty()) { this.tilesWalked = 0; this.cmdSit = false; } else { this.goalLocation = this.currentLocation; + } } } @@ -524,8 +525,11 @@ public class RoomUnit { this.room = room; } - 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) || this.canOverrideTile(this.goalLocation))) { + 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) || this.canOverrideTile(this.goalLocation))) + { + this.path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation, this); } } 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 ea675a1c..08966a11 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 @@ -15,20 +15,28 @@ import gnu.trove.set.hash.THashSet; public class RoomUserWalkEvent extends MessageHandler { @Override - public void handle() throws Exception { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - int x = this.packet.readInt(); - int y = this.packet.readInt(); + public void handle() throws Exception + { + if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) + { + int x = this.packet.readInt(); ///< Position X + int y = this.packet.readInt(); ///