mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-10-19 19:45:51 +02:00
27 lines
693 B
TypeScript
27 lines
693 B
TypeScript
import { allHeldItems } from "#app/modifier/held-items";
|
|
import type { HeldItemType } from "#app/modifier/held-items";
|
|
|
|
export class PokemonItemManager {
|
|
private heldItems: [HeldItemType, number][];
|
|
|
|
constructor() {
|
|
this.heldItems = [];
|
|
}
|
|
|
|
getHeldItems(): [HeldItemType, number][] {
|
|
return this.heldItems;
|
|
}
|
|
|
|
addHeldItem(itemType: HeldItemType, stack: number) {
|
|
const maxStack = allHeldItems[itemType].getMaxStackCount();
|
|
|
|
const existing = this.heldItems.find(([type]) => type === itemType);
|
|
|
|
if (existing) {
|
|
existing[1] = Math.min(existing[1] + stack, maxStack);
|
|
} else {
|
|
this.heldItems.push([itemType, Math.min(stack, maxStack)]);
|
|
}
|
|
}
|
|
}
|