Unify turn counters in battles

`updatePseudoWeatherLeft`, `updateToxicTurns`, and `clearTurnstatuses`
have now been merged into a new function `updateTurnCounters`, which
should simplify some things.

This should also allow OMs to use `|-singleturn|` during end-of-turn
switch-ins, as requested in
https://github.com/smogon/pokemon-showdown/issues/6996
This commit is contained in:
Guangcong Luo
2020-07-18 08:37:52 -07:00
parent ccb33eb981
commit a1686e8bf2

View File

@@ -1255,16 +1255,9 @@ class Battle {
if (turnNum === this.turn + 1) {
this.endLastTurnPending = true;
}
if (this.turn && !this.usesUpkeep) this.updatePseudoWeatherLeft(); // for compatibility with old replays
if (this.turn && !this.usesUpkeep) this.updateTurnCounters(); // for compatibility with old replays
this.turn = turnNum;
if (this.mySide.active[0]) this.mySide.active[0]!.clearTurnstatuses();
if (this.mySide.active[1]) this.mySide.active[1]!.clearTurnstatuses();
if (this.mySide.active[2]) this.mySide.active[2]!.clearTurnstatuses();
if (this.yourSide.active[0]) this.yourSide.active[0]!.clearTurnstatuses();
if (this.yourSide.active[1]) this.yourSide.active[1]!.clearTurnstatuses();
if (this.yourSide.active[2]) this.yourSide.active[2]!.clearTurnstatuses();
if (!this.fastForward) this.turnsSinceMoved++;
this.scene.incrementTurn();
@@ -1284,13 +1277,6 @@ class Battle {
this.turnsSinceMoved = 0;
this.scene.updateAcceleration();
}
updateToxicTurns() {
for (const side of this.sides) {
for (const poke of side.active) {
if (poke?.status === 'tox') poke.statusData.toxicTurns++;
}
}
}
changeWeather(weatherName: string, poke?: Pokemon, isUpkeep?: boolean, ability?: Effect) {
let weather = toID(weatherName);
if (!weather || weather === 'none') {
@@ -1325,7 +1311,7 @@ class Battle {
this.weather = weather;
this.scene.updateWeather();
}
updatePseudoWeatherLeft() {
updateTurnCounters() {
for (const pWeather of this.pseudoWeather) {
if (pWeather[1]) pWeather[1]--;
if (pWeather[2]) pWeather[2]--;
@@ -1336,6 +1322,12 @@ class Battle {
if (cond[2]) cond[2]--;
if (cond[3]) cond[3]--;
}
for (const poke of side.active) {
if (poke) {
if (poke.status === 'tox') poke.statusData.toxicTurns++;
poke.clearTurnstatuses();
}
}
}
this.scene.updateWeather();
}
@@ -3097,8 +3089,7 @@ class Battle {
}
case 'upkeep': {
this.usesUpkeep = true;
this.updatePseudoWeatherLeft();
this.updateToxicTurns();
this.updateTurnCounters();
break;
}
case 'turn': {