Fix turn-timer not matching server-side's value
This commit is contained in:
parent
e8f3c0cd52
commit
a9d2b11f65
6 changed files with 26 additions and 5 deletions
|
@ -18,6 +18,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
|
||||
public class BattleGui extends Screen {
|
||||
private AtomicInteger timeRemaining;
|
||||
|
||||
private int timerMax;
|
||||
private boolean turnTimerEnabled;
|
||||
private long lastInstant;
|
||||
private long elapsedTime;
|
||||
|
@ -82,6 +84,7 @@ public class BattleGui extends Screen {
|
|||
public BattleGui() {
|
||||
super(new TextComponent("Battle Gui"));
|
||||
timeRemaining = new AtomicInteger((int) (Config.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L));
|
||||
timerMax = timeRemaining.get();
|
||||
lastInstant = System.nanoTime();
|
||||
elapsedTime = 0;
|
||||
state = MenuState.MAIN_MENU;
|
||||
|
@ -104,7 +107,7 @@ public class BattleGui extends Screen {
|
|||
if (TurnBasedMinecraftMod.proxy.getLocalBattle() != null) {
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.DECISION);
|
||||
}
|
||||
timeRemaining.set(TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationSeconds());
|
||||
timeRemaining.set(timerMax);
|
||||
elapsedTime = 0;
|
||||
lastInstant = System.nanoTime();
|
||||
setState(MenuState.MAIN_MENU);
|
||||
|
@ -359,4 +362,8 @@ public class BattleGui extends Screen {
|
|||
public void setTurnTimerEnabled(boolean enabled) {
|
||||
turnTimerEnabled = enabled;
|
||||
}
|
||||
|
||||
public void setTurnTimerMax(int timerMax) {
|
||||
this.timerMax = timerMax;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,11 @@ public class ClientProxy extends CommonProxy {
|
|||
battleGui.setTurnTimerEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBattleGuiTurnTimerMax(int timeMax) {
|
||||
battleGui.setTurnTimerMax(timeMax);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void battleGuiTurnBegin() {
|
||||
battleGui.turnBegin();
|
||||
|
|
|
@ -445,7 +445,7 @@ public class Battle {
|
|||
if (!isServer) {
|
||||
return;
|
||||
}
|
||||
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
|
||||
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
|
||||
for (Combatant p : players.values()) {
|
||||
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) p.entity), infoPacket);
|
||||
}
|
||||
|
|
|
@ -63,6 +63,8 @@ public class CommonProxy
|
|||
public void setBattleGuiAsGui() {}
|
||||
|
||||
public void setBattleGuiTurnTimerEnabled(boolean enabled) {}
|
||||
|
||||
public void setBattleGuiTurnTimerMax(int timeMax) {}
|
||||
|
||||
public void battleGuiTurnBegin() {}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ public class PacketBattleInfo
|
|||
private Collection<Integer> sideA;
|
||||
private Collection<Integer> sideB;
|
||||
private long decisionNanos;
|
||||
|
||||
private long maxDecisionNanos;
|
||||
private boolean turnTimerEnabled;
|
||||
|
||||
public PacketBattleInfo()
|
||||
|
@ -23,14 +25,16 @@ public class PacketBattleInfo
|
|||
sideA = new ArrayList<Integer>();
|
||||
sideB = new ArrayList<Integer>();
|
||||
decisionNanos = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
|
||||
maxDecisionNanos = decisionNanos;
|
||||
turnTimerEnabled = false;
|
||||
}
|
||||
|
||||
public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos, boolean turnTimerEnabled)
|
||||
public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos, long maxDecisionNanos, boolean turnTimerEnabled)
|
||||
{
|
||||
this.sideA = sideA;
|
||||
this.sideB = sideB;
|
||||
this.decisionNanos = decisionNanos;
|
||||
this.maxDecisionNanos = maxDecisionNanos;
|
||||
this.turnTimerEnabled = turnTimerEnabled;
|
||||
}
|
||||
|
||||
|
@ -44,6 +48,7 @@ public class PacketBattleInfo
|
|||
buf.writeInt(id);
|
||||
}
|
||||
buf.writeLong(msg.decisionNanos);
|
||||
buf.writeLong(msg.maxDecisionNanos);
|
||||
buf.writeBoolean(msg.turnTimerEnabled);
|
||||
}
|
||||
|
||||
|
@ -59,8 +64,9 @@ public class PacketBattleInfo
|
|||
sideB.add(buf.readInt());
|
||||
}
|
||||
long decisionNanos = buf.readLong();
|
||||
long maxDecisionNanos = buf.readLong();
|
||||
boolean turnTimerEnabled = buf.readBoolean();
|
||||
return new PacketBattleInfo(sideA, sideB, decisionNanos, turnTimerEnabled);
|
||||
return new PacketBattleInfo(sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled);
|
||||
}
|
||||
|
||||
public static void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) {
|
||||
|
@ -89,6 +95,7 @@ public class PacketBattleInfo
|
|||
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled);
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerMax((int)(pkt.maxDecisionNanos / 1000000000L));
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class PacketBattleRequestInfo
|
|||
if(b == null) {
|
||||
return;
|
||||
}
|
||||
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get());
|
||||
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get());
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue