cleanup and add jsdocs

This commit is contained in:
ImperialSympathizer 2024-07-18 16:01:47 -04:00
parent 872542080a
commit b68abaab94
4 changed files with 80 additions and 65 deletions

View File

@ -103,6 +103,11 @@ export enum CommonAnim {
LOCK_ON = 2120 LOCK_ON = 2120
} }
/**
* Animations used for Mystery Encounters
* These are custom animations that may or may not work in any other circumstance
* Use at your own risk
*/
export enum EncounterAnim { export enum EncounterAnim {
MAGMA_BG, MAGMA_BG,
MAGMA_SPOUT MAGMA_SPOUT
@ -520,23 +525,26 @@ export function initMoveAnim(scene: BattleScene, move: Moves): Promise<void> {
}); });
} }
export function initEncounterAnims(scene: BattleScene, anims: EncounterAnim | EncounterAnim[]): Promise<void> { /**
* Fetches animation configs to be used in a Mystery Encounter
* @param scene
* @param anims - one or more animations to fetch
*/
export async function initEncounterAnims(scene: BattleScene, anims: EncounterAnim | EncounterAnim[]): Promise<void> {
anims = anims instanceof Array ? anims : [anims]; anims = anims instanceof Array ? anims : [anims];
return new Promise(resolve => { const encounterAnimNames = Utils.getEnumKeys(EncounterAnim);
const encounterAnimNames = Utils.getEnumKeys(EncounterAnim); const encounterAnimIds = Utils.getEnumValues(EncounterAnim);
const encounterAnimIds = Utils.getEnumValues(EncounterAnim); const encounterAnimFetches = [];
const encounterAnimFetches = []; for (const anim of anims) {
for (const anim of anims) { if (encounterAnims.has(anim) && !isNullOrUndefined(encounterAnims.get(anim))) {
if (encounterAnims.has(anim) && !isNullOrUndefined(encounterAnims.get(anim))) { continue;
continue;
}
const encounterAnimId = encounterAnimIds[anim];
encounterAnimFetches.push(scene.cachedFetch(`./battle-anims/encounter-${encounterAnimNames[anim].toLowerCase().replace(/\_/g, "-")}.json`)
.then(response => response.json())
.then(cas => encounterAnims.set(encounterAnimId, new AnimConfig(cas))));
} }
Promise.allSettled(encounterAnimFetches).then(() => resolve()); const encounterAnimId = encounterAnimIds[anim];
}); encounterAnimFetches.push(scene.cachedFetch(`./battle-anims/encounter-${encounterAnimNames[anim].toLowerCase().replace(/\_/g, "-")}.json`)
.then(response => response.json())
.then(cas => encounterAnims.set(encounterAnimId, new AnimConfig(cas))));
}
await Promise.allSettled(encounterAnimFetches);
} }
export function initMoveChargeAnim(scene: BattleScene, chargeAnim: ChargeAnim): Promise<void> { export function initMoveChargeAnim(scene: BattleScene, chargeAnim: ChargeAnim): Promise<void> {
@ -593,10 +601,14 @@ export function loadCommonAnimAssets(scene: BattleScene, startLoad?: boolean): P
}); });
} }
export function loadEncounterAnimAssets(scene: BattleScene, startLoad?: boolean): Promise<void> { /**
return new Promise(resolve => { * Loads encounter animation assets to scene
loadAnimAssets(scene, Array.from(encounterAnims.values()), startLoad).then(() => resolve()); * MUST be called after [initEncounterAnims()](./battle-anims.ts) to load all required animations properly
}); * @param scene
* @param startLoad
*/
export async function loadEncounterAnimAssets(scene: BattleScene, startLoad?: boolean): Promise<void> {
await loadAnimAssets(scene, Array.from(encounterAnims.values()), startLoad);
} }
export function loadMoveAnimAssets(scene: BattleScene, moveIds: Moves[], startLoad?: boolean): Promise<void> { export function loadMoveAnimAssets(scene: BattleScene, moveIds: Moves[], startLoad?: boolean): Promise<void> {

View File

@ -19,6 +19,8 @@ import { getPokemonNameWithAffix } from "#app/messages";
/** the i18n namespace for the encounter */ /** the i18n namespace for the encounter */
const namespace = "mysteryEncounter:safariZone"; const namespace = "mysteryEncounter:safariZone";
const TRAINER_THROW_ANIMATION_TIMES = [512, 184, 768];
/** /**
* Safari Zone encounter. * Safari Zone encounter.
* @see {@link https://github.com/AsdarDevelops/PokeRogue-Events/issues/39 | GitHub Issue #39} * @see {@link https://github.com/AsdarDevelops/PokeRogue-Events/issues/39 | GitHub Issue #39}
@ -314,14 +316,14 @@ async function throwBait(scene: BattleScene, pokemon: EnemyPokemon): Promise<boo
return new Promise(resolve => { return new Promise(resolve => {
scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`);
scene.time.delayedCall(512, () => { scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[0], () => {
scene.playSound("pb_throw"); scene.playSound("pb_throw");
// Trainer throw frames // Trainer throw frames
scene.trainer.setFrame("2"); scene.trainer.setFrame("2");
scene.time.delayedCall(184, () => { scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[1], () => {
scene.trainer.setFrame("3"); scene.trainer.setFrame("3");
scene.time.delayedCall(768, () => { scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[2], () => {
scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`);
}); });
}); });
@ -380,14 +382,14 @@ async function throwMud(scene: BattleScene, pokemon: EnemyPokemon): Promise<bool
return new Promise(resolve => { return new Promise(resolve => {
scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`); scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back_pb`);
scene.time.delayedCall(512, () => { scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[0], () => {
scene.playSound("pb_throw"); scene.playSound("pb_throw");
// Trainer throw frames // Trainer throw frames
scene.trainer.setFrame("2"); scene.trainer.setFrame("2");
scene.time.delayedCall(184, () => { scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[1], () => {
scene.trainer.setFrame("3"); scene.trainer.setFrame("3");
scene.time.delayedCall(768, () => { scene.time.delayedCall(TRAINER_THROW_ANIMATION_TIMES[2], () => {
scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`); scene.trainer.setTexture(`trainer_${scene.gameData.gender === PlayerGender.FEMALE ? "f" : "m"}_back`);
}); });
}); });

View File

@ -16,16 +16,16 @@ import { getPokemonSpecies } from "#app/data/pokemon-species";
import { PartyHealPhase } from "#app/phases"; import { PartyHealPhase } from "#app/phases";
/** i18n namespace for the encounter */ /** i18n namespace for the encounter */
const namespace = "mysteryEncounter:sleeping_snorlax"; const namespace = "mysteryEncounter:slumberingSnorlax";
/** /**
* Sleeping Snorlax encounter. * Sleeping Snorlax encounter.
* @see {@link https://github.com/AsdarDevelops/PokeRogue-Events/issues/103 | GitHub Issue #103} * @see {@link https://github.com/AsdarDevelops/PokeRogue-Events/issues/103 | GitHub Issue #103}
* @see For biome requirements check [mysteryEncountersByBiome](../mystery-encounters.ts) * @see For biome requirements check [mysteryEncountersByBiome](../mystery-encounters.ts)
*/ */
export const SleepingSnorlaxEncounter: IMysteryEncounter = export const SlumberingSnorlaxEncounter: IMysteryEncounter =
MysteryEncounterBuilder.withEncounterType( MysteryEncounterBuilder.withEncounterType(
MysteryEncounterType.SLEEPING_SNORLAX MysteryEncounterType.SLUMBERING_SNORLAX
) )
.withEncounterTier(MysteryEncounterTier.GREAT) .withEncounterTier(MysteryEncounterTier.GREAT)
.withSceneWaveRangeRequirement(10, 180) // waves 10 to 180 .withSceneWaveRangeRequirement(10, 180) // waves 10 to 180
@ -44,7 +44,7 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter =
]) ])
.withIntroDialogue([ .withIntroDialogue([
{ {
text: `${namespace}_intro_message`, text: `${namespace}:intro`,
}, },
]) ])
.withOnInit((scene: BattleScene) => { .withOnInit((scene: BattleScene) => {
@ -70,16 +70,16 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter =
return true; return true;
}) })
.withTitle(`${namespace}_title`) .withTitle(`${namespace}:title`)
.withDescription(`${namespace}_description`) .withDescription(`${namespace}:description`)
.withQuery(`${namespace}_query`) .withQuery(`${namespace}:query`)
.withSimpleOption( .withSimpleOption(
{ {
buttonLabel: `${namespace}_option_1_label`, buttonLabel: `${namespace}:option:1:label`,
buttonTooltip: `${namespace}_option_1_tooltip`, buttonTooltip: `${namespace}:option:1:tooltip`,
selected: [ selected: [
{ {
text: `${namespace}_option_1_selected_message`, text: `${namespace}:option:1:selected`,
}, },
], ],
}, },
@ -105,11 +105,11 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter =
) )
.withSimpleOption( .withSimpleOption(
{ {
buttonLabel: `${namespace}_option_2_label`, buttonLabel: `${namespace}:option:2:label`,
buttonTooltip: `${namespace}_option_2_tooltip`, buttonTooltip: `${namespace}:option:2:tooltip`,
selected: [ selected: [
{ {
text: `${namespace}_option_2_selected_message`, text: `${namespace}:option:2:selected`,
}, },
], ],
}, },
@ -117,7 +117,7 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter =
// Fall asleep waiting for Snorlax // Fall asleep waiting for Snorlax
// Full heal party // Full heal party
scene.unshiftPhase(new PartyHealPhase(scene, true)); scene.unshiftPhase(new PartyHealPhase(scene, true));
queueEncounterMessage(scene, `${namespace}_option_2_good_result`); queueEncounterMessage(scene, `${namespace}:option:2:rest_result`);
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
} }
) )
@ -126,15 +126,19 @@ export const SleepingSnorlaxEncounter: IMysteryEncounter =
.withOptionMode(EncounterOptionMode.DISABLED_OR_SPECIAL) .withOptionMode(EncounterOptionMode.DISABLED_OR_SPECIAL)
.withPrimaryPokemonRequirement(new MoveRequirement(STEALING_MOVES)) .withPrimaryPokemonRequirement(new MoveRequirement(STEALING_MOVES))
.withDialogue({ .withDialogue({
buttonLabel: `${namespace}_option_3_label`, buttonLabel: `${namespace}:option:3:label`,
buttonTooltip: `${namespace}_option_3_tooltip`, buttonTooltip: `${namespace}:option:3:tooltip`,
disabledButtonTooltip: `${namespace}_option_3_disabled_tooltip`, disabledButtonTooltip: `${namespace}:option:3:disabled_tooltip`,
selected: [
{
text: `${namespace}:option:3:selected`
}
]
}) })
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
// Steal the Snorlax's Leftovers // Steal the Snorlax's Leftovers
const instance = scene.currentBattle.mysteryEncounter; const instance = scene.currentBattle.mysteryEncounter;
setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [modifierTypes.LEFTOVERS], fillRemaining: false }); setEncounterRewards(scene, { guaranteedModifierTypeFuncs: [modifierTypes.LEFTOVERS], fillRemaining: false });
queueEncounterMessage(scene, `${namespace}_option_3_good_result`);
// Snorlax exp to Pokemon that did the stealing // Snorlax exp to Pokemon that did the stealing
setEncounterExp(scene, instance.primaryPokemon.id, getPokemonSpecies(Species.SNORLAX).baseExp); setEncounterExp(scene, instance.primaryPokemon.id, getPokemonSpecies(Species.SNORLAX).baseExp);
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);

