Preact: Fix bug with Revival Blessing (#2487)
Some checks are pending
Node.js CI / build (22.x) (push) Waiting to run

This commit is contained in:
Aurastic 2025-07-30 17:04:39 +05:30 committed by GitHub
parent 5b511e2b96
commit 95a720011b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View File

@ -486,9 +486,14 @@ export class BattleChoiceBuilder {
throw new Error(`That Pokémon is already in battle!`);
}
const target = request.side.pokemon[current.targetPokemon - 1];
const isReviving = this.request.side?.pokemon!.some(p => p.reviving);
if (!target) {
throw new Error(`Couldn't find Pokémon "${choice}" to switch to!`);
}
if (isReviving && target.fainted) return current;
if (isReviving && !target.fainted) {
throw new Error(`${target.name} still has energy to battle!`);
}
if (target.fainted) {
throw new Error(`${target.name} is fainted and cannot battle!`);
}

View File

@ -998,6 +998,7 @@ export interface ServerPokemon extends PokemonDetails, PokemonHealth {
details: string;
condition: string;
active: boolean;
reviving: boolean;
/** unboosted stats */
stats: {
atk: number,

View File

@ -718,9 +718,11 @@ class BattlePanel extends PSRoomPanel<BattleRoom> {
renderSwitchMenu(
request: BattleMoveRequest | BattleSwitchRequest, choices: BattleChoiceBuilder, ignoreTrapping?: boolean
) {
const battle = this.props.room.battle;
const numActive = choices.requestLength();
const maybeTrapped = !ignoreTrapping && choices.currentMoveRequest()?.maybeTrapped;
const trapped = !ignoreTrapping && !maybeTrapped && choices.currentMoveRequest()?.trapped;
const isReviving = battle.myPokemon!.some(p => p.reviving);
return <div class="switchmenu">
{maybeTrapped && <em class="movewarning">
@ -729,8 +731,12 @@ class BattlePanel extends PSRoomPanel<BattleRoom> {
{trapped && <em class="movewarning">
You're <strong>trapped</strong> and cannot switch!<br />
</em>}
{isReviving && <em class="movewarning">
Choose a pokemon to revive!<br />
</em>}
{request.side.pokemon.map((serverPokemon, i) => {
const cantSwitch = trapped || i < numActive || choices.alreadySwitchingIn.includes(i + 1) || serverPokemon.fainted;
let cantSwitch = trapped || i < numActive || choices.alreadySwitchingIn.includes(i + 1) || serverPokemon.fainted;
if (isReviving) cantSwitch = !serverPokemon.fainted;
return this.renderPokemonButton({
pokemon: serverPokemon,
cmd: `/switch ${i + 1}`,