Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/systems/InventorySystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { emptyEquipStats, type EquipStats } from './CombatSystem';
const MAX_INVENTORY = 100;
const MAX_STASH = 80;

function randomHex(bytes: number): string {
return Array.from(globalThis.crypto.getRandomValues(new Uint8Array(bytes)))
.map(b => b.toString(16).padStart(2, '0'))
.join('');
}

export class InventorySystem {
inventory: ItemInstance[] = [];
equipment: Partial<Record<EquipSlot, ItemInstance>> = {};
Expand Down Expand Up @@ -346,7 +352,7 @@ export class InventorySystem {
// Create an inventory item for the gem
const gemBase = getItemBase(gem.gemId);
const gemItem: ItemInstance = {
uid: `gem_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`,
uid: `gem_${Date.now()}_${randomHex(4)}`,
baseId: gem.gemId,
name: gem.name,
quality: 'normal',
Expand Down
Loading