Browse Source

early exits for attack message handler

feature-workorder
FatBoy-DOTC 1 year ago
parent
commit
47fe764cb0
  1. 33
      src/engine/net/client/handlers/AttackCmdMsgHandler.java

33
src/engine/net/client/handlers/AttackCmdMsgHandler.java

@ -9,6 +9,7 @@ import engine.net.client.msg.AttackCmdMsg; @@ -9,6 +9,7 @@ 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.Building;
import engine.objects.Mob;
import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
@ -39,7 +40,6 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler { @@ -39,7 +40,6 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
msg = (AttackCmdMsg) baseMsg;
int targetType;
AbstractWorldObject target;
if (TargetedActionMsg.un2cnt == 60 || TargetedActionMsg.un2cnt == 70)
return true;
@ -54,26 +54,21 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler { @@ -54,26 +54,21 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
return true;
}
targetType = msg.getTargetType();
if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal()) {
target = PlayerCharacter.getFromCache(msg.getTargetID());
} else if (targetType == Enum.GameObjectType.Building.ordinal()) {
target = BuildingManager.getBuildingFromCache(msg.getTargetID());
} else if (targetType == Enum.GameObjectType.Mob.ordinal()) {
target = Mob.getFromCache(msg.getTargetID());
} else {
playerCharacter.setCombatTarget(null);
return true; //not valid type to attack
AbstractWorldObject target = playerCharacter.combatTarget;
if(target == null)
return true; // cannot attack a null target
switch(target.getObjectType()){
case NPC:
playerCharacter.setCombatTarget(null);
return true; //cannot attack NPCs
case Building:
Building targetBuilding = (Building) target;
if(!targetBuilding.isVulnerable() || targetBuilding.getRank() < 0)
playerCharacter.setCombatTarget(null);
return true;
}
// quit of the combat target is already the current combat target
// or there is no combat target
if (target == null)
return true;
;
//set sources target
playerCharacter.setCombatTarget(target);

Loading…
Cancel
Save