mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-30 13:33:01 +02:00
Added some utility functions to check if an item fits a list of items/categories, or to filter out which held items fit
This commit is contained in:
parent
b975382f73
commit
6a4e4a345d
@ -121,10 +121,21 @@ export const HeldItemCategoryId = {
|
||||
|
||||
export type HeldItemCategoryId = (typeof HeldItemCategoryId)[keyof typeof HeldItemCategoryId];
|
||||
|
||||
const ITEM_CATEGORY_MASK = 0xFF00
|
||||
|
||||
function getHeldItemCategory(itemId: HeldItemId): HeldItemCategoryId {
|
||||
return itemId & 0xFF00;
|
||||
return itemId & ITEM_CATEGORY_MASK;
|
||||
}
|
||||
|
||||
export function isItemInCategory(itemId: HeldItemId, category: HeldItemCategoryId): boolean {
|
||||
return getHeldItemCategory(itemId) === category;
|
||||
}
|
||||
}
|
||||
|
||||
export function isItemInRequested(
|
||||
itemId: HeldItemId,
|
||||
requestedItems: (HeldItemCategoryId | HeldItemId)[]
|
||||
): boolean {
|
||||
return requestedItems.some(entry => {
|
||||
itemId === entry || (itemId & ITEM_CATEGORY_MASK) === entry
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { allHeldItems } from "#app/items/all-held-items";
|
||||
import type { HeldItemId } from "#app/enums/held-item-id";
|
||||
import type { FormChangeItem } from "#app/data/pokemon-forms";
|
||||
import { isItemInRequested, type HeldItemCategoryId, type HeldItemId } from "#app/enums/held-item-id";
|
||||
import type { FormChangeItem } from "#enums/form-change-item";
|
||||
import type { BASE_STAT_TOTAL_DATA } from "#app/items/held-items/base-stat-total";
|
||||
import type { BASE_STAT_FLAT_DATA } from "#app/items/held-items/base-stat-flat";
|
||||
|
||||
@ -102,6 +102,11 @@ export class PokemonItemManager {
|
||||
}
|
||||
}
|
||||
|
||||
filterRequestedItems(requestedItems: (HeldItemCategoryId | HeldItemId)[], transferableOnly = true, exclude = false) {
|
||||
const currentItems = transferableOnly ? this.getTransferableHeldItems() : this.getHeldItems();
|
||||
return currentItems.filter(it => !exclude && isItemInRequested(it, requestedItems));
|
||||
}
|
||||
|
||||
addFormChangeItem(id: FormChangeItem) {
|
||||
if (!(id in this.formChangeItems)) {
|
||||
this.formChangeItems[id] = { active: false };
|
||||
|
Loading…
Reference in New Issue
Block a user