shape
This commit is contained in:
@@ -12,6 +12,7 @@ package engine.devcmd.cmds;
|
|||||||
import engine.Enum;
|
import engine.Enum;
|
||||||
import engine.devcmd.AbstractDevCmd;
|
import engine.devcmd.AbstractDevCmd;
|
||||||
import engine.gameManager.BuildingManager;
|
import engine.gameManager.BuildingManager;
|
||||||
|
import engine.gameManager.NavigationManager;
|
||||||
import engine.gameManager.ZoneManager;
|
import engine.gameManager.ZoneManager;
|
||||||
import engine.math.Vector3f;
|
import engine.math.Vector3f;
|
||||||
import engine.math.Vector3fImmutable;
|
import engine.math.Vector3fImmutable;
|
||||||
@@ -68,16 +69,9 @@ public class RegionCmd extends AbstractDevCmd {
|
|||||||
//}else {
|
//}else {
|
||||||
// output += "zone: null" + newline;
|
// output += "zone: null" + newline;
|
||||||
//}
|
//}
|
||||||
if( building != null){
|
|
||||||
boolean pointBlocked = false;
|
output += "pointBlocked: " + NavigationManager.pointIsBlocked(((AbstractCharacter)target).loc);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package engine.gameManager;
|
|||||||
import engine.math.Vector3fImmutable;
|
import engine.math.Vector3fImmutable;
|
||||||
import engine.objects.*;
|
import engine.objects.*;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.geom.Path2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
@@ -12,18 +14,19 @@ public class NavigationManager {
|
|||||||
private static final int stepHeight = 2;
|
private static final int stepHeight = 2;
|
||||||
|
|
||||||
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){
|
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){
|
||||||
//try {
|
try {
|
||||||
// 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() || path.size() < 2) {
|
||||||
// character.destination = goal;
|
character.destination = goal;
|
||||||
// return; //no points to walk to
|
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
|
//something failed
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Vector3fImmutable> getOptimizedPath(ArrayList<Vector3fImmutable> startToGoal, ArrayList<Vector3fImmutable> goalToStart) {
|
public static ArrayList<Vector3fImmutable> getOptimizedPath(ArrayList<Vector3fImmutable> startToGoal, ArrayList<Vector3fImmutable> goalToStart) {
|
||||||
@@ -101,16 +104,20 @@ public class NavigationManager {
|
|||||||
public static boolean pointIsBlocked(Vector3fImmutable point) {
|
public static boolean pointIsBlocked(Vector3fImmutable point) {
|
||||||
|
|
||||||
Building building = BuildingManager.getBuildingAtLocation(point);
|
Building building = BuildingManager.getBuildingAtLocation(point);
|
||||||
if(building != null)
|
if(building != null) {
|
||||||
for(Regions region : building.getBounds().getRegions())
|
for (Regions region : building.getBounds().getRegions()) {
|
||||||
if(region.isPointInPolygon(point))
|
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 (Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
Zone currentZone = ZoneManager.findSmallestZone(point);
|
boolean pointBlocked = false;
|
||||||
if(currentZone == null)
|
for (Path2D.Float mesh : building.meshes) {
|
||||||
return false;
|
if (mesh.contains((double)point.x,(double)point.z)) {
|
||||||
else
|
pointBlocked = true;
|
||||||
return currentZone.navMesh.contains(point.x,point.z);
|
}
|
||||||
|
return pointBlocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ public class MobAI {
|
|||||||
mob.destination = captain.destination.add(Formation.getOffset(2, mob.guardCaptain.minions.indexOf(mob.getObjectUUID()) + 3));
|
mob.destination = captain.destination.add(Formation.getOffset(2, mob.guardCaptain.minions.indexOf(mob.getObjectUUID()) + 3));
|
||||||
mob.lastPatrolPointIndex = captain.lastPatrolPointIndex;
|
mob.lastPatrolPointIndex = captain.lastPatrolPointIndex;
|
||||||
} else {
|
} else {
|
||||||
NavigationManager.pathfind(mob, mob.patrolPoints.get(mob.lastPatrolPointIndex));
|
mob.destination = mob.patrolPoints.get(mob.lastPatrolPointIndex);
|
||||||
mob.lastPatrolPointIndex += 1;
|
mob.lastPatrolPointIndex += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,7 +749,7 @@ public class MobAI {
|
|||||||
if (CombatUtilities.inRange2D(mob, mob.guardCaptain, 6))
|
if (CombatUtilities.inRange2D(mob, mob.guardCaptain, 6))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NavigationManager.pathfind(mob, mob.guardCaptain.getLoc());
|
mob.destination = mob.guardCaptain.getLoc();
|
||||||
aiMove(mob, false,5);
|
aiMove(mob, false,5);
|
||||||
} else
|
} else
|
||||||
chaseTarget(mob);
|
chaseTarget(mob);
|
||||||
@@ -905,7 +905,7 @@ public class MobAI {
|
|||||||
|
|
||||||
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) {
|
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) {
|
||||||
if (mob.getRange() > 15) {
|
if (mob.getRange() > 15) {
|
||||||
NavigationManager.pathfind(mob, mob.getCombatTarget().getLoc());
|
mob.destination = mob.getCombatTarget().getLoc();
|
||||||
aiMove(mob, false,0);
|
aiMove(mob, false,0);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -1241,7 +1241,7 @@ public class MobAI {
|
|||||||
float xPoint = ThreadLocalRandom.current().nextInt(400) - 200;
|
float xPoint = ThreadLocalRandom.current().nextInt(400) - 200;
|
||||||
float zPoint = ThreadLocalRandom.current().nextInt(400) - 200;
|
float zPoint = ThreadLocalRandom.current().nextInt(400) - 200;
|
||||||
Vector3fImmutable TreePos = mob.getGuild().getOwnedCity().getLoc();
|
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);
|
aiMove(mob, true,0);
|
||||||
|
|
||||||
@@ -1345,6 +1345,22 @@ public class MobAI {
|
|||||||
|
|
||||||
public static void aiMove(Mob mob, boolean isWalking, float offset) {
|
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.
|
//update our walk/run state.
|
||||||
if (isWalking && !mob.isWalk()) {
|
if (isWalking && !mob.isWalk()) {
|
||||||
mob.setWalkMode(true);
|
mob.setWalkMode(true);
|
||||||
@@ -1354,8 +1370,7 @@ public class MobAI {
|
|||||||
MovementManager.sendRWSSMsg(mob);
|
MovementManager.sendRWSSMsg(mob);
|
||||||
}
|
}
|
||||||
if(offset > 0){
|
if(offset > 0){
|
||||||
Vector3fImmutable newLoc = Vector3fImmutable.getRandomPointInCircle(mob.destination, offset);
|
PathPoint= Vector3fImmutable.getRandomPointInCircle(PathPoint, offset);
|
||||||
mob.destination = newLoc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1364,7 +1379,7 @@ public class MobAI {
|
|||||||
msg.setSourceType(Enum.GameObjectType.Mob.ordinal());
|
msg.setSourceType(Enum.GameObjectType.Mob.ordinal());
|
||||||
msg.setSourceID(mob.getObjectUUID());
|
msg.setSourceID(mob.getObjectUUID());
|
||||||
msg.setStartCoord(mob.loc);
|
msg.setStartCoord(mob.loc);
|
||||||
msg.setEndCoord(mob.destination);
|
msg.setEndCoord(PathPoint);
|
||||||
msg.setInBuildingFloor(-1);
|
msg.setInBuildingFloor(-1);
|
||||||
msg.setInBuilding(-1);
|
msg.setInBuilding(-1);
|
||||||
msg.setStartLocType(0);
|
msg.setStartLocType(0);
|
||||||
|
|||||||
@@ -127,6 +127,8 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
|
|||||||
|
|
||||||
public ArrayList<CharacterRune> runes;
|
public ArrayList<CharacterRune> runes;
|
||||||
|
|
||||||
|
public ArrayList<Vector3fImmutable> navPath = new ArrayList<>();
|
||||||
|
|
||||||
public AbstractCharacter() {
|
public AbstractCharacter() {
|
||||||
super();
|
super();
|
||||||
this.firstName = "";
|
this.firstName = "";
|
||||||
@@ -836,8 +838,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
|
|||||||
if (this.isCasting && this.getObjectType().equals(GameObjectType.PlayerCharacter))
|
if (this.isCasting && this.getObjectType().equals(GameObjectType.PlayerCharacter))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(this.getObjectType().equals(GameObjectType.Mob) && ((Mob)this).destination.equals(Vector3fImmutable.ZERO))
|
if(this.getObjectType().equals(GameObjectType.Mob)){
|
||||||
return false;
|
if(this.destination.equals(Vector3fImmutable.ZERO))
|
||||||
|
return false;
|
||||||
|
if(this.loc.distanceSquared(this.destination) < 3){
|
||||||
|
this.stopMovement(this.loc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user