@adatechnology/game-items 0.2.25 → 0.3.0

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/README.md CHANGED
@@ -71,6 +71,7 @@ const { contents, leftover } = placeFinds(stacks, slots, items)
71
71
  | `blockChance`, `wearBlocked`, `repairPiece`, `pieceBlock` | layered clothing protection |
72
72
  | `maxLoadKg`, `carriedKg`, `loadState`, `bagOption`, `canTake` | carry weight and slots |
73
73
  | `resolveUse` | what using an item does, as data; with `UseContext.seal` a sealed item (`ItemDef.seal`, a `SealSpec` of game-contracts) still closed, holed or leaking is not eaten (`blocked`) |
74
+ | `HAND_USES`, `createHandUse`, `handUseOf` | uses of an item in the hand without a liquid (spec 015 R5): `eat_food` in three bites, `drink`, `take_medicine`, `apply_dressing`, `use_hygiene`; keys of the item's place from the hand's rest in the eye's frame (the frame of the fluid uses), `body` (`mouth` or `two_hands`) for the arms, and the `bite`/`swallow`/`apply`/`scrub` events the host acts on |
74
75
  | `canCraft`, `craft` | recipes |
75
76
  | `createFindsProvider`, `rollByCategory`, `rollExplicitPool`, `spawnData`, `depletionFactor`, `placeFinds`, `toLootTables` | finds |
76
77
  | `itemsFromArsenal` | the arsenal as items |
package/dist/index.d.ts CHANGED
@@ -879,4 +879,45 @@ declare const ARSENAL_CATEGORIES: readonly CategoryDef[];
879
879
  */
880
880
  declare const itemsFromArsenal: (arsenal: ArsenalLike, options?: ArsenalItemsOptions) => ItemPack;
