@adatechnology/game-items 0.4.1 → 0.5.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/dist/index.js CHANGED
@@ -436,14 +436,17 @@ var createInventory = (options) => {
436
436
  return slotIds;
437
437
  };
438
438
  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 });
439
- const putInBag = (stack, rest) => {
439
+ const planBag = (stack, rest) => {
440
440
  const item = items.get(stack.itemId);
441
441
  if (!item) return { ok: false, reason: "unknown_item" };
442
442
  if (!Number.isInteger(stack.count) || stack.count < 1 || stack.state !== void 0 && stack.count !== 1) return { ok: false, reason: "bad_count" };
443
443
  const plan = planSlots(item, stack);
444
444
  const verdict = fitsInBag(item, stack, plan, rest);
445
- if (verdict !== "ok") return { ok: false, reason: verdict };
446
- return { ok: true, slotIds: commit(stack, plan) };
445
+ return verdict === "ok" ? { ok: true, plan } : { ok: false, reason: verdict };
446
+ };
447
+ const putInBag = (stack, rest) => {
448
+ const planned = planBag(stack, rest);
449
+ return planned.ok ? { ok: true, slotIds: commit(stack, planned.plan) } : planned;
447
450
  };
448
451
  const findSlot = (slotId) => slotList.findIndex((slot) => slot.slotId === slotId);
449
452
  return {
@@ -452,6 +455,11 @@ var createInventory = (options) => {
452
455
  const now = totals();
453
456
  return putInBag(stack, { kg: now.kg, litres: now.litres });
454
457
  },
458
+ canTake: ({ itemId, count = 1, state }) => {
459
+ const now = totals();
460
+ const planned = planBag(state === void 0 ? { itemId, count } : { itemId, count, state }, { kg: now.kg, litres: now.litres });
461
+ return planned.ok ? { ok: true } : planned;
462
+ },
455
463
  hold: ({ itemId, state }) => {
456
464
  const item = items.get(itemId);
457
465
  if (!item) return { ok: false, reason: "unknown_item" };