|
|
@ -299,9 +299,17 @@ private static final int cellGap = 4; |
|
|
|
} |
|
|
|
} |
|
|
|
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){ |
|
|
|
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){ |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(character.region == null && Regions.getRegionAtLocation(goal) != null) {//mover not inside a building
|
|
|
|
|
|
|
|
Building building = BuildingManager.getBuildingAtLocation(goal); |
|
|
|
|
|
|
|
for (Regions region : building.getBounds().getRegions()) |
|
|
|
|
|
|
|
if (region.exit && region.level == 0) |
|
|
|
|
|
|
|
goal = new Vector3fImmutable(region.center.x, region.center.y, region.center.z); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc)); |
|
|
|
ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc)); |
|
|
|
if (path.isEmpty()) { |
|
|
|
if (path.isEmpty()) { |
|
|
|
((Mob) character).setDestination(character.loc); |
|
|
|
((Mob) character).destination = goal; |
|
|
|
return; //no points to walk to
|
|
|
|
return; //no points to walk to
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -344,10 +352,41 @@ private static final int cellGap = 4; |
|
|
|
surroundingCells.add(current.add(new Vector3fImmutable(0, 0, -cellGap))); |
|
|
|
surroundingCells.add(current.add(new Vector3fImmutable(0, 0, -cellGap))); |
|
|
|
surroundingCells.add(current.add(new Vector3fImmutable(-cellGap, 0, cellGap))); |
|
|
|
surroundingCells.add(current.add(new Vector3fImmutable(-cellGap, 0, cellGap))); |
|
|
|
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, -cellGap))); |
|
|
|
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, -cellGap))); |
|
|
|
Vector3fImmutable cheapest = new Vector3fImmutable(-10000, 0, -10000); |
|
|
|
Vector3fImmutable cheapest = new Vector3fImmutable(Vector3fImmutable.ZERO); |
|
|
|
for (Vector3fImmutable point : surroundingCells) |
|
|
|
for (Vector3fImmutable point : surroundingCells) |
|
|
|
{ |
|
|
|
{ |
|
|
|
count++; |
|
|
|
count++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Building building = BuildingManager.getBuildingAtLocation(point); |
|
|
|
|
|
|
|
if(building != null){ |
|
|
|
|
|
|
|
float halfX = building.getBounds().getHalfExtents().x; |
|
|
|
|
|
|
|
float halfY = building.getBounds().getHalfExtents().y; |
|
|
|
|
|
|
|
ArrayList<Vector3fImmutable> corners = new ArrayList<>(); |
|
|
|
|
|
|
|
corners.add(building.loc.add(new Vector3fImmutable(halfX,0,-halfY))); |
|
|
|
|
|
|
|
corners.add(building.loc.add(new Vector3fImmutable(halfX,0,halfY))); |
|
|
|
|
|
|
|
corners.add(building.loc.subtract(new Vector3fImmutable(halfX,0,halfY))); |
|
|
|
|
|
|
|
corners.add(building.loc.add(new Vector3fImmutable(-halfX,0,halfY))); |
|
|
|
|
|
|
|
Vector3fImmutable cheapCorner = Vector3fImmutable.ZERO; |
|
|
|
|
|
|
|
for(Vector3fImmutable corn : corners){ |
|
|
|
|
|
|
|
if(Bounds.collide(building.getBounds(),point,corn)) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
if(getCost(corn,start,goal) < getCost(cheapCorner,start,goal)) |
|
|
|
|
|
|
|
cheapCorner = corn; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(!cheapCorner.equals(Vector3fImmutable.ZERO)) |
|
|
|
|
|
|
|
if (path.contains(cheapCorner)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
path.add(cheapCorner); |
|
|
|
|
|
|
|
current = cheapCorner; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (path.contains(point)) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (path.contains(point)) |
|
|
|
if (path.contains(point)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
@ -361,6 +400,7 @@ private static final int cellGap = 4; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pointIsBlocked(point)) { |
|
|
|
if (pointIsBlocked(point)) { |
|
|
|
obstructed = true; |
|
|
|
obstructed = true; |
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -413,10 +453,4 @@ private static final int cellGap = 4; |
|
|
|
return (end.x > mb.minX && end.x < mb.maxX && end.z > mb.minZ && end.z < mb.maxZ); |
|
|
|
return (end.x > mb.minX && end.x < mb.maxX && end.z > mb.minZ && end.z < mb.maxZ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void printToPlayers(Vector3fImmutable loc, String message){ |
|
|
|
|
|
|
|
for(AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(loc, MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER)){ |
|
|
|
|
|
|
|
PlayerCharacter pc = (PlayerCharacter)awo; |
|
|
|
|
|
|
|
ChatManager.chatSystemInfo(pc, message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|