Prevent `PartyHealPhase` from reviving pokemon in hardcore challenge

Add `SelectModifierPhase` on waves 10, 20, ...
if "No Auto Heal" challenge is active
This commit is contained in:
NightKev 2024-09-19 02:48:14 -07:00
parent f292087d6c
commit c7df07715d
2 changed files with 50 additions and 9 deletions

View File

@ -6,7 +6,7 @@ import PokemonSpecies, { getPokemonSpecies, getPokemonSpeciesForm, speciesStarte
import { Type } from "#app/data/type";
import { TypeColor, TypeShadow } from "#app/enums/color";
import { Moves } from "#app/enums/moves";
import Pokemon, { EnemyPokemon, PokemonMove } from "#app/field/pokemon";
import Pokemon, { EnemyPokemon, PlayerPokemon, PokemonMove } from "#app/field/pokemon";
import Trainer, { TrainerVariant } from "#app/field/trainer";
import { GameMode } from "#app/game-mode";
import { ModifierTypeOption } from "#app/modifier/modifier-type";
@ -109,6 +109,11 @@ export enum ChallengeType {
* @see {@linkcode Challenge.applyMoveBlacklist}
*/
MOVE_BLACKLIST,
/**
* Checks if pokemon are allowed to be revived from fainting
* @see {@linkcode Challenge.applyRevivePrevention}
*/
PREVENT_REVIVE,
}
/**
@ -484,6 +489,16 @@ export abstract class Challenge {
applyMoveBlacklist(move: PokemonMove, moveCanBeUsed: BooleanHolder): boolean {
return false;
}
/**
* An apply function for {@linkcode ChallengeType.PREVENT_REVIVE} challenges. Derived classes should alter this.
* @param pokemon The {@linkcode PlayerPokemon} being revived
* @param canBeRevived {@linkcode BooleanHolder} Whether the pokemon can be revived.
* @returns `true` if this function did anything.
*/
applyRevivePrevention(pokemon: PlayerPokemon, canBeRevived: BooleanHolder): boolean {
return false;
}
}
type ChallengeCondition = (data: GameData) => boolean;
@ -883,6 +898,11 @@ export class HardcoreChallenge extends Challenge {
return true;
}
override applyRevivePrevention(pokemon: PlayerPokemon, canBeRevived: BooleanHolder): boolean {
canBeRevived.value = false;
return true;
}
static override loadChallenge(source: HardcoreChallenge | any): HardcoreChallenge {
const newChallenge = new HardcoreChallenge();
newChallenge.value = source.value;
@ -1094,6 +1114,15 @@ export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType
* @returns `true` if any challenge was successfully applied.
*/
export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType.MOVE_BLACKLIST, move: PokemonMove, moveCanBeUsed: BooleanHolder): boolean;
/**
* Apply all challenges that modify if pokemon can be revived.
* @param gameMode The current {@linkcode GameMode}
* @param challengeType {@linkcode ChallengeType.PREVENT_REVIVE}
* @param pokemon The {@linkcode PlayerPokemon} being revived.
* @param canBeRevived {@linkcode BooleanHolder} Whether the pokemon can be revived.
* @returns `true` if any challenge was successfully applied.
*/
export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType.PREVENT_REVIVE, pokemon: PlayerPokemon, canBeRevived: BooleanHolder): boolean;
export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType, ...args: any[]): boolean {
let ret = false;
gameMode.challenges.forEach(c => {
@ -1153,6 +1182,9 @@ export function applyChallenges(gameMode: GameMode, challengeType: ChallengeType
case ChallengeType.MOVE_BLACKLIST:
ret ||= c.applyMoveBlacklist(args[0], args[1]);
break;
case ChallengeType.PREVENT_REVIVE:
ret ||= c.applyRevivePrevention(args[0], args[1]);
break;
}
}
});

View File

@ -1,6 +1,7 @@
import BattleScene from "#app/battle-scene";
import { applyChallenges, ChallengeType } from "#app/data/challenge";
import * as Utils from "#app/utils";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import { BooleanHolder, fixedInt } from "#app/utils";
import { BattlePhase } from "./battle-phase";
export class PartyHealPhase extends BattlePhase {
@ -15,9 +16,10 @@ export class PartyHealPhase extends BattlePhase {
start() {
super.start();
const isHealPhaseActive = new Utils.BooleanHolder(true);
const isHealPhaseActive = new BooleanHolder(true);
applyChallenges(this.scene.gameMode, ChallengeType.NO_HEAL_PHASE, isHealPhaseActive);
if (!isHealPhaseActive.value) {
this.scene.unshiftPhase(new SelectModifierPhase(this.scene));
this.end();
return;
}
@ -26,17 +28,24 @@ export class PartyHealPhase extends BattlePhase {
if (bgmPlaying) {
this.scene.fadeOutBgm(1000, false);
}
const canBeRevived = new BooleanHolder(true);
this.scene.ui.fadeOut(1000).then(() => {
for (const pokemon of this.scene.getParty()) {
pokemon.hp = pokemon.getMaxHp();
pokemon.resetStatus();
for (const move of pokemon.moveset) {
move!.ppUsed = 0; // TODO: is this bang correct?
applyChallenges(this.scene.gameMode, ChallengeType.PREVENT_REVIVE, pokemon, canBeRevived);
if (canBeRevived.value || !pokemon.isFainted()) {
pokemon.hp = pokemon.getMaxHp();
pokemon.resetStatus();
for (const move of pokemon.moveset) {
if (move) {
move.ppUsed = 0;
}
}
pokemon.updateInfo(true);
}
pokemon.updateInfo(true);
}
const healSong = this.scene.playSoundWithoutBgm("heal");
this.scene.time.delayedCall(Utils.fixedInt(healSong.totalDuration * 1000), () => {
this.scene.time.delayedCall(fixedInt(healSong.totalDuration * 1000), () => {
healSong.destroy();
if (this.resumeBgm && bgmPlaying) {
this.scene.playBgm();