mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-11-25 12:38:19 +01:00
89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
import type Pokemon from "#app/field/pokemon";
|
|
import { HeldItemId } from "#enums/held-item-id";
|
|
import { getStatKey, type PermanentStat, Stat } from "#enums/stat";
|
|
import i18next from "i18next";
|
|
import { HeldItem, ITEM_EFFECT } from "../held-item";
|
|
import type { STAT_BOOST_PARAMS } from "./stat-booster";
|
|
|
|
export interface BASE_STAT_BOOSTER_PARAMS {
|
|
/** The pokemon with the item */
|
|
pokemon: Pokemon;
|
|
baseStats: number[];
|
|
}
|
|
|
|
interface PermanentStatToHeldItemMap {
|
|
[key: number]: HeldItemId;
|
|
}
|
|
|
|
export const permanentStatToHeldItem: PermanentStatToHeldItemMap = {
|
|
[Stat.HP]: HeldItemId.HP_UP,
|
|
[Stat.ATK]: HeldItemId.PROTEIN,
|
|
[Stat.DEF]: HeldItemId.IRON,
|
|
[Stat.SPATK]: HeldItemId.CALCIUM,
|
|
[Stat.SPDEF]: HeldItemId.ZINC,
|
|
[Stat.SPD]: HeldItemId.CARBOS,
|
|
};
|
|
|
|
export const statBoostItems: Record<PermanentStat, string> = {
|
|
[Stat.HP]: "hp_up",
|
|
[Stat.ATK]: "protein",
|
|
[Stat.DEF]: "iron",
|
|
[Stat.SPATK]: "calcium",
|
|
[Stat.SPDEF]: "zinc",
|
|
[Stat.SPD]: "carbos",
|
|
};
|
|
|
|
export class BaseStatBoosterHeldItem extends HeldItem {
|
|
public effects: ITEM_EFFECT[] = [ITEM_EFFECT.BASE_STAT_BOOSTER];
|
|
public stat: PermanentStat;
|
|
|
|
constructor(type: HeldItemId, maxStackCount = 1, stat: PermanentStat) {
|
|
super(type, maxStackCount);
|
|
this.stat = stat;
|
|
}
|
|
|
|
get name(): string {
|
|
return i18next.t(`modifierType:BaseStatBoosterItem.${statBoostItems[this.stat]}`);
|
|
}
|
|
|
|
get description(): string {
|
|
return i18next.t("modifierType:ModifierType.BaseStatBoosterModifierType.description", {
|
|
stat: i18next.t(getStatKey(this.stat)),
|
|
});
|
|
}
|
|
|
|
get iconName(): string {
|
|
return statBoostItems[this.stat];
|
|
}
|
|
|
|
/**
|
|
* Checks if {@linkcode BaseStatModifier} should be applied to the specified {@linkcode Pokemon}.
|
|
* @param _pokemon the {@linkcode Pokemon} to be modified
|
|
* @param baseStats the base stats of the {@linkcode Pokemon}
|
|
* @returns `true` if the {@linkcode Pokemon} should be modified
|
|
*/
|
|
// override shouldApply(_pokemon?: Pokemon, baseStats?: number[]): boolean {
|
|
// return super.shouldApply(_pokemon, baseStats) && Array.isArray(baseStats);
|
|
// }
|
|
|
|
/**
|
|
* Applies the {@linkcode BaseStatModifier} to the specified {@linkcode Pokemon}.
|
|
* @param _pokemon the {@linkcode Pokemon} to be modified
|
|
* @param baseStats the base stats of the {@linkcode Pokemon}
|
|
* @returns always `true`
|
|
*/
|
|
apply(params: BASE_STAT_BOOSTER_PARAMS): boolean {
|
|
const pokemon = params.pokemon;
|
|
const stackCount = pokemon.heldItemManager.getStack(this.type);
|
|
const baseStats = params.baseStats;
|
|
baseStats[this.stat] = Math.floor(baseStats[this.stat] * (1 + stackCount * 0.1));
|
|
return true;
|
|
}
|
|
|
|
getMaxStackCount(params: STAT_BOOST_PARAMS): number {
|
|
const pokemon = params.pokemon;
|
|
const stackCount = pokemon.heldItemManager.getStack(this.type);
|
|
return stackCount;
|
|
}
|
|
}
|