add `MysterEncounterBuilder.withOptionPhase()`
This commit is contained in:
parent
adf52bf604
commit
a8be171305
|
@ -123,12 +123,11 @@ export const DarkDealEncounter: MysteryEncounter = MysteryEncounterBuilder
|
|||
};
|
||||
return initBattleWithEnemyConfig(scene, config);
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.build()
|
||||
)
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Leave encounter with no rewards or exp
|
||||
leaveEncounterWithoutBattle(scene, true);
|
||||
return true;
|
||||
})
|
||||
.build())
|
||||
.build();
|
||||
|
|
|
@ -8,7 +8,6 @@ import { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
|||
import { Species } from "#enums/species";
|
||||
import BattleScene from "../../../battle-scene";
|
||||
import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter";
|
||||
import { MysteryEncounterOptionBuilder } from "../mystery-encounter-option";
|
||||
|
||||
export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBuilder
|
||||
.withEncounterType(MysteryEncounterType.DEPARTMENT_STORE_SALE)
|
||||
|
@ -30,7 +29,6 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
|
|||
])
|
||||
// .withHideIntroVisuals(false)
|
||||
.withSceneWaveRangeRequirement(10, 100)
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Choose TMs
|
||||
const modifiers = [];
|
||||
|
@ -52,8 +50,6 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
|
|||
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
|
||||
leaveEncounterWithoutBattle(scene);
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Choose Vitamins
|
||||
const modifiers = [];
|
||||
|
@ -72,8 +68,6 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
|
|||
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
|
||||
leaveEncounterWithoutBattle(scene);
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Choose X Items
|
||||
const modifiers = [];
|
||||
|
@ -92,8 +86,6 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
|
|||
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
|
||||
leaveEncounterWithoutBattle(scene);
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Choose Pokeballs
|
||||
const modifiers = [];
|
||||
|
@ -116,5 +108,4 @@ export const DepartmentStoreSaleEncounter: MysteryEncounter = MysteryEncounterBu
|
|||
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
|
||||
leaveEncounterWithoutBattle(scene);
|
||||
})
|
||||
.build())
|
||||
.build();
|
||||
|
|
|
@ -23,7 +23,6 @@ import { Moves } from "#enums/moves";
|
|||
import { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
||||
import BattleScene from "../../../battle-scene";
|
||||
import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter";
|
||||
import { MysteryEncounterOptionBuilder } from "../mystery-encounter-option";
|
||||
import { MoveRequirement } from "../mystery-encounter-requirements";
|
||||
|
||||
const validMovesForSteal = [
|
||||
|
@ -99,15 +98,12 @@ export const FightOrFlightEncounter: MysteryEncounter = MysteryEncounterBuilder
|
|||
|
||||
return true;
|
||||
})
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Pick battle
|
||||
const item = scene.currentBattle.mysteryEncounter.misc as ModifierTypeOption;
|
||||
setEncounterRewards(scene, { guaranteedModifierTypeOptions: [item], fillRemaining: false });
|
||||
await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter.enemyPartyConfigs[0]);
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Pick steal
|
||||
const encounter = scene.currentBattle.mysteryEncounter;
|
||||
|
@ -146,12 +142,9 @@ export const FightOrFlightEncounter: MysteryEncounter = MysteryEncounterBuilder
|
|||
leaveEncounterWithoutBattle(scene);
|
||||
}
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Leave encounter with no rewards or exp
|
||||
leaveEncounterWithoutBattle(scene, true);
|
||||
return true;
|
||||
})
|
||||
.build())
|
||||
.build();
|
||||
|
|
|
@ -12,7 +12,6 @@ import { PartyMemberStrength } from "#enums/party-member-strength";
|
|||
import BattleScene from "../../../battle-scene";
|
||||
import * as Utils from "../../../utils";
|
||||
import MysteryEncounter, { MysteryEncounterBuilder, MysteryEncounterTier } from "../mystery-encounter";
|
||||
import { MysteryEncounterOptionBuilder } from "../mystery-encounter-option";
|
||||
|
||||
export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounterBuilder
|
||||
.withEncounterType(MysteryEncounterType.MYSTERIOUS_CHALLENGERS)
|
||||
|
@ -96,7 +95,6 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter
|
|||
|
||||
return true;
|
||||
})
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
const encounter = scene.currentBattle.mysteryEncounter;
|
||||
// Spawn standard trainer battle with memory mushroom reward
|
||||
|
@ -111,8 +109,6 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter
|
|||
}, scene.currentBattle.waveIndex * 10);
|
||||
return ret;
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
const encounter = scene.currentBattle.mysteryEncounter;
|
||||
// Spawn hard fight with ULTRA/GREAT reward (can improve with luck)
|
||||
|
@ -127,8 +123,6 @@ export const MysteriousChallengersEncounter: MysteryEncounter = MysteryEncounter
|
|||
}, scene.currentBattle.waveIndex * 100);
|
||||
return ret;
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
const encounter = scene.currentBattle.mysteryEncounter;
|
||||
// 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);
|
||||
return ret;
|
||||
})
|
||||
.build())
|
||||
.build();
|
||||
|
|
|
@ -83,12 +83,11 @@ export const MysteriousChestEncounter: MysteryEncounter = MysteryEncounterBuilde
|
|||
});
|
||||
}
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.build()
|
||||
)
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Leave encounter with no rewards or exp
|
||||
leaveEncounterWithoutBattle(scene, true);
|
||||
return true;
|
||||
})
|
||||
.build())
|
||||
.build();
|
||||
|
|
|
@ -116,6 +116,7 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = MysteryEncounterBui
|
|||
chosenPokemon.updateInfo();
|
||||
})
|
||||
.build())
|
||||
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withSceneRequirement(new MoneyRequirement(0, 5)) // Wave scaling multiplier of 2 for cost
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
|
@ -136,12 +137,11 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter = MysteryEncounterBui
|
|||
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: modifiers, fillRemaining: false });
|
||||
leaveEncounterWithoutBattle(scene);
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.build()
|
||||
)
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Leave encounter with no rewards or exp
|
||||
leaveEncounterWithoutBattle(scene, true);
|
||||
return true;
|
||||
})
|
||||
.build())
|
||||
.build();
|
||||
|
|
|
@ -54,15 +54,12 @@ export const SleepingSnorlaxEncounter: MysteryEncounter = MysteryEncounterBuilde
|
|||
encounter.enemyPartyConfigs = [config];
|
||||
return true;
|
||||
})
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
// Pick battle
|
||||
// TODO: do we want special rewards for this?
|
||||
// setCustomEncounterRewards(scene, { guaranteedModifierTypeFuncs: [modifierTypes.LEFTOVERS], fillRemaining: true});
|
||||
await initBattleWithEnemyConfig(scene, scene.currentBattle.mysteryEncounter.enemyPartyConfigs[0]);
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
const instance = scene.currentBattle.mysteryEncounter;
|
||||
let roll: integer;
|
||||
|
@ -96,7 +93,6 @@ export const SleepingSnorlaxEncounter: MysteryEncounter = MysteryEncounterBuilde
|
|||
leaveEncounterWithoutBattle(scene);
|
||||
}
|
||||
})
|
||||
.build())
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withPrimaryPokemonRequirement(new MoveRequirement([Moves.PLUCK, Moves.COVET, Moves.KNOCK_OFF, Moves.THIEF, Moves.TRICK, Moves.SWITCHEROO]))
|
||||
.withOptionPhase(async (scene: BattleScene) => {
|
||||
|
@ -105,5 +101,6 @@ export const SleepingSnorlaxEncounter: MysteryEncounter = MysteryEncounterBuilde
|
|||
queueEncounterMessage(scene, "mysteryEncounter:sleeping_snorlax_option_3_good_result");
|
||||
leaveEncounterWithoutBattle(scene);
|
||||
})
|
||||
.build())
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
|
|
|
@ -134,7 +134,8 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
|
|||
|
||||
return initBattleWithEnemyConfig(scene, config);
|
||||
})
|
||||
.build())
|
||||
.build()
|
||||
)
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withPreOptionPhase(async (scene: BattleScene): Promise<boolean> => {
|
||||
// Open menu for selecting pokemon and Nature
|
||||
|
@ -190,7 +191,8 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
|
|||
|
||||
return initBattleWithEnemyConfig(scene, config);
|
||||
})
|
||||
.build())
|
||||
.build()
|
||||
)
|
||||
.withOption(new MysteryEncounterOptionBuilder()
|
||||
.withPreOptionPhase(async (scene: BattleScene): Promise<boolean> => {
|
||||
// Open menu for selecting pokemon and ability to learn
|
||||
|
@ -271,7 +273,8 @@ export const TrainingSessionEncounter: MysteryEncounter = MysteryEncounterBuilde
|
|||
|
||||
return initBattleWithEnemyConfig(scene, config);
|
||||
})
|
||||
.build())
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
|
||||
function getEnemyConfig(scene: BattleScene, playerPokemon: PlayerPokemon, segments: number, modifiers: ModifiersHolder): EnemyPartyConfig {
|
||||
|
|
|
@ -4,6 +4,9 @@ import BattleScene from "../../battle-scene";
|
|||
import { EncounterPokemonRequirement, EncounterSceneRequirement } from "./mystery-encounter-requirements";
|
||||
import { OptionTextDisplay } from "#app/data/mystery-encounters/mystery-encounter-dialogue";
|
||||
|
||||
|
||||
export type OptionPhaseCallback = (scene: BattleScene) => Promise<void | boolean>;
|
||||
|
||||
export default interface MysteryEncounterOption {
|
||||
requirements?: EncounterSceneRequirement[];
|
||||
primaryPokemonRequirements?: EncounterPokemonRequirement[];
|
||||
|
@ -19,11 +22,11 @@ export default interface MysteryEncounterOption {
|
|||
dialogue?: OptionTextDisplay;
|
||||
|
||||
// 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
|
||||
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
|
||||
onPostOptionPhase?: (scene: BattleScene) => Promise<void | boolean>;
|
||||
onPostOptionPhase?: OptionPhaseCallback;
|
||||
}
|
||||
|
||||
export default class MysteryEncounterOption implements MysteryEncounterOption {
|
||||
|
@ -121,24 +124,24 @@ export class MysteryEncounterOptionBuilder implements Partial<MysteryEncounterOp
|
|||
primaryPokemonRequirements?: EncounterPokemonRequirement[] = [];
|
||||
secondaryPokemonRequirements ?: EncounterPokemonRequirement[] = [];
|
||||
excludePrimaryFromSecondaryRequirements?: boolean;
|
||||
onPreOptionPhase?: (scene: BattleScene) => Promise<void | boolean>;
|
||||
onOptionPhase?: (scene: BattleScene) => Promise<void | boolean>;
|
||||
onPostOptionPhase?: (scene: BattleScene) => Promise<void | boolean>;
|
||||
onPreOptionPhase?: OptionPhaseCallback;
|
||||
onOptionPhase?: OptionPhaseCallback;
|
||||
onPostOptionPhase?: OptionPhaseCallback;
|
||||
|
||||
withSceneRequirement(requirement: EncounterSceneRequirement): this & Required<Pick<MysteryEncounterOption, "requirements">> {
|
||||
this.requirements.push(requirement);
|
||||
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 });
|
||||
}
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
|||
import MysteryEncounterDialogue, {
|
||||
allMysteryEncounterDialogue
|
||||
} from "./mystery-encounter-dialogue";
|
||||
import MysteryEncounterOption from "./mystery-encounter-option";
|
||||
import MysteryEncounterOption, { MysteryEncounterOptionBuilder, OptionPhaseCallback } from "./mystery-encounter-option";
|
||||
import {
|
||||
EncounterPokemonRequirement,
|
||||
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
|
||||
* Can be one or more sprites, recommended not to exceed 4
|
||||
|
|
Loading…
Reference in New Issue