Fix the way the AI player count is calculated on the server

This commit is contained in:
Alexis King 2022-12-07 02:14:52 -06:00
parent 294079b2ea
commit 2912d9d15d
3 changed files with 12 additions and 7 deletions

View File

@ -367,10 +367,11 @@ public final class ShatteredPlansClient extends JagexApplet {
STAT_DESCS[14] = StringConstants.TEXT_STAT_DESC_AGGRESSIVENESS;
STAT_DESCS[15] = StringConstants.TEXT_STAT_DESC_SOLIDITY;
StringConstants.GAMEOPT_NAMES[0] = new String[5];
final int aiPlayerChoiceCount = GAMEOPT_CHOICES_COUNTS[0] = DEBUG_MODE ? 6 : 5;
StringConstants.GAMEOPT_NAMES[0] = new String[aiPlayerChoiceCount];
GAMEOPT_TOOLTIPS = new String[5][];
GAMEOPT_TOOLTIPS[0] = new String[5];
for (int i = 0; i < 5; ++i) {
GAMEOPT_TOOLTIPS[0] = new String[aiPlayerChoiceCount];
for (int i = 0; i < aiPlayerChoiceCount; ++i) {
StringConstants.GAMEOPT_NAMES[0][i] = Integer.toString(i);
GAMEOPT_TOOLTIPS[0][i] = StringConstants.TEXT_TOTAL_PLAYERS;
}

View File

@ -109,6 +109,7 @@ public final class ClientHandler extends ChannelDuplexHandler {
};
final int newByteCount = Math.min(msg.readableBytes(), neededBytes - this.packetPayload.readableBytes());
if (newByteCount > 0) {
this.packetPayload.ensureWritable(newByteCount);
msg.readBytes(this.packetPayload, newByteCount);
}

View File

@ -11,6 +11,7 @@ import funorb.shatteredplans.game.GameState.GalaxySize;
import funorb.shatteredplans.game.GameState.GameType;
import funorb.client.lobby.LobbyPlayer;
import funorb.shatteredplans.S2CPacket;
import funorb.util.MathUtil;
import org.intellij.lang.annotations.MagicConstant;
import org.jetbrains.annotations.NotNull;
@ -20,6 +21,8 @@ import java.util.List;
import java.util.Set;
public final class LobbyRoom {
private static final int MAX_PLAYER_COUNT = 6;
private final @NotNull LobbyState lobby;
public final int id;
@ -32,7 +35,7 @@ public final class LobbyRoom {
@SuppressWarnings({"FieldCanBeLocal"})
private final boolean isRated = false;
private int maxHumanPlayerCount = 4;
private int maxAiPlayerCount = 4;
private int maxAiPlayerCount = 0;
private int turnLengthIndex = 0;
private @NotNull WhoCanJoin whoCanJoin = WhoCanJoin.INVITE_ONLY;
private @NotNull GalaxySize galaxySize = GalaxySize.MEDIUM;
@ -312,11 +315,11 @@ public final class LobbyRoom {
}
public void receiveOptions(final @NotNull Packet packet) {
this.maxHumanPlayerCount = Math.max(2, Math.min(packet.readUByte(), 6));
this.maxHumanPlayerCount = MathUtil.clamp(packet.readUByte(), 2, MAX_PLAYER_COUNT);
final int b = packet.readUByte();
this.spectatingAllowed = (b >>> 6) == 2;
this.whoCanJoin = WhoCanJoin.values()[Math.min(b & 0x3f, WhoCanJoin.values().length - 1)];
this.maxAiPlayerCount = Math.min(packet.readUByte(), 6);
this.maxAiPlayerCount = Math.min(packet.readUByte(), MAX_PLAYER_COUNT);
this.turnLengthIndex = Math.min(packet.readUByte(), GameSession.TURN_DURATIONS.length - 1);
this.gameType = GameState.GameType.decode(packet.readUByte());
this.galaxySize = GalaxySize.values()[Math.min(packet.readUByte(), GalaxySize.values().length - 1)];
@ -346,7 +349,7 @@ public final class LobbyRoom {
this.classicRuleset ? GameOptions.CLASSIC_GAME_OPTIONS : GameOptions.STREAMLINED_GAME_OPTIONS,
this.turnLengthIndex,
this.clients,
Math.max(this.clients.size() == 1 ? 1 : 0, this.maxAiPlayerCount - this.clients.size()));
MathUtil.clamp(this.maxAiPlayerCount, this.clients.size() == 1 ? 1 : 0, MAX_PLAYER_COUNT - this.clients.size()));
this.startedAt = System.currentTimeMillis();
this.clients.forEach(this.session::sendInitialState);
this.lobby.broadcastRoomUpdate(this);