Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Sep 10, 2024
1 parent 350c7c5 commit 5e4692a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/structures/Bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ export default class Bank {
this.map = this.makeFromInitialBank(initialBank);
}

private resolveItemID(item: Item | string | number): number {
if (typeof item === "number") return item;
if (typeof item === "string") return itemID(item);
return item.id;
}

public clear(item?: Item | string | number): this {
if (this.frozen) throw new Error(frozenErrorStr);
if (item) {
this.set(this.resolveItemID(item), 0);
return this;
}
this.map.clear();
return this;
}

private makeFromInitialBank(initialBank?: IntKeyBank | ItemBank | Bank) {
if (!initialBank) return new Map();
if (initialBank instanceof Bank) {
Expand Down Expand Up @@ -190,6 +206,7 @@ export default class Bank {
public items(): [Item, number][] {
const arr: [Item, number][] = [];
for (const [key, val] of this.map.entries()) {
if (val < 1) continue;
arr.push([Items.get(key)!, val]);
}
return arr;
Expand Down
2 changes: 1 addition & 1 deletion src/structures/LootTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default class LootTable {
}

roll(quantity?: number): Bank;
roll(quantity: number, options: { targetBank: undefined } & LootTableRollOptions): Bank;
roll(quantity: number, options: { targetBank?: undefined } & LootTableRollOptions): Bank;
roll(quantity: number, options: { targetBank: Bank } & LootTableRollOptions): null;
public roll(quantity = 1, options: LootTableRollOptions = {}): Bank | null {
const loot = options.targetBank ?? new Bank();
Expand Down

0 comments on commit 5e4692a

Please sign in to comment.