1.6 KiB
1.6 KiB
Inventory Module
- Inventory has two hard limits from config: max slots (distinct item types) and max stack size (quantity per item). Both are enforced in
addItemand will throwUserErrorif exceeded. - When quantity reaches 0, the inventory row is deleted (not kept with quantity 0). This means slot count = row count.
buyItemdelegates balance deduction toeconomyService.modifyUserBalancewithin the same transaction to ensure atomicity. Never deduct balance directly when purchasing.- Item usage is driven by a JSON
usageDatafield on the item record. Items withoutusageData.effectscannot be used. Theconsumeflag inusageDatacontrols whether the item is removed after use. - Effect system: effects are validated at runtime via Zod (
EffectPayloadSchema) before execution. The registry maps effect type strings to handler functions. Adding a new effect type requires: (1) add toEffectTypeenum in constants, (2) add Zod schema variant ineffect.types.ts, (3) add handler ineffect.handlers.ts, (4) register ineffect.registry.ts. XP_BOOSTandTEMP_ROLEeffects useuserTimerswith upsert -- activating while already active replaces the timer (does not stack or extend).TEMP_ROLEonly records the timer in DB; actual Discord role assignment must happen in the bot command layer.LOOTBOXeffect uses weighted random selection. Weights are relative, not percentages. ANOTHINGloot type is valid and intentional.- The
getAutocompleteItemsmethod filters to only show items that have usable effects, so non-usable items won't appear in the/useautocomplete.