@adatechnology/game-items 0.2.15 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { BodySlot, SealSpec, DeepPartial, SealState, SealBlock } from '@adatechnology/game-contracts';
1
+ import { BodySlot, SealSpec, DeepPartial, ToolCondition, SealState, SealBlock } from '@adatechnology/game-contracts';
2
2
  export { BodySlot } from '@adatechnology/game-contracts';
3
- import { ItemDef as ItemDef$1, rng, ItemStack, SlotSpec, LootTables } from '@adatechnology/game-interactables';
3
+ import { ItemDef as ItemDef$1, rng, ItemStack as ItemStack$1, SlotSpec, LootTables } from '@adatechnology/game-interactables';
4
4
  export { ItemDef as BaseItemDef } from '@adatechnology/game-interactables';
5
+ import { DestructionSnapshot } from '@adatechnology/game-destruction';
5
6
 
6
7
  /** Traits that pick any item of the catalog ("1 clothing" is any item of the category, "ingredients" is anything cookable). */
7
8
  interface RecipeMatch {
@@ -274,6 +275,14 @@ interface ItemRules {
274
275
  inventory: {
275
276
  /** Slots of a character's bag when no bag item says otherwise. */
276
277
  defaultSlots: number;
278
+ /** Volume of a character's bag, litres, when no bag item says otherwise (pockets and a belt). */
279
+ defaultLitres: number;
280
+ /** Real capacity of each bag item, litres, by item id: a bounding box says little about a soft bag. */
281
+ bagLitres: Readonly<Record<string, number>>;
282
+ /** Inside length, width and height of the default bag, metres: an item longer than this does not go in whatever the litres. */
283
+ defaultInside: readonly [number, number, number];
284
+ /** Inside dimensions of each bag item, metres, by item id. */
285
+ bagInside: Readonly<Record<string, readonly [number, number, number]>>;
277
286
  /** Running speed and breath multiplier while carrying more than `carry.encumbered` of the maximum. */
278
287
  encumberedRunFactor: number;
279
288
  };
@@ -475,19 +484,131 @@ declare const carriedKg: (parts: {
475
484
  }) => number;
476
485
  /** Above 100% of the maximum, running and breath drop 25%; above 150% the character cannot run. */
477
486
  declare const loadState: (loadKg: number, maxKg: number, rules?: ItemRules) => LoadState;
487
+ /** Volume of one unit, litres: the catalog's `volume`, or the bounding box of its size. */
488
+ declare const itemLitres: (item: ItemDef) => number;
478
489
  /** The bag of a character: how many item slots it has and how much it holds. */
479
490
  interface BagOption {
480
491
  slots: number;
481
492
  capacityKg: number;
493
+ /** Volume the bag holds, litres; without it only slots and weight limit the bag. */
494
+ capacityLitres?: number;
495
+ /** Inside length, width and height, metres; without it the shape of the item is not checked. */
496
+ inside?: readonly [number, number, number];
482
497
  }
483
- /** The bag a bag item gives: its `carry.capacityKg` is the slot count the team's game reads from `cap`; the weight limit is the character's. */
498
+ /** The bag a bag item gives: its `carry.capacityKg` is the slot count the team's game reads from `cap`; the weight limit is the character's; the volume is the bag's real litres. */
484
499
  declare const bagOption: (bag: ItemDef | undefined, characterMaxKg: number, rules?: ItemRules) => BagOption;
485
- type TakeResult = 'ok' | 'bag_full' | 'too_heavy';
486
- /** Whether `item` can go into the bag now: first the slots, then the weight. */
500
+ /** Whether a box of `size` goes into a space of `inside` turned any way: its dimensions, longest first, each within the space's. */
501
+ declare const fitsInside: (size: readonly number[], inside: readonly number[]) => boolean;
502
+ type TakeResult = 'ok' | 'bag_full' | 'too_heavy' | 'too_long' | 'too_bulky';
503
+ /** What is being added: `count` units, taking `slotsNeeded` new slots, weighing `weightFactor` of their full weight (`1 - weightReduction` inside a bag). */
504
+ interface TakeOptions {
505
+ count?: number;
506
+ slotsNeeded?: number;
507
+ weightFactor?: number;
508
+ }
509
+ /**
510
+ * Whether `item` can go into the bag now: first the shape against the inside dimensions (an item longer than the bag never goes in, however empty or light the bag is, so that is
511
+ * the reason given before any that depends on what the bag already holds), then the slots, the weight and the volume (when the bag has them).
512
+ */
487
513
  declare const canTake: (item: ItemDef, bag: BagOption, used: {
488
514
  slots: number;
489
515
  loadKg: number;
490
- }) => TakeResult;
516
+ litres?: number;
517
+ }, options?: TakeOptions) => TakeResult;
518
+
519
+ /**
520
+ * Types of the live inventory: slots that each hold one stack or one unique item with its full state, plus one item in hand.
521
+ * The inventory never looks inside the state; it only keeps it and gives it back exactly as it came.
522
+ */
523
+
524
+ /** One object as `DestructionWorld.serializeObject` writes it (spec, state with holes and bend, runtime). */
525
+ type DestructionObjectState = DestructionSnapshot['objects'][number];
526
+ interface AmmoState {
527
+ /** Rounds in the weapon. */
528
+ readonly loaded: number;
529
+ /** Rounds carried for it. */
530
+ readonly reserve: number;
531
+ }
532
+ /** Everything that makes this item different from a fresh one of the same catalog id. */
533
+ interface ItemState {
534
+ readonly destruction?: DestructionObjectState;
535
+ readonly condition?: ToolCondition;
536
+ /** 0..1 worn out. */
537
+ readonly wear?: number;
538
+ readonly temperatureC?: number;
539
+ readonly ammo?: AmmoState;
540
+ }
541
+ /** A stack (a count of the same stateless item) or one unique item (count 1, with its state). */
542
+ interface ItemStack {
543
+ readonly itemId: string;
544
+ readonly count: number;
545
+ readonly state?: ItemState;
546
+ }
547
+ interface InventorySlot extends ItemStack {
548
+ readonly slotId: number;
549
+ }
550
+ type InventoryFailure = 'unknown_item' | 'bad_count' | 'bag_full' | 'too_heavy' | 'too_long' | 'too_bulky' | 'not_found' | 'hand_full' | 'hand_empty';
551
+ type InventoryResult<TSuccess extends object = object> = ({
552
+ readonly ok: true;
553
+ } & TSuccess) | {
554
+ readonly ok: false;
555
+ readonly reason: InventoryFailure;
556
+ };
557
+ interface InventoryOptions {
558
+ /** The catalog items (`ItemsCatalog.items`). */
559
+ items: ReadonlyMap<string, ItemDef>;
560
+ /** Slots, weight limit and volume of the bag (`bagOption`). */
561
+ bag: BagOption;
562
+ /** Share of the weight inside the bag that does not count (`ItemDef.carry.weightReduction` of the bag). */
563
+ weightReduction?: number;
564
+ rules?: ItemRules;
565
+ }
566
+ interface InventoryTotals {
567
+ readonly slots: number;
568
+ readonly kg: number;
569
+ /** Volume inside the bag; the item in hand is not in it. */
570
+ readonly litres: number;
571
+ readonly load: LoadState;
572
+ }
573
+ interface TakeParams {
574
+ readonly itemId: string;
575
+ readonly count?: number;
576
+ readonly state?: ItemState;
577
+ }
578
+ interface Inventory {
579
+ /** Puts an item from the world into the bag. */
580
+ take(params: TakeParams): InventoryResult<{
581
+ slotIds: readonly number[];
582
+ }>;
583
+ /** Puts an item from the world straight into the hand (it takes no slot and no bag volume, only weight). */
584
+ hold(params: Omit<TakeParams, 'count'>): InventoryResult<{
585
+ held: ItemStack;
586
+ }>;
587
+ /** Moves the item in hand back into the bag (unequip). */
588
+ store(): InventoryResult<{
589
+ slotIds: readonly number[];
590
+ }>;
591
+ /** Moves a slot to the hand; returns what is now held. */
592
+ equip(slotId: number): InventoryResult<{
593
+ held: ItemStack;
594
+ }>;
595
+ /** Takes `count` (default all) out of a slot, or the hand when no slot is given, and returns what the world must restore. */
596
+ drop(params?: {
597
+ slotId?: number;
598
+ count?: number;
599
+ }): InventoryResult<{
600
+ dropped: ItemStack;
601
+ }>;
602
+ slots(): readonly InventorySlot[];
603
+ held(): ItemStack | undefined;
604
+ totals(): InventoryTotals;
605
+ }
606
+
607
+ /**
608
+ * A live inventory: slots (one stack or one unique item each), one item in hand, weight and volume limits from the carry rules.
609
+ * Pure: no renderer, no room. Damage and every other state field survive take, store, equip and drop unchanged.
610
+ */
611
+ declare const createInventory: (options: InventoryOptions) => Inventory;
491
612
 
