add MysterEncounterBuilder.withOptionPhase()

This commit is contained in:
Felix Staud 2024-07-09 22:34:53 -07:00 committed by ImperialSympathizer
parent adf52bf604
commit a8be171305
10 changed files with 246 additions and 257 deletions

View File

@ -123,12 +123,11 @@ export const DarkDealEncounter: MysteryEncounter = MysteryEncounterBuilder
}; };
return initBattleWithEnemyConfig(scene, config); return initBattleWithEnemyConfig(scene, config);
}) })
.build()) .build()
.withOption(new MysteryEncounterOptionBuilder() )
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Leave encounter with no rewards or exp // Leave encounter with no rewards or exp
leaveEncounterWithoutBattle(scene, true); leaveEncounterWithoutBattle(scene, true);
return true; return true;
}) })
.build())
.build(); .build();

View File

@ -8,7 +8,6 @@ import { MysteryEncounterType } from "#enums/mystery-encounter-type";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import BattleScene from "../../../battle-scene"; import BattleScene from "../../../battle-scene";
import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter"; import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter";
import { MysteryEncounterOptionBuilder } from "../mystery-encounter-option";
export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBuilder export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBuilder
.withEncounterType(MysteryEncounterType.DEPARTMENT_STORE_SALE) .withEncounterType(MysteryEncounterType.DEPARTMENT_STORE_SALE)
@ -30,7 +29,6 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
]) ])
// .withHideIntroVisuals(false) // .withHideIntroVisuals(false)
.withSceneWaveRangeRequirement(10, 100) .withSceneWaveRangeRequirement(10, 100)
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Choose TMs // Choose TMs
const modifiers = []; const modifiers = [];
@ -52,8 +50,6 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false }); setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Choose Vitamins // Choose Vitamins
const modifiers = []; const modifiers = [];
@ -72,8 +68,6 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false }); setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Choose X Items // Choose X Items
const modifiers = []; const modifiers = [];
@ -92,8 +86,6 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false }); setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Choose Pokeballs // Choose Pokeballs
const modifiers = []; const modifiers = [];
@ -116,5 +108,4 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false }); setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
}) })
.build())
.build(); .build();

View File

@ -23,7 +23,6 @@ import { Moves } from "#enums/moves";
import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type";
import BattleScene from "../../../battle-scene"; import BattleScene from "../../../battle-scene";
import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter"; import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter";
import { MysteryEncounterOptionBuilder } from "../mystery-encounter-option";
import { MoveRequirement } from "../mystery-encounter-requirements"; import { MoveRequirement } from "../mystery-encounter-requirements";
const validMovesForSteal = [ const validMovesForSteal = [
@ -99,15 +98,12 @@ export const FightOrFlightEncounter: MysteryEncounter = MysteryEncounterBuilder
return true; return true;
}) })
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Pick battle // Pick battle
const item = scene.currentBattle.mysteryEncounter.misc as ModifierTypeOption; const item = scene.currentBattle.mysteryEncounter.misc as ModifierTypeOption;
setEncounterRewards(scene, { guaranteedModifierTypeOptions: [item], fillRemaining: false }); setEncounterRewards(scene, { guaranteedModifierTypeOptions: [item], fillRemaining: false });
await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter.enemyPartyConfigs[0]); await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter.enemyPartyConfigs[0]);
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Pick steal // Pick steal
const encounter = scene.currentBattle.mysteryEncounter; const encounter = scene.currentBattle.mysteryEncounter;
@ -146,12 +142,9 @@ export const FightOrFlightEncounter: MysteryEncounter = MysteryEncounterBuilder
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
} }
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Leave encounter with no rewards or exp // Leave encounter with no rewards or exp
leaveEncounterWithoutBattle(scene, true); leaveEncounterWithoutBattle(scene, true);
return true; return true;
}) })
.build())
.build(); .build();

View File

