From 4986b9031d4163bdb99ec5996c818e193e091450 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 20 Dec 2023 16:16:58 +0200 Subject: [PATCH] Use timers for turns only if turn timer is set and for pvp battles - only if unit timer is set to avoid "bad" edge case where player can completely run out of time --- server/TurnTimerHandler.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/server/TurnTimerHandler.cpp b/server/TurnTimerHandler.cpp index 7d20ac33b..bb816a854 100644 --- a/server/TurnTimerHandler.cpp +++ b/server/TurnTimerHandler.cpp @@ -126,6 +126,10 @@ void TurnTimerHandler::onPlayerMakingTurn(PlayerColor player, int waitTime) const auto * state = gameHandler.getPlayerState(player); if(state && state->human && timer.isActive && !timer.isBattle && state->status == EPlayerStatus::INGAME) { + // turn timers are only used if turn timer is non-zero + if (si->turnTimerInfo.turnTimer == 0) + return; + if(timerCountDown(timer.turnTimer, si->turnTimerInfo.turnTimer, player, waitTime)) return; @@ -276,17 +280,21 @@ void TurnTimerHandler::onBattleLoop(const BattleID & battleID, int waitTime) auto & timer = timers[player]; if(timer.isActive && timer.isBattle) { - if (timerCountDown(timer.unitTimer, si->turnTimerInfo.unitTimer, player, waitTime)) + // in pvp battles, timers are only used if unit timer is non-zero + if(isPvpBattle(battleID) && si->turnTimerInfo.unitTimer == 0) return; - if (timerCountDown(timer.battleTimer, si->turnTimerInfo.battleTimer, player, waitTime)) - return; + if (timerCountDown(timer.unitTimer, si->turnTimerInfo.unitTimer, player, waitTime)) + return; - if (timerCountDown(timer.turnTimer, si->turnTimerInfo.turnTimer, player, waitTime)) - return; + if (timerCountDown(timer.battleTimer, si->turnTimerInfo.battleTimer, player, waitTime)) + return; - if (timerCountDown(timer.baseTimer, si->turnTimerInfo.baseTimer, player, waitTime)) - return; + if (timerCountDown(timer.turnTimer, si->turnTimerInfo.turnTimer, player, waitTime)) + return; + + if (timerCountDown(timer.baseTimer, si->turnTimerInfo.baseTimer, player, waitTime)) + return; if(isPvpBattle(battleID)) {