|
|
|
package engine.net.client.handlers;
|
|
|
|
|
|
|
|
import engine.gameManager.BuildingManager;
|
|
|
|
import engine.gameManager.CombatManager;
|
|
|
|
import engine.jobs.AttackJob;
|
|
|
|
import engine.mbEnums;
|
|
|
|
import engine.net.client.ClientConnection;
|
|
|
|
import engine.net.client.msg.AttackCmdMsg;
|
|
|
|
import engine.net.client.msg.ClientNetMsg;
|
|
|
|
import engine.net.client.msg.TargetedActionMsg;
|
|
|
|
import engine.objects.AbstractWorldObject;
|
|
|
|
import engine.objects.Mob;
|
|
|
|
import engine.objects.NPC;
|
|
|
|
import engine.objects.PlayerCharacter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @Author:
|
|
|
|
* @Summary: Processes application protocol message which keeps
|
|
|
|
* client's tcp connection open.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
|
|
|
|
|
|
|
|
public AttackCmdMsgHandler() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {
|
|
|
|
|
|
|
|
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
|
|
|
|
|
|
|
|
// Member variable declaration
|
|
|
|
|
|
|
|
AttackCmdMsg msg;
|
|
|
|
|
|
|
|
// Member variable assignment
|
|
|
|
|
|
|
|
msg = (AttackCmdMsg) baseMsg;
|
|
|
|
|
|
|
|
if (TargetedActionMsg.un2cnt == 60 || TargetedActionMsg.un2cnt == 70)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (playerCharacter == null)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
AbstractWorldObject target = null;
|
|
|
|
mbEnums.GameObjectType targetType;
|
|
|
|
|
|
|
|
targetType = mbEnums.GameObjectType.values()[msg.getTargetType()];
|
|
|
|
|
|
|
|
switch (targetType) {
|
|
|
|
case Mob:
|
|
|
|
target = Mob.getMob(msg.getTargetID());
|
|
|
|
break;
|
|
|
|
case PlayerCharacter:
|
|
|
|
target = PlayerCharacter.getPlayerCharacter(msg.getTargetID());
|
|
|
|
break;
|
|
|
|
case Building:
|
|
|
|
target = BuildingManager.getBuilding(msg.getTargetID());
|
|
|
|
break;
|
|
|
|
case NPC:
|
|
|
|
target = NPC.getNPC(msg.getTargetID());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (target == null) {
|
|
|
|
playerCharacter.setCombatTarget(null);
|
|
|
|
return true; // cannot attack a null target
|
|
|
|
}
|
|
|
|
|
|
|
|
//set sources target
|
|
|
|
|
|
|
|
playerCharacter.setCombatTarget(target);
|
|
|
|
|
|
|
|
//put in combat if not already
|
|
|
|
|
|
|
|
if (!playerCharacter.isCombat()) {
|
|
|
|
//CombatManager.toggleCombat(true, origin);
|
|
|
|
CombatManager.toggleCombat(true, origin);
|
|
|
|
}
|
|
|
|
//make character stand if sitting
|
|
|
|
|
|
|
|
if (playerCharacter.isSit())
|
|
|
|
CombatManager.toggleSit(false, origin);
|
|
|
|
|
|
|
|
long addedDelay = 0;
|
|
|
|
//check if we are changing targets, cancel outstanding jobs if so
|
|
|
|
if (playerCharacter.getTimers().containsKey("Attack" + mbEnums.EquipSlotType.RHELD)) {
|
|
|
|
AttackJob ajR = ((AttackJob)playerCharacter.getTimers().get("Attack" + mbEnums.EquipSlotType.RHELD).getJob());
|
|
|
|
if(!ajR.target.equals(target)){
|
|
|
|
playerCharacter.getTimers().get("Attack" + mbEnums.EquipSlotType.RHELD).cancelJob();
|
|
|
|
addedDelay = ajR.getStopTime() - System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playerCharacter.getTimers().containsKey("Attack" + mbEnums.EquipSlotType.LHELD)) {
|
|
|
|
AttackJob ajL = ((AttackJob)playerCharacter.getTimers().get("Attack" + mbEnums.EquipSlotType.LHELD).getJob());
|
|
|
|
if(!ajL.target.equals(target)){
|
|
|
|
playerCharacter.getTimers().get("Attack" + mbEnums.EquipSlotType.LHELD).cancelJob();
|
|
|
|
addedDelay = ajL.getStopTime() - System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CombatManager.combatCycle(playerCharacter, target, addedDelay);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|