From c426a84db0e6ea015af9d58149aad7555ccdcf9a Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 7 Nov 2023 21:45:16 -0600 Subject: [PATCH] shape --- src/engine/devcmd/cmds/RegionCmd.java | 14 ++---- src/engine/gameManager/NavigationManager.java | 45 +++++++++++-------- src/engine/mobileAI/MobAI.java | 29 +++++++++--- src/engine/objects/AbstractCharacter.java | 13 +++++- 4 files changed, 63 insertions(+), 38 deletions(-) diff --git a/src/engine/devcmd/cmds/RegionCmd.java b/src/engine/devcmd/cmds/RegionCmd.java index 3875cfdb..2f608f95 100644 --- a/src/engine/devcmd/cmds/RegionCmd.java +++ b/src/engine/devcmd/cmds/RegionCmd.java @@ -12,6 +12,7 @@ package engine.devcmd.cmds; import engine.Enum; import engine.devcmd.AbstractDevCmd; import engine.gameManager.BuildingManager; +import engine.gameManager.NavigationManager; import engine.gameManager.ZoneManager; import engine.math.Vector3f; import engine.math.Vector3fImmutable; @@ -68,16 +69,9 @@ public class RegionCmd extends AbstractDevCmd { //}else { // output += "zone: null" + newline; //} - if( building != null){ - boolean pointBlocked = false; - for(Path2D.Float area : building.meshes){ - Vector3fImmutable pos = ((AbstractCharacter)target).loc; - if(area.contains(new Point((int) pos.x, (int) pos.z))){ - pointBlocked = true; - } - } - output += "pointBlocked: " + pointBlocked; - } + + output += "pointBlocked: " + NavigationManager.pointIsBlocked(((AbstractCharacter)target).loc); + diff --git a/src/engine/gameManager/NavigationManager.java b/src/engine/gameManager/NavigationManager.java index d413bd70..b7c3a983 100644 --- a/src/engine/gameManager/NavigationManager.java +++ b/src/engine/gameManager/NavigationManager.java @@ -3,6 +3,8 @@ package engine.gameManager; import engine.math.Vector3fImmutable; import engine.objects.*; +import java.awt.*; +import java.awt.geom.Path2D; import java.util.ArrayList; @@ -12,18 +14,19 @@ public class NavigationManager { private static final int stepHeight = 2; public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){ - //try { - // ArrayList path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc)); - // if (path.isEmpty()) { - // character.destination = goal; - // return; //no points to walk to - // } + try { + ArrayList path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc)); + if (path.isEmpty() || path.size() < 2) { + character.destination = goal; + return; //no points to walk to + } - // character.destination = path.get(0); + //character.destination = path.get(1); + character.navPath = path; - //} catch(Exception e){ + } catch(Exception e){ //something failed - //} + } } public static ArrayList getOptimizedPath(ArrayList startToGoal, ArrayList goalToStart) { @@ -101,16 +104,20 @@ public class NavigationManager { public static boolean pointIsBlocked(Vector3fImmutable point) { Building building = BuildingManager.getBuildingAtLocation(point); - if(building != null) - for(Regions region : building.getBounds().getRegions()) - if(region.isPointInPolygon(point)) - if(Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height + if(building != null) { + for (Regions region : building.getBounds().getRegions()) { + if (region.isPointInPolygon(point)) + if (Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height return true; - - Zone currentZone = ZoneManager.findSmallestZone(point); - if(currentZone == null) - return false; - else - return currentZone.navMesh.contains(point.x,point.z); + } + boolean pointBlocked = false; + for (Path2D.Float mesh : building.meshes) { + if (mesh.contains((double)point.x,(double)point.z)) { + pointBlocked = true; + } + return pointBlocked; + } + } + return false; } } diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index 9d5d7efc..8fdddb36 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -291,7 +291,7 @@ public class MobAI { mob.destination = captain.destination.add(Formation.getOffset(2, mob.guardCaptain.minions.indexOf(mob.getObjectUUID()) + 3)); mob.lastPatrolPointIndex = captain.lastPatrolPointIndex; } else { - NavigationManager.pathfind(mob, mob.patrolPoints.get(mob.lastPatrolPointIndex)); + mob.destination = mob.patrolPoints.get(mob.lastPatrolPointIndex); mob.lastPatrolPointIndex += 1; } @@ -749,7 +749,7 @@ public class MobAI { if (CombatUtilities.inRange2D(mob, mob.guardCaptain, 6)) return; - NavigationManager.pathfind(mob, mob.guardCaptain.getLoc()); + mob.destination = mob.guardCaptain.getLoc(); aiMove(mob, false,5); } else chaseTarget(mob); @@ -905,7 +905,7 @@ public class MobAI { if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { if (mob.getRange() > 15) { - NavigationManager.pathfind(mob, mob.getCombatTarget().getLoc()); + mob.destination = mob.getCombatTarget().getLoc(); aiMove(mob, false,0); } else { @@ -1241,7 +1241,7 @@ public class MobAI { float xPoint = ThreadLocalRandom.current().nextInt(400) - 200; float zPoint = ThreadLocalRandom.current().nextInt(400) - 200; Vector3fImmutable TreePos = mob.getGuild().getOwnedCity().getLoc(); - NavigationManager.pathfind(mob, new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint)); + mob.destination = new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint); aiMove(mob, true,0); @@ -1345,6 +1345,22 @@ public class MobAI { public static void aiMove(Mob mob, boolean isWalking, float offset) { + if(mob.navPath.size() < 1){ + NavigationManager.pathfind(mob,mob.destination); + return; + } + if(mob.navPath.get(mob.navPath.size() -1).distanceSquared(mob.destination) > 100){ // goal has moved by at least 10 units, recalculate + NavigationManager.pathfind(mob,mob.destination); + return; + } + if(mob.isMoving()) + return; + Vector3fImmutable PathPoint = mob.navPath.get(0); + if(mob.loc.distanceSquared(mob.navPath.get(0)) < 25) { + mob.navPath.remove(0); + return; + } + //update our walk/run state. if (isWalking && !mob.isWalk()) { mob.setWalkMode(true); @@ -1354,8 +1370,7 @@ public class MobAI { MovementManager.sendRWSSMsg(mob); } if(offset > 0){ - Vector3fImmutable newLoc = Vector3fImmutable.getRandomPointInCircle(mob.destination, offset); - mob.destination = newLoc; + PathPoint= Vector3fImmutable.getRandomPointInCircle(PathPoint, offset); } @@ -1364,7 +1379,7 @@ public class MobAI { msg.setSourceType(Enum.GameObjectType.Mob.ordinal()); msg.setSourceID(mob.getObjectUUID()); msg.setStartCoord(mob.loc); - msg.setEndCoord(mob.destination); + msg.setEndCoord(PathPoint); msg.setInBuildingFloor(-1); msg.setInBuilding(-1); msg.setStartLocType(0); diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 4d6e3a92..29a2e06d 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -127,6 +127,8 @@ public abstract class AbstractCharacter extends AbstractWorldObject { public ArrayList runes; + public ArrayList navPath = new ArrayList<>(); + public AbstractCharacter() { super(); this.firstName = ""; @@ -836,8 +838,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject { if (this.isCasting && this.getObjectType().equals(GameObjectType.PlayerCharacter)) return false; - if(this.getObjectType().equals(GameObjectType.Mob) && ((Mob)this).destination.equals(Vector3fImmutable.ZERO)) - return false; + if(this.getObjectType().equals(GameObjectType.Mob)){ + if(this.destination.equals(Vector3fImmutable.ZERO)) + return false; + if(this.loc.distanceSquared(this.destination) < 3){ + this.stopMovement(this.loc); + return false; + } + + } return true; }