Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release notes for each version; the GitHub release carries the same text and the

## Unreleased

- Two more rule packs (RPG R6), both in "New game". **Turn battle**: a knight, a mage and a cleric against a band of foes, everyone acting once a round by speed; attacks, arts (shield bash stuns, fireball hits every foe, mend heals and cures), guarding, potions, poison and stun; the story spawns the foes and calls `-> battle ->`, then reads `battle_result`. **Narrative checks**: the rules of the dorm horror game *302* (2d6 checks on choices, six difficulties, five skills that speak as inner voices, fear and stamina, companions' fear and trust, fear lowering reason) plus `clamp()`; a game adds its own characters, resources and items.
- Levels and campaigns (RPG R5). `levels: { resource: xp, at: [0, 4, 10] }` gives the story `level`, `next_level_at()`, `level_up_ready()` and `level_up()`; the status bar shows the level and marks when one can be taken. Perks are ordinary items. A line tagged `#sheet` (or the command "Save character sheet", `api.saveSheet()`) writes the character being played as a note in the game's `sheets:` folder: its frontmatter is a `characters` entry (skills, items, what is worn, counts, level, resources, statuses), its body gets the adventure's epilogue. The next adventure reads such notes with `characters: { from: ../角色 }`. Characters written in `game.md` can also set `equipped`, `level`, `resources` and `statuses`.

## 0.6.0 — 2026-11-10
Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ PRD: `docs/game-engine-prd.md` — TTRPG-style rules engine on top of Inkwright
- RPG R3 rule-system packs: `src/game/system.ts` (`systemRef`, `layerSystem`: lists keyed by id joined, the game's entry wins, other values replaced, the pack's `from`/image paths moved relative to the game, `version` and `pack` dropped; `withSystem` reads `<pack>/system.md`, problems `systemMissing`/`systemVersion` (major version), finds `rules.ink` → `GameConfig.systemRules`, which `generateInk` INCLUDEs as line 2; `joinPath` keeps leading `..`, as does `normalizePath` in compile/paths). Loaded by `scripts/game-note.ts loadGameConfig` and `obsidian.ts loadGameNote` (returns the pack files as dependencies). `check-ink` skips the ink of a folder holding `system.md` (its `template/` is checked). First-party packs live in `packs/<id>/` (`system.md` with a quoted `version` and `pack: { name, description }`, `rules.ink`, `template/` with a committed `_engine.ink`, `说明.md`); `tests/system.test.ts` keeps each template's engine current and plays it. `scripts/packs-bundle.mjs` → `virtual:packs` (template engines left out); `src/templates/packs.ts` (pure: `packList`, `relativePath`, `packGame`); `main.ts createGame` (shared with the journal template) / `newGame(pack, folder?)`, command `new-game` (`NewGameModal` → `FolderModal`), `api.newGame`. The dungeon-crawl pack: `-> crawl ->`, `crawl_result` won/left/fallen, `crawl_rooms`, `depth`; balance measured with a fixed-strategy bot (always strike, potion at life ≤ 2): 68% wins.
- RPG R4 stacks, slots, statuses: `ItemDef.stack` (count VAR `<id><stackSuffix>`, `_n`; `inkgen stackInk`: `give(item, n)`/`take(item, n)` → taken/`inv_count(item)`, list-item arguments, the inventory follows the count; non-stacking items: give adds, take removes one, count 0/1), `CharacterDef.counts` (set in `pick_character`, also carried); `slots: SlotDef[]` + `ItemDef.slot` (`slotInk`: `VAR equipped`, `equip` drops the slot's other items and carries it, `unequip`; `pick_character` equips the first carried item per slot; character only); `collectModifiers` counts a slotted item only while equipped and carried, and the character's own statuses' `modifiers`. `statuses: StatusDef[]` (name, desc, modifiers, `rest`): `src/game/statuses.ts` (pure store `who|id|turns;…`, turns ≤ 0 = until cleared, re-adding keeps the longer; tested in `tests/statuses.test.ts`), `statusInk` (`VAR statuses`, pure EXTERNALs `status_put/in/left/take/tick/rest` with no-engine fallbacks where nothing takes hold, wrappers `add_status(who, id, turns)`, `has_status`, `status_turns`, `clear_status` ("" = all of who's), `tick_statuses`, `rest_statuses`; who = an entity/member id or `InkNames.self` "me"/zh "我"), `GameEngine.bindStatuses`, `statusesOf` → `hud().statuses` (the character's), `PartyMemberView.statuses`, `EntityView.statuses`; `ItemView.count/equipped/slot`. Problems `itemSlot`, `statusSkill`, `countItem`; the new InkNames are reserved only when used (`amountParam` also with stacks). Panel: `status.ts itemChip`/`statusTags` (`.inkwright-item-equipped`, `.inkwright-status`); web `renderHud` `itemText`/`statusText`. Random runs: stack counts in `resources` (as `<id>_n`, no top), `SimulateResult.statuses` (`StatusTally`: appearances between steps, runs). Tests: `tests/game-gear.test.ts`, the web gear test.
- RPG R5 levels and sheets: `levels: LevelsDef` (`resource`, `at`; problems `levelsResource`, `levelsOrder`), `inkgen levelInk` (`VAR level`, `next_level_at`, `level_up_ready`, `level_up`; InkNames reserved only with levels), `hud().level` (`{ level, next, ready }`; panel `chipRow` + `.inkwright-level-ready`, web line). `CharacterDef.equipped/level/resources/statuses` (loaded by `pick_character`; `equipped` over the first carried item per slot; problems `characterLevel`, `characterResource`, `characterStatus`). `src/game/sheet.ts` (pure): `sheetOf(config, state, current)` (the played character as a `characters` entry; `GameEngine.sheet()`), `sheetName`, `sheetNote(yaml, oldBody, epilogue, title, date)` (frontmatter replaced, body kept, a section added), `characterFromNote` (uses `isCharacter` from config.ts). `main.ts`: `saveSheet(epilogue?)` (folder `sheets` relative to the story's, default `T().sheetsFolder`; refused outside the vault; the state read at once, the write queued with `runs.enqueue`; the character's sheet found by frontmatter id, else named by `sheetName`; `ownWrites` makes the change events of that file within `OWN_WRITE_MS` not trigger a recompile, since a camp reads the folder it writes; the engine still goes stale, which is right: the next play needs the new presets), the controller's `RunHost.afterChoose(paragraphs)` (called only after the player takes a choice, with the text it produced; a `#sheet` line there writes, so back/replay/load/language never do), command `save-sheet`, `api.saveSheet`. `characters: { from }` → `GameConfig.charactersFrom` (no `noCharacters` until resolved), `resolve.ts resolveCharacters` (first in `resolveConfig`; the folder and notes are dependencies; problem `charactersFolder`). Tests: `tests/campaign.test.ts`.
- RPG R6 packs: `packs/turn-battle` (no engine changes: party + the `foe` kind; `battle` knot: rounds, `ready_all` clears `acted`, `next_actor` = the fastest standing one not yet acted, heroes first on ties (recursive `fastest` over `nth_one`); a hero's options are threads per foe/ally, a foe acts in `foe_turn`; stun/guard/poison statuses; damage atk + 2d6 - 4 - def; `battle_result`, `battle_round`; balance by a strategy bot: 2026-11-10 numbers in its `说明.md`) and `packs/narrative-check` (dorm-302's rules: difficulties, five voiced skills, fear/hp, companion fear/trust, the fear modifier; `rules.ink` = `clamp`). dorm-302 vendors a copy in `packs/narrative-check/`; its check-ink output was compared before and after the switch. `tests/system.test.ts` plays every template and a 3 on 3 round order.
- Tabletop PRD: `docs/tabletop-prd.md` — solo TTRPG / board-game support on top of game mode: five primitives (free rolls, random tables, decks, `#input`, play log to a note), what qualifies, the order to build them in. Read it before adding any of those.
- Tabletop slice 1, dice and tables: `src/game/dice.ts` parses and rolls formulas (`parseFormula`, `rollFormula`; `d66` is two d6 read as tens and units); `src/game/tables.ts` is the table logic (ranges, the dice given or inferred, `rowAt`, `tableProblems` for gaps/overlaps/bad dice, `rowsFromMarkdown` for a note's first markdown table, `resolveTables` fills `from:` tables in and lists the notes read). The engine binds one more EXTERNAL, `roll_dice(formula, label)`, on the check's seed and roll counter; `roll(formula)`, `table_roll`, `table_text`, `table_id` and `table(name)` are generated ink: the lookups are plain ink, so a story reads the same row without the engine (the fallback `roll_dice` returns each table's average, 1 for other dice). `engine.rolls` is `CheckRecord | DiceRecord` (`kind`); the panel, the web player and the journal render both kinds of card. The explorer gives the engine a fixed rng, so table rolls repeat between walks; the config's `from:` notes are compile dependencies (`GameNoteRead.files`), and `main.ts` resolves them wherever it loads a config (`resolveConfig`; `gameConfigFor` is async; `check-ink` reads them from disk). Formulas may explode (`d6!`, `DiceFormula.explode`: a top face rolls another die, faces appended, at most 20 extra; `averageFormula` uses the exploding mean). Keep highest/lowest (`4d6kh3`, `2d20kl` = kl1; `DiceFormula.keep`, not with explode/pool/d66; ties keep the earlier die; `averageFormula` sums the expected order statistics, `keptMean`) and pools (`5d6>=5`, `DiceFormula.pool` = the target; total = hits + bonus; may explode). `rollFormula` returns `dropped` (indices of faces not kept or missed), copied to `DiceRecord.dropped` when non-empty; the panel (`.inkwright-die-dropped`), the web card (`.die.dropped`) fade them and the journal strikes them out (`~~2~~`). Table ranges may be open (`6+`, `≤0`/`<=0`: `Range` with ±Infinity; `tableProblems` clamps them to the dice span, the generated lookup treats an open top as the last row). Journal: `src/play/journal.ts` (`renderJournal`, pure) and `writeJournal()` in main.ts (command `write-journal`, `api.journal()`), path from the note's `journal.path`.
- Tabletop slice 2, decks: `decks:` in the config (`DeckDef`: id, name, `cards: CardDef[]`; deck and card ids share the id namespace, each deck also owns `<id>_pile`). The generated ink declares `LIST <deck>` with the cards and `VAR <deck>_pile` holding what is left; `draw(deck)` asks `roll_dice(LIST_COUNT(pile), "<deck>")` for a position and takes the k-th lowest card out (`nth_card`), `shuffle(deck)` is `LIST_ALL`, `deck_left(deck)` is `LIST_COUNT`. The engine recognises the deck by the label, reads the pile from the state to size the die and name the card (`DiceRecord.deck`), and `hud().decks` lists each pile; the fallback draws the lowest card. A hand is any list the story keeps.
Expand Down
3 changes: 2 additions & 1 deletion docs/rpg-engine-prd.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ entities: # 开局就有的(固定的)
- **地城爬行**:原创规则,不抄 4AD;
- **单人日志**:现在的日志型模板升级而来;
- **回合战斗**:JRPG 式,敌我轮流行动、技能、状态。
- **R6 落地的做法(2026-11-10)**:回合战斗包没有加任何引擎功能,全部是 R1–R4 的积木:队员是小队(`party`),敌人是实体种类 `foe`,行动顺序是 ink 里的递归函数——每回合把站着的人的 `acted` 清零,每次挑 `spd` 最高、还没动的(速度相同队员先),轮到队员就用线程(`<- attack_option(k)`)给出"攻击第 k 个敌人"之类的选项,轮到敌人就由规则自动行动;眩晕、防御、中毒都是 R4 的状态。伤害是攻击 + 2d6 − 4 − 防御(问题 6 定的 2d6)。穷举走不完一场战斗(状态太多),和地城包一样靠固定种子的测试和策略机器人量平衡。叙事检定包把《302》的规则、难度、技能和声音、恐惧和体力、同伴的恐惧和信任、恐惧修正搬进 `system.md`,`clamp()` 搬进 `rules.ink`;`scare`/`trust` 这类按同伴名字分支的函数留在游戏里(包不知道同伴叫什么)。宿舍游戏放一份包的副本(`packs/narrative-check/`,iCloud 的游玩副本和 CI 都不用另外取 inkwright),`check-ink --all --novelty --random 300` 两种语言的输出和换包前逐字相同。
- **"新建游戏"命令**:先选一个系统包(或者不用),再选模板,生成一套能玩的游戏,和现在的日志型模板一样。
- **检查**:`check-ink` 在系统包上单独跑一遍,每个包自带一个示例剧本给 CI 用。

Expand All @@ -183,7 +184,7 @@ entities: # 开局就有的(固定的)
| R3 | 规则系统包的格式、叠加、版本、"新建游戏"按系统选模板;第一个包:地城爬行(原创) | 用这个包从零做一个小地城,不写战斗代码。已做(2026-11-10):`packs/dungeon-crawl`,"新建游戏"命令,教程 10.3 |
| R4 | 背包数量、装备栏、状态效果 | 地城包用上:箭会用完、中毒每回合扣血。已做(2026-11-10):地城爬行 1.1,教程 10.4 |
| R5 | 成长和战役:经验、升级、天赋;角色卡笔记、`characters.from`、营地 | 一个英雄连续打两次冒险,升级和装备都带过去。已做(2026-11-10):教程 10.5 |
| R6 | 回合战斗包和示例;叙事检定包(宿舍游戏的规则整理出来) | 一场 3 对 3 的回合战斗;宿舍游戏改用这个包后行为不变 |
| R6 | 回合战斗包和示例;叙事检定包(宿舍游戏的规则整理出来) | 一场 3 对 3 的回合战斗;宿舍游戏改用这个包后行为不变。已做(2026-11-10):`packs/turn-battle`、`packs/narrative-check`,教程 10.6 |
| R7 | 公开:教程第十章、ink-games 上的包和示例、"安装系统包" | 一个没写过 Inkwright 的人照着教程做出一个能玩的小游戏(找人试) |

**4AD 不改用实体(2026-11-10 决定)。** 读了 4AD 的代码以后,原定的 R1 验收不成立:4AD 一场遭遇是"一群同样的怪"——一个数量,按"每满几点打死几只"成批地杀——不是一只只有自己生命的个体,拆成实体只会更重、不会更短;那 43 个 `foe_*` 大多是这场遭遇的开关(不死、厌恶某职业、免疫魔法……),战斗里反复读,改成外部函数读取会更慢,正好和 R2 反着来;`foe_hates` 是职业的 LIST 值,实体只存数字;掷骰的先后也会变,没法和旧结果按种子对比。所以 4AD 保持扁平变量,改作 R2 性能的基准;动态实体的真实验收挪到 R6 的 3 对 3 回合战斗(那里每个敌人确实各有各的生命和行动)。
Expand Down
14 changes: 14 additions & 0 deletions packs/narrative-check/rules.ink
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Narrative check rules, pack version 1.0 (Inkwright). A game INCLUDEs this through its generated _engine.ink.
// Checks are tags on choices (* [Force the door #check:strength:hard]) read back with check(skill, n): a band 0..4,
// 3 or more is a success. Inner voices are #voice:<skill> lines. The engine rolls 2d6 + skill against the difficulty;
// every 25 fear takes 1 off reason. This file only adds the helpers stories share.

// x kept within lo..hi.
=== function clamp(x, lo, hi) ===
{ x < lo:
~ return lo
}
{ x > hi:
~ return hi
}
~ return x
27 changes: 27 additions & 0 deletions packs/narrative-check/system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
version: "1.0"
pack:
name: { zh: 叙事检定, en: Narrative checks }
description: { zh: "2d6 + 技能对难度的检定,五种技能各是一个内心的声音,恐惧和体力两条血条,同伴的恐惧和信任", en: "2d6 + skill against a difficulty, five skills that are inner voices, fear and stamina, companions' fear and trust" }
rules: { kind: sum, dice: [6, 6] }
languages: [zh, en]
difficulties: { trivial: 6, easy: 8, normal: 10, hard: 12, severe: 14, legendary: 16 }
skills:
- { id: reason, name: { zh: 理智, en: Reason }, voice: { stance: { zh: "这说得通,撑住。", en: "It adds up. Hold on." }, color: "#7a9cff" } }
- { id: stamina, name: { zh: 耐力, en: Stamina }, voice: { stance: { zh: 再坚持一下。, en: "Just a little longer." }, color: "#8fbf6a" } }
- { id: charm, name: { zh: 魅力, en: Charm }, voice: { stance: { zh: 这事能谈。, en: "We can talk about this." }, color: "#e6a23c" } }
- { id: insight, name: { zh: 洞察力, en: Insight }, voice: { stance: { zh: 注意到了吗。, en: "Did you notice?" }, color: "#b07cd8" } }
- { id: strength, name: { zh: 力量, en: Strength }, voice: { stance: { zh: 砸。, en: "Smash it." }, color: "#e26a6a" } }
resources:
- { id: fear, name: { zh: 恐惧, en: Fear }, min: 0, max: 100, initial: 0 }
- { id: hp, name: { zh: 体力, en: Stamina }, min: 0, max: 10, initial: 10 }
companionResources:
- { id: fear, name: { zh: 恐惧, en: Fear }, min: 0, max: 100, initial: 20 }
- { id: trust, name: { zh: 信任, en: Trust }, min: 0, max: 100, initial: 50 }
modifiers:
- { kind: perStep, resource: fear, step: 25, value: -1, skill: reason, label: fear }
---

# 叙事检定(Narrative checks)规则包 1.0

从宿舍恐怖游戏《302》的规则整理出来的第一方规则系统包。见 `说明.md`。
92 changes: 92 additions & 0 deletions packs/narrative-check/template/_engine.ink
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Generated by Inkwright from the game's notes. Do not edit; regenerate.
INCLUDE ../rules.ink

LIST characters = me, lin
VAR character = me

// Skills of the current character (loaded by pick_character)
VAR reason = 0
VAR stamina = 0
VAR charm = 0
VAR insight = 0
VAR strength = 0

// Resources
VAR fear = 0
VAR hp = 10

// Dice: the engine sets these; saved with the state, so back/load/replay roll the same
VAR dice_seed = 0
VAR dice_rolls = 0

// Text in the story's language: {t("zh…", "en…")}; the play panel switches lang.
VAR lang = "zh"

=== function t(zh, en) ===
{ lang == "en":
~ return en
}
~ return zh

// Companions
VAR fear_me = 20
VAR trust_me = 50
VAR fear_lin = 30
VAR trust_lin = 50

EXTERNAL check(skill, difficulty)

// Loads a character's preset by id: pick_character("me")
=== function pick_character(who) ===
{ who == "me":
~ character = me
~ reason = 3
~ stamina = 3
~ charm = 3
~ insight = 4
~ strength = 2
}
{ who == "lin":
~ character = lin
~ reason = 4
~ stamina = 2
~ charm = 3
~ insight = 3
~ strength = 2
}

// A skill's current level, by name.
=== function skill_level(skill) ===
{ skill == "reason":
~ return reason
}
{ skill == "stamina":
~ return stamina
}
{ skill == "charm":
~ return charm
}
{ skill == "insight":
~ return insight
}
{ skill == "strength":
~ return strength
}
~ return 0

// Without the engine there are no dice or modifiers: the average roll (7) decides.
=== function check(skill, difficulty) ===
{ skill_level(skill) + 7 >= difficulty:
~ return 3
}
~ return 1

// Dice outside a check: {roll("2d6+3")} → the total.
EXTERNAL roll_dice(formula, label)

=== function roll(formula) ===
~ return roll_dice(formula, "")

// Without the engine the dice are flat: each table's average, 1 for anything else.
=== function roll_dice(formula, label) ===
~ return 1
12 changes: 12 additions & 0 deletions packs/narrative-check/template/game.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
system: { path: .., version: 1 }
characters:
- { id: me, name: { zh: 我, en: Me }, skills: { reason: 3, stamina: 3, charm: 3, insight: 4, strength: 2 } }
- { id: lin, playable: false, name: { zh: 林, en: Lin }, skills: { reason: 4, stamina: 2, charm: 3, insight: 3, strength: 2 }, companion: { fear: 30, trust: 50 } }
---

# 叙事检定 · 新游戏 / Narrative checks · new game

规则、技能、恐惧和体力都来自规则包(`system:` 指向的文件夹);角色写在这里。想改什么就在这里写同名的条目,比如换一个技能的声音(`skills:` 里同 id 的条目)、加一种资源(`resources:`)。改完运行「生成游戏引擎 ink」。

The rules, the skills, fear and stamina come from the pack (`system:`); the characters are written here. To change one, write an entry with the same id here: another voice for a skill (a `skills:` entry with the same id), one more resource (`resources:`). Then run "Generate game engine ink".
Loading
Loading