HeldItem .apply() methods do not really need the stack as input, just the pokemon

This commit is contained in:
Wlowscha 2025-06-01 20:21:33 +02:00
parent 41a4c9ec2d
commit da18bf6ea9
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
3 changed files with 12 additions and 9 deletions

View File

@ -55,7 +55,8 @@ export class AttackTypeBoosterHeldItem extends HeldItem {
return `${HeldItemNames[this.type]?.toLowerCase()}`;
}
apply(stackCount: number, moveType: PokemonType, movePower: NumberHolder): void {
apply(pokemon: Pokemon, moveType: PokemonType, movePower: NumberHolder): void {
const stackCount = pokemon.heldItemManager.getStack(this.type);
if (moveType === this.moveType && movePower.value >= 1) {
movePower.value = Math.floor(movePower.value * (1 + stackCount * this.powerBoost));
}
@ -64,9 +65,9 @@ export class AttackTypeBoosterHeldItem extends HeldItem {
export function applyAttackTypeBoosterHeldItem(pokemon: Pokemon, moveType: PokemonType, movePower: NumberHolder) {
if (pokemon) {
for (const [item, props] of Object.entries(pokemon.heldItemManager.getHeldItems())) {
for (const item of Object.keys(pokemon.heldItemManager.getHeldItems())) {
if (allHeldItems[item] instanceof AttackTypeBoosterHeldItem) {
allHeldItems[item].apply(props.stack, moveType, movePower);
allHeldItems[item].apply(pokemon, moveType, movePower);
}
}
}

View File

@ -25,7 +25,8 @@ export class HitHealHeldItem extends HeldItem {
* @param pokemon The {@linkcode Pokemon} that holds the item
* @returns `true` if the {@linkcode Pokemon} was healed
*/
apply(stackCount: number, pokemon: Pokemon): boolean {
apply(pokemon: Pokemon): boolean {
const stackCount = pokemon.heldItemManager.getStack(this.type);
if (pokemon.turnData.totalDamageDealt && !pokemon.isFullHp()) {
// TODO: this shouldn't be undefined AFAIK
globalScene.unshiftPhase(
@ -46,9 +47,9 @@ export class HitHealHeldItem extends HeldItem {
export function applyHitHealHeldItem(pokemon: Pokemon) {
if (pokemon) {
for (const [item, props] of Object.entries(pokemon.heldItemManager.getHeldItems())) {
for (const item of Object.keys(pokemon.heldItemManager.getHeldItems())) {
if (allHeldItems[item] instanceof HitHealHeldItem) {
allHeldItems[item].apply(props.stack, pokemon);
allHeldItems[item].apply(pokemon);
}
}
}

View File

@ -20,7 +20,8 @@ export class TurnHealHeldItem extends HeldItem {
return "leftovers";
}
apply(stackCount: number, pokemon: Pokemon): boolean {
apply(pokemon: Pokemon): boolean {
const stackCount = pokemon.heldItemManager.getStack(this.type);
if (pokemon.isFullHp()) {
return false;
}
@ -41,9 +42,9 @@ export class TurnHealHeldItem extends HeldItem {
export function applyTurnHealHeldItem(pokemon: Pokemon) {
if (pokemon) {
for (const [item, props] of Object.entries(pokemon.heldItemManager.getHeldItems())) {
for (const item of Object.keys(pokemon.heldItemManager.getHeldItems())) {
if (allHeldItems[item] instanceof TurnHealHeldItem) {
allHeldItems[item].apply(props.stack, pokemon);
allHeldItems[item].apply(pokemon);
}
}
}