From 3ad97a7ce3611a832a445f25cd81a5c72bfa7aed Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 3 Jan 2024 19:47:30 -0600 Subject: [PATCH] collision handler --- .../client/handlers/MoveToPointHandler.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/engine/net/client/handlers/MoveToPointHandler.java b/src/engine/net/client/handlers/MoveToPointHandler.java index c6d99f63..291f28df 100644 --- a/src/engine/net/client/handlers/MoveToPointHandler.java +++ b/src/engine/net/client/handlers/MoveToPointHandler.java @@ -10,13 +10,23 @@ package engine.net.client.handlers; import engine.Enum; +import engine.InterestManagement.WorldGrid; +import engine.collision.Mesh; +import engine.collision.Triangle; import engine.exception.MsgSendException; import engine.gameManager.BuildingManager; +import engine.gameManager.ChatManager; import engine.gameManager.MovementManager; +import engine.math.Vector3f; +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.*; +import java.awt.geom.Line2D; public class MoveToPointHandler extends AbstractClientMsgHandler { @@ -32,6 +42,30 @@ 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); + for(AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(pc.loc, pc.loc.distance(endLoc), MBServerStatics.MASK_BUILDING)){ + Building building = (Building)awo; + Rectangle.Float boundsRect = new Rectangle.Float(); + boundsRect.setRect(building.getBounds().getHalfExtents().x, building.getBounds().getHalfExtents().y, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2); + if(travelLine.intersects(boundsRect)){ + //collided with building + for(Mesh mesh : building.buildingMeshes) + if(mesh.MeshCollides(travelLine,pc.getCharacterHeight())){ + for(Triangle tri : mesh.triangles){ + if(tri.collides(travelLine)){ + ChatManager.chatSystemInfo(pc, "Collision Detected"); + return true; + } + } + } + + } + } + + MovementManager.movement(msg, pc); return true; }