This commit is contained in:
iTunesko 2025-06-20 10:39:22 +01:00 committed by GitHub
commit 2bcf4a3d90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 111 additions and 11 deletions

View File

@ -468,14 +468,52 @@ function displayYesNoOptions(resolve) {
globalScene.ui.setModeWithoutClear(UiMode.OPTION_SELECT, config, null, true);
}
function handleRepeatedAbility(resolve, pokemon: PlayerPokemon, ability: AbilityId) {
showEncounterText(`${namespace}:option.1.repeated_ability`);
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) {
const onPokemonSelected = (pokemon: PlayerPokemon) => {
// Do ability swap
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());
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 = () => {

View File

@ -250,7 +250,7 @@ export const FieryFalloutEncounter: MysteryEncounter = MysteryEncounterBuilder.w
queueEncounterMessage(`${namespace}:option.2.target_burned`);
// Also permanently change the burned Pokemon's ability to Heatproof
applyAbilityOverrideToPokemon(chosenPokemon, AbilityId.HEATPROOF);
applyAbilityOverrideToPokemon(chosenPokemon, AbilityId.HEATPROOF, false);
}
}

View File

@ -1022,14 +1022,23 @@ export function isPokemonValidForEncounterOptionSelection(
/**
* Permanently overrides the ability (not passive) of a pokemon.
* 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: AbilityId) {
if (pokemon.isFusion()) {
if (!pokemon.fusionCustomPokemonData) {
pokemon.fusionCustomPokemonData = new CustomPokemonData();
}
pokemon.fusionCustomPokemonData.ability = ability;
} else {
pokemon.customPokemonData.ability = ability;
export function applyAbilityOverrideToPokemon(pokemon: Pokemon, ability: AbilityId, flagAcceptAbility: boolean) {
const isFusion = pokemon.isFusion();
const data = isFusion
? (pokemon.fusionCustomPokemonData ??= new CustomPokemonData())
: (pokemon.customPokemonData ??= new CustomPokemonData());
const shouldOverride = data.ability !== ability || flagAcceptAbility;
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 { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import { NewBattlePhase } from "#app/phases/new-battle-phase";
import { allAbilities } from "#app/data/data-lists";
const namespace = "mysteryEncounters/clowningAround";
const defaultParty = [SpeciesId.LAPRAS, SpeciesId.GENGAR, SpeciesId.ABRA];
@ -233,6 +234,58 @@ describe("Clowning Around - Mystery Encounter", () => {
const leadPokemon = scene.getPlayerParty()[0];
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.phaseManager.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 = AbilityId.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[AbilityId.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.phaseManager.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);
expect(leadPokemon.getAbility().id).toBe(abilityToTrain);
});
});
describe("Option 2 - Remain Unprovoked", () => {