diff --git a/src/engine/devcmd/cmds/RegionCmd.java b/src/engine/devcmd/cmds/RegionCmd.java index 2b227247..3cd7db9c 100644 --- a/src/engine/devcmd/cmds/RegionCmd.java +++ b/src/engine/devcmd/cmds/RegionCmd.java @@ -54,7 +54,7 @@ public class RegionCmd extends AbstractDevCmd { }else { output += "zone: null" + newline; } - this.throwbackInfo(pc, "No Region Found."); + this.throwbackInfo(pc, output); } @Override diff --git a/src/engine/mobileAI/utilities/MovementUtilities.java b/src/engine/mobileAI/utilities/MovementUtilities.java index 3748c04a..c3359f62 100644 --- a/src/engine/mobileAI/utilities/MovementUtilities.java +++ b/src/engine/mobileAI/utilities/MovementUtilities.java @@ -20,6 +20,7 @@ import engine.gameManager.ChatManager; import engine.gameManager.MovementManager; import engine.gameManager.ZoneManager; import engine.math.Bounds; +import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.mobileAI.Threads.MobAIThread; import engine.net.client.msg.MoveToPointMsg; @@ -303,9 +304,23 @@ private static final int cellGap = 1; if(character.region == null && Regions.getRegionAtLocation(goal) != null) {//mover not inside a building Building building = BuildingManager.getBuildingAtLocation(goal); - for (Regions region : building.getBounds().getRegions()) + ArrayList entrances = new ArrayList<>(); + for (Regions region : building.getBounds().getRegions()) { if (region.exit && region.level == 0) - goal = new Vector3fImmutable(region.center.x, region.center.y, region.center.z); + entrances.add(region); + } + Regions cheapest = null; + for(Regions entrance : entrances){ + if(cheapest == null) { + cheapest = entrance; + continue; + } + if(getCost(new Vector3fImmutable(entrance.center),character.loc,goal) < getCost(new Vector3fImmutable(cheapest.center),character.loc,goal)) + cheapest = entrance; + } + + goal = new Vector3fImmutable(cheapest.center.x, cheapest.center.y, cheapest.center.z); + } ArrayList path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc)); diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index f5ad448b..1425c5fa 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -33,6 +33,9 @@ import engine.net.client.msg.ApplyBuildingEffectMsg; import engine.net.client.msg.UpdateObjectMsg; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; + +import java.awt.*; +import java.awt.geom.Area; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDateTime; @@ -1533,11 +1536,13 @@ public class Building extends AbstractWorldObject { } public void updateNavMesh(){ + int xPoint = (int)(this.loc.x - this.getBounds().getHalfExtents().x); + int zPoint = (int) (this.loc.z - this.getBounds().getHalfExtents().y); + int extentsX = (int) (this.getBounds().getHalfExtents().x * 2); + int extentsZ = (int) (this.getBounds().getHalfExtents().y * 2); + this.parentZone.navMesh.subtract( new Area(new Rectangle(xPoint, zPoint, extentsX, extentsZ)));//remove entire footprint of building from navMesh + for(Regions region : this.getBounds().getRegions()) this.parentZone.navMesh.add(region.getArea()); - - MeshBounds meshBounds = Bounds.meshBoundsCache.get(this.getMeshUUID()); - if(meshBounds != null) - this.parentZone.navMesh.subtract(meshBounds.getArea(this.loc.x,this.loc.z)); } } diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index ffe0c0e0..93e52d05 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -189,7 +189,6 @@ public class Zone extends AbstractWorldObject { } public void createNavMesh(){ - Vector3fImmutable location = this.loc; int xPoint = (int)(this.absX - this.bounds.getHalfExtents().x); int zPoint = (int) (this.absZ - this.bounds.getHalfExtents().y); int extentsX = (int) (this.bounds.getHalfExtents().x * 2);