diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 835232c8..f81938bd 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -31,7 +31,6 @@ import engine.util.StringUtils; import org.pmw.tinylog.Logger; import java.sql.SQLException; -import java.util.concurrent.ThreadLocalRandom; import static engine.math.FastMath.sqr; @@ -600,37 +599,6 @@ public class ClientMessagePump implements NetMsgHandler { } - private static void randomRoll(RandomMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter source = origin.getPlayerCharacter(); - - if (source == null || !source.isAlive()) - return; - - //2 second cooldown on random rolls - long lastRandom = source.getTimeStamp("RandomRoll"); - - if (System.currentTimeMillis() - lastRandom < 2000) - return; - source.setTimeStamp("RandomRoll", System.currentTimeMillis()); - - //handle random roll - int max = msg.getMax(); - - if (max > 0) - msg.setRoll(ThreadLocalRandom.current().nextInt(max) + 1); - else if (max < 0) { - max = 1 - max; - msg.setRoll((ThreadLocalRandom.current().nextInt(max) - max) + 1); - } - - msg.setSourceType(source.getObjectType().ordinal()); - msg.setSourceID(source.getObjectUUID()); - - //send to all in range - DispatchMessage.dispatchMsgToInterestArea(source, msg, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, true); - } - protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException { PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); @@ -868,9 +836,6 @@ public class ClientMessagePump implements NetMsgHandler { case STUCK: MovementManager.stuck(origin); break; - case RANDOM: - ClientMessagePump.randomRoll((RandomMsg) msg, origin); - break; case ARCPETATTACK: petAttack((PetAttackMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 29eafe48..3c66cc1a 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -163,7 +163,7 @@ public enum Protocol { POWERACTIONDDDIE(0xC27D446B, null, null), //Modify Health/Mana/Stamina using power and kill target POWERTARGNAME(0x5A807CCE, SendSummonsRequestMsg.class, null), // Send Summons Request RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, null), // Modify Stat - RANDOM(0xAC5D0135, RandomMsg.class, null), //RequestSend random roll + RANDOM(0xAC5D0135, RandomMsg.class, RandomMsgHandler.class), //RequestSend random roll READYTOENTER(0x490E4FE0, EnterWorldReceivedMsg.class, null), //Client Ack Receive Enter World REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?) RECOMMENDNATION(0x6D4579E9, RecommendNationMsg.class, RecommendNationMsgHandler.class), // Recommend as Ally/Enemy, error diff --git a/src/engine/net/client/handlers/RandomMsgHandler.java b/src/engine/net/client/handlers/RandomMsgHandler.java new file mode 100644 index 00000000..522860fe --- /dev/null +++ b/src/engine/net/client/handlers/RandomMsgHandler.java @@ -0,0 +1,67 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.RandomMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +import java.util.concurrent.ThreadLocalRandom; + +public class RandomMsgHandler extends AbstractClientMsgHandler { + + public RandomMsgHandler() { + super(RandomMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + + RandomMsg msg = (RandomMsg) baseMsg; + + PlayerCharacter source = origin.getPlayerCharacter(); + + if (source == null || !source.isAlive()) + return true; + + //2 second cooldown on random rolls + long lastRandom = source.getTimeStamp("RandomRoll"); + + if (System.currentTimeMillis() - lastRandom < 2000) + return true; + + source.setTimeStamp("RandomRoll", System.currentTimeMillis()); + + //handle random roll + int max = msg.getMax(); + + if (max > 0) + msg.setRoll(ThreadLocalRandom.current().nextInt(max) + 1); + else if (max < 0) { + max = 1 - max; + msg.setRoll((ThreadLocalRandom.current().nextInt(max) - max) + 1); + } + + msg.setSourceType(source.getObjectType().ordinal()); + msg.setSourceID(source.getObjectUUID()); + + //send to all in range + DispatchMessage.dispatchMsgToInterestArea(source, msg, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, true); + + return true; + } + +} \ No newline at end of file