Skip to content

Commit

Permalink
Fix incorrect quantity drops
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Dec 6, 2024
1 parent affc8c8 commit 25613c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SulphurNaguaTable = new LootTable()
.add('Fire rune', [10, 40], 26)
.add('Fire rune', [40, 60], 14)
.add('Chaos rune', [40, 60], 11)
.add('Nature rune', [50, 10], 4)
.add('Nature rune', [5, 10], 4)
.add('Death rune', [40, 60], 2)

.add('Iron ore', [5, 10], 27)
Expand Down
6 changes: 5 additions & 1 deletion packages/oldschooljs/src/structures/LootTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ export default class LootTable {

public add(
item: LootTable | number | string,
quantity: number[] | number = 1,
quantity: [number, number] | number = 1,
weight = 1,
options?: LootTableMoreOptions
): this {
if (this.limit && weight + this.totalWeight > this.limit) {
throw new Error('Loot table total weight exceeds limit');
}
if (Array.isArray(quantity) && (quantity.length !== 2 || quantity[0] > quantity[1])) {
throw new Error(`Invalid quantity array: ${quantity}`);
}

if (typeof item === 'string') {
return this.add(this.resolveName(item), quantity, weight, options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/shadesKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const GoldChest = new LootTable({ limit: 143 })
.add('Redwood logs', [5, 14], 2)
.add('Dragonstone', 1, 2)
.add('Clue scroll (elite)', 1, 1)
.add('Coins', [1, 3, 160]);
.add('Coins', [1, 3160]);

const chests = [
{
Expand Down

0 comments on commit 25613c3

Please sign in to comment.