Browse Source

Handler filled in with logic.

combat-2
MagicBot 1 year ago
parent
commit
c24913d124
  1. 63
      src/engine/gameManager/CombatManager.java
  2. 3
      src/engine/net/client/ClientMessagePump.java
  3. 70
      src/engine/net/client/handlers/AttackCmdMsgHandler.java

63
src/engine/gameManager/CombatManager.java

@ -30,8 +30,6 @@ import java.util.HashSet; @@ -30,8 +30,6 @@ import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import static engine.math.FastMath.sqr;
public enum CombatManager {
COMBATMANAGER;
@ -41,63 +39,6 @@ public enum CombatManager { @@ -41,63 +39,6 @@ public enum CombatManager {
/**
* Message sent by player to attack something.
*/
public static void setAttackTarget(AttackCmdMsg msg, ClientConnection origin) throws MsgSendException {
PlayerCharacter player;
int targetType;
AbstractWorldObject target;
if (TargetedActionMsg.un2cnt == 60 || TargetedActionMsg.un2cnt == 70)
return;
player = SessionManager.getPlayerCharacter(origin);
if (player == null)
return;
//source must match player this account belongs to
if (player.getObjectUUID() != msg.getSourceID() || player.getObjectType().ordinal() != msg.getSourceType()) {
Logger.error("Msg Source ID " + msg.getSourceID() + " Does not Match Player ID " + player.getObjectUUID());
return;
}
targetType = msg.getTargetType();
if (targetType == GameObjectType.PlayerCharacter.ordinal()) {
target = PlayerCharacter.getFromCache(msg.getTargetID());
} else if (targetType == GameObjectType.Building.ordinal()) {
target = BuildingManager.getBuildingFromCache(msg.getTargetID());
} else if (targetType == GameObjectType.Mob.ordinal()) {
target = Mob.getFromCache(msg.getTargetID());
} else {
player.setCombatTarget(null);
return; //not valid type to attack
}
// quit of the combat target is already the current combat target
// or there is no combat target
if (target == null)
return;
//set sources target
player.setCombatTarget(target);
//put in combat if not already
if (!player.isCombat())
toggleCombat(true, origin);
//make character stand if sitting
if (player.isSit())
toggleSit(false, origin);
AttackTarget(player, target);
}
public static void AttackTarget(PlayerCharacter playerCharacter, AbstractWorldObject target) {
@ -1184,7 +1125,7 @@ public enum CombatManager { @@ -1184,7 +1125,7 @@ public enum CombatManager {
toggleCombat(msg.getToggle(), origin);
}
private static void toggleCombat(boolean toggle, ClientConnection origin) {
public static void toggleCombat(boolean toggle, ClientConnection origin) {
PlayerCharacter pc = SessionManager.getPlayerCharacter(origin);
@ -1201,7 +1142,7 @@ public enum CombatManager { @@ -1201,7 +1142,7 @@ public enum CombatManager {
DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
}
private static void toggleSit(boolean toggle, ClientConnection origin) {
public static void toggleSit(boolean toggle, ClientConnection origin) {
PlayerCharacter pc = SessionManager.getPlayerCharacter(origin);

3
src/engine/net/client/ClientMessagePump.java

@ -1892,9 +1892,6 @@ public class ClientMessagePump implements NetMsgHandler { @@ -1892,9 +1892,6 @@ public class ClientMessagePump implements NetMsgHandler {
case POWER:
PowersManager.usePower((PerformActionMsg) msg, origin, false);
break;
case REQUESTMELEEATTACK:
CombatManager.setAttackTarget((AttackCmdMsg) msg, origin);
break;
case READYTOENTER:
break;
case OPENVAULT:

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

@ -1,14 +1,17 @@ @@ -1,14 +1,17 @@
package engine.net.client.handlers;
import engine.Enum.DispatchChannel;
import engine.Enum;
import engine.exception.MsgSendException;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
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.KeepAliveServerClientMsg;
import engine.net.client.msg.TargetedActionMsg;
import engine.objects.AbstractWorldObject;
import engine.objects.Mob;
import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
/*
* @Author:
@ -25,22 +28,67 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler { @@ -25,22 +28,67 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter pc = origin.getPlayerCharacter();
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
// Member variable declaration
KeepAliveServerClientMsg msg;
AttackCmdMsg msg;
// Member variable assignment
msg = (KeepAliveServerClientMsg) baseMsg;
msg = (AttackCmdMsg) baseMsg;
int targetType;
AbstractWorldObject target;
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;
}
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
}
// 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);
//put in combat if not already
if (!playerCharacter.isCombat())
CombatManager.toggleCombat(true, origin);
//make character stand if sitting
// Send ping to client
if (playerCharacter.isSit())
CombatManager.toggleSit(false, origin);
Dispatch dispatch = Dispatch.borrow(pc, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
CombatManager.AttackTarget(playerCharacter, target);
return true;
}

Loading…
Cancel
Save