Compare commits

...

56 Commits

Author SHA1 Message Date
MagicBot 44f38b9ac3 Dev cmd updated 2023-11-09 14:33:10 -05:00
MagicBot 34efa3dd65 Dev cmd updated 2023-11-09 14:33:10 -05:00
FatBoy f94648c5dd shape 2023-11-07 22:55:34 -06:00
FatBoy c426a84db0 shape 2023-11-07 21:45:16 -06:00
FatBoy 1b5738f9b3 shape 2023-11-07 21:04:01 -06:00
FatBoy d502a889a6 shape 2023-11-07 20:54:45 -06:00
FatBoy 1ee8851fe0 shape 2023-11-07 20:28:44 -06:00
FatBoy 72dea668f9 shape 2023-11-07 20:17:51 -06:00
FatBoy 7fe5f8b5ac shape 2023-11-07 19:50:29 -06:00
FatBoy a54612a947 shape 2023-11-07 19:36:37 -06:00
FatBoy 92293ebed1 shape 2023-11-07 19:24:23 -06:00
FatBoy f5200abf61 shape 2023-11-07 19:18:46 -06:00
FatBoy 60b7cab0fe shape 2023-11-07 19:09:09 -06:00
FatBoy 7a3f824816 shape 2023-11-07 18:53:29 -06:00
FatBoy aca0ff52d6 disable mob movement temporarily 2023-11-07 18:48:31 -06:00
FatBoy 7203d66ace test phase 1 2023-11-07 18:47:49 -06:00
MagicBot 3e50782979 Set offset and rotation from building 2023-11-07 13:45:58 -05:00
MagicBot fc15e9310d Set offset and rotation from building 2023-11-07 13:44:29 -05:00
MagicBot 6aff5307c7 Update to bake logic 2023-11-07 12:48:12 -05:00
MagicBot d45b55d97b Dev cmd updated 2023-11-07 12:33:26 -05:00
MagicBot 17ddd7d1ff Dev cmd updated 2023-11-07 12:32:25 -05:00
MagicBot 25b508a101 Enhanced sanity checks. 2023-11-06 12:06:45 -05:00
MagicBot 2166a0a440 Method cleanup 2023-11-06 11:42:06 -05:00
MagicBot 19d43cbcb0 Method made static and moved to manager. 2023-11-06 11:37:50 -05:00
MagicBot e473aa5f08 Stencil build up of navmesh 2023-11-06 11:32:02 -05:00
MagicBot 016919675a Filter ineligible meshes 2023-11-06 09:54:34 -05:00
MagicBot bb433f6f4a Trap for parsing floats 2023-11-06 09:44:53 -05:00
MagicBot a8ccf0c67c Support for variable length vert fields 2023-11-06 00:25:25 -05:00
MagicBot 45e9311822 bugfix in db handler 2023-11-05 12:51:40 -05:00
MagicBot c81c910019 Dev cmd updated 2023-11-05 12:47:37 -05:00
MagicBot b6ac5735c6 bake data now loaded at bootstrap 2023-11-05 12:45:30 -05:00
MagicBot 9aa89a544c db handler created 2023-11-05 12:43:35 -05:00
MagicBot 19cbbd7176 db handler created 2023-11-05 12:42:18 -05:00
MagicBot 40443a82a7 Collection defined. 2023-11-05 11:57:56 -05:00
FatBoy 24a58db3a9 i hope this works 2023-11-05 10:45:35 -06:00
FatBoy bdb901afce region work 2023-10-28 12:49:27 -05:00
FatBoy 7e54426c95 region work 2023-10-28 11:33:57 -05:00
FatBoy 7236c9369a region work 2023-10-28 00:22:55 -05:00
FatBoy 12ee06e128 region work 2023-10-28 00:22:27 -05:00
FatBoy 6e22ff53d7 region work 2023-10-28 00:14:36 -05:00
FatBoy 77c32f9081 region work 2023-10-28 00:09:15 -05:00
FatBoy 2e36c01537 region work 2023-10-27 23:56:40 -05:00
FatBoy 4229999848 region work 2023-10-27 23:29:54 -05:00
FatBoy a2c7fd2404 cleanup 2023-10-27 23:17:31 -05:00
FatBoy 67af6f8c18 Revert "cleanup"
This reverts commit e128f60519.
2023-10-27 23:17:16 -05:00
FatBoy e128f60519 cleanup 2023-10-27 23:16:08 -05:00
FatBoy d57e5df356 cleanup 2023-10-27 22:42:17 -05:00
FatBoy f002de704b work 2023-10-27 21:55:31 -05:00
FatBoy c63c5e6896 work 2023-10-27 20:38:55 -05:00
FatBoy d7c7491746 dev command work 2023-10-27 20:28:18 -05:00
FatBoy 8cf1f1e60b dev command work 2023-10-27 20:07:43 -05:00
FatBoy 6cc6713650 bonus code cleanup 2023-10-27 20:03:15 -05:00
FatBoy bf1182dd2c avoidance revision 2023-10-26 21:12:11 -05:00
FatBoy 51e0098aa0 counter added 2023-10-26 20:33:22 -05:00
FatBoy 66d5752ca9 prints removed 2023-10-26 20:12:38 -05:00
FatBoy 136c8c4756 system enabled 2023-10-26 20:04:11 -05:00
21 changed files with 596 additions and 378 deletions
@@ -15,6 +15,7 @@ import engine.Enum.ProtectionState;
import engine.Enum.TaxType;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager;
import engine.math.Vector2f;
import engine.math.Vector3fImmutable;
import engine.objects.*;
import org.joda.time.DateTime;
@@ -27,6 +28,7 @@ import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -548,6 +550,63 @@ public class dbBuildingHandler extends dbHandlerBase {
return false;
}
public void LOAD_MESH_HULLS() {
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_verts")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
recordsRead++;
int propID = rs.getInt("propID");
String[] vertStrings = rs.getString("vertices").split(";");
ArrayList<Vector2f> vertArrayList = new ArrayList<>();
// Filter things that couldn't be wrapped
if (vertStrings.length < 3) {
Logger.error("Prop : " + propID + " has less than 3 vertices.");
continue;
}
ArrayList<Vector2f> vectors = new ArrayList<>();
ArrayList<Float> floats = new ArrayList<>();
for(String read : vertStrings){
floats.add(Float.parseFloat(read));
if(floats.size() == 2) {
vectors.add(new Vector2f(floats.get(0), floats.get(1)));
floats = new ArrayList<>();
}
}
//for (int i = 0; i < vertStrings.length; i += 2)
// vertArrayList.add(new Vector2f(Float.parseFloat(vertStrings[i]), Float.parseFloat(vertStrings[1 + 1])));
ArrayList<ArrayList<Vector2f>> meshList;
if (BuildingManager._hull_data.get(propID) == null) {
meshList = new ArrayList<>();
meshList.add(vectors);
BuildingManager._hull_data.put(propID, meshList);
} else {
meshList = BuildingManager._hull_data.get(propID);
meshList.add(vectors);
}
}
} catch (SQLException e) {
Logger.error(e);
}
Logger.info("read: " + recordsRead + " cached: " + BuildingManager._hull_data.size());
}
public HashMap<Integer, ArrayList<BuildingRegions>> LOAD_BUILDING_REGIONS() {
HashMap<Integer, ArrayList<BuildingRegions>> regionList = new HashMap<>();
+20 -6
View File
@@ -49,18 +49,32 @@ public class GetHeightCmd extends AbstractDevCmd {
float blendedHeight = Terrain.getWorldHeight(currentZone, playerCharacter.getLoc());
Vector2f gridSquare = heightmapZone.terrain.getTerrainCell(childZoneLoc);
gridSquare.x = (float) Math.floor(gridSquare.x);
gridSquare.y = (float) Math.floor(gridSquare.y);
Vector2f terrainCell = heightmapZone.terrain.getTerrainCell(childZoneLoc);
terrainCell.x = (float) Math.floor(terrainCell.x);
terrainCell.y = (float) Math.floor(terrainCell.y);
Vector2f cell_offset = new Vector2f(terrainCell.x % 1, terrainCell.y % 1);
short top_left_pixel = heightmapZone.terrain.terrain_pixel_data[(int) terrainCell.x][(int) terrainCell.y];
short top_right_pixel = heightmapZone.terrain.terrain_pixel_data[(int) terrainCell.x + 1][(int) terrainCell.y];
short bottom_left_pixel = heightmapZone.terrain.terrain_pixel_data[(int) terrainCell.x][(int) terrainCell.y + 1];
short bottom_right_pixel = heightmapZone.terrain.terrain_pixel_data[(int) terrainCell.x + 1][(int) terrainCell.y + 1];
this.throwbackInfo(playerCharacter, "Current Zone : " + currentZone.zoneName);
this.throwbackInfo(playerCharacter, "Heightmap Zone : " + heightmapZone.zoneName);
this.throwbackInfo(playerCharacter, "Parent Zone: " + parentZone.zoneName);
this.throwbackInfo(playerCharacter, "Grid : " + "[" + gridSquare.x + "]" + "[" + gridSquare.y + "]");
this.throwbackInfo(playerCharacter, "offset: " + "[" + childZoneOffset.x + "]" + "[" + childZoneOffset.y + "]");
this.throwbackInfo(playerCharacter, "Player loc: " + "[" + playerCharacter.loc.x + "]" + "[" + playerCharacter.loc.y + "]" + "[" + playerCharacter.loc.z + "]");
this.throwbackInfo(playerCharacter, "Terrain Cell : " + "[" + terrainCell.x + "]" + "[" + terrainCell.y + "]");
this.throwbackInfo(playerCharacter, "Cell Offset : " + "[" + cell_offset.x + "]" + "[" + cell_offset.y + "]");
this.throwbackInfo(playerCharacter, "Pixels : " + "[" + top_left_pixel + "]" + "[" + top_right_pixel + "]");
this.throwbackInfo(playerCharacter, "Pixels : " + "[" + bottom_left_pixel + "]" + "[" + bottom_right_pixel + "]");
this.throwbackInfo(playerCharacter, "Child Zone Offset: " + "[" + childZoneOffset.x + "]" + "[" + childZoneOffset.y + "]");
this.throwbackInfo(playerCharacter, "Normalized offset: " + "[" + normalizedOffset.x + "]" + "[" + normalizedOffset.y + "]");
this.throwbackInfo(playerCharacter, "template blend Values: (max/min): " + heightmapZone.template.min_blend + " /" + heightmapZone.template.max_blend);
this.throwbackInfo(playerCharacter, "template blend Values: (max/min): " + heightmapZone.template.max_blend + " /" + heightmapZone.template.min_blend);
this.throwbackInfo(playerCharacter, "terrain values (max/min): " + heightmapZone.terrain.blend_values.x + " /" + heightmapZone.terrain.blend_values.y);
this.throwbackInfo(playerCharacter, "Blend coefficient: " + heightmapZone.terrain.getTerrainBlendCoefficient(childZoneOffset));
+34 -7
View File
@@ -12,10 +12,22 @@ 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;
import engine.objects.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.lang.reflect.Field;
import static java.awt.geom.Path2D.WIND_EVEN_ODD;
import static java.awt.geom.Path2D.WIND_NON_ZERO;
public class RegionCmd extends AbstractDevCmd {
public RegionCmd() {
@@ -35,20 +47,35 @@ public class RegionCmd extends AbstractDevCmd {
this.throwbackInfo(pc, "No Building At This Location.") ;
}
Regions region = ((AbstractCharacter)target).region;
output += "In Floor: " + ((AbstractCharacter) target).getInFloorID() + newline;
output += "In Building: " + ((AbstractCharacter) target).getInBuilding() + newline;
if (region == null) {
this.throwbackInfo(pc, "No Region Found.");
return;
}
if(region != null) {
output += "No Region Found." + newline;
}else{
output += "Player Info: " + ((AbstractCharacter) target).getName() + newline;
output += "Region Building: " + building.getName() + newline;
output += "Region Height: " + region.lerpY((AbstractCharacter)target) + newline;
output += "Region Height: " + region.lerpY(((AbstractCharacter)target).loc) + newline;
output += "is Stairs: " + region.isStairs() + newline;
output += "is Outside: " + region.isOutside();
output += "is Outside: " + region.isOutside() + newline;
for(Vector3f point : region.regionPoints)
output += point + newline;
output += "NavMesh Data" + newline;
this.throwbackInfo(pc, output);
}
//Zone zone = ZoneManager.findSmallestZone(((AbstractCharacter) target).loc);
//if(zone != null) {
// output += "zone: " + zone.zoneName + newline;
// output += "on navmesh: " + zone.navMesh.contains(((AbstractCharacter) target).loc.x,((AbstractCharacter) target).loc.z) + newline;
//}else {
// output += "zone: null" + newline;
//}
output += "pointBlocked: " + NavigationManager.pointIsBlocked(((AbstractCharacter)target).loc);
this.throwbackInfo(pc, output);
}
@Override
+7
View File
@@ -13,6 +13,7 @@ import engine.Enum;
import engine.Enum.GameObjectType;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.PowersManager;
import engine.math.Vector3fImmutable;
import engine.mobileAI.MobAI;
import engine.objects.AbstractGameObject;
import engine.objects.Mob;
@@ -150,6 +151,12 @@ public class aiInfoCmd extends AbstractDevCmd {
for (Integer outlawUUID : outlaws)
output += outlawUUID + newline;
}
output += "Walking: " + ((Mob) target).isMoving() + newline;
output += "Destination: " + ((Mob) target).destination + newline;
output += "NavPath: " + newline;
for(Vector3fImmutable point : ((Mob) target).navPath){
output += "(" + ((Mob) target).navPath.indexOf(point) + ")(" +((Mob) target).loc.distanceSquared2D(point) + ") "+ point + newline;
}
throwbackInfo(playerCharacter, output);
}
@@ -18,6 +18,7 @@ import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.UpgradeBuildingJob;
import engine.math.Bounds;
import engine.math.Vector2f;
import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ErrorPopupMsg;
@@ -27,6 +28,10 @@ import engine.objects.*;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
@@ -38,6 +43,7 @@ public enum BuildingManager {
BUILDINGMANAGER;
public static HashMap<Integer, ArrayList<ArrayList<Vector2f>>> _hull_data = new HashMap<>();
public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations = new HashMap<>();
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>();
@@ -960,4 +966,40 @@ public enum BuildingManager {
return null;
}
public static void bakeNavMesh(Building building) {
building.meshes = new ArrayList<>();
if (building.parentZone == null) {
Logger.error("Attempt to bake navmesh with no parent: " + building.getObjectUUID());
return;
}
// Build up navmesh by stencil of the
// convex hull meshes that comprise the prop.
ArrayList<ArrayList<Vector2f>> convexHullList;
convexHullList = _hull_data.get(building.meshUUID);
if (convexHullList == null) {
Logger.error("Attempt to bake navmesh with no meshes: " + building.getObjectUUID());
return;
}
for (ArrayList<Vector2f> meshEntry : convexHullList) {
Path2D.Float meshBound = new Path2D.Float();
Vector3fImmutable offsetVect = new Vector3fImmutable(meshEntry.get(0).x + building.loc.x, building.loc.y,meshEntry.get(0).y + building.loc.z);
Vector3fImmutable rotatedStart = Vector3fImmutable.rotateAroundPoint(building.loc,offsetVect,building.getRot().y);
meshBound.moveTo(rotatedStart.x,rotatedStart.z);
for (Vector2f vect : meshEntry) {
if(meshEntry.indexOf(vect) == 0){
continue;
}
Vector3fImmutable pos = new Vector3fImmutable(vect.x + building.loc.x, building.loc.y,vect.y + building.loc.z);
Vector3fImmutable rotatedPos = Vector3fImmutable.rotateAroundPoint(building.loc,pos,building.getRot().getRotation());
meshBound.lineTo(rotatedPos.x,rotatedPos.z);
}
meshBound.lineTo(rotatedStart.x,rotatedStart.z);
meshBound.closePath();
building.meshes.add(meshBound);
}
}
}
@@ -0,0 +1,138 @@
package engine.gameManager;
import engine.Enum;
import engine.math.Vector3fImmutable;
import engine.net.client.msg.MoveToPointMsg;
import engine.objects.*;
import java.awt.geom.Path2D;
import java.util.ArrayList;
public class NavigationManager {
private static final int cellGap = 1;
private static final int stepHeight = 2;
public static void pathfind(AbstractCharacter character, Vector3fImmutable goal) {
try {
ArrayList<Vector3fImmutable> path = getPath(character.loc, goal);//getOptimizedPath(getPath(character.loc, goal), getPath(goal, character.loc));
if (path.isEmpty()) {
MoveToPointMsg msg = new MoveToPointMsg();
msg.setSourceType(Enum.GameObjectType.Mob.ordinal());
msg.setSourceID(character.getObjectUUID());
msg.setStartCoord(character.loc);
msg.setEndCoord(goal);
Regions region = Regions.getRegionAtLocation(goal);
if (region != null) {
msg.setInBuildingFloor(region.room);
msg.setInBuilding(region.level);
msg.setStartLocType(0);
msg.setInBuildingUUID(region.parentBuildingID);
} else {
msg.setInBuildingFloor(-1);
msg.setInBuilding(-1);
msg.setStartLocType(0);
msg.setInBuildingUUID(0);
}
return; //no points to walk to
}
//character.destination = path.get(1);
character.navPath = path;
} catch (Exception e) {
//something failed
}
}
public static ArrayList<Vector3fImmutable> getOptimizedPath(ArrayList<Vector3fImmutable> startToGoal, ArrayList<Vector3fImmutable> goalToStart) {
ArrayList<Vector3fImmutable> optimalPath = new ArrayList<>();
optimalPath.add(startToGoal.get(0));
for (Vector3fImmutable point : startToGoal) {
if (goalToStart.contains(point) && !optimalPath.contains(point)) {
optimalPath.add(point);
}
}
//optimize the path to its smallest possible amount of points
return optimalPath;
}
private static ArrayList<Vector3fImmutable> getPath(Vector3fImmutable start, Vector3fImmutable goal) {
ArrayList<Vector3fImmutable> path = new ArrayList<>();
path.add(start);
Vector3fImmutable current = start;
boolean obstructed = false;
int count = 0;
while (current.distanceSquared(goal) > 9 && count < 250) {
//gather the 8 cells around the player
ArrayList<Vector3fImmutable> surroundingCells = new ArrayList<>();
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, 0)));
surroundingCells.add(current.add(new Vector3fImmutable(cellGap, 0, cellGap)));
surroundingCells.add(current.add(new Vector3fImmutable(0, 0, cellGap)));
surroundingCells.add(current.add(new Vector3fImmutable(-cellGap, 0, 0)));
surroundingCells.add(current.add(new Vector3fImmutable(-cellGap, 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)));
Vector3fImmutable cheapest = new Vector3fImmutable(Vector3fImmutable.ZERO);
for (Vector3fImmutable point : surroundingCells) {
count++;
if (path.contains(point))
continue;
if (pointIsBlocked(point)) {
obstructed = true;
continue;
}
if (getCost(cheapest, current, goal) > getCost(point, current, goal))
cheapest = point;
}
current = cheapest;
path.add(cheapest);
}
if (obstructed) {
return path;
} else {
ArrayList<Vector3fImmutable> goalPath = new ArrayList<>();
goalPath.add(start);
goalPath.add(start.moveTowards(goal,32));
goalPath.add(goal);
return goalPath; //if the path isn't obstructed we can walk directly from start to the goal
}
}
public static float getCost(Vector3fImmutable point, Vector3fImmutable start, Vector3fImmutable goal) {
float gCost = start.distanceSquared(point);
float hCost = goal.distanceSquared(point);
return gCost + hCost;
}
public static boolean pointIsBlocked(Vector3fImmutable point) {
Building building = BuildingManager.getBuildingAtLocation(point);
if(building != null) {
for (Path2D.Float mesh : building.meshes) {
if (mesh.contains(point.x,point.z)) {
return true;
}
}
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;
}
}
return false;
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ public class Bounds {
private boolean flipExtents;
private ArrayList<Regions> regions = new ArrayList<>();
private ArrayList<Colliders> colliders = new ArrayList<>();
public ArrayList<Colliders> colliders = new ArrayList<>();
// Default constructor
+124 -20
View File
@@ -11,14 +11,15 @@ package engine.mobileAI;
import engine.Enum;
import engine.Enum.DispatchChannel;
import engine.InterestManagement.WorldGrid;
import engine.exception.MsgSendException;
import engine.gameManager.*;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.mobileAI.Threads.MobAIThread;
import engine.mobileAI.Threads.Respawner;
import engine.mobileAI.utilities.CombatUtilities;
import engine.mobileAI.utilities.MovementUtilities;
import engine.net.DispatchMessage;
import engine.net.client.msg.MoveToPointMsg;
import engine.net.client.msg.PerformActionMsg;
import engine.net.client.msg.PowerProjectileMsg;
import engine.objects.*;
@@ -103,7 +104,7 @@ public class MobAI {
if (mob.behaviourType.callsForHelp)
MobCallForHelp(mob);
if (!MovementUtilities.inRangeDropAggro(mob, target)) {
if (inRangeDropAggro(mob, target)) {
mob.setCombatTarget(null);
return;
}
@@ -303,7 +304,7 @@ public class MobAI {
MobAI.Patrol(minion);
}
MovementUtilities.aiMove(mob, mob.destination, true);
aiMove(mob, true,0);
} catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage());
@@ -584,7 +585,7 @@ public class MobAI {
if(mob.isPlayerGuard() || mob.isSiege()) {
bypassLoadedPlayerCheck = true;
if(mob.combatTarget != null && mob.combatTarget.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))
if(mob.combatTarget.loc.distanceSquared(mob.loc) > 10000)
if(mob.combatTarget.loc.distanceSquared(mob.loc) > 62500)
mob.setCombatTarget(null);
}
@@ -689,7 +690,7 @@ public class MobAI {
if (aiAgent.enemy.size() > 0 && aiAgent.enemy.contains(loadedPlayer.getRace().getRaceType().getMonsterType()) == false)
continue;
if (MovementUtilities.inRangeToAggro(aiAgent, loadedPlayer)) {
if (inRangeToAggro(aiAgent, loadedPlayer)) {
aiAgent.setCombatTarget(loadedPlayer);
return;
}
@@ -722,7 +723,7 @@ public class MobAI {
try {
if (!MovementUtilities.canMove(mob))
if (!canMove(mob))
return;
mob.updateLocation();
@@ -749,7 +750,7 @@ public class MobAI {
return;
mob.destination = mob.guardCaptain.getLoc();
MovementUtilities.moveToLocation(mob, mob.destination, 5, false);
aiMove(mob, false,5);
} else
chaseTarget(mob);
break;
@@ -834,7 +835,7 @@ public class MobAI {
if (mob.getCombatTarget() == null)
return;
if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && MovementUtilities.inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) == false &&
if (mob.getCombatTarget().getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && inRangeDropAggro(mob, (PlayerCharacter) mob.getCombatTarget()) &&
mob.agentType.equals(Enum.AIAgentType.PET) == false) {
mob.setCombatTarget(null);
@@ -877,7 +878,7 @@ public class MobAI {
}
}
}
} else if (MovementUtilities.inRangeOfBindLocation(mob) == false) {
} else if (inRangeOfBindLocation(mob) == false) {
PowersBase recall = PowersManager.getPowerByToken(-1994153779);
PowersManager.useMobPower(mob, mob, recall, 40);
@@ -905,7 +906,7 @@ public class MobAI {
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) {
if (mob.getRange() > 15) {
mob.destination = mob.getCombatTarget().getLoc();
MovementUtilities.moveToLocation(mob, mob.destination, 0, false);
aiMove(mob, false,0);
} else {
//check if building
@@ -913,12 +914,12 @@ public class MobAI {
switch (mob.getCombatTarget().getObjectType()) {
case PlayerCharacter:
case Mob:
mob.destination = MovementUtilities.GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
MovementUtilities.moveToLocation(mob, mob.destination, mob.getRange() + 1, false);
mob.destination = mob.combatTarget.loc;//GetDestinationToCharacter(mob, (AbstractCharacter) mob.getCombatTarget());
aiMove(mob, false,mob.getRange() + 1);
break;
case Building:
mob.destination = mob.getCombatTarget().getLoc();
MovementUtilities.moveToLocation(mob, mob.getCombatTarget().getLoc(), 0, false);
aiMove(mob, false,0);
break;
}
}
@@ -1000,7 +1001,7 @@ public class MobAI {
if (ZoneManager.seaFloor.zoneMobSet.contains(mob))
mob.killCharacter("no owner");
if (MovementUtilities.canMove(mob) && mob.behaviourType.canRoam)
if (canMove(mob) && mob.behaviourType.canRoam)
CheckMobMovement(mob);
CheckForAttack(mob);
@@ -1130,7 +1131,7 @@ public class MobAI {
if (GuardCanAggro(mob, loadedPlayer) == false)
continue;
if (MovementUtilities.inRangeToAggro(mob, loadedPlayer) && mob.getCombatTarget() == null) {
if (inRangeToAggro(mob, loadedPlayer) && mob.getCombatTarget() == null) {
mob.setCombatTarget(loadedPlayer);
return;
}
@@ -1240,9 +1241,9 @@ public class MobAI {
float xPoint = ThreadLocalRandom.current().nextInt(400) - 200;
float zPoint = ThreadLocalRandom.current().nextInt(400) - 200;
Vector3fImmutable TreePos = mob.getGuild().getOwnedCity().getLoc();
mob.destination = new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint);
mob.destination = new Vector3fImmutable(TreePos.x + xPoint, TreePos.y, TreePos.z + zPoint);
MovementUtilities.aiMove(mob, mob.destination, true);
aiMove(mob, true,0);
if (mob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN)) {
for (Integer minionUUID : mob.minions) {
@@ -1252,11 +1253,12 @@ public class MobAI {
//make sure mob is out of combat stance
if (minion.despawned == false) {
if (MovementUtilities.canMove(minion)) {
if (canMove(minion)) {
Vector3f minionOffset = Formation.getOffset(2, mob.minions.indexOf(minionUUID) + 3);
minion.updateLocation();
Vector3fImmutable formationPatrolPoint = new Vector3fImmutable(mob.destination.x + minionOffset.x, mob.destination.y, mob.destination.z + minionOffset.z);
MovementUtilities.aiMove(minion, formationPatrolPoint, true);
minion.destination = formationPatrolPoint;
aiMove(minion, true,0);
}
}
}
@@ -1284,7 +1286,7 @@ public class MobAI {
if (potentialTarget.equals(mob.getCombatTarget()))
continue;
if (potentialTarget != null && mob.playerAgroMap.get(potentialTarget.getObjectUUID()).floatValue() > CurrentHateValue && MovementUtilities.inRangeToAggro(mob, potentialTarget)) {
if (potentialTarget != null && mob.playerAgroMap.get(potentialTarget.getObjectUUID()).floatValue() > CurrentHateValue && inRangeToAggro(mob, potentialTarget)) {
CurrentHateValue = mob.playerAgroMap.get(potentialTarget.getObjectUUID()).floatValue();
mostHatedTarget = potentialTarget;
}
@@ -1296,4 +1298,106 @@ public class MobAI {
}
return null;
}
public static boolean inRangeDropAggro(Mob agent, AbstractCharacter target) {
float rangeSquared = MobAIThread.AI_BASE_AGGRO_RANGE * MobAIThread.AI_BASE_AGGRO_RANGE;
if(agent.isPlayerGuard())
rangeSquared = 62500;
if(agent.isSiege())
rangeSquared = agent.getRange() * agent.getRange();
return agent.loc.distanceSquared(target.loc) > rangeSquared;
}
public static boolean inRangeToAggro(Mob agent, PlayerCharacter target) {
return MobAIThread.AI_BASE_AGGRO_RANGE * MobAIThread.AI_BASE_AGGRO_RANGE > agent.loc.distanceSquared(target.loc) ;
}
public static boolean inRangeOfBindLocation(Mob agent) {
if(agent.isPlayerGuard() && agent.guardedCity.isLocationOnCityZone(agent.loc))
return true;
float bindRangeSquared = (agent.parentZone.getBounds().getHalfExtents().x * agent.parentZone.getBounds().getHalfExtents().x) + (MobAIThread.AI_DROP_AGGRO_RANGE * MobAIThread.AI_DROP_AGGRO_RANGE);
return agent.loc.distanceSquared(agent.bindLoc) < bindRangeSquared;
}
public static boolean canMove(Mob agent) {
if (!agent.behaviourType.canRoam)
return false;
return (agent.isAlive() && !agent.getBonuses().getBool(Enum.ModType.Stunned, Enum.SourceType.None) && !agent.getBonuses().getBool(Enum.ModType.CannotMove, Enum.SourceType.None));
}
public static Vector3fImmutable GetDestinationToCharacter(Mob aiAgent, AbstractCharacter character) {
if (!character.isMoving())
return character.getLoc();
float agentDistanceEndLoc = aiAgent.getLoc().distanceSquared2D(character.getEndLoc());
float characterDistanceEndLoc = character.getLoc().distanceSquared2D(character.getEndLoc());
if (agentDistanceEndLoc > characterDistanceEndLoc)
return character.getEndLoc();
return character.getLoc();
}
public static void aiMove(Mob mob, boolean isWalking, float offset) {
if(mob.navPath.isEmpty() || mob.navPath.size() == 1){
NavigationManager.pathfind(mob,mob.destination);
return;
}
if(mob.isMoving()) {
return;
}
Vector3fImmutable PathPoint = mob.navPath.get(0);
if(mob.loc.distanceSquared(mob.destination) > mob.loc.distanceSquared2D(mob.destination)) {
mob.navPath.remove(0);
return;
}
//update our walk/run state.
if (isWalking && !mob.isWalk()) {
mob.setWalkMode(true);
MovementManager.sendRWSSMsg(mob);
} else if (!isWalking && mob.isWalk()) {
mob.setWalkMode(false);
MovementManager.sendRWSSMsg(mob);
}
if(offset > 0){
PathPoint= Vector3fImmutable.getRandomPointInCircle(PathPoint, offset);
}
mob.endLoc = PathPoint;
MoveToPointMsg msg = new MoveToPointMsg();
msg.setSourceType(Enum.GameObjectType.Mob.ordinal());
msg.setSourceID(mob.getObjectUUID());
msg.setStartCoord(mob.loc);
msg.setEndCoord(PathPoint);
Regions region = Regions.getRegionAtLocation(PathPoint);
if(region != null){
msg.setInBuildingFloor(region.room);
msg.setInBuilding(region.level);
msg.setStartLocType(0);
msg.setInBuildingUUID(region.parentBuildingID);
} else{
msg.setInBuildingFloor(-1);
msg.setInBuilding(-1);
msg.setStartLocType(0);
msg.setInBuildingUUID(0);
}
try {
MovementManager.movement(msg, mob);
} catch (MsgSendException e) {
// TODO Figure out how we want to handle the msg send exception
e.printStackTrace();
}
}
}
@@ -1,295 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.mobileAI.utilities;
import engine.Enum;
import engine.Enum.GameObjectType;
import engine.Enum.ModType;
import engine.Enum.SourceType;
import engine.exception.MsgSendException;
import engine.gameManager.MovementManager;
import engine.math.Vector3fImmutable;
import engine.mobileAI.Threads.MobAIThread;
import engine.net.client.msg.MoveToPointMsg;
import engine.objects.*;
import org.pmw.tinylog.Logger;
import java.util.concurrent.ThreadLocalRandom;
import static engine.math.FastMath.sqr;
import static engine.math.FastMath.sqrt;
public class MovementUtilities {
public static boolean inRangeOfBindLocation(Mob agent) {
if (agent.isPlayerGuard()) {
Mob guardCaptain = null;
if (agent.getContract() != null)
guardCaptain = agent;
else
guardCaptain = (Mob) agent.guardCaptain;
if (guardCaptain != null) {
Building barracks = guardCaptain.building;
if (barracks != null) {
City city = barracks.getCity();
if (city != null) {
Building tol = city.getTOL();
//Guards recall distance = 814.
if (tol != null) {
return !(agent.getLoc().distanceSquared2D(tol.getLoc()) > sqr(Enum.CityBoundsType.ZONE.halfExtents));
}
}
}
}
return true;
}
Vector3fImmutable sl = new Vector3fImmutable(agent.getLoc().getX(), 0, agent.getLoc().getZ());
Vector3fImmutable tl = new Vector3fImmutable(agent.getTrueBindLoc().x, 0, agent.getTrueBindLoc().z);
float distanceSquaredToTarget = sl.distanceSquared2D(tl); //distance to center of target
float zoneRange = 250;
if (agent.getParentZone() != null) {
if (agent.getParentZone().bounds != null)
zoneRange = agent.getParentZone().bounds.getHalfExtents().x * 2;
}
if (zoneRange > 300)
zoneRange = 300;
if (agent.getSpawnRadius() > zoneRange)
zoneRange = agent.getSpawnRadius();
return distanceSquaredToTarget < sqr(MobAIThread.AI_DROP_AGGRO_RANGE + zoneRange);
}
public static boolean inRangeToAggro(Mob agent, PlayerCharacter target) {
Vector3fImmutable sl = agent.getLoc();
Vector3fImmutable tl = target.getLoc();
float distanceSquaredToTarget = sl.distanceSquared2D(tl) - sqr(agent.calcHitBox() + target.calcHitBox()); //distance to center of target
float range = MobAIThread.AI_BASE_AGGRO_RANGE;
if (agent.isPlayerGuard())
range = 150;
return distanceSquaredToTarget < sqr(range);
}
public static boolean inRangeDropAggro(Mob agent, AbstractCharacter target) {
Vector3fImmutable sl = agent.getLoc();
Vector3fImmutable tl = target.getLoc();
float distanceSquaredToTarget = sl.distanceSquared2D(tl) - sqr(agent.calcHitBox() + target.calcHitBox()); //distance to center of target
float range = agent.getRange() + 150;
if (range > 200)
range = 200;
return distanceSquaredToTarget < sqr(range);
}
public static Vector3fImmutable GetMoveLocation(Mob aiAgent, AbstractCharacter aggroTarget) {
// Player isnt moving and neither is mob. Just return
// the mobile's current location. Ain't goin nowhere!
// *** Refactor: Check to ensure methods calling us
// all don't sent move messages when not moving.
if ((aggroTarget.isMoving() == false))
return aggroTarget.getLoc();
if (aggroTarget.getEndLoc().x != 0) {
float aggroTargetDistanceSquared = aggroTarget.getLoc().distanceSquared2D(aggroTarget.getEndLoc());
float aiAgentDistanceSquared = aiAgent.getLoc().distanceSquared2D(aggroTarget.getEndLoc());
if (aiAgentDistanceSquared >= aggroTargetDistanceSquared)
return aggroTarget.getEndLoc();
else {
float distanceToMove = sqrt(aggroTargetDistanceSquared + aiAgentDistanceSquared) * .5f;
return aggroTarget.getFaceDir().scaleAdd(distanceToMove, aggroTarget.getLoc());
}
}
// One of us is moving so let's calculate our destination loc for this
// simulation frame. We will simply project our position onto the
// character's movement vector and return the closest point.
return aiAgent.getLoc().ClosestPointOnLine(aggroTarget.getLoc(), aggroTarget.getEndLoc());
}
public static void moveToLocation(Mob agent, Vector3fImmutable newLocation, float offset, boolean isWalking) {
try {
//don't move farther than 30 units from player.
if (offset > 30)
offset = 30;
Vector3fImmutable newLoc = Vector3fImmutable.getRandomPointInCircle(newLocation, offset);
agent.setFaceDir(newLoc.subtract2D(agent.getLoc()).normalize());
aiMove(agent, newLoc, isWalking);
} catch (Exception e) {
Logger.error(e.toString());
}
}
public static boolean canMove(Mob agent) {
if (agent.getMobBase() != null && Enum.MobFlagType.SENTINEL.elementOf(agent.getMobBase().getFlags()))
return false;
return (agent.isAlive() && !agent.getBonuses().getBool(ModType.Stunned, SourceType.None) && !agent.getBonuses().getBool(ModType.CannotMove, SourceType.None));
}
public static Vector3fImmutable randomPatrolLocation(Mob agent, Vector3fImmutable center, float radius) {
//Determing where I want to move.
return new Vector3fImmutable((center.x - radius) + ((ThreadLocalRandom.current().nextFloat() + .1f * 2) * radius),
center.y,
(center.z - radius) + ((ThreadLocalRandom.current().nextFloat() + .1f * 2) * radius));
}
public static Long estimateMovementTime(Mob agent) {
if (agent.getEndLoc().x == 0 && agent.getEndLoc().y == 0)
return 0L;
return (long) ((agent.getLoc().distance2D(agent.getEndLoc()) * 1000) / agent.getSpeed());
}
public static void aiMove(Mob agent, Vector3fImmutable vect, boolean isWalking) {
//update our walk/run state.
if (isWalking && !agent.isWalk()) {
agent.setWalkMode(true);
MovementManager.sendRWSSMsg(agent);
} else if (!isWalking && agent.isWalk()) {
agent.setWalkMode(false);
MovementManager.sendRWSSMsg(agent);
}
MoveToPointMsg msg = new MoveToPointMsg();
// Regions currentRegion = Mob.InsideBuildingRegion(agent);
//
// if (currentRegion != null){
//
//
// if (currentRegion.isGroundLevel()){
// agent.setInBuilding(0);
// agent.setInFloorID(-1);
// }else{
// agent.setInBuilding(currentRegion.getLevel());
// agent.setInFloorID(currentRegion.getRoom());
// }
// }else{
// agent.setInBuilding(-1);
// agent.setInFloorID(-1);
// agent.setInBuildingID(0);
// }
// agent.setLastRegion(currentRegion);
Vector3fImmutable startLoc = null;
Vector3fImmutable endLoc = null;
// if (agent.getLastRegion() != null){
// Building inBuilding = Building.getBuildingFromCache(agent.getInBuildingID());
// if (inBuilding != null){
// startLoc = ZoneManager.convertWorldToLocal(inBuilding, agent.getLoc());
// endLoc = ZoneManager.convertWorldToLocal(inBuilding, vect);
// }
// }else{
// agent.setBuildingID(0);
// agent.setInBuildingID(0);
// startLoc = agent.getLoc();
// endLoc = vect;
// }
startLoc = agent.getLoc();
endLoc = vect;
msg.setSourceType(GameObjectType.Mob.ordinal());
msg.setSourceID(agent.getObjectUUID());
msg.setStartCoord(startLoc);
msg.setEndCoord(endLoc);
msg.setInBuildingFloor(-1);
msg.setInBuilding(-1);
msg.setStartLocType(0);
msg.setInBuildingUUID(0);
try {
MovementManager.movement(msg, agent);
} catch (MsgSendException e) {
// TODO Figure out how we want to handle the msg send exception
e.printStackTrace();
}
}
public static Vector3fImmutable GetDestinationToCharacter(Mob aiAgent, AbstractCharacter character) {
if (!character.isMoving())
return character.getLoc();
float agentDistanceEndLoc = aiAgent.getLoc().distanceSquared2D(character.getEndLoc());
float characterDistanceEndLoc = character.getLoc().distanceSquared2D(character.getEndLoc());
if (agentDistanceEndLoc > characterDistanceEndLoc)
return character.getEndLoc();
return character.getLoc();
}
public static boolean updateMovementToCharacter(Mob aiAgent, AbstractCharacter aggroTarget) {
if (aiAgent.destination.equals(Vector3fImmutable.ZERO))
return true;
if (!aiAgent.isMoving())
return true;
if (aggroTarget.isMoving()) {
return !aiAgent.destination.equals(aggroTarget.getEndLoc()) && !aiAgent.destination.equals(aggroTarget.getLoc());
} else {
if (aiAgent.destination.equals(aggroTarget.getLoc()))
return false;
}
return false;
}
}
@@ -0,0 +1,80 @@
package engine.mobileAI.utilities;
import engine.objects.Regions;
import java.awt.geom.Area;
import java.util.ArrayList;
public class PathingUtilities {
public static class Point {
public int x;
public int y;
public Point previous;
public Point(int x, int y, Point previous) {
this.x = x;
this.y = y;
this.previous = previous;
}
public Point offset(int ox, int oy) { return new Point(x + ox, y + oy, this); }
}
public static boolean IsWalkable(Area navMesh, Point point) {
if (navMesh.contains(point.x, point.y))
return true;
Regions region = Regions.getRegionAtPoint(point);
if (region != null) {
return !(region.getHeightAtPoint(point) - point.y > 2);
}
return false;
}
public static ArrayList<Point> FindNeighbors(Area navMesh, Point point) {
ArrayList<Point> neighbors = new ArrayList<>();
Point up = point.offset(0, 1);
Point down = point.offset(0, -1);
Point left = point.offset(-1, 0);
Point right = point.offset(1, 0);
if (IsWalkable(navMesh, up)) neighbors.add(up);
if (IsWalkable(navMesh, down)) neighbors.add(down);
if (IsWalkable(navMesh, left)) neighbors.add(left);
if (IsWalkable(navMesh, right)) neighbors.add(right);
return neighbors;
}
public static ArrayList<Point> FindPath(Area navMesh, Point start, Point end) {
boolean finished = false;
ArrayList<Point> used = new ArrayList<>();
used.add(start);
while (!finished) {
ArrayList<Point> newOpen = new ArrayList<>();
for(int i = 0; i < used.size(); ++i){
Point point = used.get(i);
for (Point neighbor : FindNeighbors(navMesh, point)) {
if (!used.contains(neighbor) && !newOpen.contains(neighbor)) {
newOpen.add(neighbor);
}
}
}
for(Point point : newOpen) {
used.add(point);
if (end.equals(point)) {
finished = true;
break;
}
}
if (!finished && newOpen.isEmpty())
return null;
}
ArrayList<Point> path = new ArrayList<>();
Point point = used.get(used.size() - 1);
while(point.previous != null) {
path.add(0, point);
point = point.previous;
}
return path;
}
}
@@ -79,7 +79,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler {
float startAlt = 0;
Building regionBuilding = Regions.GetBuildingForRegion(upRegion);
if (upRegion != null)
startAlt = upRegion.lerpY(pc) - regionBuilding.getLoc().y;
startAlt = upRegion.lerpY(pc.loc) - regionBuilding.getLoc().y;
float rounded = startAlt * .10f;
rounded = ((int) rounded) * 10;
@@ -143,7 +143,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler {
float landingAltitude = 0;
Building building = Regions.GetBuildingForRegion(region);
if (building != null)
landingAltitude = region.lerpY(pc) - building.getLoc().y;
landingAltitude = region.lerpY(pc.loc) - building.getLoc().y;
if (landingAltitude >= targetAlt) {
pc.landingRegion = region;
+10 -13
View File
@@ -120,11 +120,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
private long lastHateUpdate = 0;
private byte aoecntr = 0;
public Vector3fImmutable destination = Vector3fImmutable.ZERO;
public int hidden = 0; // current rank of hide/sneak/invis
public CopyOnWriteArrayList<Integer> minions = new CopyOnWriteArrayList();
public ArrayList<CharacterRune> runes;
public ArrayList<Vector3fImmutable> navPath = new ArrayList<>();
public AbstractCharacter() {
super();
this.firstName = "";
@@ -834,6 +838,10 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
if (this.isCasting && this.getObjectType().equals(GameObjectType.PlayerCharacter))
return false;
if(this.getObjectType().equals(GameObjectType.Mob)){
if(this.destination.equals(Vector3fImmutable.ZERO))
return false;
}
return true;
}
@@ -987,22 +995,11 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
@Override
public final void setLoc(final Vector3fImmutable value) {
Building building = BuildingManager.getBuildingAtLocation(this.loc);
Regions region = null;
if(building != null) {
//look for region in the building we are in
for (Regions regionCycle : building.getBounds().getRegions()) {
float regionHeight = regionCycle.highLerp.y - regionCycle.lowLerp.y;
if(regionHeight < 10)
regionHeight = 10;
if (regionCycle.isPointInPolygon(value) && Math.abs(regionCycle.highLerp.y - value.y) < regionHeight)
region = regionCycle;
}
}
Regions region = Regions.getRegionAtLocation(value);
float regionHeightOffset = 0;
if(region != null){
this.region = region;
regionHeightOffset = region.lerpY(this);
regionHeightOffset = region.lerpY(this.loc);
this.inBuilding = region.level; // -1 not in building 0 on ground floor, 1 on first floor etc
this.inBuildingID = region.parentBuildingID;
this.inFloorID = region.room;
+2 -2
View File
@@ -179,7 +179,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
if (region.center.y == region.highLerp.y)
worldObject.loc = worldObject.loc.setY(region.center.y + worldObject.getAltitude());
else
worldObject.loc = worldObject.loc.setY(region.lerpY(worldObject) + worldObject.getAltitude());
worldObject.loc = worldObject.loc.setY(region.lerpY(worldObject.loc) + worldObject.getAltitude());
return region;
}
@@ -504,7 +504,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
this.loc = loc;
if(this instanceof AbstractCharacter && this.region != null){
this.loc = this.loc.setY(this.region.lerpY(this) + this.getAltitude());
this.loc = this.loc.setY(this.region.lerpY(this.loc) + this.getAltitude());
} else{
this.loc = this.loc.setY(Terrain.getWorldHeight(this.getLoc()) + this.getAltitude());
}
+7
View File
@@ -34,6 +34,8 @@ import engine.net.client.msg.UpdateObjectMsg;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
@@ -99,6 +101,8 @@ public class Building extends AbstractWorldObject {
private ConcurrentHashMap<Integer, Condemned> condemned;
private ArrayList<Building> children = null;
public ArrayList<Path2D.Float> meshes;
/**
* ResultSet Constructor
*/
@@ -1003,6 +1007,8 @@ public class Building extends AbstractWorldObject {
if (this.upgradeDateTime != null)
BuildingManager.submitUpgradeJob(this);
BuildingManager.bakeNavMesh(this); // update the navmesh of the parent zone
}
public synchronized boolean setOwner(AbstractCharacter newOwner) {
@@ -1530,4 +1536,5 @@ public class Building extends AbstractWorldObject {
public void RemoveFromBarracksList() {
}
}
+8 -1
View File
@@ -12,6 +12,8 @@ package engine.objects;
import engine.gameManager.DbManager;
import engine.math.Bounds;
import java.awt.*;
import java.awt.geom.Area;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -45,5 +47,10 @@ public class MeshBounds {
Bounds.meshBoundsCache = DbManager.BuildingQueries.LOAD_MESH_BOUNDS();
}
public Area getArea(float x, float z){
Polygon area = new Polygon();
area.addPoint((int)(x + this.minX), (int) (z + this.minZ));
area.addPoint((int)(x + this.maxX), (int)(z + this.maxZ));
return new Area(area);
}
}
+2 -1
View File
@@ -53,7 +53,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
public long nextCallForHelp = 0;
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
public boolean despawned = false;
public Vector3fImmutable destination = Vector3fImmutable.ZERO;
public MobBase mobBase;
public int spawnDelay;
public Zone parentZone;
@@ -1899,4 +1899,5 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
public int compareTo(@NotNull Delayed o) {
return toIntExact(this.respawnTime - ((Mob) o).respawnTime);
}
}
+1 -1
View File
@@ -4828,7 +4828,7 @@ public class PlayerCharacter extends AbstractCharacter {
if (this.landingRegion != null) {
this.altitude = 0;
this.region = this.landingRegion;
this.loc = this.loc.setY(this.landingRegion.lerpY(this));
this.loc = this.loc.setY(this.landingRegion.lerpY(this.loc));
} else
this.altitude = this.getDesiredAltitude();
+41 -27
View File
@@ -9,14 +9,18 @@
package engine.objects;
import engine.InterestManagement.Terrain;
import engine.InterestManagement.WorldGrid;
import engine.gameManager.BuildingManager;
import engine.math.Bounds;
import engine.math.FastMath;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.mobileAI.utilities.PathingUtilities;
import engine.server.MBServerStatics;
import java.awt.*;
import java.awt.geom.Area;
import java.util.ArrayList;
import java.util.HashMap;
@@ -178,7 +182,7 @@ public class Regions {
boolean movingUp = false;
boolean movingDown = false;
float yLerp = worldObject.region.lerpY(worldObject);
float yLerp = worldObject.region.lerpY(worldObject.loc);
if (yLerp == (worldObject.region.highLerp.y))
movingUp = true;
@@ -270,35 +274,37 @@ public class Regions {
return BuildingManager.getBuildingFromCache(region.parentBuildingID);
}
public static Regions GetRegionForTeleport(Vector3fImmutable location) {
public static Regions getRegionAtLocation(Vector3fImmutable location) {
Regions region = null;
//Find building
for (AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(location, 128, MBServerStatics.MASK_BUILDING)) {
Building building = (Building) awo;
if (!Bounds.collide(location, building.getBounds()))
continue;
if(building != null) {
region = BuildingManager.GetRegion(building, location.x, location.y, location.z);
Building building = BuildingManager.getBuildingAtLocation(location);
if(building != null) {
//look for region in the building we are in
for (Regions regionCycle : building.getBounds().getRegions()) {
float regionHeight = regionCycle.highLerp.y - regionCycle.lowLerp.y;
if(regionHeight < 10)
regionHeight = 10;
if (regionCycle.isPointInPolygon(location) && Math.abs(regionCycle.highLerp.y - location.y) < regionHeight)
region = regionCycle;
}
//find regions that intersect x and z, check if object can enter.
//for (Regions toEnter : building.getBounds().getRegions()) {
// if (toEnter.isPointInPolygon(location)) {
// if (region == null)
// region = toEnter;
// else // we're using a low level to high level tree structure, database not always in order low to high.
//check for highest level index.
// if (region != null && toEnter.highLerp.y > region.highLerp.y)
// region = toEnter;
// }
// }
}
return region;
}
public static Regions getRegionAtPoint(PathingUtilities.Point point) {
Vector3fImmutable baseLoc = new Vector3fImmutable(point.x,0,point.y);
baseLoc.setY(Terrain.getWorldHeight(baseLoc));
Building building = BuildingManager.getBuildingAtLocation(baseLoc);
if(building == null)
return null;
for(Regions region : building.getBounds().getRegions())
if(region.isPointInPolygon(baseLoc))
return region;
return null;
}
public float getHeightAtPoint(PathingUtilities.Point point){
Vector3fImmutable baseLoc = new Vector3fImmutable(point.x,0,point.y);
return this.lerpY(baseLoc);
}
public int getRoom() {
return room;
@@ -350,10 +356,10 @@ public class Regions {
return inside;
}
public float lerpY(AbstractWorldObject lerper) {
public float lerpY(Vector3fImmutable lerper) {
Vector3fImmutable lengthVector = this.highLerp.subtract2D(this.lowLerp);
Vector3fImmutable characterVector = lerper.getLoc().subtract2D(this.lowLerp);
Vector3fImmutable characterVector = lerper.subtract2D(this.lowLerp);
float lengthVectorMagnitude = lengthVector.magnitude();
float characterVectorMagnitude = characterVector.magnitude();
float percentDistance = characterVectorMagnitude / lengthVectorMagnitude;
@@ -374,4 +380,12 @@ public class Regions {
public boolean isExit() {
return exit;
}
public Area getArea(){
Polygon area = new Polygon();
for( Vector3f point : this.regionPoints){
area.addPoint((int) point.x, (int) point.z);
}
return new Area(area);
}
}
+14 -1
View File
@@ -9,6 +9,7 @@
package engine.objects;
import java.awt.geom.Area;
import engine.Enum;
import engine.InterestManagement.Terrain;
import engine.db.archive.DataWarehouse;
@@ -19,7 +20,7 @@ import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -65,6 +66,8 @@ public class Zone extends AbstractWorldObject {
public Terrain terrain = null;
public Area navMesh;
/**
* ResultSet Constructor
*/
@@ -181,8 +184,18 @@ public class Zone extends AbstractWorldObject {
ZoneManager.populateZoneCollections(this);
//this.createNavMesh();
}
public void createNavMesh(){
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);
int extentsZ = (int) (this.bounds.getHalfExtents().y * 2);
this.navMesh = new Area(new Rectangle(xPoint, zPoint, extentsX, extentsZ));
}
/* Method sets a default value for player cities
* otherwise using values derived from the loadnum
* field in the obj_zone database table.
@@ -96,7 +96,7 @@ public class TeleportPowerAction extends AbstractPowerAction {
//TODO verify target loc is valid loc
Regions region = Regions.GetRegionForTeleport(targetLoc);
Regions region = Regions.getRegionAtLocation(targetLoc);
if (region != null && !region.isOutside())
return;
+3
View File
@@ -403,6 +403,9 @@ public class WorldServer {
Logger.info("Loading building slot/stuck location data.");
BuildingLocation.loadBuildingLocations();
Logger.info("Loading mesh hulls.");
DbManager.BuildingQueries.LOAD_MESH_HULLS();
// Starting before loading of structures/guilds/characters
// so the database connections are available to write
// historical data.