Skip to content

Commit

Permalink
Prevent PartyHealPhase from reviving pokemon in hardcore challenge
Browse files Browse the repository at this point in the history
Add `SelectModifierPhase` on waves 10, 20, ...
if "No Auto Heal" challenge is active
  • Loading branch information
DayKev committed Sep 19, 2024
1 parent f292087 commit c7df077
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
34 changes: 33 additions & 1 deletion src/data/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
}
}
});
Expand Down
25 changes: 17 additions & 8 deletions src/phases/party-heal-phase.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}
Expand All @@ -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();
Expand Down

0 comments on commit c7df077

Please sign in to comment.