Handler created for RandomMsg
This commit is contained in:
@@ -31,7 +31,6 @@ import engine.util.StringUtils;
|
|||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
import static engine.math.FastMath.sqr;
|
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 {
|
protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException {
|
||||||
|
|
||||||
PlayerCharacter pc = SessionManager.getPlayerCharacter(conn);
|
PlayerCharacter pc = SessionManager.getPlayerCharacter(conn);
|
||||||
@@ -868,9 +836,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
|||||||
case STUCK:
|
case STUCK:
|
||||||
MovementManager.stuck(origin);
|
MovementManager.stuck(origin);
|
||||||
break;
|
break;
|
||||||
case RANDOM:
|
|
||||||
ClientMessagePump.randomRoll((RandomMsg) msg, origin);
|
|
||||||
break;
|
|
||||||
case ARCPETATTACK:
|
case ARCPETATTACK:
|
||||||
petAttack((PetAttackMsg) msg, origin);
|
petAttack((PetAttackMsg) msg, origin);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ public enum Protocol {
|
|||||||
POWERACTIONDDDIE(0xC27D446B, null, null), //Modify Health/Mana/Stamina using power and kill target
|
POWERACTIONDDDIE(0xC27D446B, null, null), //Modify Health/Mana/Stamina using power and kill target
|
||||||
POWERTARGNAME(0x5A807CCE, SendSummonsRequestMsg.class, null), // Send Summons Request
|
POWERTARGNAME(0x5A807CCE, SendSummonsRequestMsg.class, null), // Send Summons Request
|
||||||
RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, null), // Modify Stat
|
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
|
READYTOENTER(0x490E4FE0, EnterWorldReceivedMsg.class, null), //Client Ack Receive Enter World
|
||||||
REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?)
|
REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?)
|
||||||
RECOMMENDNATION(0x6D4579E9, RecommendNationMsg.class, RecommendNationMsgHandler.class), // Recommend as Ally/Enemy, error
|
RECOMMENDNATION(0x6D4579E9, RecommendNationMsg.class, RecommendNationMsgHandler.class), // Recommend as Ally/Enemy, error
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user