[BUG] Fixes #5288 Clowning Around doesn’t check if Pokemon

already  has the ability

When offering the same ability a Pokemon
already has, a menu should
now appear informing the user. The user can then choose a different
Pokemon or proceed to give the same ability anyway.
This commit is contained in:
Inês Antunes 2025-05-11 21:47:55 +01:00
parent 718c8cfbb9
commit b072f91649
3 changed files with 110 additions and 10 deletions

View File

@ -467,14 +467,52 @@ function displayYesNoOptions(resolve) {
globalScene.ui.setModeWithoutClear(UiMode.OPTION_SELECT, config, null, true); globalScene.ui.setModeWithoutClear(UiMode.OPTION_SELECT, config, null, true);
} }
function handleRepeatedAbility(resolve, pokemon: PlayerPokemon, ability: Abilities) {
showEncounterText("Your pokemon already has this ability. Are you sure you want to apply it?");
const fullOptions = [
{
label: i18next.t("menu:yes"),
handler: () => {
applyAbilityOverrideToPokemon(pokemon, ability, true);
globalScene.ui.setMode(UiMode.MESSAGE).then(() => resolve(true));
return true;
},
},
{
label: i18next.t("menu:no"),
handler: () => {
onYesAbilitySwap(resolve);
return true;
},
},
];
const config: OptionSelectConfig = {
options: fullOptions,
maxOptions: 7,
yOffset: 0,
};
globalScene.ui.setModeWithoutClear(UiMode.OPTION_SELECT, config, null, true);
}
function onYesAbilitySwap(resolve) { function onYesAbilitySwap(resolve) {
const onPokemonSelected = (pokemon: PlayerPokemon) => { const onPokemonSelected = (pokemon: PlayerPokemon) => {
// Do ability swap // Do ability swap
const encounter = globalScene.currentBattle.mysteryEncounter!; const encounter = globalScene.currentBattle.mysteryEncounter!;
applyAbilityOverrideToPokemon(pokemon, encounter.misc.ability); // Choose a random ability, to give a pokemon on the end of a battle
const randomAbility = encounter.misc.ability;
const newAbility = applyAbilityOverrideToPokemon(pokemon, randomAbility, false);
encounter.setDialogueToken("chosenPokemon", pokemon.getNameToRender()); encounter.setDialogueToken("chosenPokemon", pokemon.getNameToRender());
globalScene.ui.setMode(UiMode.MESSAGE).then(() => resolve(true));
globalScene.ui.setMode(UiMode.MESSAGE).then(() => {
// if Pokemon already has the same Ability
if (!newAbility) {
handleRepeatedAbility(resolve, pokemon, randomAbility);
} else {
resolve(true);
}
});
}; };
const onPokemonNotSelected = () => { const onPokemonNotSelected = () => {

View File

@ -1023,14 +1023,22 @@ export function isPokemonValidForEncounterOptionSelection(
/** /**
* Permanently overrides the ability (not passive) of a pokemon. * Permanently overrides the ability (not passive) of a pokemon.
* If the pokemon is a fusion, instead overrides the fused pokemon's ability. * If the pokemon is a fusion, instead overrides the fused pokemon's ability.
* @param ability
* @param pokemon
* @param flagAcceptAbility
*/ */
export function applyAbilityOverrideToPokemon(pokemon: Pokemon, ability: Abilities) { export function applyAbilityOverrideToPokemon(pokemon: Pokemon, ability: Abilities, flagAcceptAbility: boolean) {
if (pokemon.isFusion()) { const isFusion = pokemon.isFusion();
if (!pokemon.fusionCustomPokemonData) { const data = isFusion
pokemon.fusionCustomPokemonData = new CustomPokemonData(); ? (pokemon.fusionCustomPokemonData ??= new CustomPokemonData())
} : (pokemon.customPokemonData ??= new CustomPokemonData());
pokemon.fusionCustomPokemonData.ability = ability;
} else { const shouldOverride = data.ability !== ability || flagAcceptAbility;
pokemon.customPokemonData.ability = ability;
if (shouldOverride) {
data.ability = ability;
return true;
} }
return false;
} }

View File

@ -37,6 +37,7 @@ import { CommandPhase } from "#app/phases/command-phase";
import { MovePhase } from "#app/phases/move-phase"; import { MovePhase } from "#app/phases/move-phase";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import { NewBattlePhase } from "#app/phases/new-battle-phase"; import { NewBattlePhase } from "#app/phases/new-battle-phase";
import { allAbilities } from "#app/data/data-lists";
const namespace = "mysteryEncounters/clowningAround"; const namespace = "mysteryEncounters/clowningAround";
const defaultParty = [Species.LAPRAS, Species.GENGAR, Species.ABRA]; const defaultParty = [Species.LAPRAS, Species.GENGAR, Species.ABRA];
@ -234,6 +235,59 @@ describe("Clowning Around - Mystery Encounter", () => {
const leadPokemon = scene.getPlayerParty()[0]; const leadPokemon = scene.getPlayerParty()[0];
expect(leadPokemon.customPokemonData?.ability).toBe(abilityToTrain); expect(leadPokemon.customPokemonData?.ability).toBe(abilityToTrain);
}); });
it("should let the player know their pokemon already has the ability and accept it", async () => {
await game.runToMysteryEncounter(MysteryEncounterType.CLOWNING_AROUND, defaultParty);
await runMysteryEncounterToEnd(game, 1, undefined, true);
await skipBattleRunMysteryEncounterRewardsPhase(game);
await game.phaseInterceptor.to(SelectModifierPhase, false);
expect(scene.getCurrentPhase()?.constructor.name).toBe(SelectModifierPhase.name);
await game.phaseInterceptor.run(SelectModifierPhase);
const leadPokemon = scene.getPlayerParty()[0];
// offer Prankster abiliy for winning the battle
const abilityToTrain = Abilities.PRANKSTER;
game.onNextPrompt("PostMysteryEncounterPhase", UiMode.MESSAGE, () => {
game.scene.ui.getHandler().processInput(Button.ACTION);
});
// Give fto the first Pokemon the Prankster ability
vi.spyOn(leadPokemon, "getAbility").mockReturnValue(allAbilities[Abilities.PRANKSTER]);
// Run to ability train option selection
const optionSelectUiHandler = game.scene.ui.handlers[UiMode.OPTION_SELECT] as OptionSelectUiHandler;
vi.spyOn(optionSelectUiHandler, "show");
const partyUiHandler = game.scene.ui.handlers[UiMode.PARTY] as PartyUiHandler;
vi.spyOn(partyUiHandler, "show");
const optionSelectUiHandlerRepeatedAbility = game.scene.ui.handlers[
UiMode.OPTION_SELECT
] as OptionSelectUiHandler;
vi.spyOn(optionSelectUiHandlerRepeatedAbility, "show");
game.endPhase();
await game.phaseInterceptor.to(PostMysteryEncounterPhase);
expect(scene.getCurrentPhase()?.constructor.name).toBe(PostMysteryEncounterPhase.name);
// Wait for Yes/No confirmation to appear -> accepting the Ability
await vi.waitFor(() => expect(optionSelectUiHandler.show).toHaveBeenCalled());
// Select "Yes" on train ability
optionSelectUiHandler.processInput(Button.ACTION);
// Select first pokemon in party to train
await vi.waitFor(() => expect(partyUiHandler.show).toHaveBeenCalled());
partyUiHandler.processInput(Button.ACTION);
// Click "Select" on Pokemon
partyUiHandler.processInput(Button.ACTION);
// Wait for Yes/No confirmation to appear -> Accepting the Ability, besides being repeated
await vi.waitFor(() => expect(optionSelectUiHandlerRepeatedAbility.show).toHaveBeenCalled());
// Select "Yes" on train the same ability as before
optionSelectUiHandlerRepeatedAbility.processInput(Button.ACTION);
// Stop next battle before it runs
await game.phaseInterceptor.to(NewBattlePhase, false);
//game.override.ability(Abilities.PRANKSTER);
expect(leadPokemon.getAbility().id).toBe(abilityToTrain);
});
}); });
describe("Option 2 - Remain Unprovoked", () => { describe("Option 2 - Remain Unprovoked", () => {