@adatechnology/game-items 0.5.4 → 0.6.1
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 +1 -0
- package/dist/index.d.ts +61 -1
- package/dist/index.global.js +36 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -72,6 +72,7 @@ const { contents, leftover } = placeFinds(stacks, slots, items)
|
|
|
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
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
|
+
| `takeDose`, `fullConsumable`, `isSpent`, `remainingShare`, `barScale`, `consumableMassKg`, `consumableOf` | what an item spends a use (`ItemDef.consumable`: `form` bar/liquid/paste, `unit` g/ml, `amount` new, `dose` per use, `emptyKg` packaging, `density`): the dose the action asks for or the spec's, the last one short, `empty` once nothing is left; a bar wears to the cube root of what is left |
|
|
75
76
|
| `canCraft`, `craft` | recipes |
|
|
76
77
|
| `createFindsProvider`, `rollByCategory`, `rollExplicitPool`, `spawnData`, `depletionFactor`, `placeFinds`, `toLootTables` | finds |
|
|
77
78
|
| `itemsFromArsenal` | the arsenal as items |
|
package/dist/index.d.ts
CHANGED
|
@@ -87,6 +87,27 @@ interface Durability {
|
|
|
87
87
|
/** Source qualifier when the amount alone is not enough (for example the voltage of a battery). */
|
|
88
88
|
per?: string;
|
|
89
89
|
}
|
|
90
|
+
/** How what an item spends is measured: grams (a bar, a paste) or millilitres (a liquid). */
|
|
91
|
+
type ConsumableUnit = 'g' | 'ml';
|
|
92
|
+
/** The shape of what is spent: a `bar` wears down on every face, a `liquid` or `paste` drops inside a package that keeps its size. */
|
|
93
|
+
type ConsumableForm = 'bar' | 'liquid' | 'paste';
|
|
94
|
+
/** What an item spends at each use (`consumable.ts`): what it holds new, one use's dose and the packaging's weight. */
|
|
95
|
+
interface ConsumableSpec {
|
|
96
|
+
readonly form: ConsumableForm;
|
|
97
|
+
readonly unit: ConsumableUnit;
|
|
98
|
+
/** What it holds when new, in `unit`. */
|
|
99
|
+
readonly amount: number;
|
|
100
|
+
/** What one use takes, in `unit`; an action may ask for its own. */
|
|
101
|
+
readonly dose: number;
|
|
102
|
+
/** Kilograms of the packaging (the bottle, the tube) with nothing left; 0 for a bar. */
|
|
103
|
+
readonly emptyKg: number;
|
|
104
|
+
/** Kilograms per litre of a liquid or paste; water's 1 when missing. */
|
|
105
|
+
readonly density?: number;
|
|
106
|
+
}
|
|
107
|
+
/** What is left of a consumable item, in its `unit`. */
|
|
108
|
+
interface ConsumableState {
|
|
109
|
+
readonly remaining: number;
|
|
110
|
+
}
|
|
90
111
|
/** Id of a place where items turn up (house, hospital, farm...). Places are a registry: a pack or the game declares the ones it uses. */
|
|
91
112
|
type PlaceTag = string;
|
|
92
113
|
/** Id of an item category. The 14 of `ITEM_CATEGORIES` are always present; a game adds its own through `createItems({ categories })`. */
|
|
@@ -132,6 +153,8 @@ interface ItemDef extends ItemDef$1 {
|
|
|
132
153
|
/** Litres. Derived from `size` when the pack does not give it. */
|
|
133
154
|
volume?: number;
|
|
134
155
|
durability?: Durability;
|
|
156
|
+
/** What it spends at each use (soap, shampoo, toothpaste): read by `takeDose`. */
|
|
157
|
+
consumable?: ConsumableSpec;
|
|
135
158
|
/** Days to spoil at room temperature. */
|
|
136
159
|
shelfLife?: number;
|
|
137
160
|
portions?: number;
|
|
@@ -937,4 +960,41 @@ declare const aimHandUse: (def: HandUseDef, target: readonly [number, number, nu
|
|
|
937
960
|
/** Plays a hand use: the pose between its keys, and its actions as the time passes them. */
|
|
938
961
|
declare const createHandUse: (def: HandUseDef) => HandUsePlayer;
|
|
939
962
|
|
|
940
|
-
|
|
963
|
+
/**
|
|
964
|
+
* What an item spends a little of at each use (a bar of soap, a bottle of shampoo, a tube of toothpaste, a bottle of dish soap): how much it holds when new, how much
|
|
965
|
+
* one use takes and what the packaging weighs. Engine-agnostic and pure: a host keeps a `ConsumableState` per item, asks `takeDose` at each use, and reads back the
|
|
966
|
+
* share left, the mass and, for a bar, the size the bar has worn down to. The last use takes what is left; with nothing left the use is refused (`empty`).
|
|
967
|
+
*/
|
|
968
|
+
|
|
969
|
+
/** The consumable spec of an item, or undefined when using it spends nothing. */
|
|
970
|
+
declare const consumableOf: (item: Pick<ItemDef, "consumable">) => ConsumableSpec | undefined;
|
|
971
|
+
/** A new item: full. */
|
|
972
|
+
declare const fullConsumable: (spec: ConsumableSpec) => ConsumableState;
|
|
973
|
+
/** Nothing left to use. */
|
|
974
|
+
declare const isSpent: (state: ConsumableState) => boolean;
|
|
975
|
+
/** Share of the new amount still there, 0..1. */
|
|
976
|
+
declare const remainingShare: (spec: ConsumableSpec, state: ConsumableState) => number;
|
|
977
|
+
/** What one use took: the state after it, the amount taken, whether it was short of a full dose and whether the item is now empty. */
|
|
978
|
+
interface DoseResult {
|
|
979
|
+
readonly state: ConsumableState;
|
|
980
|
+
readonly taken: number;
|
|
981
|
+
/** The use got less than it asked for (the last of the bar, the last squeeze of the tube). */
|
|
982
|
+
readonly short: boolean;
|
|
983
|
+
/** Nothing was left: the use got nothing and must not play. */
|
|
984
|
+
readonly empty: boolean;
|
|
985
|
+
/** The item has nothing left after this use. */
|
|
986
|
+
readonly spent: boolean;
|
|
987
|
+
}
|
|
988
|
+
/** Takes one dose (`dose`, or the spec's own) out of `state`. */
|
|
989
|
+
declare const takeDose: (spec: ConsumableSpec, state: ConsumableState, dose?: number) => DoseResult;
|
|
990
|
+
/** Mass of the item now: the packaging plus what is left in it. */
|
|
991
|
+
declare const consumableMassKg: (spec: ConsumableSpec, state: ConsumableState) => number;
|
|
992
|
+
/**
|
|
993
|
+
* The size a bar has worn down to, as a scale of its new size: soap wears off every face, so the volume goes with the mass left and each side with its cube root.
|
|
994
|
+
* Anything that is not a bar keeps its size (the bottle and the tube stay; what is inside drops).
|
|
995
|
+
*/
|
|
996
|
+
declare const barScale: (spec: ConsumableSpec, state: ConsumableState) => number;
|
|
997
|
+
/** Problems with a consumable spec, for `checkItems`. */
|
|
998
|
+
declare const consumableProblems: (spec: ConsumableSpec) => string[];
|
|
999
|
+
|
|
1000
|
+
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 ConsumableForm, type ConsumableSpec, type ConsumableState, type ConsumableUnit, type Consumption, type ContainerDef, type CraftCheck, type CraftContext, type CraftOutcome, type CraftResult, DEFAULT_RULES, DURABILITY_KINDS, type DepletionRule, type DestructionObjectState, type DoseResult, 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, barScale, blockChance, canCraft, canTake, carriedKg, chargeLevel, checkItems, consumableMassKg, consumableOf, consumableProblems, craft, createFindsProvider, createHandUse, createInventory, createItems, depletionFactor, failsToStart, fitsInside, freshness, fullConsumable, handUseOf, isSpent, itemLitres, itemsFromArsenal, loadState, maxLoadKg, moveToStorage, pieceBlock, placeFinds, remainingShare, repairPiece, resolveUse, rollByCategory, rollExplicitPool, scaleCount, shelfRatio, spawnAgeDays, spawnData, storageMultiplier, takeDose, toLootTables, wearBlocked };
|
package/dist/index.global.js
CHANGED
|
@@ -32,12 +32,16 @@ var GameItems = (() => {
|
|
|
32
32
|
advanceAge: () => advanceAge,
|
|
33
33
|
aimHandUse: () => aimHandUse,
|
|
34
34
|
bagOption: () => bagOption,
|
|
35
|
+
barScale: () => barScale,
|
|
35
36
|
blockChance: () => blockChance,
|
|
36
37
|
canCraft: () => canCraft,
|
|
37
38
|
canTake: () => canTake,
|
|
38
39
|
carriedKg: () => carriedKg,
|
|
39
40
|
chargeLevel: () => chargeLevel,
|
|
40
41
|
checkItems: () => checkItems,
|
|
42
|
+
consumableMassKg: () => consumableMassKg,
|
|
43
|
+
consumableOf: () => consumableOf,
|
|
44
|
+
consumableProblems: () => consumableProblems,
|
|
41
45
|
craft: () => craft,
|
|
42
46
|
createFindsProvider: () => createFindsProvider,
|
|
43
47
|
createHandUse: () => createHandUse,
|
|
@@ -47,7 +51,9 @@ var GameItems = (() => {
|
|
|
47
51
|
failsToStart: () => failsToStart,
|
|
48
52
|
fitsInside: () => fitsInside,
|
|
49
53
|
freshness: () => freshness,
|
|
54
|
+
fullConsumable: () => fullConsumable,
|
|
50
55
|
handUseOf: () => handUseOf,
|
|
56
|
+
isSpent: () => isSpent,
|
|
51
57
|
itemLitres: () => itemLitres,
|
|
52
58
|
itemsFromArsenal: () => itemsFromArsenal,
|
|
53
59
|
loadState: () => loadState,
|
|
@@ -55,6 +61,7 @@ var GameItems = (() => {
|
|
|
55
61
|
moveToStorage: () => moveToStorage,
|
|
56
62
|
pieceBlock: () => pieceBlock,
|
|
57
63
|
placeFinds: () => placeFinds,
|
|
64
|
+
remainingShare: () => remainingShare,
|
|
58
65
|
repairPiece: () => repairPiece,
|
|
59
66
|
resolveUse: () => resolveUse,
|
|
60
67
|
rollByCategory: () => rollByCategory,
|
|
@@ -64,6 +71,7 @@ var GameItems = (() => {
|
|
|
64
71
|
spawnAgeDays: () => spawnAgeDays,
|
|
65
72
|
spawnData: () => spawnData,
|
|
66
73
|
storageMultiplier: () => storageMultiplier,
|
|
74
|
+
takeDose: () => takeDose,
|
|
67
75
|
toLootTables: () => toLootTables,
|
|
68
76
|
wearBlocked: () => wearBlocked
|
|
69
77
|
});
|
|
@@ -376,6 +384,33 @@ var GameItems = (() => {
|
|
|
376
384
|
{ id: "keys", name: "Keys" }
|
|
377
385
|
];
|
|
378
386
|
|
|
387
|
+
// src/consumable.ts
|
|
388
|
+
var KG_PER_GRAM = 1e-3;
|
|
389
|
+
var WATER_DENSITY = 1;
|
|
390
|
+
var consumableOf = (item) => item.consumable;
|
|
391
|
+
var fullConsumable = (spec) => ({ remaining: spec.amount });
|
|
392
|
+
var isSpent = (state) => state.remaining <= 0;
|
|
393
|
+
var remainingShare = (spec, state) => Math.min(1, Math.max(0, state.remaining / spec.amount));
|
|
394
|
+
var takeDose = (spec, state, dose = spec.dose) => {
|
|
395
|
+
if (isSpent(state)) return { state, taken: 0, short: true, empty: true, spent: true };
|
|
396
|
+
const asked = Math.max(0, dose);
|
|
397
|
+
const taken = Math.min(asked, state.remaining);
|
|
398
|
+
const remaining = state.remaining - taken;
|
|
399
|
+
return { state: { remaining }, taken, short: taken < asked, empty: false, spent: remaining <= 0 };
|
|
400
|
+
};
|
|
401
|
+
var unitKg = (spec) => spec.unit === "g" ? KG_PER_GRAM : (spec.density ?? WATER_DENSITY) * KG_PER_GRAM;
|
|
402
|
+
var consumableMassKg = (spec, state) => spec.emptyKg + Math.max(0, state.remaining) * unitKg(spec);
|
|
403
|
+
var barScale = (spec, state) => spec.form === "bar" ? Math.cbrt(remainingShare(spec, state)) : 1;
|
|
404
|
+
var consumableProblems = (spec) => {
|
|
405
|
+
const problems = [];
|
|
406
|
+
if (!(spec.amount > 0) || !Number.isFinite(spec.amount)) problems.push(`holds ${spec.amount} ${spec.unit} when new`);
|
|
407
|
+
if (!(spec.dose > 0) || !(spec.dose <= spec.amount)) problems.push(`spends ${spec.dose} ${spec.unit} a use (above 0, at most what it holds)`);
|
|
408
|
+
if (!(spec.emptyKg >= 0) || !Number.isFinite(spec.emptyKg)) problems.push(`has packaging of ${spec.emptyKg} kg`);
|
|
409
|
+
if (spec.density !== void 0 && !(spec.density > 0)) problems.push(`has a density of ${spec.density} kg/L`);
|
|
410
|
+
if (spec.form === "bar" && spec.unit !== "g") problems.push("is a bar measured in millilitres");
|
|
411
|
+
return problems;
|
|
412
|
+
};
|
|
413
|
+
|
|
379
414
|
// src/types.ts
|
|
380
415
|
var RARITIES = ["common", "uncommon", "rare", "very_rare", "legendary", "unique"];
|
|
381
416
|
var BODY_SLOTS = ["head", "eyes", "torso", "arms", "hands", "legs", "feet", "over"];
|
|
@@ -404,6 +439,7 @@ var GameItems = (() => {
|
|
|
404
439
|
if (item.shelfLife !== void 0 && !isPositive(item.shelfLife)) issue(`has a shelf life of ${item.shelfLife} days`);
|
|
405
440
|
if (item.portions !== void 0 && !(Number.isInteger(item.portions) && item.portions > 0)) issue(`has ${item.portions} portions`);
|
|
406
441
|
if (item.durability && !DURABILITY_KINDS.includes(item.durability.kind)) issue(`has unknown durability kind "${item.durability.kind}"`);
|
|
442
|
+
if (item.consumable) for (const problem of consumableProblems(item.consumable)) issue(problem);
|
|
407
443
|
const { protection } = item;
|
|
408
444
|
if (protection) {
|
|
409
445
|
for (const slot of protection.slots) if (!BODY_SLOTS.includes(slot)) issue(`protects unknown body slot "${slot}"`);
|