Files
lakebane/src/engine/net/client/handlers/MoveToPointHandler.java
T

73 lines
3.5 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
2024-01-03 19:47:30 -06:00
import engine.InterestManagement.WorldGrid;
2022-04-30 09:41:17 -04:00
import engine.exception.MsgSendException;
2024-01-16 10:40:07 -06:00
import engine.gameManager.BuildingManager;
2024-01-03 19:47:30 -06:00
import engine.gameManager.ChatManager;
2024-01-05 19:28:43 -06:00
import engine.CollisionEngine.CollisionManager;
2022-04-30 09:41:17 -04:00
import engine.gameManager.MovementManager;
2024-01-03 19:47:30 -06:00
import engine.math.Vector3fImmutable;
2022-04-30 09:41:17 -04:00
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.MoveToPointMsg;
2023-09-10 14:08:54 -05:00
import engine.objects.*;
2024-01-03 19:47:30 -06:00
import engine.server.MBServerStatics;
import java.awt.geom.Line2D;
2022-04-30 09:41:17 -04:00
2024-01-03 20:39:18 -06:00
import java.util.HashSet;
2022-04-30 09:41:17 -04:00
public class MoveToPointHandler extends AbstractClientMsgHandler {
public MoveToPointHandler() {
super(MoveToPointMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
2023-07-15 09:23:48 -04:00
ClientConnection origin) throws MsgSendException {
2022-04-30 09:41:17 -04:00
MoveToPointMsg msg = (MoveToPointMsg) baseMsg;
2023-09-11 01:36:45 -05:00
PlayerCharacter pc = origin.getPlayerCharacter();
if(pc == null)
return true;
2024-01-03 19:47:30 -06:00
//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);
2024-01-16 10:40:07 -06:00
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);
2024-01-05 19:21:24 -06:00
//msg.setEndCoord();
MovementManager.movement(msg, pc);
return true;
2024-01-05 19:06:56 -06:00
}
2024-01-03 19:47:30 -06:00
}
2024-01-16 10:40:07 -06:00
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;
}
}
}
2024-01-16 09:25:31 -06:00
//ChatManager.chatSystemInfo(pc, "No Collision Detected");
MovementManager.movement(msg, pc);
2022-04-30 09:41:17 -04:00
return true;
}
}