mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-30 21:42:20 +02:00
Introducing a PokemonItemManager class
This commit is contained in:
parent
24845bcf82
commit
dfc0d29ec9
26
src/field/pokemon-item-manager.ts
Normal file
26
src/field/pokemon-item-manager.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -259,7 +259,7 @@ import { MoveFlags } from "#enums/MoveFlags";
|
|||||||
import { timedEventManager } from "#app/global-event-manager";
|
import { timedEventManager } from "#app/global-event-manager";
|
||||||
import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader";
|
import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader";
|
||||||
import { ResetStatusPhase } from "#app/phases/reset-status-phase";
|
import { ResetStatusPhase } from "#app/phases/reset-status-phase";
|
||||||
import { allHeldItems, HeldItemType } from "#app/modifier/held-items";
|
import { PokemonItemManager } from "./pokemon-item-manager";
|
||||||
|
|
||||||
export enum LearnMoveSituation {
|
export enum LearnMoveSituation {
|
||||||
MISC,
|
MISC,
|
||||||
@ -342,7 +342,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
|
|
||||||
private shinySparkle: Phaser.GameObjects.Sprite;
|
private shinySparkle: Phaser.GameObjects.Sprite;
|
||||||
|
|
||||||
private heldItems: [HeldItemType, number][] = [];
|
public heldItemManager: PokemonItemManager;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
x: number,
|
x: number,
|
||||||
@ -537,6 +537,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
if (!dataSource) {
|
if (!dataSource) {
|
||||||
this.calculateStats();
|
this.calculateStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.heldItemManager = new PokemonItemManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1189,22 +1191,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
) as PokemonHeldItemModifier[];
|
) as PokemonHeldItemModifier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeldItems2(): [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)]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateScale(): void {
|
updateScale(): void {
|
||||||
this.setScale(this.getSpriteScale());
|
this.setScale(this.getSpriteScale());
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ export class AttackTypeBoosterHeldItemAttr extends HeldItemAttr {
|
|||||||
|
|
||||||
export function applyHeldItemAttrs(attrType: Constructor<HeldItemAttr>, pokemon: Pokemon, ...args: any[]) {
|
export function applyHeldItemAttrs(attrType: Constructor<HeldItemAttr>, pokemon: Pokemon, ...args: any[]) {
|
||||||
if (pokemon) {
|
if (pokemon) {
|
||||||
for (const [item, stackCount] of pokemon.getHeldItems2()) {
|
for (const [item, stackCount] of pokemon.heldItemManager.getHeldItems()) {
|
||||||
if (allHeldItems[item].hasAttr(attrType)) {
|
if (allHeldItems[item].hasAttr(attrType)) {
|
||||||
attrType.apply(stackCount, ...args);
|
attrType.apply(stackCount, ...args);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user