Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fe4f32302 | |||
| d6ad0ecbd3 | |||
| efdf19f22e | |||
| 76a71b5984 | |||
| cf09f447bd | |||
| 8dc6a0627c | |||
| 8b095976ef | |||
| 83606046ba | |||
| adcf3fd9b6 | |||
| e983a32b5d | |||
| 9d8f800c2a | |||
| 05e90d495f | |||
| 18f70b6d5c | |||
| 86c8e985be | |||
| b6b5db41bd | |||
| d573534f6d | |||
| 06df109a18 | |||
| f077370034 | |||
| 94e16bdf3d | |||
| a52f0941b7 | |||
| 840dc83987 | |||
| 5b9d1dd6eb | |||
| 6215e15e82 | |||
| e8a39e596e | |||
| 90b516bbb9 | |||
| 561170eb44 | |||
| 68920f150d | |||
| a54e8c2176 | |||
| c77f38dec1 | |||
| 5a57677013 | |||
| 306c64d236 | |||
| 0b05e661c7 | |||
| a94a400102 | |||
| 4bff36d7bb | |||
| 969b36e6fd | |||
| 688553e6c6 | |||
| 4f057ee851 | |||
| fd47c90f4f | |||
| 253ca2344e | |||
| 95f09a255e | |||
| 31ea74f98c | |||
| 67c474dbdf | |||
| c65a713bae | |||
| e3641872d0 | |||
| c25fdf3823 | |||
| 7c28efb47c | |||
| c92316f03e | |||
| e330f190fe | |||
| ae52735131 | |||
| 59025c2585 | |||
| 6354eb2893 | |||
| 3ad97a7ce3 | |||
| f8cbeb4cc6 | |||
| f1e41e47cf |
@@ -0,0 +1,27 @@
|
||||
package engine.CollisionEngine;
|
||||
|
||||
import engine.math.Vector3f;
|
||||
import engine.objects.Building;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CollisionManager {
|
||||
public static HashMap<Integer, ArrayList<MeshData>> structure_meshes;
|
||||
public static HashMap<Integer,ArrayList<Triangle>> mesh_triangles;
|
||||
public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){
|
||||
|
||||
if(building.buildingRect != null)
|
||||
if(!travelLine.intersects(building.buildingRect) && !building.buildingRect.contains(travelLine.getP1()) && !building.buildingRect.contains(travelLine.getP2()))
|
||||
return false;
|
||||
|
||||
for(Mesh mesh : building.buildingMeshes)
|
||||
if(mesh.collides(travelLine))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package engine.CollisionEngine;
|
||||
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.math.Vector2f;
|
||||
import engine.math.Vector3f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.Building;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Mesh {
|
||||
public ArrayList<Triangle> triangles;
|
||||
public Vector3f mesh_end_point;
|
||||
public Vector3f mesh_ref_point;
|
||||
public Vector3f mesh_location;
|
||||
public float mesh_max_y;
|
||||
public float mesh_min_y;
|
||||
public Vector3f mesh_scale;
|
||||
public int mesh_id;
|
||||
public int parent_prop_id;
|
||||
public int parent_structure_id;
|
||||
public int parentUUID;
|
||||
public Rectangle2D.Float mesh_bounds;
|
||||
public MeshData meshData;
|
||||
|
||||
public void update(){
|
||||
this.BakeTriangles();
|
||||
}
|
||||
public Vector3f getLocation(){
|
||||
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
|
||||
int degrees = (int)Math.toDegrees(parentBuilding.getBounds().getQuaternion().angleY);
|
||||
Vector3f parentLoc = new Vector3f(parentBuilding.loc.x,parentBuilding.loc.y,parentBuilding.loc.z);
|
||||
Vector3f offsetLoc = parentLoc.add(this.meshData.loc);
|
||||
Vector3f rotatedPoint = Vector3f.rotateAroundPoint(offsetLoc,parentLoc,degrees);
|
||||
return rotatedPoint;
|
||||
}
|
||||
|
||||
public void BakeTriangles(){
|
||||
|
||||
if(CollisionManager.mesh_triangles.containsKey(this.meshData.meshID) == false){
|
||||
Logger.error("Failed To Bake Triangles For Mesh: " + this.meshData.meshID);
|
||||
return;
|
||||
}
|
||||
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
|
||||
int degrees = (int)Math.toDegrees(parentBuilding.getBounds().getQuaternion().angleY);
|
||||
Vector3f parentLoc = new Vector3f(parentBuilding.loc.x,parentBuilding.loc.y,parentBuilding.loc.z);
|
||||
Vector3f offsetLoc = parentLoc.add(this.meshData.loc);
|
||||
|
||||
for(Triangle tri : CollisionManager.mesh_triangles.get(this.meshData.meshID)) {
|
||||
|
||||
Triangle newTri = new Triangle();
|
||||
|
||||
Vector3f Point1 = offsetLoc.add(new Vector3f(tri.point1.x,offsetLoc.y,tri.point1.y));
|
||||
Vector3f Point2 = offsetLoc.add(new Vector3f(tri.point2.x,offsetLoc.y,tri.point2.y));
|
||||
Vector3f Point3 = offsetLoc.add(new Vector3f(tri.point3.x,offsetLoc.y,tri.point3.y));
|
||||
|
||||
Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(Point1,offsetLoc,degrees);
|
||||
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(Point2,offsetLoc,degrees);
|
||||
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(Point3,offsetLoc,degrees);
|
||||
|
||||
newTri.point1 = new Point2D.Float(rotatedPoint1.x,rotatedPoint1.z);
|
||||
newTri.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z);
|
||||
newTri.point3 = new Point2D.Float(rotatedPoint3.x,rotatedPoint3.z);
|
||||
|
||||
newTri.sides = new ArrayList<>();
|
||||
newTri.sides.add(new Line2D.Float(newTri.point1,newTri.point2));
|
||||
newTri.sides.add(new Line2D.Float(newTri.point2,newTri.point3));
|
||||
newTri.sides.add(new Line2D.Float(newTri.point3,newTri.point1));
|
||||
|
||||
this.triangles.add(newTri);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean collides(Line2D line){
|
||||
for(Triangle tri : this.triangles)
|
||||
if(tri.collides(line))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package engine.CollisionEngine;
|
||||
|
||||
import engine.math.Vector3f;
|
||||
|
||||
public class MeshData {
|
||||
public int propID;
|
||||
public int meshID;
|
||||
public Vector3f loc;
|
||||
public Vector3f scale;
|
||||
public Vector3f refPoint;
|
||||
public Vector3f endPoint;
|
||||
public float maxY;
|
||||
public float minY;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package engine.CollisionEngine;
|
||||
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Triangle {
|
||||
public Point2D.Float point1;
|
||||
public Point2D.Float point2;
|
||||
public Point2D.Float point3;
|
||||
public ArrayList<Line2D> sides;
|
||||
public boolean collides(Line2D line)
|
||||
{
|
||||
for(Line2D side : sides)
|
||||
if(side.intersectsLine(line))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -9,17 +9,25 @@
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.CollisionEngine.CollisionManager;
|
||||
import engine.CollisionEngine.MeshData;
|
||||
import engine.CollisionEngine.Triangle;
|
||||
import engine.Enum;
|
||||
import engine.Enum.DbObjectType;
|
||||
import engine.Enum.ProtectionState;
|
||||
import engine.Enum.TaxType;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector2f;
|
||||
import engine.math.Vector3f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.*;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -27,6 +35,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;
|
||||
|
||||
@@ -849,4 +858,167 @@ public class dbBuildingHandler extends dbHandlerBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LOAD_MESH_DATA(){
|
||||
CollisionManager.structure_meshes = new HashMap<>();
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `final_structure_meshes`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
MeshData md = new MeshData();
|
||||
md.propID = rs.getInt("propID");
|
||||
md.meshID = rs.getInt("meshID");
|
||||
md.loc = new Vector3f(rs.getFloat("locX"), rs.getFloat("locY"),rs.getFloat("locz"));
|
||||
md.scale = new Vector3f(rs.getFloat("scaleX"), rs.getFloat("scaleY"),rs.getFloat("scaleZ"));
|
||||
md.refPoint = new Vector3f(rs.getFloat("refX"), rs.getFloat("refY"),rs.getFloat("refZ"));
|
||||
md.endPoint = new Vector3f(rs.getFloat("endX"), rs.getFloat("endY"),rs.getFloat("endZ"));
|
||||
md.minY = rs.getFloat("minY");
|
||||
md.maxY = rs.getFloat("maxY");
|
||||
if(CollisionManager.structure_meshes.containsKey(rs.getInt("propID"))){
|
||||
CollisionManager.structure_meshes.get(rs.getInt("propID")).add(md);
|
||||
} else{
|
||||
ArrayList<MeshData> meshData = new ArrayList<>();
|
||||
meshData.add(md);
|
||||
CollisionManager.structure_meshes.put(rs.getInt("propID"),meshData);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
public void LOAD_MESH_TRIANGLE_DATA(){
|
||||
CollisionManager.mesh_triangles = new HashMap<>();
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `final_mesh_triangles`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Triangle tri = new Triangle();
|
||||
tri.point1 = new Point2D.Float(rs.getFloat("P1X"),rs.getFloat("P1Z"));
|
||||
tri.point2 = new Point2D.Float(rs.getFloat("P2X"),rs.getFloat("P2Z"));
|
||||
tri.point3 = new Point2D.Float(rs.getFloat("P3X"),rs.getFloat("P3Z"));
|
||||
if(CollisionManager.mesh_triangles.containsKey(rs.getInt("meshID"))){
|
||||
CollisionManager.mesh_triangles.get(rs.getInt("meshID")).add(tri);
|
||||
} else{
|
||||
ArrayList<Triangle> triData = new ArrayList<>();
|
||||
triData.add(tri);
|
||||
CollisionManager.mesh_triangles.put(rs.getInt("meshID"),triData);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
public void LOAD_PROP_MESHES() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_structure_meshes`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
BuildingManager.prop_meshes = new HashMap<>();
|
||||
while (rs.next()) {
|
||||
if(BuildingManager.prop_meshes.containsKey(rs.getInt("propID")) == false){
|
||||
ArrayList<Integer> meshList = new ArrayList<>();
|
||||
meshList.add(rs.getInt("meshID"));
|
||||
BuildingManager.prop_meshes.put(rs.getInt("propID"),meshList);
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayList<Integer> meshes = BuildingManager.prop_meshes.get(rs.getInt("propID"));
|
||||
meshes.add(rs.getInt("meshID"));
|
||||
//BuildingManager.prop_meshes.get(rs.getInt("propID")).add(rs.getInt("meshID"));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_MESH_DATA_OLD() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_mesh_triangles`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
BuildingManager.mesh_triangle_points = new HashMap<>();
|
||||
while (rs.next()) {
|
||||
|
||||
ArrayList<Float> floatPoints = new ArrayList<>();
|
||||
for(String f : rs.getString("vertices").split(";"))
|
||||
{
|
||||
floatPoints.add(Float.parseFloat(f));
|
||||
}
|
||||
ArrayList<Vector3f> triPoints = new ArrayList<>();
|
||||
for(int i = 0; i < floatPoints.size(); i += 3){
|
||||
triPoints.add(new Vector3f(floatPoints.get(i),floatPoints.get(i+1),floatPoints.get(i+2)));
|
||||
}
|
||||
|
||||
if(BuildingManager.mesh_triangle_points.containsKey(rs.getInt("meshID")) == false){
|
||||
ArrayList<ArrayList<Vector3f>> newPoints = new ArrayList<>();
|
||||
newPoints.add(triPoints);
|
||||
BuildingManager.mesh_triangle_points.put(rs.getInt("meshID"),newPoints);
|
||||
}
|
||||
else
|
||||
{
|
||||
BuildingManager.mesh_triangle_points.get(rs.getInt("meshID")).add(triPoints);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_mesh_heights`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
BuildingManager.mesh_heights = new HashMap<>();
|
||||
while (rs.next()) {
|
||||
|
||||
if(BuildingManager.mesh_heights.containsKey(rs.getInt("meshID")) == false){
|
||||
Vector2f heights = new Vector2f(rs.getFloat("maxY"),rs.getFloat("minY"));
|
||||
BuildingManager.mesh_heights.put(rs.getInt("meshID"),heights);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_MESH_BOUNDING_BOXES() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_mesh_bounding_boxes`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
BuildingManager.mesh_bounding_boxes = new HashMap<>();
|
||||
while (rs.next()) {
|
||||
int meshID = rs.getInt("meshId");
|
||||
if(BuildingManager.mesh_bounding_boxes.containsKey(meshID) == false){
|
||||
float endX = Float.parseFloat(rs.getString("mesh_end_point").split(";")[0]);
|
||||
float endZ = Float.parseFloat(rs.getString("mesh_end_point").split(";")[1]);
|
||||
float refX = Float.parseFloat(rs.getString("mesh_ref_point").split(";")[0]);
|
||||
float refZ = Float.parseFloat(rs.getString("mesh_ref_point").split(";")[1]);
|
||||
|
||||
|
||||
Vector2f topLeft = new Vector2f(refX,refZ);
|
||||
float width = Math.abs(Math.abs(endX)-Math.abs(refX));
|
||||
float height = Math.abs(Math.abs(endZ)-Math.abs(refZ));
|
||||
Rectangle2D boundRect = new Rectangle2D.Float();
|
||||
boundRect.setRect(topLeft.x,topLeft.y,width,height);
|
||||
BuildingManager.mesh_bounding_boxes.put(meshID,boundRect);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.CollisionEngine.Mesh;
|
||||
import engine.Enum;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.objects.*;
|
||||
|
||||
public class ColliderCmd extends AbstractDevCmd {
|
||||
|
||||
public ColliderCmd() {
|
||||
super("collider");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
String newline = "\r\n ";
|
||||
String output;
|
||||
if(target.getObjectType().equals(Enum.GameObjectType.Building) == false){
|
||||
throwbackInfo(pc,"Please Select A Building To Show Collider Data");
|
||||
}
|
||||
Building building = (Building)target;
|
||||
output = "Collision Info:" + newline;
|
||||
output += "Total Meshes: " + building.buildingMeshes.size() + newline;
|
||||
for(Mesh mesh : building.buildingMeshes){
|
||||
output += "-----------------------------" + newline;
|
||||
output += "Mesh ID: " + mesh.mesh_id + newline;
|
||||
output += "Mesh Location: " + mesh.mesh_location + newline;
|
||||
output += "Mesh Scale: " + mesh.mesh_scale + newline;
|
||||
output += "Mesh Min/Max: " + mesh.mesh_min_y + "/" + mesh.mesh_max_y + newline;
|
||||
output += "Mesh Triangle Count: " + mesh.triangles.size() + newline;
|
||||
output += "Mesh Rect: " + mesh.mesh_bounds + newline;
|
||||
output += "-----------------------------" + newline;
|
||||
}
|
||||
|
||||
throwbackInfo(pc,output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Displays Information About Colliders";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /collider displays collision info when selected on a building";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.CollisionEngine.Mesh;
|
||||
import engine.Enum;
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.Enum.GameObjectType;
|
||||
@@ -244,7 +245,6 @@ public class InfoCmd extends AbstractDevCmd {
|
||||
for (Regions regions : targetBuilding.getBounds().getRegions()) {
|
||||
//TODO ADD REGION INFO
|
||||
}
|
||||
|
||||
break;
|
||||
case PlayerCharacter:
|
||||
output += newline;
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.CollisionEngine.Mesh;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.objects.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
public class RegionCmd extends AbstractDevCmd {
|
||||
|
||||
@@ -37,7 +37,6 @@ public class RegionCmd extends AbstractDevCmd {
|
||||
Regions region = ((AbstractCharacter)target).region;
|
||||
if (region == null) {
|
||||
this.throwbackInfo(pc, "No Region Found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(region != null) {
|
||||
@@ -48,7 +47,6 @@ public class RegionCmd extends AbstractDevCmd {
|
||||
output += "is Outside: " + region.isOutside();
|
||||
this.throwbackInfo(pc, output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,15 +9,21 @@
|
||||
|
||||
package engine.gameManager;
|
||||
|
||||
import engine.CollisionEngine.CollisionManager;
|
||||
import engine.CollisionEngine.MeshData;
|
||||
import engine.Enum;
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.InterestManagement.InterestManager;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.CollisionEngine.Mesh;
|
||||
import engine.CollisionEngine.Triangle;
|
||||
import engine.job.JobContainer;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.UpgradeBuildingJob;
|
||||
import engine.math.Bounds;
|
||||
import engine.math.Vector2f;
|
||||
import engine.math.Vector3f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
@@ -27,6 +33,9 @@ import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
@@ -38,6 +47,12 @@ public enum BuildingManager {
|
||||
|
||||
BUILDINGMANAGER;
|
||||
|
||||
public static HashMap<Integer,ArrayList<Integer>> prop_meshes = new HashMap<>();
|
||||
public static HashMap<Integer, Vector2f> mesh_heights = new HashMap<>();
|
||||
public static HashMap<Integer,ArrayList<ArrayList<Vector3f>>> mesh_triangle_points = new HashMap<>();
|
||||
|
||||
public static HashMap<Integer, Rectangle2D> mesh_bounding_boxes = new HashMap<>();
|
||||
|
||||
public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations = new HashMap<>();
|
||||
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>();
|
||||
|
||||
@@ -942,6 +957,9 @@ public enum BuildingManager {
|
||||
|
||||
cleanupHirelings(building);
|
||||
|
||||
//rebake colliders for change in rank
|
||||
//BuildingManager.BakeBuildingMeshes(building);
|
||||
BuildingManager.BakeBuildingColliders(building);
|
||||
building.isDeranking.compareAndSet(true, false);
|
||||
}
|
||||
|
||||
@@ -960,4 +978,46 @@ public enum BuildingManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void BakeBuildingColliders(Building building){
|
||||
|
||||
if(CollisionManager.structure_meshes.containsKey(building.meshUUID) == false) {
|
||||
Logger.error("No Meshes Found For Structure: " + building.meshUUID);
|
||||
return;
|
||||
}
|
||||
|
||||
//create the empty array of meshes
|
||||
building.buildingMeshes = new ArrayList<>();
|
||||
|
||||
//create the actual meshes from the stored mesh data
|
||||
for(MeshData meshData : CollisionManager.structure_meshes.get(building.meshUUID)){
|
||||
if(meshData.meshID == 0)
|
||||
continue;
|
||||
|
||||
int degrees = (int)Math.toDegrees(building.getBounds().getQuaternion().angleY);
|
||||
|
||||
Mesh generatedMesh = new Mesh();
|
||||
|
||||
generatedMesh.meshData = meshData;
|
||||
|
||||
Vector3f buildingLoc = new Vector3f(building.loc.x,building.loc.y,building.loc.z);
|
||||
|
||||
Vector3f offset_mesh_loc = buildingLoc.add(meshData.loc);
|
||||
Vector3f offset_mesh_end = buildingLoc.add(meshData.endPoint);
|
||||
Vector3f offset_mesh_ref = buildingLoc.add(meshData.refPoint);
|
||||
|
||||
generatedMesh.mesh_location = Vector3f.rotateAroundPoint(offset_mesh_loc,buildingLoc,degrees);
|
||||
generatedMesh.mesh_end_point = Vector3f.rotateAroundPoint(offset_mesh_end,buildingLoc,degrees);
|
||||
generatedMesh.mesh_ref_point = Vector3f.rotateAroundPoint(offset_mesh_ref,buildingLoc,degrees);
|
||||
|
||||
generatedMesh.mesh_max_y = building.loc.y + meshData.maxY;
|
||||
generatedMesh.mesh_min_y = building.loc.y + meshData.minY;
|
||||
generatedMesh.mesh_scale = meshData.scale;
|
||||
generatedMesh.mesh_id = meshData.meshID;
|
||||
generatedMesh.parent_prop_id = meshData.propID;
|
||||
generatedMesh.parent_structure_id = building.meshUUID;
|
||||
generatedMesh.parentUUID = building.getObjectUUID();
|
||||
generatedMesh.update();
|
||||
building.buildingMeshes.add(generatedMesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +140,7 @@ public enum DevCmdManager {
|
||||
DevCmdManager.registerDevCmd(new BoundsCmd());
|
||||
DevCmdManager.registerDevCmd(new GotoBoundsCmd());
|
||||
DevCmdManager.registerDevCmd(new RegionCmd());
|
||||
DevCmdManager.registerDevCmd(new ColliderCmd());
|
||||
DevCmdManager.registerDevCmd(new SetMaintCmd());
|
||||
DevCmdManager.registerDevCmd(new ApplyBonusCmd());
|
||||
DevCmdManager.registerDevCmd(new AuditFailedItemsCmd());
|
||||
|
||||
@@ -9,14 +9,22 @@
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.CollisionEngine.CollisionManager;
|
||||
import engine.gameManager.MovementManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.MoveToPointMsg;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class MoveToPointHandler extends AbstractClientMsgHandler {
|
||||
|
||||
@@ -32,6 +40,32 @@ public class MoveToPointHandler extends AbstractClientMsgHandler {
|
||||
if(pc == null)
|
||||
return true;
|
||||
|
||||
//check for collisions
|
||||
Line2D travelLine = new Line2D.Float();
|
||||
Vector3fImmutable endLoc = new Vector3fImmutable(msg.getEndLat(),msg.getEndAlt(),msg.getEndLon());
|
||||
travelLine.setLine(pc.loc.x,pc.loc.z,endLoc.x,endLoc.z);
|
||||
if(BuildingManager.getBuildingAtLocation(pc.loc) != null){
|
||||
Building current = BuildingManager.getBuildingAtLocation(pc.loc);
|
||||
if (CollisionManager.CollisionDetected(current, travelLine, pc.getCharacterHeight(), pc.loc.y)) {
|
||||
ChatManager.chatSystemInfo(pc, "Collision Detected With : " + current.getName() + " Rect: " + current.buildingRect);
|
||||
//msg.setEndCoord();
|
||||
MovementManager.movement(msg, pc);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(pc.loc, 1000, MBServerStatics.MASK_BUILDING);
|
||||
for(AbstractWorldObject awo : awoList){
|
||||
Building building = (Building)awo;
|
||||
if(travelLine.intersects(building.buildingRect) || building.buildingRect.contains(travelLine.getP1()) || building.buildingRect.contains(travelLine.getP2())) {
|
||||
if (CollisionManager.CollisionDetected(building, travelLine, pc.getCharacterHeight(), pc.loc.y)) {
|
||||
ChatManager.chatSystemInfo(pc, "Collision Detected With : " + building.getName() + " Rect: " + building.buildingRect);
|
||||
//msg.setEndCoord();
|
||||
MovementManager.movement(msg, pc);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//ChatManager.chatSystemInfo(pc, "No Collision Detected");
|
||||
MovementManager.movement(msg, pc);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
|
||||
package engine.objects;
|
||||
|
||||
import engine.CollisionEngine.Triangle;
|
||||
import engine.Enum;
|
||||
import engine.Enum.*;
|
||||
import engine.InterestManagement.RealmMap;
|
||||
import engine.InterestManagement.Terrain;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.CollisionEngine.Mesh;
|
||||
import engine.db.archive.CityRecord;
|
||||
import engine.db.archive.DataWarehouse;
|
||||
import engine.db.archive.MineRecord;
|
||||
@@ -34,6 +36,7 @@ import engine.net.client.msg.UpdateObjectMsg;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -99,6 +102,9 @@ public class Building extends AbstractWorldObject {
|
||||
private ConcurrentHashMap<Integer, Condemned> condemned;
|
||||
private ArrayList<Building> children = null;
|
||||
|
||||
public ArrayList<Mesh> buildingMeshes;
|
||||
public Rectangle2D.Float buildingRect;
|
||||
|
||||
/**
|
||||
* ResultSet Constructor
|
||||
*/
|
||||
@@ -1003,6 +1009,9 @@ public class Building extends AbstractWorldObject {
|
||||
|
||||
if (this.upgradeDateTime != null)
|
||||
BuildingManager.submitUpgradeJob(this);
|
||||
|
||||
//BuildingManager.BakeBuildingMeshes(this);
|
||||
BuildingManager.BakeBuildingColliders(this);
|
||||
}
|
||||
|
||||
public synchronized boolean setOwner(AbstractCharacter newOwner) {
|
||||
|
||||
@@ -309,6 +309,12 @@ public class WorldServer {
|
||||
Logger.info("Initializing Errant Guild");
|
||||
Guild.getErrantGuild();
|
||||
|
||||
Logger.info("Loading Server Collision Meshes.");
|
||||
//DbManager.BuildingQueries.LOAD_PROP_MESHES();
|
||||
DbManager.BuildingQueries.LOAD_MESH_DATA();
|
||||
DbManager.BuildingQueries.LOAD_MESH_TRIANGLE_DATA();
|
||||
//DbManager.BuildingQueries.LOAD_MESH_BOUNDING_BOXES();
|
||||
|
||||
Logger.info("Loading zone template data");
|
||||
DbManager.ZoneQueries.LOAD_ALL_ZONE_TEMPLATES();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user