mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-11-27 09:16:03 +00:00
ME: add damage/heal application utils
This commit is contained in:
parent
93fbb0e401
commit
47f12b665b
@ -1,4 +1,4 @@
|
|||||||
import i18next from "i18next";
|
import i18next, { ParseKeys } from "i18next";
|
||||||
import { BattleType } from "#app/battle";
|
import { BattleType } from "#app/battle";
|
||||||
import BattleScene from "../../battle-scene";
|
import BattleScene from "../../battle-scene";
|
||||||
import PokemonSpecies, { getPokemonSpecies, speciesStarters } from "../pokemon-species";
|
import PokemonSpecies, { getPokemonSpecies, speciesStarters } from "../pokemon-species";
|
||||||
@ -179,7 +179,7 @@ function getTextWithDialogueTokens(scene: BattleScene, textKey: TemplateStringsA
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let textString: string = i18next.t(textKey);
|
let textString: string = i18next.t(textKey as ParseKeys);
|
||||||
|
|
||||||
// Apply dialogue tokens
|
// Apply dialogue tokens
|
||||||
const dialogueTokens = scene.currentBattle?.mysteryEncounter?.dialogueTokens;
|
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}`);
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user