@adatechnology/game-items 0.5.4 → 0.6.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 +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/dist/index.js
CHANGED
|
@@ -162,6 +162,33 @@ var ITEM_CATEGORIES = [
|
|
|
162
162
|
{ id: "keys", name: "Keys" }
|
|
163
163
|
];
|
|
164
164
|
|
|
165
|
+
// src/consumable.ts
|
|
166
|
+
var KG_PER_GRAM = 1e-3;
|
|
167
|
+
var WATER_DENSITY = 1;
|
|
168
|
+
var consumableOf = (item) => item.consumable;
|
|
169
|
+
var fullConsumable = (spec) => ({ remaining: spec.amount });
|
|
170
|
+
var isSpent = (state) => state.remaining <= 0;
|
|
171
|
+
var remainingShare = (spec, state) => Math.min(1, Math.max(0, state.remaining / spec.amount));
|
|
172
|
+
var takeDose = (spec, state, dose = spec.dose) => {
|
|
173
|
+
if (isSpent(state)) return { state, taken: 0, short: true, empty: true, spent: true };
|
|
174
|
+
const asked = Math.max(0, dose);
|
|
175
|
+
const taken = Math.min(asked, state.remaining);
|
|
176
|
+
const remaining = state.remaining - taken;
|
|
177
|
+
return { state: { remaining }, taken, short: taken < asked, empty: false, spent: remaining <= 0 };
|
|
178
|
+
};
|
|
179
|
+
var unitKg = (spec) => spec.unit === "g" ? KG_PER_GRAM : (spec.density ?? WATER_DENSITY) * KG_PER_GRAM;
|
|
180
|
+
var consumableMassKg = (spec, state) => spec.emptyKg + Math.max(0, state.remaining) * unitKg(spec);
|
|
181
|
+
var barScale = (spec, state) => spec.form === "bar" ? Math.cbrt(remainingShare(spec, state)) : 1;
|
|
182
|
+
var consumableProblems = (spec) => {
|
|
183
|
+
const problems = [];
|
|
184
|
+
if (!(spec.amount > 0) || !Number.isFinite(spec.amount)) problems.push(`holds ${spec.amount} ${spec.unit} when new`);
|
|
185
|
+
if (!(spec.dose > 0) || !(spec.dose <= spec.amount)) problems.push(`spends ${spec.dose} ${spec.unit} a use (above 0, at most what it holds)`);
|
|
186
|
+
if (!(spec.emptyKg >= 0) || !Number.isFinite(spec.emptyKg)) problems.push(`has packaging of ${spec.emptyKg} kg`);
|
|
187
|
+
if (spec.density !== void 0 && !(spec.density > 0)) problems.push(`has a density of ${spec.density} kg/L`);
|
|
188
|
+
if (spec.form === "bar" && spec.unit !== "g") problems.push("is a bar measured in millilitres");
|
|
189
|
+
return problems;
|
|
190
|
+
};
|
|
191
|
+
|
|
165
192
|
// src/types.ts
|
|
166
193
|
var RARITIES = ["common", "uncommon", "rare", "very_rare", "legendary", "unique"];
|
|
167
194
|
var BODY_SLOTS = ["head", "eyes", "torso", "arms", "hands", "legs", "feet", "over"];
|
|
@@ -190,6 +217,7 @@ var checkItem = (item, { categories, places }) => {
|
|
|
190
217
|
if (item.shelfLife !== void 0 && !isPositive(item.shelfLife)) issue(`has a shelf life of ${item.shelfLife} days`);
|
|
191
218
|
if (item.portions !== void 0 && !(Number.isInteger(item.portions) && item.portions > 0)) issue(`has ${item.portions} portions`);
|
|
192
219
|
if (item.durability && !DURABILITY_KINDS.includes(item.durability.kind)) issue(`has unknown durability kind "${item.durability.kind}"`);
|
|
220
|
+
if (item.consumable) for (const problem of consumableProblems(item.consumable)) issue(problem);
|
|
193
221
|
const { protection } = item;
|
|
194
222
|
if (protection) {
|
|
195
223
|
for (const slot of protection.slots) if (!BODY_SLOTS.includes(slot)) issue(`protects unknown body slot "${slot}"`);
|
|
@@ -1963,12 +1991,16 @@ export {
|
|
|
1963
1991
|
advanceAge,
|
|
1964
1992
|
aimHandUse,
|
|
1965
1993
|
bagOption,
|
|
1994
|
+
barScale,
|
|
1966
1995
|
blockChance,
|
|
1967
1996
|
canCraft,
|
|
1968
1997
|
canTake,
|
|
1969
1998
|
carriedKg,
|
|
1970
1999
|
chargeLevel,
|
|
1971
2000
|
checkItems,
|
|
2001
|
+
consumableMassKg,
|
|
2002
|
+
consumableOf,
|
|
2003
|
+
consumableProblems,
|
|
1972
2004
|
craft,
|
|
1973
2005
|
createFindsProvider,
|
|
1974
2006
|
createHandUse,
|
|
@@ -1978,7 +2010,9 @@ export {
|
|
|
1978
2010
|
failsToStart,
|
|
1979
2011
|
fitsInside,
|
|
1980
2012
|
freshness,
|
|
2013
|
+
fullConsumable,
|
|
1981
2014
|
handUseOf,
|
|
2015
|
+
isSpent,
|
|
1982
2016
|
itemLitres,
|
|
1983
2017
|
itemsFromArsenal,
|
|
1984
2018
|
loadState,
|
|
@@ -1986,6 +2020,7 @@ export {
|
|
|
1986
2020
|
moveToStorage,
|
|
1987
2021
|
pieceBlock,
|
|
1988
2022
|
placeFinds,
|
|
2023
|
+
remainingShare,
|
|
1989
2024
|
repairPiece,
|
|
1990
2025
|
resolveUse,
|
|
1991
2026
|
rollByCategory,
|
|
@@ -1995,6 +2030,7 @@ export {
|
|
|
1995
2030
|
spawnAgeDays,
|
|
1996
2031
|
spawnData,
|
|
1997
2032
|
storageMultiplier,
|
|
2033
|
+
takeDose,
|
|
1998
2034
|
toLootTables,
|
|
1999
2035
|
wearBlocked
|
|
2000
2036
|
};
|