MagicBot
8 months ago
3 changed files with 96 additions and 59 deletions
@ -0,0 +1,95 @@
@@ -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…
Reference in new issue