492
613
  interface UseContext {
493
614
  /** State of the food, from `freshness()`. Default `fresh`. */
@@ -674,7 +795,7 @@ declare function createFindsProvider(catalog: ItemsCatalog, options?: FindsProvi
674
795
 
675
796
  interface PlacedFinds {
676
797
  /** One entry per slot, in the order of `slots`; null is empty. */
677
- contents: Array<ItemStack | null>;
798
+ contents: Array<ItemStack$1 | null>;
678
799
  /** Stacks that fit no free slot. */
679
800
  leftover: FindStack[];
680
801
  }
@@ -758,4 +879,4 @@ declare const ARSENAL_CATEGORIES: readonly CategoryDef[];
758
879
  */
759
880
  declare const itemsFromArsenal: (arsenal: ArsenalLike, options?: ArsenalItemsOptions) => ItemPack;
760
881
 
761
- export { ARSENAL_CATEGORIES, type AgeOptions, type AgeState, type ArsenalCaliberLike, type ArsenalItemRecord, type ArsenalItemsOptions, type ArsenalLike, type ArsenalWeaponLike, type AttackKind, BODY_SLOTS, type BagOption, type CarryEntry, type CategoryDef, type Consumption, type ContainerDef, type CraftCheck, type CraftContext, type CraftOutcome, type CraftResult, DEFAULT_RULES, DURABILITY_KINDS, type DepletionRule, type Durability, type DurabilityKind, type FindData, type FindStack, type FindState, type FindsProvider, type FindsProviderOptions, type FindsQuery, type Freshness, type FreshnessEffect, ITEM_CATEGORIES, type ItemCategory, type ItemDef, type ItemPack, type ItemRules, type ItemsCatalog, type ItemsOptions, type LoadLevel, type LoadState, type LootTablesQuery, type NutritionResult, type PlaceDef, type PlaceTag, type PlacedFinds, type PoolEntry, type PoolPick, RARITIES, type Rarity, type RecipeDef, type RecipeInput, type RecipeMatch, type RecipeOutput, type RecipeTool, type Rng, type StorageId, type StorageRule, type StorageRules, type TakeResult, type UseContext, type UseEffectDef, type UseResult, type WornPiece, advanceAge, bagOption, blockChance, canCraft, canTake, carriedKg, chargeLevel, checkItems, craft, createFindsProvider, createItems, depletionFactor, failsToStart, freshness, itemsFromArsenal, loadState, maxLoadKg, moveToStorage, pieceBlock, placeFinds, repairPiece, resolveUse, rollByCategory, rollExplicitPool, scaleCount, shelfRatio, spawnAgeDays, spawnData, storageMultiplier, toLootTables, wearBlocked };
882
+ export { ARSENAL_CATEGORIES, type AgeOptions, type AgeState, type AmmoState, type ArsenalCaliberLike, type ArsenalItemRecord, type ArsenalItemsOptions, type ArsenalLike, type ArsenalWeaponLike, type AttackKind, BODY_SLOTS, type BagOption, type CarryEntry, type CategoryDef, type Consumption, type ContainerDef, type CraftCheck, type CraftContext, type CraftOutcome, type CraftResult, DEFAULT_RULES, DURABILITY_KINDS, type DepletionRule, type DestructionObjectState, type Durability, type DurabilityKind, type FindData, type FindStack, type FindState, type FindsProvider, type FindsProviderOptions, type FindsQuery, type Freshness, type FreshnessEffect, ITEM_CATEGORIES, type Inventory, type InventoryFailure, type InventoryOptions, type InventoryResult, type InventorySlot, type InventoryTotals, type ItemCategory, type ItemDef, type ItemPack, type ItemRules, type ItemStack, type ItemState, type ItemsCatalog, type ItemsOptions, type LoadLevel, type LoadState, type LootTablesQuery, type NutritionResult, type PlaceDef, type PlaceTag, type PlacedFinds, type PoolEntry, type PoolPick, RARITIES, type Rarity, type RecipeDef, type RecipeInput, type RecipeMatch, type RecipeOutput, type RecipeTool, type Rng, type StorageId, type StorageRule, type StorageRules, type TakeOptions, type TakeParams, type TakeResult, type UseContext, type UseEffectDef, type UseResult, type WornPiece, advanceAge, bagOption, blockChance, canCraft, canTake, carriedKg, chargeLevel, checkItems, craft, createFindsProvider, createInventory, createItems, depletionFactor, failsToStart, fitsInside, freshness, itemLitres, itemsFromArsenal, loadState, maxLoadKg, moveToStorage, pieceBlock, placeFinds, repairPiece, resolveUse, rollByCategory, rollExplicitPool, scaleCount, shelfRatio, spawnAgeDays, spawnData, storageMultiplier, toLootTables, wearBlocked };
@@ -37,10 +37,13 @@ var GameItems = (() => {
37
37
  checkItems: () => checkItems,
38
38
  craft: () => craft,
39
39
  createFindsProvider: () => createFindsProvider,
40
+ createInventory: () => createInventory,
40
41
  createItems: () => createItems,
41
42
  depletionFactor: () => depletionFactor,
42
43
  failsToStart: () => failsToStart,
44
+ fitsInside: () => fitsInside,
43
45
  freshness: () => freshness,
46
+ itemLitres: () => itemLitres,
44
47
  itemsFromArsenal: () => itemsFromArsenal,
45
48
  loadState: () => loadState,
46
49
  maxLoadKg: () => maxLoadKg,
@@ -72,15 +75,37 @@ var GameItems = (() => {
72
75
  var DEFERRED_QUEUE_ID = {
73
76
  DESTRUCTION_EVENTS: "destruction.events",
74
77
  BREACH_PAINT: "floorplan.breach-paint",
78
+ BREACH_CUT: "floorplan.breach-cut",
75
79
  AUDIO_VOICES: "audio.voices",
76
- VEHICLE_CREASE: "vehicles.crease"
80
+ VEHICLE_CREASE: "vehicles.crease",
81
+ AUDIO_OCCLUSION: "audio.occlusion",
82
+ FLUID_FILM: "fluids.film",
83
+ VEHICLE_LOD_BATCH: "vehicles.lod-batch",
84
+ SETTLED_BATCH: "destruction.settled-batch",
85
+ STATIC_BATCH: "render.static-batch",
86
+ ANIMALS_STATIC_BATCH: "animals.static-batch",
87
+ CHARACTERS_STATIC_BATCH: "characters.static-batch",
88
+ HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
89
+ DESTRUCTION_PREFIT: "destruction.prefit"
77
90
  };
78
91
  var DEFERRED_PRIORITY = {
79
92
  [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
80
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
93
+ // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
94
+ [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
95
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
81
96
  [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
82
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
97
+ [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
98
+ [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
99
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
100
+ [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
101
+ [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
102
+ [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
103
+ [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
104
+ [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
105
+ [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
106
+ [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
83
107
  };
108
+ var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
84
109
  var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
85
110
  var warnedKeys = () => {
86
111
  const holder = globalThis;
@@ -166,6 +191,165 @@ var GameItems = (() => {
166
191
  var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
167
192
  var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
168
193
  var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
194
+ var WORKER_KIND_ID = {
195
+ GROUND_TILES: "destruction.ground-tiles",
196
+ CROWD_PHYSICS: "crowd.physics",
197
+ PIECE_BOXES: "destruction.piece-boxes",
198
+ STATIC_COLLIDERS: "destruction.static-colliders",
199
+ SHAPES_GENERATE: "shapes.generate",
200
+ WORLD_REGION: "world.region"
201
+ };
202
+ var WORKER_KIND_DEFAULTS = {
203
+ [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
204
+ [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
205
+ [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
206
+ [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
207
+ [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
208
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
209
+ };
210
+
211
+ // src/rules.ts
212
+ var DEFAULT_RULES = {
213
+ rarity: {
214
+ weights: { common: 60, uncommon: 28, rare: 9, very_rare: 2.5, legendary: 0.5, unique: 0 },
215
+ fixedOnly: ["legendary", "unique"]
216
+ },
217
+ freshness: { stale: 0.5, spoiled: 1, rotten: 1.5 },
218
+ storage: {
219
+ fridge: { multiplier: 0.33, needsPower: true },
220
+ freezer: { multiplier: 0.1, needsPower: true },
221
+ cooler: { multiplier: 0.5, limitDays: 2, afterLimit: 1 },
222
+ delivery_bag: { multiplier: 0.8 },
223
+ cellar: { multiplier: 0.66 },
224
+ ambient: { multiplier: 1 },
225
+ hot: { multiplier: 2 }
226
+ },
227
+ carry: { baseKg: 8, perStrengthKg: 2.5, factor: 1.2, encumbered: 1, overloaded: 1.5 },
228
+ protection: { cap: 0.9, wear: { bite: 8, scratch: 3 }, tornShare: 0.25, repairMargin: 10 },
229
+ aging: { thawShelfDays: { freezer: 2 } },
230
+ inventory: {
231
+ defaultSlots: 10,
232
+ encumberedRunFactor: 0.75,
233
+ defaultLitres: 12,
234
+ defaultInside: [0.3, 0.25, 0.16],
235
+ bagInside: {
236
+ shopping_bag: [0.4, 0.35, 0.15],
237
+ trash_bag: [0.6, 0.45, 0.12],
238
+ fanny_pack: [0.22, 0.12, 0.1],
239
+ crossbody_bag: [0.25, 0.2, 0.12],
240
+ backpack: [0.5, 0.3, 0.2],
241
+ delivery_bag: [0.45, 0.45, 0.25],
242
+ hiking_backpack_40l: [0.6, 0.35, 0.19],
243
+ military_backpack: [0.6, 0.35, 0.21],
244
+ trekking_backpack_70l: [0.75, 0.38, 0.25],
245
+ rolling_suitcase: [0.6, 0.4, 0.21],
246
+ tactical_vest: [0.3, 0.2, 0.1],
247
+ tool_belt: [0.4, 0.2, 0.1],
248
+ cooler_box: [0.32, 0.25, 0.23],
249
+ shopping_cart: [0.9, 0.55, 0.16],
250
+ wheelbarrow: [1.2, 0.6, 0.15]
251
+ },
252
+ bagLitres: {
253
+ shopping_bag: 20,
254
+ trash_bag: 30,
255
+ fanny_pack: 3,
256
+ crossbody_bag: 6,
257
+ backpack: 30,
258
+ delivery_bag: 50,
259
+ hiking_backpack_40l: 40,
260
+ military_backpack: 45,
261
+ trekking_backpack_70l: 70,
262
+ rolling_suitcase: 50,
263
+ tactical_vest: 6,
264
+ tool_belt: 8,
265
+ cooler_box: 18,
266
+ shopping_cart: 80,
267
+ wheelbarrow: 100
268
+ }
269
+ },
270
+ use: {
271
+ freshness: {
272
+ stale: { satietyFactor: 0.7, poisonChance: 0.1, morale: 0, isEdible: true },
273
+ spoiled: { satietyFactor: 0.7, poisonChance: 0.5, morale: -20, isEdible: true },
274
+ rotten: { satietyFactor: 0, poisonChance: 0, morale: 0, isEdible: false }
275
+ },
276
+ cookedPoisonFactor: 0.25
277
+ },
278
+ spawn: {
279
+ retailNew: true,
280
+ retailPlaces: ["supermarket", "pharmacy", "mall", "gas_station", "gun_shop"],
281
+ retailContainers: ["store_shelf", "stockroom"],
282
+ condition: { common: [30, 90], uncommon: [40, 90], rare: [50, 100], very_rare: [50, 100], legendary: [50, 100], unique: [50, 100] },
283
+ ageShare: [0, 0.6],
284
+ charge: [0.2, 1],
285
+ fillable: ["fuel_jerrycan"],
286
+ fill: [0, 0.6]
287
+ },
288
+ finds: {
289
+ fallbackContainer: "zombie_corpse",
290
+ rollExcluded: ["ammo_7_62x39"],
291
+ depletion: [
292
+ { places: ["pharmacy", "gun_shop", "police_station"], perDay: 0.05, floor: 0.3 },
293
+ { places: ["supermarket", "gas_station"], perDay: 0.04, floor: 0.35 },
294
+ { places: ["mall", "hospital"], perDay: 0.025, floor: 0.5 },
295
+ { places: ["house", "apartment"], perDay: 0.01, floor: 0.7 },
296
+ { places: ["farm", "warehouse", "mine", "dam", "lodge", "church"], perDay: 5e-3, floor: 0.85 },
297
+ { places: ["military_base"], perDay: 0, floor: 1 }
298
+ ],
299
+ regionMultiplier: {},
300
+ states: { normal: "normal", fortified: "fortified", abandoned: "abandoned" },
301
+ pool: {
302
+ defaultFootprint: 0.5,
303
+ offset: 1.5,
304
+ perSquareMetre: 3,
305
+ jitter: 1.5,
306
+ min: 2,
307
+ max: 5,
308
+ fortifiedExtra: 2,
309
+ supplyWeight: 2.5,
310
+ supplyExtraQty: 1,
311
+ abandonedEmptyChance: 0.4,
312
+ abandonedKept: 1,
313
+ junkChance: 0.5,
314
+ junkItem: "food_packaging",
315
+ spoiledFoodItem: "leftover_meal",
316
+ coldContainers: ["geladeira", "refrig_exp", "freezer"]
317
+ }
318
+ }
319
+ };
320
+
321
+ // src/carry.ts
322
+ var maxLoadKg = (strength, rules = DEFAULT_RULES) => (rules.carry.baseKg + rules.carry.perStrengthKg * strength) * rules.carry.factor;
323
+ var sumKg = (entries) => entries.reduce((total, entry) => total + entry.item.weight * entry.count, 0);
324
+ var carriedKg = (parts) => sumKg(parts.loose) + sumKg(parts.packed ?? []) * (1 - (parts.weightReduction ?? 0));
325
+ var loadState = (loadKg, maxKg, rules = DEFAULT_RULES) => {
326
+ const ratio = maxKg > 0 ? loadKg / maxKg : Number.POSITIVE_INFINITY;
327
+ if (ratio > rules.carry.overloaded) return { ratio, level: "overloaded", runFactor: 0, canRun: false };
328
+ if (ratio > rules.carry.encumbered) return { ratio, level: "encumbered", runFactor: rules.inventory.encumberedRunFactor, canRun: true };
329
+ return { ratio, level: "normal", runFactor: 1, canRun: true };
330
+ };
331
+ var LITRES_PER_CUBIC_METRE = 1e3;
332
+ var itemLitres = (item) => item.volume ?? item.size[0] * item.size[1] * item.size[2] * LITRES_PER_CUBIC_METRE;
333
+ var bagOption = (bag, characterMaxKg, rules = DEFAULT_RULES) => ({
334
+ slots: bag?.carry ? Math.round(bag.carry.capacityKg) : rules.inventory.defaultSlots,
335
+ capacityKg: characterMaxKg,
336
+ inside: (bag ? rules.inventory.bagInside[bag.id] : void 0) ?? rules.inventory.defaultInside,
337
+ capacityLitres: (bag ? rules.inventory.bagLitres[bag.id] ?? bag.volume : void 0) ?? rules.inventory.defaultLitres
338
+ });
339
+ var fitsInside = (size, inside) => {
340
+ const byLength = (a, b) => b - a;
341
+ const sorted = [...size].sort(byLength);
342
+ const room = [...inside].sort(byLength);
343
+ return sorted.every((length, index) => length <= (room[index] ?? 0) + 1e-9);
344
+ };
345
+ var canTake = (item, bag, used, options = {}) => {
346
+ const { count = 1, slotsNeeded = 1, weightFactor = 1 } = options;
347
+ if (bag.inside !== void 0 && !fitsInside(item.size, bag.inside)) return "too_long";
348
+ if (used.slots + slotsNeeded > bag.slots) return "bag_full";
349
+ if (used.loadKg + item.weight * count * weightFactor > bag.capacityKg) return "too_heavy";
350
+ if (bag.capacityLitres !== void 0 && (used.litres ?? 0) + itemLitres(item) * count > bag.capacityLitres) return "too_bulky";
351
+ return "ok";
352
+ };
169
353
 
170
354
  // src/categories.ts
171
355
  var ITEM_CATEGORIES = [
@@ -252,80 +436,8 @@ var GameItems = (() => {
252
436
  ...checkRules(parts.rules)
253
437
  ];
254
438
 
255
- // src/rules.ts
256
- var DEFAULT_RULES = {
257
- rarity: {
258
- weights: { common: 60, uncommon: 28, rare: 9, very_rare: 2.5, legendary: 0.5, unique: 0 },
259
- fixedOnly: ["legendary", "unique"]
260
- },
261
- freshness: { stale: 0.5, spoiled: 1, rotten: 1.5 },
262
- storage: {
263
- fridge: { multiplier: 0.33, needsPower: true },
264
- freezer: { multiplier: 0.1, needsPower: true },
265
- cooler: { multiplier: 0.5, limitDays: 2, afterLimit: 1 },
266
- delivery_bag: { multiplier: 0.8 },
267
- cellar: { multiplier: 0.66 },
268
- ambient: { multiplier: 1 },
269
- hot: { multiplier: 2 }
270
- },
271
- carry: { baseKg: 8, perStrengthKg: 2.5, factor: 1.2, encumbered: 1, overloaded: 1.5 },
272
- protection: { cap: 0.9, wear: { bite: 8, scratch: 3 }, tornShare: 0.25, repairMargin: 10 },
273
- aging: { thawShelfDays: { freezer: 2 } },
274
- inventory: { defaultSlots: 10, encumberedRunFactor: 0.75 },
275
- use: {
276
- freshness: {
277
- stale: { satietyFactor: 0.7, poisonChance: 0.1, morale: 0, isEdible: true },
278
- spoiled: { satietyFactor: 0.7, poisonChance: 0.5, morale: -20, isEdible: true },
279
- rotten: { satietyFactor: 0, poisonChance: 0, morale: 0, isEdible: false }
280
- },
281
- cookedPoisonFactor: 0.25
282
- },
283
- spawn: {
284
- retailNew: true,
285
- retailPlaces: ["supermarket", "pharmacy", "mall", "gas_station", "gun_shop"],
286
- retailContainers: ["store_shelf", "stockroom"],
287
- condition: { common: [30, 90], uncommon: [40, 90], rare: [50, 100], very_rare: [50, 100], legendary: [50, 100], unique: [50, 100] },
288
- ageShare: [0, 0.6],
289
- charge: [0.2, 1],
290
- fillable: ["fuel_jerrycan"],
291
- fill: [0, 0.6]
292
- },
293
- finds: {
294
- fallbackContainer: "zombie_corpse",
295
- rollExcluded: ["ammo_7_62x39"],
296
- depletion: [
297
- { places: ["pharmacy", "gun_shop", "police_station"], perDay: 0.05, floor: 0.3 },
298
- { places: ["supermarket", "gas_station"], perDay: 0.04, floor: 0.35 },
299
- { places: ["mall", "hospital"], perDay: 0.025, floor: 0.5 },
300
- { places: ["house", "apartment"], perDay: 0.01, floor: 0.7 },
301
- { places: ["farm", "warehouse", "mine", "dam", "lodge", "church"], perDay: 5e-3, floor: 0.85 },
302
- { places: ["military_base"], perDay: 0, floor: 1 }
303
- ],
304
- regionMultiplier: {},
305
- states: { normal: "normal", fortified: "fortified", abandoned: "abandoned" },
306
- pool: {
307
- defaultFootprint: 0.5,
308
- offset: 1.5,
309
- perSquareMetre: 3,
310
- jitter: 1.5,
311
- min: 2,
312
- max: 5,
313
- fortifiedExtra: 2,
314
- supplyWeight: 2.5,
315
- supplyExtraQty: 1,
316
- abandonedEmptyChance: 0.4,
317
- abandonedKept: 1,
318
- junkChance: 0.5,
319
- junkItem: "food_packaging",
320
- spoiledFoodItem: "leftover_meal",
321
- coldContainers: ["geladeira", "refrig_exp", "freezer"]
322
- }
323
- }
324
- };
325
-
326
439
  // src/create-items.ts
327
- var LITRES_PER_CUBIC_METRE = 1e3;
328
- var withDerivedFields = (item) => item.volume === void 0 ? { ...item, volume: item.size[0] * item.size[1] * item.size[2] * LITRES_PER_CUBIC_METRE } : item;
440
+ var withDerivedFields = (item) => item.volume === void 0 ? { ...item, volume: itemLitres(item) } : item;
329
441
  var buildPools = (options, packs) => {
330
442
  const pools = /* @__PURE__ */ new Map();
331
443
  for (const source of [...packs, options]) for (const [key, entries] of Object.entries(source.pools ?? {})) pools.set(key, entries);
@@ -478,24 +590,126 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
478
590
  condition: Math.max(piece.condition, maxCondition - rules.protection.repairMargin)
479
591
  });
480
592
 
481
- // src/carry.ts
482
- var maxLoadKg = (strength, rules = DEFAULT_RULES) => (rules.carry.baseKg + rules.carry.perStrengthKg * strength) * rules.carry.factor;
483
- var sumKg = (entries) => entries.reduce((total, entry) => total + entry.item.weight * entry.count, 0);
484
- var carriedKg = (parts) => sumKg(parts.loose) + sumKg(parts.packed ?? []) * (1 - (parts.weightReduction ?? 0));
485
- var loadState = (loadKg, maxKg, rules = DEFAULT_RULES) => {
486
- const ratio = maxKg > 0 ? loadKg / maxKg : Number.POSITIVE_INFINITY;
487
- if (ratio > rules.carry.overloaded) return { ratio, level: "overloaded", runFactor: 0, canRun: false };
488
- if (ratio > rules.carry.encumbered) return { ratio, level: "encumbered", runFactor: rules.inventory.encumberedRunFactor, canRun: true };
489
- return { ratio, level: "normal", runFactor: 1, canRun: true };
490
- };
491
- var bagOption = (bag, characterMaxKg, rules = DEFAULT_RULES) => ({
492
- slots: bag?.carry ? Math.round(bag.carry.capacityKg) : rules.inventory.defaultSlots,
493
- capacityKg: characterMaxKg
494
- });
495
- var canTake = (item, bag, used) => {
496
- if (used.slots >= bag.slots) return "bag_full";
497
- if (used.loadKg + item.weight > bag.capacityKg) return "too_heavy";
498
- return "ok";
593
+ // src/inventory.ts
594
+ var copyStack = (stack) => structuredClone(stack);
595
+ var isStackable = (item, stack) => stack.state === void 0 && (item.stack ?? 1) > 1;
596
+ var createInventory = (options) => {
597
+ const { items, bag, weightReduction = 0, rules = DEFAULT_RULES } = options;
598
+ const slotList = [];
599
+ let held;
600
+ let nextSlotId = 1;
601
+ const entryOf = (stack) => {
602
+ const item = items.get(stack.itemId);
603
+ return item ? { item, count: stack.count } : void 0;
604
+ };
605
+ const entries = (stacks) => stacks.flatMap((stack) => entryOf(stack) ?? []);
606
+ const slotKg = (stack) => carriedKg({ loose: [], packed: entries([stack]), weightReduction });
607
+ const litresOf = (stacks) => entries(stacks).reduce((sum, entry) => sum + itemLitres(entry.item) * entry.count, 0);
608
+ const totals = () => {
609
+ const kg = carriedKg({ loose: entries(held ? [held] : []), packed: entries(slotList), weightReduction });
610
+ return { slots: slotList.length, kg, litres: litresOf(slotList), load: loadState(kg, bag.capacityKg, rules) };
611
+ };
612
+ const planSlots = (item, stack) => {
613
+ const fills = /* @__PURE__ */ new Map();
614
+ const limit = item.stack ?? 1;
615
+ let left = stack.count;
616
+ if (isStackable(item, stack)) {
617
+ for (const slot of slotList) {
618
+ if (left === 0) break;
619
+ if (slot.itemId !== stack.itemId || slot.state !== void 0 || slot.count >= limit) continue;
620
+ const added = Math.min(left, limit - slot.count);
621
+ fills.set(slot.slotId, added);
622
+ left -= added;
623
+ }
624
+ }
625
+ const perSlot = isStackable(item, stack) ? limit : 1;
626
+ const newStacks = [];
627
+ for (; left > 0; left -= Math.min(left, perSlot)) newStacks.push(Math.min(left, perSlot));
628
+ return { fills, newStacks };
629
+ };
630
+ const commit = (stack, plan) => {
631
+ const slotIds = [];
632
+ for (const [slotId, added] of plan.fills) {
633
+ const index = slotList.findIndex((slot2) => slot2.slotId === slotId);
634
+ const slot = slotList[index];
635
+ slotList[index] = { ...slot, count: slot.count + added };
636
+ slotIds.push(slotId);
637
+ }
638
+ for (const count of plan.newStacks) {
639
+ const slotId = nextSlotId++;
640
+ slotList.push({ ...copyStack(stack), count, slotId });
641
+ slotIds.push(slotId);
642
+ }
643
+ return slotIds;
644
+ };
645
+ const fitsInBag = (item, stack, plan, rest) => canTake(item, bag, { slots: slotList.length, loadKg: rest.kg, litres: rest.litres }, { count: stack.count, slotsNeeded: plan.newStacks.length, weightFactor: 1 - weightReduction });
646
+ const putInBag = (stack, rest) => {
647
+ const item = items.get(stack.itemId);
648
+ if (!item) return { ok: false, reason: "unknown_item" };
649
+ if (!Number.isInteger(stack.count) || stack.count < 1 || stack.state !== void 0 && stack.count !== 1) return { ok: false, reason: "bad_count" };
650
+ const plan = planSlots(item, stack);
651
+ const verdict = fitsInBag(item, stack, plan, rest);
652
+ if (verdict !== "ok") return { ok: false, reason: verdict };
653
+ return { ok: true, slotIds: commit(stack, plan) };
654
+ };
655
+ const findSlot = (slotId) => slotList.findIndex((slot) => slot.slotId === slotId);
656
+ return {
657
+ take: ({ itemId, count = 1, state }) => {
658
+ const stack = state === void 0 ? { itemId, count } : { itemId, count, state };
659
+ const now = totals();
660
+ return putInBag(stack, { kg: now.kg, litres: now.litres });
661
+ },
662
+ hold: ({ itemId, state }) => {
663
+ const item = items.get(itemId);
664
+ if (!item) return { ok: false, reason: "unknown_item" };
665
+ if (held) return { ok: false, reason: "hand_full" };
666
+ const verdict = canTake(item, { ...bag, capacityLitres: void 0, inside: void 0 }, { slots: 0, loadKg: totals().kg }, { slotsNeeded: 0 });
667
+ if (verdict !== "ok") return { ok: false, reason: verdict };
668
+ held = state === void 0 ? { itemId, count: 1 } : copyStack({ itemId, count: 1, state });
669
+ return { ok: true, held: copyStack(held) };
670
+ },
671
+ store: () => {
672
+ if (!held) return { ok: false, reason: "hand_empty" };
673
+ const now = totals();
674
+ const result = putInBag(held, { kg: now.kg - carriedKg({ loose: entries([held]) }), litres: now.litres });
675
+ if (result.ok) held = void 0;
676
+ return result;
677
+ },
678
+ equip: (slotId) => {
679
+ const index = findSlot(slotId);
680
+ if (index < 0) return { ok: false, reason: "not_found" };
681
+ if (held) return { ok: false, reason: "hand_full" };
682
+ const slot = slotList[index];
683
+ const item = items.get(slot.itemId);
684
+ if (!item) return { ok: false, reason: "unknown_item" };
685
+ const now = totals();
686
+ const verdict = canTake(item, { ...bag, capacityLitres: void 0, inside: void 0 }, { slots: 0, loadKg: now.kg - slotKg(slot), litres: 0 }, { count: slot.count, slotsNeeded: 0 });
687
+ if (verdict !== "ok") return { ok: false, reason: verdict };
688
+ slotList.splice(index, 1);
689
+ held = { itemId: slot.itemId, count: slot.count, ...slot.state ? { state: slot.state } : {} };
690
+ return { ok: true, held: copyStack(held) };
691
+ },
692
+ drop: ({ slotId, count } = {}) => {
693
+ if (slotId === void 0) {
694
+ if (!held) return { ok: false, reason: "hand_empty" };
695
+ const dropped2 = held;
696
+ held = void 0;
697
+ return { ok: true, dropped: copyStack(dropped2) };
698
+ }
699
+ const index = findSlot(slotId);
700
+ if (index < 0) return { ok: false, reason: "not_found" };
701
+ const slot = slotList[index];
702
+ const taken = count ?? slot.count;
703
+ if (!Number.isInteger(taken) || taken < 1 || taken > slot.count) return { ok: false, reason: "bad_count" };
704
+ const dropped = { itemId: slot.itemId, count: taken, ...slot.state ? { state: slot.state } : {} };
705
+ if (taken === slot.count) slotList.splice(index, 1);
706
+ else slotList[index] = { ...slot, count: slot.count - taken };
707
+ return { ok: true, dropped: copyStack(dropped) };
708
+ },
709
+ slots: () => slotList.map((slot) => structuredClone(slot)),
710
+ held: () => held ? copyStack(held) : void 0,
711
+ totals
712
+ };
499
713
  };
500
714
 
501
715
  // src/use-effect.ts