2023-09-10 13:43:28 -04:00
|
|
|
package engine.net.client.handlers;
|
|
|
|
|
|
2023-09-10 13:25:08 -05:00
|
|
|
import engine.gameManager.BuildingManager;
|
2024-03-23 19:22:14 -04:00
|
|
|
import engine.gameManager.CombatManager;
|
2024-04-05 07:59:44 -04:00
|
|
|
import engine.mbEnums;
|
2023-09-10 13:43:28 -04:00
|
|
|
import engine.net.client.ClientConnection;
|
|
|
|
|
import engine.net.client.msg.AttackCmdMsg;
|
|
|
|
|
import engine.net.client.msg.ClientNetMsg;
|
2023-09-10 13:52:04 -04:00
|
|
|
import engine.net.client.msg.TargetedActionMsg;
|
2024-03-23 19:22:14 -04:00
|
|
|
import engine.objects.AbstractWorldObject;
|
|
|
|
|
import engine.objects.Mob;
|
|
|
|
|
import engine.objects.NPC;
|
|
|
|
|
import engine.objects.PlayerCharacter;
|
2023-09-10 13:43:28 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @Author:
|
|
|
|
|
* @Summary: Processes application protocol message which keeps
|
|
|
|
|
* client's tcp connection open.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
|
|
|
|
|
|
|
|
|
|
public AttackCmdMsgHandler() {
|
2024-05-12 11:55:12 -04:00
|
|
|
super();
|
2023-09-10 13:43:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-05-12 13:42:11 -04:00
|
|
|
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {
|
2023-09-10 13:43:28 -04:00
|
|
|
|
2023-09-10 13:52:04 -04:00
|
|
|
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
|
2023-09-10 13:43:28 -04:00
|
|
|
|
|
|
|
|
// Member variable declaration
|
|
|
|
|
|
2023-09-10 13:52:04 -04:00
|
|
|
AttackCmdMsg msg;
|
2023-09-10 13:43:28 -04:00
|
|
|
|
|
|
|
|
// Member variable assignment
|
|
|
|
|
|
2023-09-10 13:52:04 -04:00
|
|
|
msg = (AttackCmdMsg) baseMsg;
|
|
|
|
|
|
|
|
|
|
if (TargetedActionMsg.un2cnt == 60 || TargetedActionMsg.un2cnt == 70)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (playerCharacter == null)
|
|
|
|
|
return true;
|
|
|
|
|
|
2023-09-10 15:51:25 -05:00
|
|
|
AbstractWorldObject target = null;
|
2024-04-05 07:59:44 -04:00
|
|
|
mbEnums.GameObjectType targetType;
|
2023-09-10 13:52:04 -04:00
|
|
|
|
2024-04-05 07:59:44 -04:00
|
|
|
targetType = mbEnums.GameObjectType.values()[msg.getTargetType()];
|
2023-09-10 14:33:04 -04:00
|
|
|
|
2024-03-24 09:42:27 -04:00
|
|
|
switch (targetType) {
|
2023-09-10 13:38:07 -05:00
|
|
|
case Mob:
|
|
|
|
|
target = Mob.getMob(msg.getTargetID());
|
|
|
|
|
break;
|
|
|
|
|
case PlayerCharacter:
|
|
|
|
|
target = PlayerCharacter.getPlayerCharacter(msg.getTargetID());
|
|
|
|
|
break;
|
|
|
|
|
case Building:
|
|
|
|
|
target = BuildingManager.getBuilding(msg.getTargetID());
|
|
|
|
|
break;
|
2023-09-10 16:45:17 -05:00
|
|
|
case NPC:
|
|
|
|
|
target = NPC.getNPC(msg.getTargetID());
|
|
|
|
|
break;
|
2023-09-10 13:52:04 -04:00
|
|
|
}
|
2024-03-24 09:42:27 -04:00
|
|
|
if (target == null) {
|
2023-09-10 16:45:17 -05:00
|
|
|
playerCharacter.setCombatTarget(null);
|
2023-09-10 13:26:28 -05:00
|
|
|
return true; // cannot attack a null target
|
|
|
|
|
}
|
2024-04-02 12:33:01 -04:00
|
|
|
|
2023-09-10 13:52:04 -04:00
|
|
|
//set sources target
|
|
|
|
|
|
|
|
|
|
playerCharacter.setCombatTarget(target);
|
|
|
|
|
|
|
|
|
|
//put in combat if not already
|
|
|
|
|
|
2024-03-17 15:56:47 -05:00
|
|
|
if (!playerCharacter.isCombat()) {
|
|
|
|
|
//CombatManager.toggleCombat(true, origin);
|
2024-03-23 19:22:14 -04:00
|
|
|
CombatManager.toggleCombat(true, origin);
|
2024-03-17 15:56:47 -05:00
|
|
|
}
|
2023-09-10 13:52:04 -04:00
|
|
|
//make character stand if sitting
|
2023-09-10 13:43:28 -04:00
|
|
|
|
2023-09-10 13:52:04 -04:00
|
|
|
if (playerCharacter.isSit())
|
2024-03-23 19:22:14 -04:00
|
|
|
CombatManager.toggleSit(false, origin);
|
2023-09-10 13:43:28 -04:00
|
|
|
|
2024-03-23 19:22:14 -04:00
|
|
|
CombatManager.combatCycle(playerCharacter, target);
|
2023-09-10 13:43:28 -04:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|