forked from MagicBane/Server
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.7 KiB
91 lines
2.7 KiB
package engine.net.client.handlers; |
|
|
|
import engine.Enum; |
|
import engine.exception.MsgSendException; |
|
import engine.gameManager.BuildingManager; |
|
import engine.gameManager.CombatManager; |
|
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.Building; |
|
import engine.objects.Mob; |
|
import engine.objects.PlayerCharacter; |
|
import org.pmw.tinylog.Logger; |
|
|
|
/* |
|
* @Author: |
|
* @Summary: Processes application protocol message which keeps |
|
* client's tcp connection open. |
|
*/ |
|
|
|
public class AttackCmdMsgHandler extends AbstractClientMsgHandler { |
|
|
|
public AttackCmdMsgHandler() { |
|
super(AttackCmdMsg.class); |
|
} |
|
|
|
@Override |
|
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { |
|
|
|
PlayerCharacter playerCharacter = origin.getPlayerCharacter(); |
|
|
|
// Member variable declaration |
|
|
|
AttackCmdMsg msg; |
|
|
|
// Member variable assignment |
|
|
|
msg = (AttackCmdMsg) baseMsg; |
|
|
|
int targetType; |
|
|
|
if (TargetedActionMsg.un2cnt == 60 || TargetedActionMsg.un2cnt == 70) |
|
return true; |
|
|
|
if (playerCharacter == null) |
|
return true; |
|
|
|
//source must match player this account belongs to |
|
|
|
if (playerCharacter.getObjectUUID() != msg.getSourceID() || playerCharacter.getObjectType().ordinal() != msg.getSourceType()) { |
|
Logger.error("Msg Source ID " + msg.getSourceID() + " Does not Match Player ID " + playerCharacter.getObjectUUID()); |
|
return true; |
|
} |
|
|
|
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; |
|
} |
|
|
|
//set sources target |
|
|
|
playerCharacter.setCombatTarget(target); |
|
|
|
//put in combat if not already |
|
|
|
if (!playerCharacter.isCombat()) |
|
CombatManager.toggleCombat(true, origin); |
|
|
|
//make character stand if sitting |
|
|
|
if (playerCharacter.isSit()) |
|
CombatManager.toggleSit(false, origin); |
|
|
|
CombatManager.AttackTarget(playerCharacter, target); |
|
|
|
return true; |
|
} |
|
|
|
} |