Browse Source

shape

hull4
FatBoy-DOTC 1 year ago
parent
commit
c426a84db0
  1. 14
      src/engine/devcmd/cmds/RegionCmd.java
  2. 45
      src/engine/gameManager/NavigationManager.java
  3. 29
      src/engine/mobileAI/MobAI.java
  4. 13
      src/engine/objects/AbstractCharacter.java

14
src/engine/devcmd/cmds/RegionCmd.java

@ -12,6 +12,7 @@ package engine.devcmd.cmds; @@ -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 { @@ -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);

45
src/engine/gameManager/NavigationManager.java

@ -3,6 +3,8 @@ package engine.gameManager; @@ -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 { @@ -12,18 +14,19 @@ public class NavigationManager {
private static final int stepHeight = 2;
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal){
//try {
// ArrayList<Vector3fImmutable> path = getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
// if (path.isEmpty()) {
// character.destination = goal;
// return; //no points to walk to
// }
try {
ArrayList<Vector3fImmutable> 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<Vector3fImmutable> getOptimizedPath(ArrayList<Vector3fImmutable> startToGoal, ArrayList<Vector3fImmutable> goalToStart) {
@ -101,16 +104,20 @@ public class NavigationManager { @@ -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;
}
}

29
src/engine/mobileAI/MobAI.java

@ -291,7 +291,7 @@ public class MobAI { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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);

13
src/engine/objects/AbstractCharacter.java

@ -127,6 +127,8 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @@ -127,6 +127,8 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
public ArrayList<CharacterRune> runes;
public ArrayList<Vector3fImmutable> navPath = new ArrayList<>();
public AbstractCharacter() {
super();
this.firstName = "";
@ -836,8 +838,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @@ -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;
}

Loading…
Cancel
Save