@adatechnology/game-items 0.3.0 → 0.4.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,7 +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
+ | `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`, `toggle_flashlight` (the thumb on the switch), `light_lighter` (the wheel struck, the flame caught), `use_radio` (to the face, the knob turned, talking), `turn_key` (into the lock and turned); keys of the item's place from the hand's rest in the eye's frame (the frame of the fluid uses), `body` (`mouth`, `two_hands`, `hand` or `reach`) for the arms, and the `bite`/`swallow`/`apply`/`scrub`/`switch`/`ignite`/`tune`/`talk`/`turn` events the host acts on. `aimHandUse(def, target)` moves the keys marked `reach` onto a point the host aims them at (a lock), within an arm's length (`HAND_USE_REACH`) |
75
75
  | `canCraft`, `craft` | recipes |
76
76
  | `createFindsProvider`, `rollByCategory`, `rollExplicitPool`, `spawnData`, `depletionFactor`, `placeFinds`, `toLootTables` | finds |
77
77
  | `itemsFromArsenal` | the arsenal as items |
package/dist/index.d.ts CHANGED
@@ -879,15 +879,23 @@ declare const ARSENAL_CATEGORIES: readonly CategoryDef[];
879
879
  */
880
880
  declare const itemsFromArsenal: (arsenal: ArsenalLike, options?: ArsenalItemsOptions) => ItemPack;
881
881
 
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';
882
+ /**
883
+ * What happens at a key: a bite taken, a pill or a sip swallowed, the dressing pressed on, soap rubbed; a switch pressed (a flashlight), a flame struck (a lighter), a knob
884
+ * turned and words spoken (a radio), a key turned in its lock.
885
+ */
886
+ type HandUseAction = 'bite' | 'swallow' | 'apply' | 'scrub' | 'switch' | 'ignite' | 'tune' | 'talk' | 'turn';
887
+ /**
888
+ * Which arms the use takes: the item to the `mouth`, both hands together in front of the body (`two_hands`), the one `hand` that holds it raised before the chest, or
889
+ * that arm stretched out to `reach` something ahead (a lock).
890
+ */
891
+ type HandUseBody = 'mouth' | 'two_hands' | 'hand' | 'reach';
886
892
  interface HandUseKey {
887
893
  readonly t: number;
888
894
  readonly position: readonly [number, number, number];
889
895
  readonly rotation: readonly [number, number, number];
890
896
  readonly action?: HandUseAction;
897
+ /** The item is at what the use reaches for at this key (a key in its lock): `aimHandUse` moves it there when the host has a target. */
898
+ readonly reach?: boolean;
891
899
  }
892
900
  interface HandUseDef {
893
901
  readonly id: string;
@@ -917,7 +925,14 @@ interface HandUsePlayer {
917
925
  declare const HAND_USES: readonly HandUseDef[];
918
926
  /** The hand use with that id, among `defs`. */
919
927
  declare const handUseOf: (id: string, defs?: readonly HandUseDef[]) => HandUseDef | undefined;
928
+ /** Farthest the hand carries an item from the eye (metres): an arm's length. */
929
+ declare const HAND_USE_REACH = 0.62;
930
+ /**
931
+ * The use with its `reach` keys moved onto `target` (a point in the eye's frame, as the keys are: a lock seen ahead), kept within `HAND_USE_REACH` of the eye; the keys keep
932
+ * how they lay around the first reach key, so a key still goes in, turns and comes out. Without reach keys the use is returned as it is.
933
+ */
934
+ declare const aimHandUse: (def: HandUseDef, target: readonly [number, number, number]) => HandUseDef;
920
935
  /** Plays a hand use: the pose between its keys, and its actions as the time passes them. */
921
936
  declare const createHandUse: (def: HandUseDef) => HandUsePlayer;
922
937
 
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 };
938
+ 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, HAND_USE_REACH, 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, aimHandUse, 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 };
@@ -26,9 +26,11 @@ var GameItems = (() => {
26
26
  DEFAULT_RULES: () => DEFAULT_RULES,
27
27
  DURABILITY_KINDS: () => DURABILITY_KINDS,
28
28
  HAND_USES: () => HAND_USES,
29
+ HAND_USE_REACH: () => HAND_USE_REACH,
29
30
  ITEM_CATEGORIES: () => ITEM_CATEGORIES,
30
31
  RARITIES: () => RARITIES,
31
32
  advanceAge: () => advanceAge,
33
+ aimHandUse: () => aimHandUse,
32
34
  bagOption: () => bagOption,
33
35
  blockChance: () => blockChance,
34
36
  canCraft: () => canCraft,
@@ -1620,12 +1622,499 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
1620
1622
  ]
1621
1623
  }
