@adatechnology/game-items

中文文档
0.2.5发布于 2026/11/06MITTypeScriptES Module构建来源已验证近 30 天下载 3379

Engine-agnostic item catalog engine: item definitions (category, size, weight, rarity, durability, shelf life, protection, carry), an extensible registry with patch/remove/include, and the default rules for finds, freshness, storage, carry weight and prot

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. Logic
  4. API
  5. Goldens against the team's code

@adatechnology/game-items

Engine-agnostic item catalog engine. It defines what an item is (category, real size in metres, weight in kg, rarity, durability, shelf life, nutrition, protection, carry capacity, weapon link, where it is found), a registry that games extend and patch, and the default rules for finds, freshness, storage, carry weight and clothing protection. It has no content (the catalog lives in @adatechnology/game-items-goods) and no renderer (3D lives in @adatechnology/game-items-three), and it knows nothing about any game.

Status: engine complete (T3.1a and T3.1e of spec 001): registry, rules, lazy aging, carry, protection, use effects, recipes, finds and the arsenal bridge. Everything is pure; the host keeps the state.

Units: metres, kilograms, litres, days.

Install

pnpm add @adatechnology/game-items

A plain <script src=".../dist/index.global.js"> exposes the GameItems global.

Usage

import { createItems } from '@adatechnology/game-items'
import type { ItemDef } from '@adatechnology/game-items'

const beans: ItemDef = { id: 'canned_beans', category: 'food', size: [0.075, 0.11, 0.075], weight: 0.43, rarity: 'common', shelfLife: 1460, portions: 2 }

const items = createItems({
  packs: [{ id: 'mine', items: [beans], places: [{ id: 'house' }] }],
  patch: { canned_beans: { weight: 0.45 } },        // field by field; arrays replace
  rules: { carry: { baseKg: 10 } },                 // merged over DEFAULT_RULES
})
items.get('canned_beans').volume // 0.928 L, derived from size
items.byCategory('food')

Order: packs (a later item with the same id replaces), patch, remove, include. Every inconsistency (unknown category, rarity or place, invalid size, weight, shelf life, protection, carry or rule) is reported in one error.

Logic

import { createFindsProvider, freshness, blockChance, maxLoadKg, placeFinds } from '@adatechnology/game-items'

freshness(milk, { ageDays: 0, since: 0, storage: 'fridge', storedAt: 0 }, 20)   // closes the account lazily, then 'fresh' | 'stale' | 'spoiled' | 'rotten'
blockChance(pieces, 'arms', 'bite')                                              // 1 - PROD(1 - value x condition), capped at 90%
maxLoadKg(strength)                                                              // (8 + 2.5 x strength) x 1.2
const stacks = createFindsProvider(items).findsFor({ place: 'house', container: 'fridge', state: 'fortified', rng, day: 12 })
const { contents, leftover } = placeFinds(stacks, slots, items)                  // the floorplan's `contents`
  • Aging is lazy. Nothing ticks: advanceAge closes ageDays += (now - since) x multiplier when an item moves or is looked at. Fridge and freezer need power (the host passes powered); a freezer without power makes the food fresh with 2 days to go; a cooler ages at x0.5 for its first 2 days; batteries lose 10% of charge per month; gasoline past 180 days fails 10% of the starts.
  • Finds are two ports behind one provider. A container with an explicit pool (the 3D viewer's sorteiaConteudo: count by footprint, weighted order, fortified x2.5 and +1 on supplies, abandoned 40% empty plus junk) draws from it; any other draws like the game's rollItems (count range, category weights, rarity 60/28/9/2.5 among the items of the place). Both keep the order of the random draws of their source; the stacks are chosen first and the state of each (age, condition, charge, fill) is drawn after. The count falls with the days of the outbreak (max(floor, 1 - perDay x days), none on day 0) and can be scaled by region.
  • The provider is the floorplan's FindsProvider by shape (findsFor(query) -> FindStack[]); this package does not import game-floorplan.
  • The arsenal becomes items: itemsFromArsenal(arsenal, { records }) makes ammo_<caliber>, firearm_<id> and throwable_<id>; the game's boxes (records) give rounds, weight and rarity, the rest is estimated.
  • Packs also carry pools (what a kind of furniture holds), poolAliases, useEffects and recipes; resolveUse, canCraft and craft read them and leave applying the result to the host.

API

NameWhat it is
createItems(options?)ItemsCatalog: maps items, categories, places, containers, pools, recipes, useEffects, rules; has, get (throws on unknown), list, byCategory, byPlace, byTag
ItemDefextends the interactables ItemDef; fields in src/types.ts
ITEM_CATEGORIESthe 14 categories (food, drink, medical, tools, melee, materials, clothing, bags, electronics, fuel, outdoors, books, collectibles, keys); games add more with categories
DEFAULT_RULES, ItemRulesrarity weights 60/28/9/2.5/0.5 (legendary and unique only at fixed spots), freshness 0.5/1/1.5, storage multipliers, carry (8 + 2.5 × strength) × 1.2 with 100% / 150%, protection cap 90%, wear -8 / -3, torn 25%, aging, inventory, use (past-its-best food), spawn (new shop stock, condition by rarity, age, charge, fill), finds (depletion by day, states, pool numbers)
advanceAge, moveToStorage, storageMultiplier, freshness, shelfRatio, chargeLevel, failsToStartaging and decay
blockChance, wearBlocked, repairPiece, pieceBlocklayered clothing protection
maxLoadKg, carriedKg, loadState, bagOption, canTakecarry weight and slots
resolveUsewhat 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)
canCraft, craftrecipes
createFindsProvider, rollByCategory, rollExplicitPool, spawnData, depletionFactor, placeFinds, toLootTablesfinds
itemsFromArsenalthe arsenal as items
checkItems(parts)the consistency check createItems runs
RARITIES, BODY_SLOTS, DURABILITY_KINDSthe closed vocabularies

Places are a registry too: none ships, the pack or the game declares them; finds.places is checked only when at least one place is registered.

Goldens against the team's code

tests/team-golden.test.ts compares the two ports with what the team's own code answers: rollByCategory with the game's rollItems (2400 cases) and rollExplicitPool with the 3D house viewer's sorteiaConteudo (1875 cases), same result and same number of random draws. The fixtures in tests/fixtures/team-golden/ are recorded once by pnpm --filter @adatechnology/game-items record:team-golden, which cuts the functions out of the delivered sources and runs them in a vm with a seeded random stream.

版本与发布记录

@adatechnology/game-items 共发布 19 个版本,首次发布于 2026/10/24;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.5latest2026/11/06今天
0.2.42026/11/042 天前
0.2.32026/11/042 天前
0.2.22026/11/042 天前
0.2.12026/11/033 天前
0.2.02026/11/015 天前

关于 @adatechnology/game-items 的常见问题

@adatechnology/game-items 是什么?

Engine-agnostic item catalog engine: item definitions (category, size, weight, rarity, durability, shelf life, protection, carry), an extensible registry with patch/remove/include, and the default rules for finds, freshness, storage, carry weight and prot

如何安装 @adatechnology/game-items?

在项目目录运行 npm install @adatechnology/game-items,或使用 pnpm add / yarn add / bun add。

@adatechnology/game-items 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adatechnology/game-items 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adatechnology/game-items 可以商用吗?

@adatechnology/game-items 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adatechnology/game-items 的下载量有多少?

根据 npm 官方下载统计,@adatechnology/game-items 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,379 次,日均约 113 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adatechnology/game-items 还在维护吗?

最新版本 0.2.5 发布于 2026/11/06(今天);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/10/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。