lost at sea encounter finishing touches

This commit is contained in:
Felix Staud 2024-07-11 10:30:26 -07:00
parent 85df834811
commit 5a79b50f1d
3 changed files with 61 additions and 28 deletions

View File

@ -5,8 +5,8 @@ const namepsace = "mysteryEncounter:lostAtSea";
export const LostAtSeaDialogue: MysteryEncounterDialogue = { export const LostAtSeaDialogue: MysteryEncounterDialogue = {
intro: [ intro: [
{ {
text: `${namepsace}:intro` text: `${namepsace}:intro`,
} },
], ],
encounterOptionsDialogue: { encounterOptionsDialogue: {
title: `${namepsace}:title`, title: `${namepsace}:title`,
@ -42,9 +42,4 @@ export const LostAtSeaDialogue: MysteryEncounterDialogue = {
}, },
], ],
}, },
outro: [
{
text: `${namepsace}:outro`,
},
],
}; };

View File

@ -8,7 +8,11 @@ import MysteryEncounter, {
MysteryEncounterTier, MysteryEncounterTier,
} from "../mystery-encounter"; } from "../mystery-encounter";
import { MysteryEncounterOptionBuilder } from "../mystery-encounter-option"; import { MysteryEncounterOptionBuilder } from "../mystery-encounter-option";
import { leaveEncounterWithoutBattle } from "../mystery-encounter-utils"; import {
applyDamageToPokemon,
leaveEncounterWithoutBattle,
setEncounterExp,
} from "../mystery-encounter-utils";
/** /**
* Damage percentage taken when wandering aimlessly. * Damage percentage taken when wandering aimlessly.
@ -17,9 +21,12 @@ import { leaveEncounterWithoutBattle } from "../mystery-encounter-utils";
*/ */
const DAMAGE_PERCENTAGE: number = 30; // 0 - 100 const DAMAGE_PERCENTAGE: number = 30; // 0 - 100
let waterPkm: PlayerPokemon;
let flyingPkm: PlayerPokemon;
/** /**
* Lost at sea encounter. * Lost at sea encounter.
* @see {@link https://github.com/AsdarDevelops/PokeRogue-Events/issues/9|GitHub Issue #9} * @see {@link https://github.com/AsdarDevelops/PokeRogue-Events/issues/9 | GitHub Issue #9}
* @see For biome requirements check [mysteryEncountersByBiome](../mystery-encounters.ts) * @see For biome requirements check [mysteryEncountersByBiome](../mystery-encounters.ts)
*/ */
export const LostAtSeaEncounter: MysteryEncounter = export const LostAtSeaEncounter: MysteryEncounter =
@ -39,7 +46,9 @@ export const LostAtSeaEncounter: MysteryEncounter =
]) ])
.withSceneWaveRangeRequirement(11, 179) .withSceneWaveRangeRequirement(11, 179)
.withOnInit((scene: BattleScene) => { .withOnInit((scene: BattleScene) => {
const party = scene.getParty(); const allowedPokemon = scene
.getParty()
.filter((p) => p.isAllowedInBattle());
const { mysteryEncounter } = scene.currentBattle; const { mysteryEncounter } = scene.currentBattle;
mysteryEncounter.setDialogueToken( mysteryEncounter.setDialogueToken(
@ -48,11 +57,11 @@ export const LostAtSeaEncounter: MysteryEncounter =
); );
// check for water pokemon // check for water pokemon
const waterPkm = findPokemonByType(party, Type.WATER); waterPkm = findPokemonByType(allowedPokemon, Type.WATER);
mysteryEncounter.setDialogueToken("waterPkm", waterPkm?.name ?? "<NONE>"); mysteryEncounter.setDialogueToken("waterPkm", waterPkm?.name ?? "<NONE>");
// check for flying pokemon // check for flying pokemon
const flyingPkm = findPokemonByType(party, Type.FLYING); flyingPkm = findPokemonByType(allowedPokemon, Type.FLYING);
mysteryEncounter.setDialogueToken( mysteryEncounter.setDialogueToken(
"flyingPkm", "flyingPkm",
flyingPkm?.name ?? "<NONE>" flyingPkm?.name ?? "<NONE>"
@ -67,10 +76,9 @@ export const LostAtSeaEncounter: MysteryEncounter =
.withOption( .withOption(
new MysteryEncounterOptionBuilder() new MysteryEncounterOptionBuilder()
.withPokemonTypeRequirement(Type.WATER, true, 1) .withPokemonTypeRequirement(Type.WATER, true, 1)
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) =>
console.debug("Lost at sea: Option 1 - Water Pokemon"); handleGuidingOption(scene, waterPkm)
leaveEncounterWithoutBattle(scene); )
})
.build() .build()
) )
/** /**
@ -80,26 +88,57 @@ export const LostAtSeaEncounter: MysteryEncounter =
.withOption( .withOption(
new MysteryEncounterOptionBuilder() new MysteryEncounterOptionBuilder()
.withPokemonTypeRequirement(Type.FLYING, true, 1) .withPokemonTypeRequirement(Type.FLYING, true, 1)
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) =>
console.debug("Lost at sea: Option 2 - Flying Pokemon"); handleGuidingOption(scene, flyingPkm)
leaveEncounterWithoutBattle(scene); )
})
.build() .build()
) )
/** /**
* Option 3: Wander aimlessly. All pokemons lose 30% of their HP (or KO on 0 HP). * Option 3: Wander aimlessly. All pokemons lose 30% of their HP (or KO on 0 HP).
*/ */
.withOptionPhase(async (scene: BattleScene) => { .withOptionPhase(async (scene: BattleScene) => {
const party = scene.getParty().filter((p) => !p.isFainted()); const allowedPokemon = scene
party.forEach((pkm) => { .getParty()
const damage = Math.round(pkm.getMaxHp() / (DAMAGE_PERCENTAGE / 100)); .filter((p) => p.isAllowedInBattle());
pkm.hp = Math.min(pkm.hp, damage);
allowedPokemon.forEach((pkm) => {
const percentage = DAMAGE_PERCENTAGE / 100;
const damage = Math.floor(pkm.getMaxHp() * percentage);
return applyDamageToPokemon(pkm, damage);
}); });
leaveEncounterWithoutBattle(scene); leaveEncounterWithoutBattle(scene);
return true; return true;
}) })
.build(); .build();
const findPokemonByType = (party: PlayerPokemon[], type: Type) => { /**
* Find a pokemon inside the given party by a given type
*
* @param party player pokemon party
* @param type type to search for
* @returns
*/
function findPokemonByType(party: PlayerPokemon[], type: Type) {
return party.find((p) => p.getTypes(true).includes(type)); return party.find((p) => p.getTypes(true).includes(type));
}; }
/**
* Generic handler for using a guiding pokemon to guide you back.
*
* @param scene Battle scene
* @param guidePokemon pokemon choosen as a guide
*/
function handleGuidingOption(scene: BattleScene, guidePokemon: PlayerPokemon) {
/** Base EXP value for guiding pokemon. Currently Lapras base-value */
const baseExpValue: number = 187;
if (guidePokemon) {
setEncounterExp(scene, guidePokemon.id, baseExpValue, true);
} else {
console.warn(
"Lost at sea: No guide pokemon found but pokemon guides player. huh!?"
);
}
leaveEncounterWithoutBattle(scene);
}

View File

@ -12,7 +12,7 @@ export const lostAtSea = {
selected: "@ec{waterPkm} guides you back and earns EXP.", selected: "@ec{waterPkm} guides you back and earns EXP.",
}, },
2: { 2: {
label: "Use @ec{flyingPkm}", // pkm has to be of type water label: "Use @ec{flyingPkm}", // pkm has to be of type flying
tooltip: tooltip:
"Use @ec{flyingPkm} to guide you back. @ec{flyingPkm} earns EXP as if having defeated a Lapras.", "Use @ec{flyingPkm} to guide you back. @ec{flyingPkm} earns EXP as if having defeated a Lapras.",
selected: "@ec{flyingPkm} guides you back and earns EXP.", selected: "@ec{flyingPkm} guides you back and earns EXP.",
@ -25,5 +25,4 @@ export const lostAtSea = {
"You wander aimlessly around. After hours of wandering, you find your way back. You and your team take the toll.", "You wander aimlessly around. After hours of wandering, you find your way back. You and your team take the toll.",
}, },
}, },
// outro: "TBA: OUTRO MESSAGE",
}; };