881
881
 
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 };
882
+ /** What happens at a key: a bite taken, a pill or a sip swallowed, the dressing pressed on, soap rubbed. */
883
+ type HandUseAction = 'bite' | 'swallow' | 'apply' | 'scrub';
884
+ /** Which arms the use takes: the item to the `mouth`, or both hands together in front of the body. */
885
+ type HandUseBody = 'mouth' | 'two_hands';
886
+ interface HandUseKey {
887
+ readonly t: number;
888
+ readonly position: readonly [number, number, number];
889
+ readonly rotation: readonly [number, number, number];
890
+ readonly action?: HandUseAction;
891
+ }
892
+ interface HandUseDef {
893
+ readonly id: string;
894
+ readonly body: HandUseBody;
895
+ readonly duration: number;
896
+ readonly keys: readonly HandUseKey[];
897
+ readonly note?: string;
898
+ }
899
+ /** An action reached: which one, and the share of the use's actions done with it (the third bite of three is 1). */
900
+ interface HandUseEvent {
901
+ readonly action: HandUseAction;
902
+ readonly share: number;
903
+ }
904
+ interface HandUsePlayer {
905
+ readonly def: HandUseDef;
906
+ readonly time: number;
907
+ readonly done: boolean;
908
+ /** Where the item is now, from the hand's rest: position in the eye's frame and rotation as Euler XYZ. */
909
+ pose(): {
910
+ position: [number, number, number];
911
+ rotation: [number, number, number];
912
+ };
913
+ /** Advances the use; answers the actions reached in this step. */
914
+ update(dt: number): HandUseEvent[];
915
+ cancel(): void;
916
+ }
917
+ declare const HAND_USES: readonly HandUseDef[];
918
+ /** The hand use with that id, among `defs`. */
919
+ declare const handUseOf: (id: string, defs?: readonly HandUseDef[]) => HandUseDef | undefined;
920
+ /** Plays a hand use: the pose between its keys, and its actions as the time passes them. */
921
+ declare const createHandUse: (def: HandUseDef) => HandUsePlayer;
922
+
923
+ 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, HAND_USES, type HandUseAction, type HandUseBody, type HandUseDef, type HandUseEvent, type HandUseKey, type HandUsePlayer, 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, createHandUse, createInventory, createItems, depletionFactor, failsToStart, fitsInside, freshness, handUseOf, itemLitres, itemsFromArsenal, loadState, maxLoadKg, moveToStorage, pieceBlock, placeFinds, repairPiece, resolveUse, rollByCategory, rollExplicitPool, scaleCount, shelfRatio, spawnAgeDays, spawnData, storageMultiplier, toLootTables, wearBlocked };
@@ -25,6 +25,7 @@ var GameItems = (() => {
25
25
  BODY_SLOTS: () => BODY_SLOTS,
26
26
  DEFAULT_RULES: () => DEFAULT_RULES,
27
27
  DURABILITY_KINDS: () => DURABILITY_KINDS,
28
+ HAND_USES: () => HAND_USES,
28
29
  ITEM_CATEGORIES: () => ITEM_CATEGORIES,
29
30
  RARITIES: () => RARITIES,
30
31
  advanceAge: () => advanceAge,
@@ -37,12 +38,14 @@ var GameItems = (() => {
37
38
  checkItems: () => checkItems,
38
39
  craft: () => craft,
39
40
  createFindsProvider: () => createFindsProvider,
41
+ createHandUse: () => createHandUse,
40
42
  createInventory: () => createInventory,
41
43
  createItems: () => createItems,
42
44
  depletionFactor: () => depletionFactor,
43
45
  failsToStart: () => failsToStart,
44
46
  fitsInside: () => fitsInside,
45
47
  freshness: () => freshness,
48
+ handUseOf: () => handUseOf,
46
49
  itemLitres: () => itemLitres,
47
50
  itemsFromArsenal: () => itemsFromArsenal,
48
51
  loadState: () => loadState,
@@ -1084,6 +1087,591 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
1084
1087
  }
1085
1088
  return { id: "arsenal", items, categories: ARSENAL_CATEGORIES };
1086
1089
  };
1090
+
1091
+ // src/data/hand-uses.json
1092
+ var hand_uses_default = [
1093
+ {
1094
+ id: "eat_food",
1095
+ body: "mouth",
1096
+ duration: 3.4,
1097
+ note: "three bites: the food to the mouth, a bite, down a little to chew, and again",
1098
+ keys: [
1099
+ {
1100
+ t: 0,
1101
+ position: [
1102
+ 0.22,
1103
+ -0.2,
1104
+ -0.4
1105
+ ],
1106
+ rotation: [
1107
+ 0,
1108
+ 0,
1109
+ 0
1110
+ ]
1111
+ },
1112
+ {
1113
+ t: 0.45,
1114
+ position: [
1115
+ 0.01,
1116
+ 0,
1117
+ -0.17
1118
+ ],
1119
+ rotation: [
1120
+ -0.3,
1121
+ 0,
1122
+ 0
1123
+ ],
1124
+ action: "bite"
1125
+ },
1126
+ {
1127
+ t: 0.8,
1128
+ position: [
1129
+ 0.05,
1130
+ -0.08,
1131
+ -0.26
1132
+ ],
1133
+ rotation: [
1134
+ -0.15,
1135
+ 0,
1136
+ 0
1137
+ ]
1138
+ },
1139
+ {
1140
+ t: 1.25,
1141
+ position: [
1142
+ 0.01,
1143
+ 0,
1144
+ -0.17
1145
+ ],
1146
+ rotation: [
1147
+ -0.3,
1148
+ 0,
1149
+ 0
1150
+ ],
1151
+ action: "bite"
1152
+ },
1153
+ {
1154
+ t: 1.6,
1155
+ position: [
1156
+ 0.05,
1157
+ -0.08,
1158
+ -0.26
1159
+ ],
1160
+ rotation: [
1161
+ -0.15,
1162
+ 0,
1163
+ 0
1164
+ ]
1165
+ },
1166
+ {
1167
+ t: 2.05,
1168
+ position: [
1169
+ 0.01,
1170
+ 0,
1171
+ -0.17
1172
+ ],
1173
+ rotation: [
1174
+ -0.3,
1175
+ 0,
1176
+ 0
1177
+ ],
1178
+ action: "bite"
1179
+ },
1180
+ {
1181
+ t: 2.8,
1182
+ position: [
1183
+ 0.05,
1184
+ -0.08,
1185
+ -0.26
1186
+ ],
1187
+ rotation: [
1188
+ -0.15,
1189
+ 0,
1190
+ 0
1191
+ ]
1192
+ },
1193
+ {
1194
+ t: 3.4,
1195
+ position: [
1196
+ 0.22,
1197
+ -0.2,
1198
+ -0.4
1199
+ ],
1200
+ rotation: [
1201
+ 0,
1202
+ 0,
1203
+ 0
1204
+ ]
1205
+ }
1206
+ ]
1207
+ },
1208
+ {
1209
+ id: "drink",
1210
+ body: "mouth",
1211
+ duration: 2.5,
1212
+ note: "a drink without a liquid of its own (a juice box): to the mouth and tipped up, as the fluid drink",
1213
+ keys: [
1214
+ {
1215
+ t: 0,
1216
+ position: [
1217
+ 0.22,
1218
+ -0.2,
1219
+ -0.4
1220
+ ],
1221
+ rotation: [
1222
+ 0,
1223
+ 0,
1224
+ 0
1225
+ ]
1226
+ },
1227
+ {
1228
+ t: 0.5,
1229
+ position: [
1230
+ 0,
1231
+ 0.02,
1232
+ -0.2
1233
+ ],
1234
+ rotation: [
1235
+ 0,
1236
+ 0,
1237
+ 0
1238
+ ]
1239
+ },
1240
+ {
1241
+ t: 0.8,
1242
+ position: [
1243
+ 0,
1244
+ 0.02,
1245
+ -0.2
1246
+ ],
1247
+ rotation: [
1248
+ -1.22,
1249
+ 0,
1250
+ 0
1251
+ ],
1252
+ action: "swallow"
1253
+ },
1254
+ {
1255
+ t: 2,
1256
+ position: [
1257
+ 0,
1258
+ 0.02,
1259
+ -0.2
1260
+ ],
1261
+ rotation: [
1262
+ -1.22,
1263
+ 0,
1264
+ 0
1265
+ ]
1266
+ },
1267
+ {
1268
+ t: 2.5,
1269
+ position: [
1270
+ 0.22,
1271
+ -0.2,
1272
+ -0.4
1273
+ ],
1274
+ rotation: [
1275
+ 0,
1276
+ 0,
1277
+ 0
1278
+ ]
1279
+ }
1280
+ ]
1281
+ },
1282
+ {
1283
+ id: "take_medicine",
1284
+ body: "mouth",
1285
+ duration: 2.6,
1286
+ note: "the box before the chest, shaken for a pill, the pill to the mouth and swallowed",
1287
+ keys: [
1288
+ {
1289
+ t: 0,
1290
+ position: [
1291
+ 0.22,
1292
+ -0.2,
1293
+ -0.4
1294
+ ],
1295
+ rotation: [
1296
+ 0,
1297
+ 0,
1298
+ 0
1299
+ ]
1300
+ },
1301
+ {
1302
+ t: 0.4,
1303
+ position: [
1304
+ 0.06,
1305
+ -0.16,
1306
+ -0.3
1307
+ ],
1308
+ rotation: [
1309
+ 0,
1310
+ 0,
1311
+ 0
1312
+ ]
1313
+ },
1314
+ {
1315
+ t: 0.65,
1316
+ position: [
1317
+ 0.06,
1318
+ -0.16,
1319
+ -0.3
1320
+ ],
1321
+ rotation: [
1322
+ 0,
1323
+ 0,
1324
+ 0.5
1325
+ ]
1326
+ },
1327
+ {
1328
+ t: 0.85,
1329
+ position: [
1330
+ 0.06,
1331
+ -0.16,
1332
+ -0.3
1333
+ ],
1334
+ rotation: [
1335
+ 0,
1336
+ 0,
1337
+ -0.5
1338
+ ]
1339
+ },
1340
+ {
1341
+ t: 1.05,
1342
+ position: [
1343
+ 0.06,
1344
+ -0.16,
1345
+ -0.3
1346
+ ],
1347
+ rotation: [
1348
+ 0,
1349
+ 0,
1350
+ 0
1351
+ ]
1352
+ },
1353
+ {
1354
+ t: 1.6,
1355
+ position: [
1356
+ 0,
1357
+ 0.02,
1358
+ -0.18
1359
+ ],
1360
+ rotation: [
1361
+ -0.6,
1362
+ 0,
1363
+ 0
1364
+ ],
1365
+ action: "swallow"
1366
+ },
1367
+ {
1368
+ t: 2,
1369
+ position: [
1370
+ 0,
1371
+ 0.02,
1372
+ -0.18
1373
+ ],
1374
+ rotation: [
1375
+ -0.6,
1376
+ 0,
1377
+ 0
1378
+ ]
1379
+ },
1380
+ {
1381
+ t: 2.6,
1382
+ position: [
1383
+ 0.22,
1384
+ -0.2,
1385
+ -0.4
1386
+ ],
1387
+ rotation: [
1388
+ 0,
1389
+ 0,
1390
+ 0
1391
+ ]
1392
+ }
1393
+ ]
1394
+ },
1395
+ {
1396
+ id: "apply_dressing",
1397
+ body: "two_hands",
1398
+ duration: 3.2,
1399
+ note: "the dressing laid on the other forearm and wound round it twice",
1400
+ keys: [
1401
+ {
1402
+ t: 0,
1403
+ position: [
1404
+ 0.22,
1405
+ -0.2,
1406
+ -0.4
1407
+ ],
1408
+ rotation: [
1409
+ 0,
1410
+ 0,
1411
+ 0
1412
+ ]
1413
+ },
1414
+ {
1415
+ t: 0.5,
1416
+ position: [
1417
+ -0.06,
1418
+ -0.12,
1419
+ -0.3
1420
+ ],
1421
+ rotation: [
1422
+ 0,
1423
+ 0,
1424
+ 1.2
1425
+ ]
1426
+ },
1427
+ {
1428
+ t: 1,
1429
+ position: [
1430
+ -0.1,
1431
+ -0.15,
1432
+ -0.28
1433
+ ],
1434
+ rotation: [
1435
+ 0.4,
1436
+ 0,
1437
+ 1.4
1438
+ ],
1439
+ action: "apply"
1440
+ },
1441
+ {
1442
+ t: 1.5,
1443
+ position: [
1444
+ -0.02,
1445
+ -0.1,
1446
+ -0.32
1447
+ ],
1448
+ rotation: [
1449
+ 0,
1450
+ 0,
1451
+ 1.2
1452
+ ]
1453
+ },
1454
+ {
1455
+ t: 2,
1456
+ position: [
1457
+ -0.1,
1458
+ -0.15,
1459
+ -0.28
1460
+ ],
1461
+ rotation: [
1462
+ 0.4,
1463
+ 0,
1464
+ 1.4
1465
+ ],
1466
+ action: "apply"
1467
+ },
1468
+ {
1469
+ t: 2.6,
1470
+ position: [
1471
+ -0.06,
1472
+ -0.12,
1473
+ -0.3
1474
+ ],
1475
+ rotation: [
1476
+ 0,
1477
+ 0,
1478
+ 1.2
1479
+ ]
1480
+ },
1481
+ {
1482
+ t: 3.2,
1483
+ position: [
1484
+ 0.22,
1485
+ -0.2,
1486
+ -0.4
1487
+ ],
1488
+ rotation: [
1489
+ 0,
1490
+ 0,
1491
+ 0
1492
+ ]
1493
+ }
1494
+ ]
1495
+ },
1496
+ {
1497
+ id: "use_hygiene",
1498
+ body: "two_hands",
1499
+ duration: 3,
1500
+ note: "soap (or what is rubbed in) between both hands in front of the body, rubbed side to side",
1501
+ keys: [
1502
+ {
1503
+ t: 0,
1504
+ position: [
1505
+ 0.22,
1506
+ -0.2,
1507
+ -0.4
1508
+ ],
1509
+ rotation: [
1510
+ 0,
1511
+ 0,
1512
+ 0
1513
+ ]
1514
+ },
1515
+ {
1516
+ t: 0.4,
1517
+ position: [
1518
+ 0.02,
1519
+ -0.18,
1520
+ -0.32
1521
+ ],
1522
+ rotation: [
1523
+ 0,
1524
+ 0,
1525
+ 1.5
1526
+ ]
1527
+ },
1528
+ {
1529
+ t: 0.7,
1530
+ position: [
1531
+ -0.04,
1532
+ -0.18,
1533
+ -0.32
1534
+ ],
1535
+ rotation: [
1536
+ 0,
1537
+ 0,
1538
+ 1.5
1539
+ ],
1540
+ action: "scrub"
1541
+ },
1542
+ {
1543
+ t: 1,
1544
+ position: [
1545
+ 0.06,
1546
+ -0.18,
1547
+ -0.32
1548
+ ],
1549
+ rotation: [
1550
+ 0,
1551
+ 0,
1552
+ 1.5
1553
+ ]
1554
+ },
1555
+ {
1556
+ t: 1.3,
1557
+ position: [
1558
+ -0.04,
1559
+ -0.18,
1560
+ -0.32
1561
+ ],
1562
+ rotation: [
1563
+ 0,
1564
+ 0,
1565
+ 1.5
1566
+ ],
1567
+ action: "scrub"
1568
+ },
1569
+ {
1570
+ t: 1.6,
1571
+ position: [
1572
+ 0.06,
1573
+ -0.18,
1574
+ -0.32
1575
+ ],
1576
+ rotation: [
1577
+ 0,
1578
+ 0,
1579
+ 1.5
1580
+ ]
1581
+ },
1582
+ {
1583
+ t: 1.9,
1584
+ position: [
1585
+ -0.04,
1586
+ -0.18,
1587
+ -0.32
1588
+ ],
1589
+ rotation: [
1590
+ 0,
1591
+ 0,
1592
+ 1.5
1593
+ ],
1594
+ action: "scrub"
1595
+ },
1596
+ {
1597
+ t: 2.3,
1598
+ position: [
1599
+ 0.02,
1600
+ -0.18,
1601
+ -0.32
1602
+ ],
1603
+ rotation: [
1604
+ 0,
1605
+ 0,
1606
+ 1.5
1607
+ ]
1608
+ },
1609
+ {
1610
+ t: 3,
1611
+ position: [
1612
+ 0.22,
1613
+ -0.2,
1614
+ -0.4
1615
+ ],
1616
+ rotation: [
1617
+ 0,
1618
+ 0,
1619
+ 0
1620
+ ]
1621
+ }
1622
+ ]
1623
+ }
1624
+ ];
1625
+
1626
+ // src/hand-use.ts
1627
+ var HAND_USES = hand_uses_default;
1628
+ var handUseOf = (id, defs = HAND_USES) => defs.find((def) => def.id === id);
1629
+ var lerp = (a, b, k) => [
1630
+ a[0] + (b[0] - a[0]) * k,
1631
+ a[1] + (b[1] - a[1]) * k,
1632
+ a[2] + (b[2] - a[2]) * k
1633
+ ];
1634
+ var createHandUse = (def) => {
1635
+ const keys = [...def.keys].sort((a, b) => a.t - b.t);
1636
+ const actions = keys.filter((key) => key.action !== void 0);
1637
+ let time = 0;
1638
+ let reached = 0;
1639
+ let done = keys.length === 0 || def.duration <= 0;
1640
+ const pose3 = () => {
1641
+ const first = keys[0];
1642
+ if (!first) return { position: [0, 0, 0], rotation: [0, 0, 0] };
1643
+ let index = 0;
1644
+ while (index + 1 < keys.length && keys[index + 1].t <= time) index++;
1645
+ const a = keys[index];
1646
+ const b = keys[Math.min(index + 1, keys.length - 1)];
1647
+ const k = b.t > a.t ? Math.min(1, Math.max(0, (time - a.t) / (b.t - a.t))) : 1;
1648
+ return { position: lerp(a.position, b.position, k), rotation: lerp(a.rotation, b.rotation, k) };
1649
+ };
1650
+ return {
1651
+ def,
1652
+ get time() {
1653
+ return time;
1654
+ },
1655
+ get done() {
1656
+ return done;
1657
+ },
1658
+ pose: pose3,
1659
+ update(dt) {
1660
+ if (done) return [];
1661
+ time = Math.min(def.duration, time + Math.max(0, dt));
1662
+ const events = [];
1663
+ while (reached < actions.length && actions[reached].t <= time) {
1664
+ reached++;
1665
+ events.push({ action: actions[reached - 1].action, share: reached / actions.length });
1666
+ }
1667
+ done = time >= def.duration;
1668
+ return events;
1669
+ },
1670
+ cancel() {
1671
+ done = true;
1672
+ }
1673
+ };
1674
+ };
1087
1675
  return __toCommonJS(index_exports);
1088
1676
  })();
1089
1677
  //# sourceMappingURL=index.global.js.map