Handler created for RandomMsg

This commit is contained in:
2024-03-27 14:01:32 -04:00
parent 2d246a6773
commit c33cd9773f
3 changed files with 68 additions and 36 deletions
@@ -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;