ME: add damage/heal application utils

This commit is contained in:
Felix Staud 2024-07-11 09:23:43 -07:00
parent 93fbb0e401
commit 47f12b665b
1 changed files with 51 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import i18next from "i18next";
import i18next, { ParseKeys } from "i18next";
import { BattleType } from "#app/battle";
import BattleScene from "../../battle-scene";
import PokemonSpecies, { getPokemonSpecies, speciesStarters } from "../pokemon-species";
@ -179,7 +179,7 @@ function getTextWithDialogueTokens(scene: BattleScene, textKey: TemplateStringsA
return null;
}
let textString: string = i18next.t(textKey);
let textString: string = i18next.t(textKey as ParseKeys);
// Apply dialogue tokens
const dialogueTokens = scene.currentBattle?.mysteryEncounter?.dialogueTokens;
@ -821,3 +821,52 @@ export function calculateMEAggregateStats(scene: BattleScene, baseSpawnWeight: n
console.log(`Starting weight: ${baseSpawnWeight}\nAverage MEs per run: ${totalMean}\nStandard Deviation: ${totalStd}\nAvg Commons: ${commonMean}\nAvg Uncommons: ${uncommonMean}\nAvg Rares: ${rareMean}\nAvg Super Rares: ${superRareMean}`);
}
/**
* Handles applying hp changes to a player pokemon.
* Takes care of not going below `0`, above max-hp, adding `FNT` status correctly and updating the pokemon info.
* TODO: handle special cases like wonder-guard/ninjask
*
* @param pokemon the player pokemon to apply the hp change to
* @param damage the hp change amount. Positive for heal. Negative for damage
*
*/
function applyHpChangeToPokemon(pokemon: PlayerPokemon, value: number) {
const hpChange = Math.round(pokemon.hp + value);
const nextHp = Math.max(Math.min(hpChange, pokemon.getMaxHp()), 0);
if (nextHp === 0) {
koPlayerPokemon(pokemon);
} else {
pokemon.hp = nextHp;
}
}
/**
* Handles applying damage to a player pokemon
*
* @param pokemon the player pokemon to apply damage to
* @param damage the amount of damage to apply
* @see {@linkcode applyHpChangeToPokemon}
*/
export function applyDamageToPokemon(pokemon: PlayerPokemon, damage: number) {
if (damage <= 0) {
console.warn("Healing pokemon with `applyDamageToPokemon` is not recommended! Please use `applyHealToPokemon` instead.");
}
applyHpChangeToPokemon(pokemon, -damage);
}
/**
* Handles applying heal to a player pokemon
*
* @param pokemon the player pokemon to apply heal to
* @param heal the amount of heal to apply
* @see {@linkcode applyHpChangeToPokemon}
*/
export function applyHealToPokemon(pokemon: PlayerPokemon, heal: number) {
if (heal <= 0) {
console.warn("Damaging pokemong with `applyHealToPokemon` is not recommended! Please use `applyDamageToPokemon` instead.");
}
applyHpChangeToPokemon(pokemon, heal);
}