@ -12,7 +12,6 @@ import { PartyMemberStrength } from "#enums/party-member-strength";
import BattleScene from "../../../battle-scene"; import BattleScene from "../../../battle-scene";
import * as Utils from "../../../utils"; import * as Utils from "../../../utils";
import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter"; import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter";
import { MysteryEncounterOptionBuilder } from "../mystery-encounter-option";
export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounterBuilder export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounterBuilder
.withEncounterType(MysteryEncounterType.MYSTERIOUS_CHALLENGERS) .withEncounterType(MysteryEncounterType.MYSTERIOUS_CHALLENGERS)
@ -96,7 +95,6 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter
return true; return true;
}) })
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
const encounter = scene.currentBattle.mysteryEncounter; const encounter = scene.currentBattle.mysteryEncounter;
// Spawn standard trainer battle with memory mushroom reward // Spawn standard trainer battle with memory mushroom reward
@ -111,8 +109,6 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter
}, scene.currentBattle.waveIndex * 10); }, scene.currentBattle.waveIndex * 10);
return ret; return ret;
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
const encounter = scene.currentBattle.mysteryEncounter; const encounter = scene.currentBattle.mysteryEncounter;
// Spawn hard fight with ULTRA/GREAT reward (can improve with luck) // Spawn hard fight with ULTRA/GREAT reward (can improve with luck)
@ -127,8 +123,6 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter
}, scene.currentBattle.waveIndex * 100); }, scene.currentBattle.waveIndex * 100);
return ret; return ret;
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
const encounter = scene.currentBattle.mysteryEncounter; const encounter = scene.currentBattle.mysteryEncounter;
// Spawn brutal fight with ROGUE/ULTRA/GREAT reward (can improve with luck) // Spawn brutal fight with ROGUE/ULTRA/GREAT reward (can improve with luck)
@ -146,5 +140,4 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter
}, scene.currentBattle.waveIndex * 1000); }, scene.currentBattle.waveIndex * 1000);
return ret; return ret;
}) })
.build())
.build(); .build();

View File

@ -83,12 +83,11 @@ export const MysteriousChestEncounter: MysteryEncounter = MysteryEncounterBuilde
}); });
} }
}) })
.build()) .build()
.withOption(new MysteryEncounterOptionBuilder() )
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Leave encounter with no rewards or exp // Leave encounter with no rewards or exp
leaveEncounterWithoutBattle(scene, true); leaveEncounterWithoutBattle(scene, true);
return true; return true;
}) })
.build())
.build(); .build();

View File

@ -116,6 +116,7 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = MysteryEncounterBui
chosenPokemon.updateInfo(); chosenPokemon.updateInfo();
}) })
.build()) .build())
.withOption(new MysteryEncounterOptionBuilder() .withOption(new MysteryEncounterOptionBuilder()
.withSceneRequirement(new MoneyRequirement(0, 5)) // Wave scaling multiplier of 2 for cost .withSceneRequirement(new MoneyRequirement(0, 5)) // Wave scaling multiplier of 2 for cost
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
@ -136,12 +137,11 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = MysteryEncounterBui
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false }); setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
}) })
.build()) .build()
.withOption(new MysteryEncounterOptionBuilder() )
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Leave encounter with no rewards or exp // Leave encounter with no rewards or exp
leaveEncounterWithoutBattle(scene, true); leaveEncounterWithoutBattle(scene, true);
return true; return true;
}) })
.build())
.build(); .build();

View File

@ -54,15 +54,12 @@ export const SleepingSnorlaxEncounter: MysteryEncounter = MysteryEncounterBuilde
encounter.enemyPartyConfigs = [config]; encounter.enemyPartyConfigs = [config];
return true; return true;
}) })
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Pick battle // Pick battle
// TODO: do we want special rewards for this? // TODO: do we want special rewards for this?
// setCustomEncounterRewards(scene, { guaranteedModifierTypeFuncs: [modifierTypes.LEFTOVERS], fillRemaining: true}); // setCustomEncounterRewards(scene, { guaranteedModifierTypeFuncs: [modifierTypes.LEFTOVERS], fillRemaining: true});
await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter.enemyPartyConfigs[0]); await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter.enemyPartyConfigs[0]);
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder()
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
const instance = scene.currentBattle.mysteryEncounter; const instance = scene.currentBattle.mysteryEncounter;
let roll: integer; let roll: integer;
@ -96,7 +93,6 @@ export const SleepingSnorlaxEncounter: MysteryEncounter = MysteryEncounterBuilde
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
} }
}) })
.build())
.withOption(new MysteryEncounterOptionBuilder() .withOption(new MysteryEncounterOptionBuilder()
.withPrimaryPokemonRequirement(new MoveRequirement([Moves.PLUCK, Moves.COVET, Moves.KNOCK_OFF, Moves.THIEF, Moves.TRICK, Moves.SWITCHEROO])) .withPrimaryPokemonRequirement(new MoveRequirement([Moves.PLUCK, Moves.COVET, Moves.KNOCK_OFF, Moves.THIEF, Moves.TRICK, Moves.SWITCHEROO]))
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
@ -105,5 +101,6 @@ export const SleepingSnorlaxEncounter: MysteryEncounter = MysteryEncounterBuilde
queueEncounterMessage(scene, "mysteryEncounter:sleeping_snorlax_option_3_good_result"); queueEncounterMessage(scene, "mysteryEncounter:sleeping_snorlax_option_3_good_result");
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
}) })
.build()) .build()
)
.build(); .build();

