Browse Source

Handler created for RespawnMsg

combat-2
MagicBot 8 months ago
parent
commit
1acb74ade1
  1. 58
      src/engine/net/client/ClientMessagePump.java
  2. 2
      src/engine/net/client/Protocol.java
  3. 95
      src/engine/net/client/handlers/RespawnMsgHandler.java

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

@ -13,8 +13,6 @@ import engine.Enum.DispatchChannel;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.*; import engine.gameManager.*;
import engine.job.JobScheduler;
import engine.jobs.RefreshGroupJob;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.NetMsgHandler; import engine.net.NetMsgHandler;
@ -25,7 +23,6 @@ import engine.objects.AbstractCharacter;
import engine.objects.Mob; import engine.objects.Mob;
import engine.objects.NPC; import engine.objects.NPC;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import engine.session.Session; import engine.session.Session;
import engine.util.StringUtils; import engine.util.StringUtils;
@ -48,58 +45,6 @@ public class ClientMessagePump implements NetMsgHandler {
this.server = server; this.server = server;
} }
// called when player clicks respawn button
private static void respawn(RespawnMsg msg, ClientConnection origin) throws MsgSendException {
PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin);
if (sourcePlayer == null)
return;
if (msg.getObjectType() != sourcePlayer.getObjectType().ordinal() || msg.getObjectID() != sourcePlayer.getObjectUUID()) {
Logger.error("Player " + sourcePlayer.getObjectUUID() + " respawning character of id " + msg.getObjectType() + ' '
+ msg.getObjectID());
return;
}
if (sourcePlayer.isAlive()) {
Logger.error("Player " + sourcePlayer.getObjectUUID() + " respawning while alive");
return;
}
// ResetAfterDeath player
sourcePlayer.respawnLock.writeLock().lock();
try {
sourcePlayer.respawn(true, false, true);
} catch (Exception e) {
Logger.error(e);
} finally {
sourcePlayer.respawnLock.writeLock().unlock();
}
// Echo ResetAfterDeath message back
msg.setPlayerHealth(sourcePlayer.getHealth());
// TODO calculate any experience loss before this point
msg.setPlayerExp(sourcePlayer.getExp() + sourcePlayer.getOverFlowEXP());
Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
MoveToPointMsg moveMsg = new MoveToPointMsg();
moveMsg.setPlayer(sourcePlayer);
moveMsg.setStartCoord(sourcePlayer.getLoc());
moveMsg.setEndCoord(sourcePlayer.getLoc());
moveMsg.setInBuilding(-1);
moveMsg.setInBuildingFloor(-1);
dispatch = Dispatch.borrow(sourcePlayer, moveMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
MovementManager.sendRWSSMsg(sourcePlayer);
// refresh the whole group with what just happened
JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(sourcePlayer), MBServerStatics.LOAD_OBJECT_DELAY);
}
// called when player types /show // called when player types /show
private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException { private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException {
@ -229,9 +174,6 @@ public class ClientMessagePump implements NetMsgHandler {
break; break;
case OPENVAULT: case OPENVAULT:
break; break;
case RESETAFTERDEATH:
respawn((RespawnMsg) msg, origin);
break;
case SHOWCOMBATINFO: case SHOWCOMBATINFO:
show((ShowMsg) msg, origin); show((ShowMsg) msg, origin);
break; break;

2
src/engine/net/client/Protocol.java

@ -180,7 +180,7 @@ public enum Protocol {
REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, null), // Trade Request REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, null), // Trade Request
REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade
REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request
RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, null), //Respawn Request/Response RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, RespawnMsgHandler.class), //Respawn Request/Response
ROTATEMSG(0x57F2088E, RotateObjectMsg.class, null), ROTATEMSG(0x57F2088E, RotateObjectMsg.class, null),
SAFEMODE(0x9CF3922A, SafeModeMsg.class, null), //Tell client they're in safe mode SAFEMODE(0x9CF3922A, SafeModeMsg.class, null), //Tell client they're in safe mode
SCALEOBJECT(0xE2B392D9, null, null), // Adjust scale of object SCALEOBJECT(0xE2B392D9, null, null), // Adjust scale of object

95
src/engine/net/client/handlers/RespawnMsgHandler.java

@ -0,0 +1,95 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.Enum.DispatchChannel;
import engine.exception.MsgSendException;
import engine.gameManager.MovementManager;
import engine.job.JobScheduler;
import engine.jobs.RefreshGroupJob;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.MoveToPointMsg;
import engine.net.client.msg.RespawnMsg;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
public class RespawnMsgHandler extends AbstractClientMsgHandler {
public RespawnMsgHandler() {
super(RespawnMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
// Member variable declaration
RespawnMsg msg;
// Member variable assignment
msg = (RespawnMsg) baseMsg;
if (playerCharacter == null)
return true;
if (msg.getObjectType() != playerCharacter.getObjectType().ordinal() || msg.getObjectID() != playerCharacter.getObjectUUID()) {
Logger.error("Player " + playerCharacter.getObjectUUID() + " respawning character of id " + msg.getObjectType() + ' '
+ msg.getObjectID());
return true;
}
if (playerCharacter.isAlive()) {
Logger.error("Player " + playerCharacter.getObjectUUID() + " respawning while alive");
return true;
}
// ResetAfterDeath player
playerCharacter.respawnLock.writeLock().lock();
try {
playerCharacter.respawn(true, false, true);
} catch (Exception e) {
Logger.error(e);
} finally {
playerCharacter.respawnLock.writeLock().unlock();
}
// Echo ResetAfterDeath message back
msg.setPlayerHealth(playerCharacter.getHealth());
// TODO calculate any experience loss before this point
msg.setPlayerExp(playerCharacter.getExp() + playerCharacter.getOverFlowEXP());
Dispatch dispatch = Dispatch.borrow(playerCharacter, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
MoveToPointMsg moveMsg = new MoveToPointMsg();
moveMsg.setPlayer(playerCharacter);
moveMsg.setStartCoord(playerCharacter.getLoc());
moveMsg.setEndCoord(playerCharacter.getLoc());
moveMsg.setInBuilding(-1);
moveMsg.setInBuildingFloor(-1);
dispatch = Dispatch.borrow(playerCharacter, moveMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
MovementManager.sendRWSSMsg(playerCharacter);
// refresh the whole group with what just happened
JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(playerCharacter), MBServerStatics.LOAD_OBJECT_DELAY);
return true;
}
}
Loading…
Cancel
Save