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

79 lines
3.2 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;
2023-09-10 14:08:54 -05:00
import engine.Enum;
2022-04-30 09:41:17 -04:00
import engine.exception.MsgSendException;
2023-09-10 14:08:54 -05:00
import engine.gameManager.BuildingManager;
2022-04-30 09:41:17 -04:00
import engine.gameManager.MovementManager;
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.*;
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;
PlayerCharacter pc = (origin != null) ? (origin.getPlayerCharacter()) : null;
if (pc == null)
return false;
2023-09-10 15:02:26 -05:00
AbstractWorldObject target = null;
2023-09-10 14:08:54 -05:00
Enum.GameObjectType targetType;
2023-09-10 14:58:56 -05:00
targetType = Enum.GameObjectType.values()[msg.getTargetType()];
switch(targetType){
case Building:
target = BuildingManager.getBuilding(msg.getTargetID());
break;
2023-09-10 15:02:26 -05:00
case NPC:
target = NPC.getNPC(msg.getTargetID());
2023-09-10 14:58:56 -05:00
break;
}
2023-09-10 14:12:01 -05:00
if(target != null) {
switch (target.getObjectType()) {
2023-09-10 14:09:48 -05:00
case Building:
target = BuildingManager.getBuilding(msg.getTargetID());
2023-09-10 14:58:56 -05:00
if (target == null) {
pc.teleport(pc.loc);
msg.setEndCoord(pc.loc);
origin.sendMsg(msg);
2023-09-10 14:09:48 -05:00
return true;// early exit for no building pulled
2023-09-10 14:58:56 -05:00
}
2023-09-10 14:09:48 -05:00
Building targetBuilding = (Building) target;
2023-09-10 14:58:56 -05:00
if (!targetBuilding.isVulnerable() || targetBuilding.getRank() < 0) {
pc.teleport(pc.loc);
msg.setEndCoord(pc.loc);
origin.sendMsg(msg);
2023-09-10 14:09:48 -05:00
return true;// cannot attack destroyed building or protected building
2023-09-10 14:58:56 -05:00
}
2023-09-10 14:09:48 -05:00
break;
case NPC:
2023-09-10 14:58:56 -05:00
pc.teleport(pc.loc);
msg.setEndCoord(pc.loc);
origin.sendMsg(msg);
2023-09-10 14:09:48 -05:00
return true;//cannot attack anything other than the 3 above
}
2023-09-10 12:31:39 -05:00
}
2022-04-30 09:41:17 -04:00
MovementManager.movement(msg, pc);
return true;
}
}