From 4de5572b0ebb60bb20973c95eee05da8024a7348 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Thu, 24 Oct 2024 01:45:35 -0700 Subject: [PATCH] Prevent fainted pokemon from being spliced in hardcore --- src/data/challenge.ts | 37 +++++++++++++++++++++---------------- src/ui/party-ui-handler.ts | 15 +++++++++++---- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/data/challenge.ts b/src/data/challenge.ts index 5bff8b8bd3c..8cf63b47ae5 100644 --- a/src/data/challenge.ts +++ b/src/data/challenge.ts @@ -1,22 +1,22 @@ -import { BattleType, FixedBattleConfig } from "#app/battle"; -import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; -import { speciesStarterCosts } from "#app/data/balance/starters"; -import { Nature } from "#app/data/nature"; -import { pokemonFormChanges } from "#app/data/pokemon-forms"; +import { BooleanHolder, NumberHolder, randSeedItem } from "#app/utils"; +import i18next from "i18next"; +import { defaultStarterSpecies, DexAttrProps, GameData } from "#app/system/game-data"; import PokemonSpecies, { getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species"; -import { Type } from "#app/data/type"; -import Pokemon, { EnemyPokemon, PlayerPokemon, PokemonMove } from "#app/field/pokemon"; +import { speciesStarterCosts } from "#app/data/balance/starters"; +import Pokemon, { type EnemyPokemon, PokemonMove, type PlayerPokemon } from "#app/field/pokemon"; +import { BattleType, FixedBattleConfig } from "#app/battle"; import Trainer, { TrainerVariant } from "#app/field/trainer"; import { GameMode } from "#app/game-mode"; -import { ModifierTypeOption } from "#app/modifier/modifier-type"; -import { defaultStarterSpecies, DexAttrProps, GameData } from "#app/system/game-data"; -import { BooleanHolder, NumberHolder, randSeedItem } from "#app/utils"; +import { Type } from "#app/data/type"; import { Challenges } from "#enums/challenges"; -import { TypeColor, TypeShadow } from "#enums/color"; -import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import { TrainerType } from "#enums/trainer-type"; -import i18next from "i18next"; +import { Nature } from "#app/data/nature"; +import { Moves } from "#enums/moves"; +import { TypeColor, TypeShadow } from "#enums/color"; +import { pokemonEvolutions } from "#app/data/balance/pokemon-evolutions"; +import { pokemonFormChanges } from "#app/data/pokemon-forms"; +import type { ModifierTypeOption } from "#app/modifier/modifier-type"; /** A constant for the default max cost of the starting party before a run */ const DEFAULT_PARTY_MAX_COST = 10; @@ -862,12 +862,18 @@ export class NoAutomaticHealChallenge extends Challenge { /** Challenge that removes the ability to revive fallen pokemon */ export class HardcoreChallenge extends Challenge { - private itemBlackList = [ "modifierType:ModifierType.REVIVE", "modifierType:ModifierType.MAX_REVIVE", "modifierType:ModifierType.SACRED_ASH", "modifierType:ModifierType.REVIVER_SEED" ]; + private readonly itemBlackList = [ "modifierType:ModifierType.REVIVE", "modifierType:ModifierType.MAX_REVIVE", "modifierType:ModifierType.SACRED_ASH", "modifierType:ModifierType.REVIVER_SEED" ]; + private readonly moveBlacklist = [ Moves.REVIVAL_BLESSING ]; constructor() { super(Challenges.HARDCORE, 1); } + override applyPokemonInBattle(pokemon: Pokemon, valid: BooleanHolder): boolean { + valid.value = !pokemon.isFainted(); + return true; + } + override applyRandomItemBlacklist(randomItem: ModifierTypeOption | null, isValid: BooleanHolder): boolean { if (randomItem !== null) { isValid.value = !this.itemBlackList.includes(randomItem.type.localeKey); @@ -881,8 +887,7 @@ export class HardcoreChallenge extends Challenge { } override applyMoveBlacklist(move: PokemonMove, moveCanBeUsed: BooleanHolder): boolean { - const moveBlacklist = [ Moves.REVIVAL_BLESSING ]; - moveCanBeUsed.value = !moveBlacklist.includes(move.moveId); + moveCanBeUsed.value = !this.moveBlacklist.includes(move.moveId); return true; } diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index e96fde8d54f..1692c101769 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -391,12 +391,14 @@ export default class PartyUiHandler extends MessageUiHandler { this.clearOptions(); } else { this.clearOptions(); - this.showText(filterResult as string, undefined, () => this.showText("", 0), undefined, true); + this.showText(filterResult, undefined, () => this.showText("", 0), undefined, true); } ui.playSelect(); return true; - } else if ((option !== PartyOption.SUMMARY && option !== PartyOption.UNPAUSE_EVOLUTION && option !== PartyOption.UNSPLICE && option !== PartyOption.RELEASE && option !== PartyOption.CANCEL && option !== PartyOption.RENAME) - || (option === PartyOption.RELEASE && this.partyUiMode === PartyUiMode.RELEASE)) { + } else if ( + ![ PartyOption.SUMMARY, PartyOption.UNPAUSE_EVOLUTION, PartyOption.UNSPLICE, PartyOption.RELEASE, PartyOption.CANCEL, PartyOption.RENAME ].includes(option) + || (option === PartyOption.RELEASE && this.partyUiMode === PartyUiMode.RELEASE) + ) { let filterResult: string | null; const getTransferrableItemsFromPokemon = (pokemon: PlayerPokemon) => this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && m.isTransferable && m.pokemonId === pokemon.id) as PokemonHeldItemModifier[]; @@ -834,7 +836,7 @@ export default class PartyUiHandler extends MessageUiHandler { case PartyUiMode.POST_BATTLE_SWITCH: if (this.cursor >= this.scene.currentBattle.getBattlerCount()) { const allowBatonModifierSwitch = - this.partyUiMode !== PartyUiMode.FAINT_SWITCH + this.partyUiMode !== PartyUiMode.FAINT_SWITCH && this.scene.findModifier(m => m instanceof SwitchEffectTransferModifier && (m as SwitchEffectTransferModifier).pokemonId === this.scene.getPlayerField()[this.fieldIndex].id); @@ -865,6 +867,11 @@ export default class PartyUiHandler extends MessageUiHandler { this.options.push(PartyOption.TRANSFER); break; case PartyUiMode.SPLICE: + const isAllowedInChallenge = new Utils.BooleanHolder(true); + applyChallenges(this.scene.gameMode, ChallengeType.POKEMON_IN_BATTLE, pokemon, isAllowedInChallenge); + if (!isAllowedInChallenge.value) { + break; + } if (this.transferMode) { if (this.cursor !== this.transferCursor) { this.options.push(PartyOption.SPLICE);