1622
1624
  ]
1625
+ },
1626
+ {
1627
+ id: "toggle_flashlight",
1628
+ body: "hand",
1629
+ duration: 1.1,
1630
+ note: "the flashlight raised before the chest and pointed ahead, the thumb pressing the tail switch (a small push), and back",
1631
+ keys: [
1632
+ {
1633
+ t: 0,
1634
+ position: [
1635
+ 0.22,
1636
+ -0.2,
1637
+ -0.4
1638
+ ],
1639
+ rotation: [
1640
+ 0,
1641
+ 0,
1642
+ 0
1643
+ ]
1644
+ },
1645
+ {
1646
+ t: 0.35,
1647
+ position: [
1648
+ 0.12,
1649
+ -0.12,
1650
+ -0.42
1651
+ ],
1652
+ rotation: [
1653
+ -1.45,
1654
+ 0,
1655
+ 0
1656
+ ]
1657
+ },
1658
+ {
1659
+ t: 0.47,
1660
+ position: [
1661
+ 0.12,
1662
+ -0.13,
1663
+ -0.42
1664
+ ],
1665
+ rotation: [
1666
+ -1.5,
1667
+ 0,
1668
+ 0
1669
+ ]
1670
+ },
1671
+ {
1672
+ t: 0.52,
1673
+ position: [
1674
+ 0.12,
1675
+ -0.125,
1676
+ -0.42
1677
+ ],
1678
+ rotation: [
1679
+ -1.47,
1680
+ 0,
1681
+ 0
1682
+ ],
1683
+ action: "switch"
1684
+ },
1685
+ {
1686
+ t: 0.7,
1687
+ position: [
1688
+ 0.12,
1689
+ -0.12,
1690
+ -0.42
1691
+ ],
1692
+ rotation: [
1693
+ -1.45,
1694
+ 0,
1695
+ 0
1696
+ ]
1697
+ },
1698
+ {
1699
+ t: 1.1,
1700
+ position: [
1701
+ 0.22,
1702
+ -0.2,
1703
+ -0.4
1704
+ ],
1705
+ rotation: [
1706
+ 0,
1707
+ 0,
1708
+ 0
1709
+ ]
1710
+ }
1711
+ ]
1712
+ },
1713
+ {
1714
+ id: "light_lighter",
1715
+ body: "hand",
1716
+ duration: 1.5,
1717
+ note: "the lighter brought before the chest, the thumb rolled down over the wheel (the lighter dips and tips with it), the flame catches and is held up a moment, and back",
1718
+ keys: [
1719
+ {
1720
+ t: 0,
1721
+ position: [
1722
+ 0.22,
1723
+ -0.2,
1724
+ -0.4
1725
+ ],
1726
+ rotation: [
1727
+ 0,
1728
+ 0,
1729
+ 0
1730
+ ]
1731
+ },
1732
+ {
1733
+ t: 0.4,
1734
+ position: [
1735
+ 0.07,
1736
+ -0.12,
1737
+ -0.34
1738
+ ],
1739
+ rotation: [
1740
+ 0,
1741
+ 0,
1742
+ 0
1743
+ ]
1744
+ },
1745
+ {
1746
+ t: 0.52,
1747
+ position: [
1748
+ 0.07,
1749
+ -0.137,
1750
+ -0.34
1751
+ ],
1752
+ rotation: [
1753
+ 0.14,
1754
+ 0,
1755
+ -0.12
1756
+ ]
1757
+ },
1758
+ {
1759
+ t: 0.58,
1760
+ position: [
1761
+ 0.07,
1762
+ -0.125,
1763
+ -0.34
1764
+ ],
1765
+ rotation: [
1766
+ 0,
1767
+ 0,
1768
+ 0
1769
+ ],
1770
+ action: "ignite"
1771
+ },
1772
+ {
1773
+ t: 1.15,
1774
+ position: [
1775
+ 0.07,
1776
+ -0.115,
1777
+ -0.34
1778
+ ],
1779
+ rotation: [
1780
+ 0,
1781
+ 0,
1782
+ 0
1783
+ ]
1784
+ },
1785
+ {
1786
+ t: 1.5,
1787
+ position: [
1788
+ 0.22,
1789
+ -0.2,
1790
+ -0.4
1791
+ ],
1792
+ rotation: [
1793
+ 0,
1794
+ 0,
1795
+ 0
1796
+ ]
1797
+ }
1798
+ ]
1799
+ },
1800
+ {
1801
+ id: "use_radio",
1802
+ body: "mouth",
1803
+ duration: 3,
1804
+ note: "the radio brought up beside the face, the thumb turning the knob (the radio twists a little with it), held at the mouth while talking, and back down",
1805
+ keys: [
1806
+ {
1807
+ t: 0,
1808
+ position: [
1809
+ 0.22,
1810
+ -0.2,
1811
+ -0.4
1812
+ ],
1813
+ rotation: [
1814
+ 0,
1815
+ 0,
1816
+ 0
1817
+ ]
1818
+ },
1819
+ {
1820
+ t: 0.5,
1821
+ position: [
1822
+ 0.08,
1823
+ -0.05,
1824
+ -0.22
1825
+ ],
1826
+ rotation: [
1827
+ 0,
1828
+ 0,
1829
+ 0.15
1830
+ ]
1831
+ },
1832
+ {
1833
+ t: 0.85,
1834
+ position: [
1835
+ 0.08,
1836
+ -0.05,
1837
+ -0.22
1838
+ ],
1839
+ rotation: [
1840
+ 0,
1841
+ 0,
1842
+ 0.15
1843
+ ]
1844
+ },
1845
+ {
1846
+ t: 1.05,
1847
+ position: [
1848
+ 0.08,
1849
+ -0.05,
1850
+ -0.22
1851
+ ],
1852
+ rotation: [
1853
+ 0,
1854
+ 0.3,
1855
+ 0.15
1856
+ ],
1857
+ action: "tune"
1858
+ },
1859
+ {
1860
+ t: 1.25,
1861
+ position: [
1862
+ 0.08,
1863
+ -0.05,
1864
+ -0.22
1865
+ ],
1866
+ rotation: [
1867
+ 0,
1868
+ 0,
1869
+ 0.15
1870
+ ]
1871
+ },
1872
+ {
1873
+ t: 1.45,
1874
+ position: [
1875
+ 0.05,
1876
+ -0.02,
1877
+ -0.19
1878
+ ],
1879
+ rotation: [
1880
+ -0.1,
1881
+ 0,
1882
+ 0.15
1883
+ ],
1884
+ action: "talk"
1885
+ },
1886
+ {
1887
+ t: 2.4,
1888
+ position: [
1889
+ 0.05,
1890
+ -0.02,
1891
+ -0.19
1892
+ ],
1893
+ rotation: [
1894
+ -0.1,
1895
+ 0,
1896
+ 0.15
1897
+ ]
1898
+ },
1899
+ {
1900
+ t: 3,
1901
+ position: [
1902
+ 0.22,
1903
+ -0.2,
1904
+ -0.4
1905
+ ],
1906
+ rotation: [
1907
+ 0,
1908
+ 0,
1909
+ 0
1910
+ ]
1911
+ }
1912
+ ]
1913
+ },
1914
+ {
1915
+ id: "turn_key",
1916
+ body: "reach",
1917
+ duration: 1.9,
1918
+ note: "the key carried out at arm's length and pointed into the lock (the keys marked reach go to the lock the host aims them at, or stay in the air before the chest), turned about itself a quarter and more, turned back, drawn out",
1919
+ keys: [
1920
+ {
1921
+ t: 0,
1922
+ position: [
1923
+ 0.22,
1924
+ -0.2,
1925
+ -0.4
1926
+ ],
1927
+ rotation: [
1928
+ 0,
1929
+ 0,
1930
+ 0
1931
+ ]
1932
+ },
1933
+ {
1934
+ t: 0.5,
1935
+ position: [
1936
+ 0.1,
1937
+ -0.15,
1938
+ -0.55
1939
+ ],
1940
+ rotation: [
1941
+ 0,
1942
+ 1.524,
1943
+ 0
1944
+ ],
1945
+ reach: true
1946
+ },
1947
+ {
1948
+ t: 0.75,
1949
+ position: [
1950
+ 0.1,
1951
+ -0.15,
1952
+ -0.57
1953
+ ],
1954
+ rotation: [
1955
+ 0,
1956
+ 1.524,
1957
+ 0
1958
+ ],
1959
+ reach: true
1960
+ },
1961
+ {
1962
+ t: 0.84,
1963
+ position: [
1964
+ 0.1,
1965
+ -0.15,
1966
+ -0.57
1967
+ ],
1968
+ rotation: [
1969
+ -1.46,
1970
+ 1.168,
1971
+ 1.45
1972
+ ],
1973
+ reach: true
1974
+ },
1975
+ {
1976
+ t: 0.93,
1977
+ position: [
1978
+ 0.1,
1979
+ -0.15,
1980
+ -0.57
1981
+ ],
1982
+ rotation: [
1983
+ -1.525,
1984
+ 0.77,
1985
+ 1.505
1986
+ ],
1987
+ reach: true
1988
+ },
1989
+ {
1990
+ t: 1.01,
1991
+ position: [
1992
+ 0.1,
1993
+ -0.15,
1994
+ -0.57
1995
+ ],
1996
+ rotation: [
1997
+ -1.552,
1998
+ 0.37,
1999
+ 1.52
2000
+ ],
2001
+ reach: true
2002
+ },
2003
+ {
2004
+ t: 1.1,
2005
+ position: [
2006
+ 0.1,
2007
+ -0.15,
2008
+ -0.57
2009
+ ],
2010
+ rotation: [
2011
+ -1.572,
2012
+ -0.029,
2013
+ 1.524
2014
+ ],
2015
+ action: "turn",
2016
+ reach: true
2017
+ },
2018
+ {
2019
+ t: 1.19,
2020
+ position: [
2021
+ 0.1,
2022
+ -0.15,
2023
+ -0.57
2024
+ ],
2025
+ rotation: [
2026
+ -1.552,
2027
+ 0.37,
2028
+ 1.52
2029
+ ],
2030
+ reach: true
2031
+ },
2032
+ {
2033
+ t: 1.27,
2034
+ position: [
2035
+ 0.1,
2036
+ -0.15,
2037
+ -0.57
2038
+ ],
2039
+ rotation: [
2040
+ -1.525,
2041
+ 0.77,
2042
+ 1.505
2043
+ ],
2044
+ reach: true
2045
+ },
2046
+ {
2047
+ t: 1.34,
2048
+ position: [
2049
+ 0.1,
2050
+ -0.15,
2051
+ -0.57
2052
+ ],
2053
+ rotation: [
2054
+ -1.46,
2055
+ 1.168,
2056
+ 1.45
2057
+ ],
2058
+ reach: true
2059
+ },
2060
+ {
2061
+ t: 1.4,
2062
+ position: [
2063
+ 0.1,
2064
+ -0.15,
2065
+ -0.57
2066
+ ],
2067
+ rotation: [
2068
+ 0,
2069
+ 1.524,
2070
+ 0
2071
+ ],
2072
+ reach: true
2073
+ },
2074
+ {
2075
+ t: 1.55,
2076
+ position: [
2077
+ 0.1,
2078
+ -0.15,
2079
+ -0.55
2080
+ ],
2081
+ rotation: [
2082
+ 0,
2083
+ 1.524,
2084
+ 0
2085
+ ],
2086
+ reach: true
2087
+ },
2088
+ {
2089
+ t: 1.9,
2090
+ position: [
2091
+ 0.22,
2092
+ -0.2,
2093
+ -0.4
2094
+ ],
2095
+ rotation: [
2096
+ 0,
2097
+ 0,
2098
+ 0
2099
+ ]
2100
+ }
2101
+ ]
1623
2102
  }
1624
2103
  ];
1625
2104
 
1626
2105
  // src/hand-use.ts
1627
2106
  var HAND_USES = hand_uses_default;
1628
2107
  var handUseOf = (id, defs = HAND_USES) => defs.find((def) => def.id === id);
2108
+ var HAND_USE_REACH = 0.62;
2109
+ var aimHandUse = (def, target) => {
2110
+ const anchor = def.keys.find((key) => key.reach);
2111
+ if (!anchor) return def;
2112
+ const length = Math.hypot(target[0], target[1], target[2]);
2113
+ const k = length > HAND_USE_REACH ? HAND_USE_REACH / length : 1;
2114
+ const shift = [target[0] * k - anchor.position[0], target[1] * k - anchor.position[1], target[2] * k - anchor.position[2]];
2115
+ const moved = (key) => ({ ...key, position: [key.position[0] + shift[0], key.position[1] + shift[1], key.position[2] + shift[2]] });
2116
+ return { ...def, keys: def.keys.map((key) => key.reach ? moved(key) : key) };
2117
+ };
1629
2118
  var lerp = (a, b, k) => [
1630
2119
  a[0] + (b[0] - a[0]) * k,
1631
2120
  a[1] + (b[1] - a[1]) * k,