View File

@ -134,7 +134,8 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
return initBattleWithEnemyConfig(scene, config); return initBattleWithEnemyConfig(scene, config);
}) })
.build()) .build()
)
.withOption(new MysteryEncounterOptionBuilder() .withOption(new MysteryEncounterOptionBuilder()
.withPreOptionPhase(async (scene: BattleScene): Promise<boolean> => { .withPreOptionPhase(async (scene: BattleScene): Promise<boolean> => {
// Open menu for selecting pokemon and Nature // Open menu for selecting pokemon and Nature
@ -190,7 +191,8 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
return initBattleWithEnemyConfig(scene, config); return initBattleWithEnemyConfig(scene, config);
}) })
.build()) .build()
)
.withOption(new MysteryEncounterOptionBuilder() .withOption(new MysteryEncounterOptionBuilder()
.withPreOptionPhase(async (scene: BattleScene): Promise<boolean> => { .withPreOptionPhase(async (scene: BattleScene): Promise<boolean> => {
// Open menu for selecting pokemon and ability to learn // Open menu for selecting pokemon and ability to learn
@ -271,7 +273,8 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
return initBattleWithEnemyConfig(scene, config); return initBattleWithEnemyConfig(scene, config);
}) })
.build()) .build()
)
.build(); .build();
function getEnemyConfig(scene: BattleScene, playerPokemon: PlayerPokemon, segments: number, modifiers: ModifiersHolder): EnemyPartyConfig { function getEnemyConfig(scene: BattleScene, playerPokemon: PlayerPokemon, segments: number, modifiers: ModifiersHolder): EnemyPartyConfig {

View File

@ -4,6 +4,9 @@ import BattleScene from "../../battle-scene";
import { EncounterPokemonRequirement, EncounterSceneRequirement } from "./mystery-encounter-requirements"; import { EncounterPokemonRequirement, EncounterSceneRequirement } from "./mystery-encounter-requirements";
import { OptionTextDisplay } from "#app/data/mystery-encounters/mystery-encounter-dialogue"; import { OptionTextDisplay } from "#app/data/mystery-encounters/mystery-encounter-dialogue";
export type OptionPhaseCallback = (scene: BattleScene) => Promise<void | boolean>;
export default interface MysteryEncounterOption { export default interface MysteryEncounterOption {
requirements?: EncounterSceneRequirement[]; requirements?: EncounterSceneRequirement[];
primaryPokemonRequirements?: EncounterPokemonRequirement[]; primaryPokemonRequirements?: EncounterPokemonRequirement[];
@ -19,11 +22,11 @@ export default interface MysteryEncounterOption {
dialogue?: OptionTextDisplay; dialogue?: OptionTextDisplay;
// Executes before any following dialogue or business logic from option. Usually this will be for calculating dialogueTokens or performing scene/data updates // Executes before any following dialogue or business logic from option. Usually this will be for calculating dialogueTokens or performing scene/data updates
onPreOptionPhase?: (scene: BattleScene) => Promise<void | boolean>; onPreOptionPhase?: OptionPhaseCallback;
// Business logic for option // Business logic for option
onOptionPhase?: (scene: BattleScene) => Promise<void | boolean>; onOptionPhase?: OptionPhaseCallback;
// Executes after the encounter is over. Usually this will be for calculating dialogueTokens or performing data updates // Executes after the encounter is over. Usually this will be for calculating dialogueTokens or performing data updates
onPostOptionPhase?: (scene: BattleScene) => Promise<void | boolean>; onPostOptionPhase?: OptionPhaseCallback;
} }
export default class MysteryEncounterOption implements MysteryEncounterOption { export default class MysteryEncounterOption implements MysteryEncounterOption {
@ -121,24 +124,24 @@ export class MysteryEncounterOptionBuilder implements Partial<MysteryEncounterOp
primaryPokemonRequirements?: EncounterPokemonRequirement[] = []; primaryPokemonRequirements?: EncounterPokemonRequirement[] = [];
secondaryPokemonRequirements ?: EncounterPokemonRequirement[] = []; secondaryPokemonRequirements ?: EncounterPokemonRequirement[] = [];
excludePrimaryFromSecondaryRequirements?: boolean; excludePrimaryFromSecondaryRequirements?: boolean;
onPreOptionPhase?: (scene: BattleScene) => Promise<void | boolean>; onPreOptionPhase?: OptionPhaseCallback;
onOptionPhase?: (scene: BattleScene) => Promise<void | boolean>; onOptionPhase?: OptionPhaseCallback;
onPostOptionPhase?: (scene: BattleScene) => Promise<void | boolean>; onPostOptionPhase?: OptionPhaseCallback;
withSceneRequirement(requirement: EncounterSceneRequirement): this & Required<Pick<MysteryEncounterOption, "requirements">> { withSceneRequirement(requirement: EncounterSceneRequirement): this & Required<Pick<MysteryEncounterOption, "requirements">> {
this.requirements.push(requirement); this.requirements.push(requirement);
return Object.assign(this, { requirements: this.requirements }); return Object.assign(this, { requirements: this.requirements });
} }
withPreOptionPhase(onPreOptionPhase: (scene: BattleScene) => Promise<void | boolean>): this & Required<Pick<MysteryEncounterOption, "onPreOptionPhase">> { withPreOptionPhase(onPreOptionPhase: OptionPhaseCallback): this & Required<Pick<MysteryEncounterOption, "onPreOptionPhase">> {
return Object.assign(this, { onPreOptionPhase: onPreOptionPhase }); return Object.assign(this, { onPreOptionPhase: onPreOptionPhase });
} }
withOptionPhase(onOptionPhase: (scene: BattleScene) => Promise<void | boolean>): this & Required<Pick<MysteryEncounterOption, "onOptionPhase">> { withOptionPhase(onOptionPhase: OptionPhaseCallback): this & Required<Pick<MysteryEncounterOption, "onOptionPhase">> {
return Object.assign(this, { onOptionPhase: onOptionPhase }); return Object.assign(this, { onOptionPhase: onOptionPhase });
} }
withPostOptionPhase(onPostOptionPhase: (scene: BattleScene) => Promise<void | boolean>): this & Required<Pick<MysteryEncounterOption, "onPostOptionPhase">> { withPostOptionPhase(onPostOptionPhase: OptionPhaseCallback): this & Required<Pick<MysteryEncounterOption, "onPostOptionPhase">> {
return Object.assign(this, { onPostOptionPhase: onPostOptionPhase }); return Object.assign(this, { onPostOptionPhase: onPostOptionPhase });
} }

View File

@ -4,7 +4,7 @@ import { MysteryEncounterType } from "#enums/mystery-encounter-type";
import MysteryEncounterDialogue, { import MysteryEncounterDialogue, {
allMysteryEncounterDialogue allMysteryEncounterDialogue
} from "./mystery-encounter-dialogue"; } from "./mystery-encounter-dialogue";
import MysteryEncounterOption from "./mystery-encounter-option"; import MysteryEncounterOption, { MysteryEncounterOptionBuilder, OptionPhaseCallback } from "./mystery-encounter-option";
import { import {
EncounterPokemonRequirement, EncounterPokemonRequirement,
EncounterSceneRequirement, EncounterSceneRequirement,
@ -387,6 +387,17 @@ export class MysteryEncounterBuilder implements Partial<MysteryEncounter> {
} }
} }
/**
* Adds a streamlined option phase.
* Only use if no pre-/post-options or condtions necessary.
*
* @param callback - OptionPhaseCallback
* @returns
*/
withOptionPhase(callback: OptionPhaseCallback) {
return this.withOption(new MysteryEncounterOptionBuilder().withOptionPhase(callback).build());
}
/** /**
* Defines the sprites that will be shown on the enemy field when the encounter spawns * Defines the sprites that will be shown on the enemy field when the encounter spawns
* Can be one or more sprites, recommended not to exceed 4 * Can be one or more sprites, recommended not to exceed 4