View File

@ -1,31 +1,28 @@
export const sleepingSnorlaxDialogue = { export const slumberingSnorlaxDialogue = {
intro: "Wandering aimlessly through the sea, you've effectively gotten nowhere.", intro: `As you walk down a narrow pathway, you see a towering silhouette blocking your path.
title: "Lost at Sea", $You get closer to see a Snorlax sleeping peacefully.\nIt seems like there's no way around it.`,
description: "The sea is turbulent in this area, and you're running out of energy.\nThis is bad. Is there a way out of the situation?", title: "Slumbering Snorlax",
description: "You could attack it to try and get it to move, or simply wait for it to wake up. Who knows how long that could take, though...",
query: "What will you do?", query: "What will you do?",
option: { option: {
1: { 1: {
label: "{{option1PrimaryName}} can help", label: "Battle it",
label_disabled: "Can't {{option1RequiredMove}}", tooltip: "(-) Fight Sleeping Snorlax\n(+) Special Reward",
tooltip: "(+) {{option1PrimaryName}} saves you\n(+) {{option1PrimaryName}} gains some EXP", selected: "You approach the\nPokémon without fear.",
tooltip_disabled: "You have no Pokémon to {{option1RequiredMove}} on",
selected: `{{option1PrimaryName}} swims ahead, guiding you back on track.
\${{option1PrimaryName}} seems to also have gotten stronger in this time of need!`,
}, },
2: { 2: {
label: "{{option2PrimaryName}} can help", label: "Wait for it to move",
label_disabled: "Can't {{option2RequiredMove}}", tooltip: "(-) Wait a Long Time\n(+) Recover Party",
tooltip: "(+) {{option2PrimaryName}} saves you\n(+) {{option2PrimaryName}} gains some EXP", selected: `.@d{32}.@d{32}.@d{32}
tooltip_disabled: "You have no Pokémon to {{option2RequiredMove}} with", $You wait for a time, but the Snorlax's yawns make your party sleepy...`,
selected: `{{option2PrimaryName}} flies ahead of your boat, guiding you back on track. rest_result: "When you all awaken, the Snorlax is no where to be found -\nbut your Pokémon are all healed!",
\${{option2PrimaryName}} seems to also have gotten stronger in this time of need!`,
}, },
3: { 3: {
label: "Wander aimlessly", label: "Steal its item",
tooltip: "(-) Each of your Pokémon lose {{damagePercentage}}% of their total HP", tooltip: "(+) {{option3PrimaryName}} uses {{option3PrimaryMove}}\n(+) Special Reward",
selected: `You float about in the boat, steering without direction until you finally spot a landmark you remember. disabled_tooltip: "Your Pokémon need to know certain moves to choose this",
$You and your Pokémon are fatigued from the whole ordeal.`, selected: `Your {{option3PrimaryName}} uses {{option3PrimaryMove}}!
$@s{item_fanfare}It steals Leftovers off the sleeping\nSnorlax and you make out like bandits!`,
}, },
}, }
outro: "You are back on track."
}; };