dsh-dungeon-master 0.5.2 → 0.7.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.
Files changed (195) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/CHANGELOG_EN.md +24 -2
  3. package/README.md +203 -198
  4. package/README_EN.md +203 -198
  5. package/cordis.patch.yml +32 -32
  6. package/cordis.yml +112 -112
  7. package/dist/commands/dnd.d.ts.map +1 -1
  8. package/dist/commands/dnd.js +4 -3
  9. package/dist/commands/dnd.js.map +1 -1
  10. package/dist/config.d.ts +2 -0
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +2 -0
  13. package/dist/config.js.map +1 -1
  14. package/dist/dnd/battle-image.d.ts +11 -4
  15. package/dist/dnd/battle-image.d.ts.map +1 -1
  16. package/dist/dnd/battle-image.js +86 -7
  17. package/dist/dnd/battle-image.js.map +1 -1
  18. package/dist/dnd/battlefield.d.ts +39 -3
  19. package/dist/dnd/battlefield.d.ts.map +1 -1
  20. package/dist/dnd/battlefield.js +378 -88
  21. package/dist/dnd/battlefield.js.map +1 -1
  22. package/dist/dnd/campaign.d.ts +192 -16
  23. package/dist/dnd/campaign.d.ts.map +1 -1
  24. package/dist/dnd/campaign.js +645 -92
  25. package/dist/dnd/campaign.js.map +1 -1
  26. package/dist/dnd/combat-agent.d.ts +53 -5
  27. package/dist/dnd/combat-agent.d.ts.map +1 -1
  28. package/dist/dnd/combat-agent.js +612 -62
  29. package/dist/dnd/combat-agent.js.map +1 -1
  30. package/dist/dnd/combat-context.d.ts +74 -2
  31. package/dist/dnd/combat-context.d.ts.map +1 -1
  32. package/dist/dnd/combat-context.js +62 -21
  33. package/dist/dnd/combat-context.js.map +1 -1
  34. package/dist/dnd/conditions.d.ts +217 -0
  35. package/dist/dnd/conditions.d.ts.map +1 -0
  36. package/dist/dnd/conditions.js +1216 -0
  37. package/dist/dnd/conditions.js.map +1 -0
  38. package/dist/dnd/custom-effects.d.ts +121 -0
  39. package/dist/dnd/custom-effects.d.ts.map +1 -0
  40. package/dist/dnd/custom-effects.js +446 -0
  41. package/dist/dnd/custom-effects.js.map +1 -0
  42. package/dist/dnd/dice.d.ts +5 -1
  43. package/dist/dnd/dice.d.ts.map +1 -1
  44. package/dist/dnd/dice.js +4 -3
  45. package/dist/dnd/dice.js.map +1 -1
  46. package/dist/dnd/dnd-service.d.ts +8 -6
  47. package/dist/dnd/dnd-service.d.ts.map +1 -1
  48. package/dist/dnd/dnd-service.js +43 -7
  49. package/dist/dnd/dnd-service.js.map +1 -1
  50. package/dist/dnd/dnd-tools.d.ts.map +1 -1
  51. package/dist/dnd/dnd-tools.js +2 -0
  52. package/dist/dnd/dnd-tools.js.map +1 -1
  53. package/dist/dnd/formula.d.ts +40 -0
  54. package/dist/dnd/formula.d.ts.map +1 -0
  55. package/dist/dnd/formula.js +219 -0
  56. package/dist/dnd/formula.js.map +1 -0
  57. package/dist/dnd/map-view.d.ts +3 -1
  58. package/dist/dnd/map-view.d.ts.map +1 -1
  59. package/dist/dnd/map-view.js +33 -10
  60. package/dist/dnd/map-view.js.map +1 -1
  61. package/dist/dnd/movement.d.ts +3 -3
  62. package/dist/dnd/movement.d.ts.map +1 -1
  63. package/dist/dnd/movement.js +14 -8
  64. package/dist/dnd/movement.js.map +1 -1
  65. package/dist/dnd/pending-attack.d.ts +23 -13
  66. package/dist/dnd/pending-attack.d.ts.map +1 -1
  67. package/dist/dnd/pending-attack.js +198 -27
  68. package/dist/dnd/pending-attack.js.map +1 -1
  69. package/dist/dnd/save-effect.d.ts +12 -0
  70. package/dist/dnd/save-effect.d.ts.map +1 -1
  71. package/dist/dnd/save-effect.js +72 -8
  72. package/dist/dnd/save-effect.js.map +1 -1
  73. package/dist/dnd/spell-links.d.ts +32 -11
  74. package/dist/dnd/spell-links.d.ts.map +1 -1
  75. package/dist/dnd/spell-links.js +105 -20
  76. package/dist/dnd/spell-links.js.map +1 -1
  77. package/dist/dnd/srd-lookup.d.ts.map +1 -1
  78. package/dist/dnd/srd-lookup.js +23 -0
  79. package/dist/dnd/srd-lookup.js.map +1 -1
  80. package/dist/dnd/terrain.d.ts +8 -2
  81. package/dist/dnd/terrain.d.ts.map +1 -1
  82. package/dist/dnd/terrain.js +13 -8
  83. package/dist/dnd/terrain.js.map +1 -1
  84. package/dist/dnd/tool-scope.d.ts.map +1 -1
  85. package/dist/dnd/tool-scope.js +1 -1
  86. package/dist/dnd/tool-scope.js.map +1 -1
  87. package/dist/dnd/tool-views.js +4 -4
  88. package/dist/dnd/tool-views.js.map +1 -1
  89. package/dist/dnd/tools/character.d.ts.map +1 -1
  90. package/dist/dnd/tools/character.js +223 -21
  91. package/dist/dnd/tools/character.js.map +1 -1
  92. package/dist/dnd/tools/combat.d.ts.map +1 -1
  93. package/dist/dnd/tools/combat.js +222 -32
  94. package/dist/dnd/tools/combat.js.map +1 -1
  95. package/dist/dnd/tools/dice.d.ts.map +1 -1
  96. package/dist/dnd/tools/dice.js +406 -53
  97. package/dist/dnd/tools/dice.js.map +1 -1
  98. package/dist/dnd/tools/explore.d.ts.map +1 -1
  99. package/dist/dnd/tools/explore.js +3 -2
  100. package/dist/dnd/tools/explore.js.map +1 -1
  101. package/dist/dnd/tools/rules.d.ts +3 -0
  102. package/dist/dnd/tools/rules.d.ts.map +1 -0
  103. package/dist/dnd/tools/rules.js +190 -0
  104. package/dist/dnd/tools/rules.js.map +1 -0
  105. package/dist/dnd/tools/saves.d.ts.map +1 -1
  106. package/dist/dnd/tools/saves.js +23 -6
  107. package/dist/dnd/tools/saves.js.map +1 -1
  108. package/dist/dnd/tools/shared.d.ts +8 -2
  109. package/dist/dnd/tools/shared.d.ts.map +1 -1
  110. package/dist/dnd/tools/shared.js +239 -39
  111. package/dist/dnd/tools/shared.js.map +1 -1
  112. package/dist/dnd/turn-buttons.d.ts +4 -0
  113. package/dist/dnd/turn-buttons.d.ts.map +1 -1
  114. package/dist/dnd/turn-buttons.js +49 -25
  115. package/dist/dnd/turn-buttons.js.map +1 -1
  116. package/dist/dnd/zones.d.ts +123 -0
  117. package/dist/dnd/zones.d.ts.map +1 -0
  118. package/dist/dnd/zones.js +545 -0
  119. package/dist/dnd/zones.js.map +1 -0
  120. package/dist/features/button-utils.d.ts +2 -1
  121. package/dist/features/button-utils.d.ts.map +1 -1
  122. package/dist/features/button-utils.js.map +1 -1
  123. package/dist/features/note-judge.d.ts +24 -7
  124. package/dist/features/note-judge.d.ts.map +1 -1
  125. package/dist/features/note-judge.js +112 -24
  126. package/dist/features/note-judge.js.map +1 -1
  127. package/dist/features/reply-judge.d.ts.map +1 -1
  128. package/dist/features/reply-judge.js +22 -4
  129. package/dist/features/reply-judge.js.map +1 -1
  130. package/dist/gateway/bootstrap.d.ts.map +1 -1
  131. package/dist/gateway/bootstrap.js +28 -1
  132. package/dist/gateway/bootstrap.js.map +1 -1
  133. package/dist/gateway/middleware-setup.d.ts +3 -1
  134. package/dist/gateway/middleware-setup.d.ts.map +1 -1
  135. package/dist/gateway/middleware-setup.js +24 -5
  136. package/dist/gateway/middleware-setup.js.map +1 -1
  137. package/dist/middleware/reply-decider.d.ts +8 -1
  138. package/dist/middleware/reply-decider.d.ts.map +1 -1
  139. package/dist/middleware/reply-decider.js +22 -8
  140. package/dist/middleware/reply-decider.js.map +1 -1
  141. package/dist/middleware/serial-merge.d.ts +7 -3
  142. package/dist/middleware/serial-merge.d.ts.map +1 -1
  143. package/dist/middleware/serial-merge.js +125 -9
  144. package/dist/middleware/serial-merge.js.map +1 -1
  145. package/dist/model/status-watch.d.ts +4 -0
  146. package/dist/model/status-watch.d.ts.map +1 -1
  147. package/dist/model/status-watch.js +6 -2
  148. package/dist/model/status-watch.js.map +1 -1
  149. package/dist/session/index.d.ts +1 -1
  150. package/dist/session/index.d.ts.map +1 -1
  151. package/dist/session/index.js.map +1 -1
  152. package/dist/session/session-manager.d.ts +21 -5
  153. package/dist/session/session-manager.d.ts.map +1 -1
  154. package/dist/session/session-manager.js +141 -18
  155. package/dist/session/session-manager.js.map +1 -1
  156. package/dist/session/types.d.ts +8 -0
  157. package/dist/session/types.d.ts.map +1 -1
  158. package/dist/setup/bind-routes.d.ts.map +1 -1
  159. package/dist/setup/bind-routes.js +2 -1
  160. package/dist/setup/bind-routes.js.map +1 -1
  161. package/dist/transport/agent-turn.d.ts +7 -3
  162. package/dist/transport/agent-turn.d.ts.map +1 -1
  163. package/dist/transport/agent-turn.js +20 -2
  164. package/dist/transport/agent-turn.js.map +1 -1
  165. package/dist/transport/events.d.ts +6 -1
  166. package/dist/transport/events.d.ts.map +1 -1
  167. package/dist/transport/events.js +1 -0
  168. package/dist/transport/events.js.map +1 -1
  169. package/dist/transport/inbound.d.ts +6 -0
  170. package/dist/transport/inbound.d.ts.map +1 -1
  171. package/dist/transport/inbound.js +66 -13
  172. package/dist/transport/inbound.js.map +1 -1
  173. package/dist/transport/outbound-buffer.d.ts +6 -0
  174. package/dist/transport/outbound-buffer.d.ts.map +1 -1
  175. package/dist/transport/outbound-buffer.js +13 -0
  176. package/dist/transport/outbound-buffer.js.map +1 -1
  177. package/dist/transport/outbound.d.ts.map +1 -1
  178. package/dist/transport/outbound.js +95 -21
  179. package/dist/transport/outbound.js.map +1 -1
  180. package/dist/transport/turn-steer.d.ts +70 -0
  181. package/dist/transport/turn-steer.d.ts.map +1 -0
  182. package/dist/transport/turn-steer.js +206 -0
  183. package/dist/transport/turn-steer.js.map +1 -0
  184. package/lib/client.js +10 -0
  185. package/lib/client.js.map +1 -1
  186. package/package.json +143 -137
  187. package/skills/dnd-module-authoring/SKILL.md +91 -0
  188. package/skills/dnd-module-authoring/guide.md +76 -47
  189. package/skills/dnd-rule-extension/SKILL.md +126 -0
  190. package/skills/qqbot-sticker-maker/SKILL.md +87 -0
  191. package/skills/qqbot-sticker-maker/references/character-specs.md +94 -0
  192. package/skills/qqbot-sticker-maker/references/meme-adaptation-notes.md +46 -0
  193. package/skills/qqbot-sticker-maker/resources/zipzippipe/sources.json +105 -0
  194. package/skills/qqbot-sticker-maker/scripts/sticker-cli.cjs +1158 -0
  195. package/skills/qqbot-sticker-maker/scripts/sticker-export.cjs +147 -0
@@ -6,16 +6,21 @@
6
6
  * 一格 5 尺,x 向东、y 向南;斜走也算 5 尺(5e 默认规则;2026-11-07 本桌定了不改 DMG 的 5-10-5 变体)。
7
7
  * 只提醒不拦截的地方是故意的:冲刺、触及武器、特性都可能让「超速」「够不到」其实合法,那是 DM 的裁量。
8
8
  */
9
- import { findCharacter, isOut, isRangedWeapon, inInitiative, reactionBlocked, reactionsOf, requireCharacter, requireInitiative, roomOf, } from "./campaign.js";
9
+ import { changeCondition, findCharacter, isOut, isRangedWeapon, inInitiative, pushLog, reactionBlocked, reactionsOf, requireCharacter, requireInitiative, roomOf, } from "./campaign.js";
10
+ import { breakConcentration, concentratingOn, concentratingZoneNames, ensureTurnState, hasCondition, isIncapacitated, isInvisibleState, movementSpeedInfo, } from "./conditions.js";
11
+ import { cryptoRoller } from "./dice.js";
12
+ import { createBattleZoneInput, extraCellCostMultiplier, formatZonePlayerLegend, formatZoneSummary, isCellHeavilyObscured, settleMovementHazards, zonesAtCell, zonesInRoom, } from "./zones.js";
10
13
  import { areaAt, areaCells, areaName, blocksMove, cellKey, findArea, nearestFree, parseBattleMap, parseKey, pathTo, terrainLine, walk, wallBetween, } from "./terrain.js";
11
14
  export const CELL_FEET = 5;
12
15
  export const DEFAULT_SPEED = 30;
13
16
  const MELEE_REACH_FEET = 5;
14
17
  const MAX_COORD = 99;
15
- /** 这些状态下做不了反应,不会打借机 */
16
- const CANNOT_REACT = ['昏迷', '麻痹', '石化', '失能', '震慑'];
18
+ const MAX_ALTITUDE_FEET = 300;
17
19
  export function distanceFeet(a, b) {
18
- return Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y)) * CELL_FEET;
20
+ return Math.max(Math.abs(a.x - b.x) * CELL_FEET, Math.abs(a.y - b.y) * CELL_FEET, Math.abs((a.z ?? 0) - (b.z ?? 0)));
21
+ }
22
+ function fmtCoord(cell) {
23
+ return (cell.z ?? 0) > 0 ? `(${cell.x},${cell.y},↑${cell.z}尺)` : `(${cell.x},${cell.y})`;
19
24
  }
20
25
  /** 角色当前的格子;换过房间后旧坐标作废(room 对不上就当没摆位,比沿用错坐标安全) */
21
26
  export function cellOf(c, ch) {
@@ -26,7 +31,7 @@ function isHostile(a, b) {
26
31
  return (a.kind === 'monster') !== (b.kind === 'monster');
27
32
  }
28
33
  export function canReact(ch) {
29
- return !isOut(ch) && ch.hp > 0 && !ch.conditions.some((cond) => CANNOT_REACT.includes(cond));
34
+ return !isOut(ch) && ch.hp > 0 && !isIncapacitated(ch) && !hasCondition(ch, '迟缓术');
30
35
  }
31
36
  /** 房间字段不能成为绕过战场路线、借机和出口位置的捷径。 */
32
37
  export function assertCombatExit(c, ch, targetRoom) {
@@ -47,7 +52,8 @@ function placedIn(c, room) {
47
52
  });
48
53
  }
49
54
  function occupant(c, room, at, except) {
50
- return placedIn(c, room).find(({ ch, cell }) => ch.name !== except && cell.x === at.x && cell.y === at.y)?.ch;
55
+ const az = at.z ?? 0;
56
+ return placedIn(c, room).find(({ ch, cell }) => ch.name !== except && cell.x === at.x && cell.y === at.y && (cell.z ?? 0) === az)?.ch;
51
57
  }
52
58
  function requireCoord(value, label) {
53
59
  if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value > MAX_COORD) {
@@ -55,6 +61,17 @@ function requireCoord(value, label) {
55
61
  }
56
62
  return value;
57
63
  }
64
+ function requireAltitude(value, label, ceiling) {
65
+ if (value === undefined)
66
+ return 0;
67
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value > MAX_ALTITUDE_FEET || value % CELL_FEET !== 0) {
68
+ throw new Error(`${label} 要是 0-${MAX_ALTITUDE_FEET} 且为 5 的整数倍(离地尺数,如 0 / 15 / 30),收到 ${String(value)}`);
69
+ }
70
+ if (ceiling !== undefined && value > ceiling) {
71
+ throw new Error(`房间层高上限为 ${ceiling} 尺,不能升空到 ${value} 尺`);
72
+ }
73
+ return value;
74
+ }
58
75
  /** 这个房间的战斗场地图(没画过就是 undefined:空地,不限边界) */
59
76
  export function mapOf(c, room) {
60
77
  return c.battlemaps?.[room];
@@ -79,6 +96,20 @@ export function setBattleMap(c, room, input) {
79
96
  : placedIn(c, room).filter(({ cell }) => blocksMove(map, cell)).map(({ ch, cell }) => `${ch.name}(${cell.x},${cell.y})`);
80
97
  return { map, misplaced };
81
98
  }
99
+ /** 清除房间中临时手绘的场地图:模组自带底图则恢复模组版,否则清空 */
100
+ export function clearBattleMap(c, room, authored) {
101
+ if (authored !== undefined) {
102
+ const restored = structuredClone(authored);
103
+ (c.battlemaps ??= {})[room] = restored;
104
+ return restored;
105
+ }
106
+ if (c.battlemaps !== undefined) {
107
+ delete c.battlemaps[room];
108
+ if (Object.keys(c.battlemaps).length === 0)
109
+ delete c.battlemaps;
110
+ }
111
+ return undefined;
112
+ }
82
113
  /** 一个地点名对应的格子:同房间的人 → 地标 → 地形区域 */
83
114
  function spotCells(c, room, query) {
84
115
  const ch = findCharacter(c, query);
@@ -125,12 +156,13 @@ export function setPositions(c, placements) {
125
156
  if (room === undefined)
126
157
  throw new Error(`${ch.name} 没有所在房间,先 dnd_character update room`);
127
158
  const map = mapOf(c, room);
159
+ const z = requireAltitude(p.z, `${p.name} 的 z`, map?.ceiling);
128
160
  let at;
129
161
  if (p.x === undefined && p.y === undefined && p.near !== undefined) {
130
162
  const spot = spotCells(c, room, p.near);
131
163
  if (spot === undefined)
132
164
  throw unknownSpot(c, room, p.near);
133
- const taken = (cell) => occupant(c, room, cell, ch.name) !== undefined || (spot.blocking && spot.cells.some((s) => s.x === cell.x && s.y === cell.y));
165
+ const taken = (cell) => occupant(c, room, { ...cell, z }, ch.name) !== undefined || (spot.blocking && z < 15 && spot.cells.some((s) => s.x === cell.x && s.y === cell.y));
134
166
  const free = nearestFree(map, spot.cells, taken);
135
167
  if (free === undefined)
136
168
  throw new Error(`${spot.label} 附近没有空格了`);
@@ -138,10 +170,13 @@ export function setPositions(c, placements) {
138
170
  }
139
171
  else {
140
172
  at = { x: requireCoord(p.x, `${p.name} 的 x`), y: requireCoord(p.y, `${p.name} 的 y`) };
141
- if (blocksMove(map, at))
173
+ if (blocksMove(map, at, z >= 15))
142
174
  throw new Error(`(${at.x},${at.y}) 是${map === undefined ? '' : terrainHere(map, at)},${ch.name} 站不上去;换一格,或用 near`);
143
175
  }
144
- (state.positions ??= {})[ch.name] = { x: at.x, y: at.y, room };
176
+ (state.positions ??= {})[ch.name] = { x: at.x, y: at.y, ...(z > 0 ? { z } : {}), room };
177
+ if (z > 0 && (ch.flySpeed ?? 0) <= 0 && ch.hover !== true && !hasCondition(ch, '飞行术')) {
178
+ notes.push(`【DM】${ch.name} 置于高空 ↑${z}尺,但角色卡未记录 fly_speed 且未挂「飞行术」;若天生会飞请用 dnd_character update fly_speed=60 补齐。`);
179
+ }
145
180
  }
146
181
  // 全部放好再查重叠:同一次调用里两个人互换位置不算冲突
147
182
  for (const p of placements) {
@@ -150,8 +185,8 @@ export function setPositions(c, placements) {
150
185
  const ch = requireCharacter(c, p.name);
151
186
  const cell = state.positions[ch.name];
152
187
  const other = occupant(c, cell.room, cell, ch.name);
153
- if (other !== undefined && !notes.some((n) => n.includes(ch.name))) {
154
- notes.push(`【DM】${ch.name} 和 ${other.name} 在同一格 (${cell.x},${cell.y}),不是故意的话改一下。`);
188
+ if (other !== undefined && !notes.some((n) => n.includes(ch.name) && n.includes('同一格'))) {
189
+ notes.push(`【DM】${ch.name} 和 ${other.name} 在同一格 ${fmtCoord(cell)},不是故意的话改一下。`);
155
190
  }
156
191
  }
157
192
  return notes;
@@ -176,6 +211,62 @@ export function removePosition(c, name) {
176
211
  delete state.positions?.[ch.name];
177
212
  return `${ch.name} 已从站位上拿掉`;
178
213
  }
214
+ /** 放置或更新战场持续区域效果(黑暗术、毒雾、蛛网术、荆棘丛生、月华之光等) */
215
+ export function upsertBattleZone(c, raw) {
216
+ const state = requireInitiative(c);
217
+ const caster = raw.source !== undefined ? requireCharacter(c, raw.source) : undefined;
218
+ const room = raw.room ?? (caster !== undefined ? roomOf(c, caster) : undefined) ?? markRoom(c, state);
219
+ const x = requireCoord(raw.x, '区域 x');
220
+ const y = requireCoord(raw.y, '区域 y');
221
+ const seqHint = (state.zones?.length ?? 0) + 1;
222
+ const zone = createBattleZoneInput({ ...raw, room, x, y, ...(caster !== undefined ? { source: caster.name } : {}) }, seqHint);
223
+ const broken = [];
224
+ if (zone.concentration === true && zone.source !== undefined) {
225
+ const prevStates = concentratingOn(c, zone.source).filter((s) => s.state.name !== zone.name);
226
+ const prevZones = concentratingZoneNames(c, zone.source).filter((zName) => zName !== zone.name);
227
+ if (prevStates.length > 0 || prevZones.length > 0) {
228
+ broken.push(...breakConcentration(c, zone.source, `改换专注为「${zone.name}」`));
229
+ for (const line of broken)
230
+ pushLog(c, line);
231
+ }
232
+ }
233
+ const existing = (state.zones ?? []).filter((z) => {
234
+ if (z.id === zone.id)
235
+ return false;
236
+ // 同一施法者重放/挪动同名专注区域(如移动月华之光)时原地更新,不留残影
237
+ if (zone.concentration === true && zone.source !== undefined && z.source === zone.source && z.name === zone.name)
238
+ return false;
239
+ return true;
240
+ });
241
+ existing.push(zone);
242
+ state.zones = existing;
243
+ pushLog(c, `放置战场区域:${formatZoneSummary(zone)}`);
244
+ const affected = placedIn(c, room)
245
+ .filter(({ cell }) => zonesAtCell(c, room, cell).some((z) => z.id === zone.id))
246
+ .map(({ ch }) => ch.name);
247
+ return { zone, broken, affected };
248
+ }
249
+ /** 手动移除战场持续区域(按区域 id 或名称) */
250
+ export function removeBattleZone(c, idOrName, room) {
251
+ const state = requireInitiative(c);
252
+ const q = idOrName.trim();
253
+ if (!q)
254
+ throw new Error('remove_zone 要给 name(区域名称或 id)');
255
+ const list = state.zones ?? [];
256
+ const removed = list.filter((z) => (room === undefined || z.room === room) && (z.id === q || z.name === q || z.name.includes(q)));
257
+ if (removed.length === 0) {
258
+ const existing = list.map((z) => `${z.name}(${z.id})`).join('、') || '无';
259
+ throw new Error(`找不到持续区域「${q}」。当前场上区域:${existing}`);
260
+ }
261
+ const rest = list.filter((z) => !removed.includes(z));
262
+ if (rest.length === 0)
263
+ delete state.zones;
264
+ else
265
+ state.zones = rest;
266
+ for (const r of removed)
267
+ pushLog(c, `移除战场区域「${r.name}」`);
268
+ return removed;
269
+ }
179
270
  /** 按直线走过的格子(含起点终点);没有场地图、直接给坐标时用 */
180
271
  function straightPath(from, to) {
181
272
  const steps = Math.max(Math.abs(to.x - from.x), Math.abs(to.y - from.y));
@@ -187,32 +278,67 @@ function straightPath(from, to) {
187
278
  }));
188
279
  }
189
280
  const minFeet = (cells, at) => Math.min(...cells.map((c) => distanceFeet(c, at)));
281
+ function hasBlindOrSpecialSight(ch) {
282
+ const text = `${ch.notes ?? ''} ${(ch.traits ?? []).join(' ')}`;
283
+ return /盲视|blindsight|真实视觉|truesight|魔鬼视界|devil'?s\s*sight|震颤感知|tremorsense/i.test(text);
284
+ }
190
285
  /**
191
- * 回合内移动:算走了多少尺,报出会触发谁的借机。
286
+ * 回合内移动:算走了多少尺,报出会触发谁的借机,联动结算持续地形(难行/遮蔽/进圈伤害)与 2.5D 飞行高度。
192
287
  * 有场地图时按最短路绕墙、难行地形算双倍;目的地可以是坐标,也可以是「走到谁身边 / 门口 / 离谁远点」,
193
288
  * 由工具挑格子:今晚的错位都出在模型自己把「靠着熊二往门口挪」换算成坐标时丢了条件。
194
289
  */
195
- export function moveOnGrid(c, name, request) {
290
+ export function moveOnGrid(c, name, request, options = {}) {
196
291
  const state = requireInitiative(c);
197
292
  const ch = requireCharacter(c, name);
198
293
  const from = cellOf(c, ch);
199
294
  if (from === undefined)
200
295
  throw new Error(`${ch.name} 还没摆位,先 dnd_position set`);
201
296
  const map = mapOf(c, from.room);
297
+ const fromZ = from.z ?? 0;
298
+ const targetZ = request.z !== undefined ? requireAltitude(request.z, 'z', map?.ceiling) : fromZ;
299
+ const isAirborneMove = fromZ > 0 || targetZ > 0;
300
+ const canFly = (ch.flySpeed ?? 0) > 0 || ch.hover === true || hasCondition(ch, '飞行术');
301
+ if (targetZ > 0 && !canFly && request.ignoreStateMods !== true) {
302
+ throw new Error(`${ch.name} 没有飞行速度(fly_speed)也未处于「飞行术」状态,无法升空到 z=${targetZ} 尺`);
303
+ }
202
304
  const reaction = request.reaction === true;
203
- if (request.disengage === true)
305
+ if (request.disengage === true) {
204
306
  state.disengaged = [...new Set([...(state.disengaged ?? []), ch.name])];
307
+ if (!reaction) {
308
+ const ts = ensureTurnState(c);
309
+ if (ts?.actor === ch.name)
310
+ ts.actionUsed ??= '撤离';
311
+ }
312
+ }
205
313
  const disengaged = state.disengaged?.includes(ch.name) === true;
206
314
  if (request.dash === true && !reaction) {
207
315
  const dashed = state.dashed ?? [];
208
316
  if (!dashed.includes(ch.name))
209
317
  dashed.push(ch.name);
210
318
  state.dashed = dashed;
319
+ const ts = ensureTurnState(c);
320
+ if (ts?.actor === ch.name)
321
+ ts.actionUsed ??= '冲刺';
211
322
  }
212
323
  const isDashed = state.dashed?.includes(ch.name) === true;
213
- const baseSpeed = ch.speed ?? DEFAULT_SPEED;
324
+ const rawBaseSpeed = isAirborneMove
325
+ ? (ch.flySpeed ?? (hasCondition(ch, '飞行术') ? 60 : (ch.speed ?? DEFAULT_SPEED)))
326
+ : (ch.speed ?? DEFAULT_SPEED);
327
+ const moveInfo = request.ignoreStateMods === true
328
+ ? { baseSpeed: rawBaseSpeed, zeroSpeed: false, zeroReasons: [], notes: [], fearSources: [], hasUnboundFear: false }
329
+ : movementSpeedInfo(ch, rawBaseSpeed);
330
+ const baseSpeed = moveInfo.zeroSpeed ? rawBaseSpeed : moveInfo.baseSpeed;
214
331
  const speed = baseSpeed * (isDashed ? 2 : 1);
215
- const used = reaction ? 0 : state.moved?.[ch.name] ?? 0;
332
+ const usedBefore = reaction ? 0 : state.moved?.[ch.name] ?? 0;
333
+ const isProne = !reaction && request.ignoreStateMods !== true && hasCondition(ch, '倒地');
334
+ const crawling = isProne && request.crawl === true;
335
+ const ts = ensureTurnState(c);
336
+ const autoStandUp = isProne && !crawling && ts?.stoodUp !== true;
337
+ const standCost = autoStandUp ? Math.floor(baseSpeed / 2) : 0;
338
+ if (autoStandUp && request.interrupt === true && usedBefore + standCost > speed) {
339
+ throw new Error(`${ch.name} 处于「倒地」,起身需先消耗一半速度(${standCost} 尺),但本回合只剩 ${Math.max(0, speed - usedBefore)}/${speed} 尺移动力;若冲刺请传 dash=true,若倒地爬行请传 crawl=true`);
340
+ }
341
+ const used = usedBefore + standCost;
216
342
  const dragged = request.drag === undefined ? undefined : requireCharacter(c, request.drag);
217
343
  if (dragged !== undefined) {
218
344
  const at = cellOf(c, dragged);
@@ -225,46 +351,75 @@ export function moveOnGrid(c, name, request) {
225
351
  throw new Error(`${keep.name} 不在这个房间的站位上`);
226
352
  const others = placedIn(c, from.room).filter(({ ch: o }) => o.name !== ch.name && o.name !== dragged?.name);
227
353
  const foes = others.filter(({ ch: o }) => isHostile(ch, o));
228
- const reactors = foes.filter(({ ch: o }) => canReact(o) && !o.conditions.includes('失明') && reactionBlocked(c, o.name) === undefined
354
+ const moverInvisible = request.ignoreStateMods !== true && isInvisibleState(ch) && !hasCondition(ch, '妖火');
355
+ const reactors = moverInvisible ? [] : foes.filter(({ ch: o }) => inInitiative(c, o.name) && canReact(o) && !hasCondition(o, '失明') && reactionBlocked(c, o.name) === undefined
229
356
  && !request.ignoredReactors?.includes(o.name));
230
357
  const reachOf = (other) => Math.max(MELEE_REACH_FEET, ...(other.weapons ?? []).map((w) => weaponReach(w, true) ?? 0));
231
- // 5e:能穿过友方的格子,不能穿过敌人的
232
- const blocked = (at) => foes.some(({ cell }) => cell.x === at.x && cell.y === at.y);
233
- const taken = (at) => others.some(({ cell }) => cell.x === at.x && cell.y === at.y);
358
+ const highAltitude = fromZ >= 15 && targetZ >= 15;
359
+ // 5e:能穿过友方的格子,不能穿过同一高度层的敌人的格子;高空飞越地面敌人不阻挡
360
+ const blocked = (at) => foes.some(({ cell }) => cell.x === at.x && cell.y === at.y && Math.abs((cell.z ?? 0) - targetZ) < CELL_FEET);
361
+ const taken = (at) => others.some(({ cell }) => cell.x === at.x && cell.y === at.y && (cell.z ?? 0) === targetZ);
362
+ const cellCostMult = (at) => extraCellCostMultiplier(c, ch, { ...at, z: targetZ }, from.room, options.globalEffects);
363
+ const canReactorSeeAt = (other, reactorCell, moverCell) => {
364
+ if (hasBlindOrSpecialSight(other))
365
+ return { ok: true };
366
+ const obs = isCellHeavilyObscured(c, moverCell) ?? isCellHeavilyObscured(c, reactorCell);
367
+ if (obs !== undefined)
368
+ return { ok: false, reason: `「${obs.name}」遮蔽视线,${other.name} 无法借机攻击` };
369
+ return { ok: true };
370
+ };
234
371
  const provokesOn = (a, b) => disengaged ? 0
235
- : reactors.filter(({ ch: other, cell }) => distanceFeet(a, cell) <= reachOf(other) && distanceFeet(b, cell) > reachOf(other)).length;
236
- const factor = dragged === undefined ? 1 : 2;
372
+ : reactors.filter(({ ch: other, cell }) => {
373
+ const a3 = { ...a, ...(targetZ > 0 ? { z: targetZ } : {}), room: from.room };
374
+ const b3 = { ...b, ...(targetZ > 0 ? { z: targetZ } : {}), room: from.room };
375
+ return canReactorSeeAt(other, cell, a3).ok && distanceFeet(a3, cell) <= reachOf(other) && distanceFeet(b3, cell) > reachOf(other);
376
+ }).length;
377
+ const factor = (dragged === undefined ? 1 : 2) * (crawling ? 2 : 1);
237
378
  let dest;
238
379
  let path;
239
- let feet;
380
+ let horizFeet;
240
381
  let short;
241
382
  const explicit = request.x !== undefined || request.y !== undefined;
242
383
  const target = request.to ?? request.adjacentTo;
243
- if (explicit) {
384
+ const pureVertical = !explicit && target === undefined && request.awayFrom === undefined && request.z !== undefined;
385
+ if (pureVertical) {
386
+ dest = { x: from.x, y: from.y };
387
+ if (blocksMove(map, dest, targetZ >= 15))
388
+ throw new Error(`(${dest.x},${dest.y}) 无法停靠`);
389
+ const occupied = occupant(c, from.room, { ...dest, z: targetZ }, ch.name);
390
+ if (occupied !== undefined && occupied.name !== dragged?.name) {
391
+ throw new Error(`${fmtCoord({ ...dest, z: targetZ })} 已经站着 ${occupied.name},换一格或换高度`);
392
+ }
393
+ path = [{ x: from.x, y: from.y }];
394
+ horizFeet = 0;
395
+ }
396
+ else if (explicit) {
244
397
  if (target !== undefined || request.awayFrom !== undefined)
245
398
  throw new Error('x/y 和 to/away_from 二选一');
246
- dest = { x: requireCoord(request.x, 'x'), y: requireCoord(request.y, 'y') };
247
- if (blocksMove(map, dest))
399
+ dest = { x: requireCoord(request.x ?? from.x, 'x'), y: requireCoord(request.y ?? from.y, 'y') };
400
+ if (blocksMove(map, dest, targetZ >= 15))
248
401
  throw new Error(`(${dest.x},${dest.y}) 是${terrainHere(map, dest)},站不上去;要去旁边用 to`);
249
- const occupied = occupant(c, from.room, dest, ch.name);
402
+ const occupied = occupant(c, from.room, { ...dest, z: targetZ }, ch.name);
250
403
  if (occupied !== undefined && occupied.name !== dragged?.name)
251
- throw new Error(`(${dest.x},${dest.y}) 已经站着 ${occupied.name},换一格,或用 to`);
252
- if (map === undefined && foes.length === 0) {
404
+ throw new Error(`${fmtCoord({ ...dest, z: targetZ })} 已经站着 ${occupied.name},换一格,或用 to`);
405
+ const hasExtraTerrain = map !== undefined || foes.length > 0 || (state.zones?.length ?? 0) > 0
406
+ || c.characters.some((o) => o.name !== ch.name && (o.activeStates?.length ?? 0) > 0);
407
+ if (!hasExtraTerrain) {
253
408
  path = straightPath(from, dest);
254
- feet = distanceFeet(from, dest) * factor;
409
+ horizFeet = Math.max(Math.abs(from.x - dest.x), Math.abs(from.y - dest.y)) * CELL_FEET * factor;
255
410
  }
256
411
  else {
257
- const reached = walk(map, from, { blocked, provokes: provokesOn, costFactor: factor, stopAt: dest });
412
+ const reached = walk(map, from, { blocked, provokes: provokesOn, costFactor: factor, highAltitude, cellCostMultiplier: cellCostMult, stopAt: dest });
258
413
  const found = pathTo(reached, dest);
259
414
  if (found === undefined)
260
415
  throw new Error(`走不到 (${dest.x},${dest.y}):被墙或敌人堵死了`);
261
416
  path = found;
262
- feet = reached.get(cellKey(dest)).feet;
417
+ horizFeet = reached.get(cellKey(dest)).feet;
263
418
  }
264
419
  }
265
420
  else {
266
421
  if (target === undefined && request.awayFrom === undefined)
267
- throw new Error('move 要给 x/y,或者 to / adjacent_to / away_from 之一');
422
+ throw new Error('move 要给 x/y/z,或者 to / adjacent_to / away_from 之一');
268
423
  if (target !== undefined && request.awayFrom !== undefined)
269
424
  throw new Error('to 和 away_from 二选一');
270
425
  const remaining = reaction ? baseSpeed : speed - used;
@@ -289,16 +444,16 @@ export function moveOnGrid(c, name, request) {
289
444
  const awayCell = cellOf(c, away);
290
445
  if (awayCell === undefined || awayCell.room !== from.room)
291
446
  throw new Error(`${away.name} 不在这个房间的站位上`);
292
- score = (at) => -distanceFeet(at, awayCell);
447
+ score = (at) => -distanceFeet({ ...at, z: targetZ }, awayCell);
293
448
  goal = `远离 ${away.name}`;
294
449
  }
295
- const reached = walk(map, from, { blocked, provokes: provokesOn, costFactor: factor, maxFeet });
450
+ const reached = walk(map, from, { blocked, provokes: provokesOn, costFactor: factor, highAltitude, cellCostMultiplier: cellCostMult, maxFeet });
296
451
  let best;
297
452
  for (const [k, r] of reached) {
298
453
  const at = parseKey(k);
299
- if (taken(at) && !(at.x === from.x && at.y === from.y))
454
+ if (taken(at) && !(at.x === from.x && at.y === from.y && targetZ === fromZ))
300
455
  continue;
301
- if (keepCell !== undefined && distanceFeet(at, keepCell) > MELEE_REACH_FEET)
456
+ if (keepCell !== undefined && distanceFeet({ ...at, z: targetZ }, keepCell) > MELEE_REACH_FEET)
302
457
  continue;
303
458
  const s = score(at);
304
459
  if (best === undefined || s < best.s || (s === best.s && (r.feet < best.feet || (r.feet === best.feet && r.provokes < best.provokes)))) {
@@ -309,32 +464,79 @@ export function moveOnGrid(c, name, request) {
309
464
  throw new Error(`${keep === undefined ? '' : `贴着 ${keep.name} 的`}格子都走不到或站满了`);
310
465
  dest = best.at;
311
466
  path = pathTo(reached, dest);
312
- feet = best.feet;
467
+ horizFeet = best.feet;
313
468
  if (target !== undefined && best.s > 0) {
314
469
  const limit = keep !== undefined ? `要贴着 ${keep.name},最多` : request.feet !== undefined ? `限 ${request.feet} 尺,只够` : '移动力只够';
315
470
  short = `${limit}走到这里,离 ${goal} 还有 ${best.s} 尺`;
316
471
  }
317
472
  }
318
- const blocker = occupant(c, from.room, dest, ch.name);
473
+ const blocker = occupant(c, from.room, { ...dest, z: targetZ }, ch.name);
319
474
  if (blocker !== undefined && blocker.name !== dragged?.name)
320
- throw new Error(`(${dest.x},${dest.y}) 已经站着 ${blocker.name},换一格,或用 to`);
321
- if (keepCell !== undefined && distanceFeet(dest, keepCell) > MELEE_REACH_FEET) {
322
- throw new Error(`走到 (${dest.x},${dest.y}) 就不贴着 ${keep.name} 了;不给坐标、传 to + keep_adjacent,工具会挑贴着他的格子`);
475
+ throw new Error(`${fmtCoord({ ...dest, z: targetZ })} 已经站着 ${blocker.name},换一格,或用 to`);
476
+ if (keepCell !== undefined && distanceFeet({ ...dest, z: targetZ }, keepCell) > MELEE_REACH_FEET) {
477
+ throw new Error(`走到 ${fmtCoord({ ...dest, z: targetZ })} 就不贴着 ${keep.name} 了;不给坐标、传 to + keep_adjacent,工具会挑贴着他的格子`);
478
+ }
479
+ // 生成完整 3D 轨迹(支持原地升空/俯冲与斜飞)
480
+ const horizSteps = path.length - 1;
481
+ const vertSteps = Math.abs(targetZ - fromZ) / CELL_FEET;
482
+ const totalSteps = Math.max(horizSteps, vertSteps);
483
+ let path3d;
484
+ if (totalSteps === 0) {
485
+ path3d = [{ x: from.x, y: from.y, ...(fromZ > 0 ? { z: fromZ } : {}), room: from.room }];
486
+ }
487
+ else {
488
+ path3d = Array.from({ length: totalSteps + 1 }, (_, k) => {
489
+ const hIdx = horizSteps === 0 ? 0 : Math.min(horizSteps, Math.round((k * horizSteps) / totalSteps));
490
+ const hc = path[hIdx];
491
+ const zk = Math.round((fromZ + ((targetZ - fromZ) * k) / totalSteps) / CELL_FEET) * CELL_FEET;
492
+ return { x: hc.x, y: hc.y, ...(zk > 0 ? { z: zk } : {}), room: from.room };
493
+ });
323
494
  }
495
+ let feet = horizSteps === 0
496
+ ? path3d.slice(1).reduce((sum, step) => sum + CELL_FEET * factor * extraCellCostMultiplier(c, ch, step, from.room, options.globalEffects), 0)
497
+ : Math.max(horizFeet, Math.abs(targetZ - fromZ) * factor);
498
+ if (!reaction && request.ignoreStateMods !== true && moveInfo.fearSources.length > 0) {
499
+ for (const srcName of moveInfo.fearSources) {
500
+ const srcCh = findCharacter(c, srcName);
501
+ const srcCell = srcCh === undefined ? undefined : cellOf(c, srcCh);
502
+ if (srcCh !== undefined && srcCell !== undefined && srcCell.room === from.room) {
503
+ const startDist = distanceFeet(from, srcCell);
504
+ const closer = path3d.some((step, i) => i > 0 && distanceFeet(step, srcCell) < startDist);
505
+ if (closer) {
506
+ throw new Error(`${ch.name} 正对 ${srcCh.name} 处于「恐慌」状态,不能主动移向恐惧源(若免疫或强制位移请传 ignore_state_mods=true 或用 set)`);
507
+ }
508
+ }
509
+ }
510
+ }
511
+ const blockedSightNotes = new Set();
324
512
  let opportunity;
513
+ const fullDestZ = targetZ;
514
+ const fullDest = { ...dest };
325
515
  if (request.interrupt === true && !disengaged) {
326
516
  const triggers = [];
327
517
  for (const { ch: other, cell } of reactors) {
328
518
  const reach = reachOf(other);
329
- for (let i = 0; i + 1 < path.length; i++) {
330
- if (distanceFeet(path[i], cell) <= reach && distanceFeet(path[i + 1], cell) > reach && wallBetween(map, path[i], cell) === undefined) {
519
+ for (let i = 0; i + 1 < path3d.length; i++) {
520
+ if (distanceFeet(path3d[i], cell) <= reach && distanceFeet(path3d[i + 1], cell) > reach && wallBetween(map, path3d[i], cell) === undefined) {
521
+ const sight = canReactorSeeAt(other, cell, path3d[i]);
522
+ if (!sight.ok) {
523
+ if (sight.reason)
524
+ blockedSightNotes.add(sight.reason);
525
+ continue;
526
+ }
331
527
  triggers.push({ stop: i, character: other.name, reaction: '借机攻击' });
332
528
  break;
333
529
  }
334
530
  }
335
531
  for (const r of reactionsOf(other).filter((r) => r.enter === true)) {
336
- for (let i = 0; i + 1 < path.length; i++) {
337
- if (distanceFeet(path[i], cell) > (r.range ?? MELEE_REACH_FEET) && distanceFeet(path[i + 1], cell) <= (r.range ?? MELEE_REACH_FEET) && wallBetween(map, path[i + 1], cell) === undefined) {
532
+ for (let i = 0; i + 1 < path3d.length; i++) {
533
+ if (distanceFeet(path3d[i], cell) > (r.range ?? MELEE_REACH_FEET) && distanceFeet(path3d[i + 1], cell) <= (r.range ?? MELEE_REACH_FEET) && wallBetween(map, path3d[i + 1], cell) === undefined) {
534
+ const sight = canReactorSeeAt(other, cell, path3d[i + 1]);
535
+ if (!sight.ok) {
536
+ if (sight.reason)
537
+ blockedSightNotes.add(sight.reason);
538
+ continue;
539
+ }
338
540
  triggers.push({ stop: i + 1, character: other.name, reaction: r.name });
339
541
  break;
340
542
  }
@@ -344,17 +546,25 @@ export function moveOnGrid(c, name, request) {
344
546
  if (triggers.length > 0) {
345
547
  const first = Math.min(...triggers.map((t) => t.stop));
346
548
  const here = triggers.filter((t) => t.stop === first);
347
- const options = here.map(({ character, reaction }) => ({ character, reaction,
549
+ const reactorOptions = here.map(({ character, reaction }) => ({ character, reaction,
348
550
  ...(requireCharacter(c, character).kind !== 'pc' || requireCharacter(c, character).playerId === undefined ? { npc: true } : {}) }));
349
- opportunity = { reactors: options, resume: {
350
- x: dest.x, y: dest.y, interrupt: true, reaction,
551
+ opportunity = { reactors: reactorOptions, resume: {
552
+ x: fullDest.x, y: fullDest.y, ...(fullDestZ !== 0 || fromZ !== 0 ? { z: fullDestZ } : {}), interrupt: true, reaction,
351
553
  ignoredReactors: [...new Set([...(request.ignoredReactors ?? []), ...here.map((t) => t.character)])],
352
554
  ...(request.drag !== undefined ? { drag: request.drag } : {}),
353
555
  ...(request.keepAdjacent !== undefined ? { keepAdjacent: request.keepAdjacent } : {}),
556
+ ...(request.crawl === true ? { crawl: true } : {}),
557
+ ...(request.ignoreStateMods === true ? { ignoreStateMods: true } : {}),
354
558
  } };
355
- path = path.slice(0, first + 1);
356
- dest = path.at(-1);
357
- feet = path.slice(1).reduce((sum, step) => sum + CELL_FEET * factor * (map !== undefined && areaAt(map, step)?.kind === 'difficult' ? 2 : 1), 0);
559
+ path3d = path3d.slice(0, first + 1);
560
+ const stopCell = path3d.at(-1);
561
+ dest = { x: stopCell.x, y: stopCell.y };
562
+ feet = path3d.slice(1).reduce((sum, step) => {
563
+ const stepHigh = (step.z ?? 0) >= 15;
564
+ const mapMult = !stepHigh && map !== undefined && areaAt(map, step)?.kind === 'difficult' ? 2 : 1;
565
+ const zoneMult = extraCellCostMultiplier(c, ch, step, from.room, options.globalEffects);
566
+ return sum + CELL_FEET * factor * Math.max(mapMult, zoneMult);
567
+ }, 0);
358
568
  short = '已在借机触发处暂停,剩余路程等反应结算后再走';
359
569
  }
360
570
  }
@@ -363,55 +573,88 @@ export function moveOnGrid(c, name, request) {
363
573
  const enters = [];
364
574
  if (!disengaged) {
365
575
  for (const { ch: other, cell } of reactors) {
366
- const leaves = path.some((step, i) => {
367
- const next = path[i + 1];
368
- return next !== undefined && distanceFeet(step, cell) <= reachOf(other) && distanceFeet(next, cell) > reachOf(other);
576
+ const leaves = path3d.some((step, i) => {
577
+ const next = path3d[i + 1];
578
+ if (next === undefined || distanceFeet(step, cell) > reachOf(other) || distanceFeet(next, cell) <= reachOf(other))
579
+ return false;
580
+ const sight = canReactorSeeAt(other, cell, step);
581
+ if (!sight.ok) {
582
+ if (sight.reason)
583
+ blockedSightNotes.add(sight.reason);
584
+ return false;
585
+ }
586
+ return true;
369
587
  });
370
588
  if (leaves)
371
589
  provokes.push(other.name);
372
- else if (!opportunity?.reactors.some((r) => r.character === other.name) && path.length > 1 && path.every((step) => distanceFeet(step, cell) <= reachOf(other)))
590
+ else if (!opportunity?.reactors.some((r) => r.character === other.name) && path3d.length > 1 && path3d.every((step) => distanceFeet(step, cell) <= reachOf(other)))
373
591
  stayedIn.push(other.name);
374
592
  // 长柄大师:拿着长柄武器时,敌人「进入」触及范围也吃借机——方向反着算,一回合至多一次
375
593
  for (const r of reactionsOf(other)) {
376
594
  if (r.enter !== true)
377
595
  continue;
378
596
  const reach = r.range ?? MELEE_REACH_FEET;
379
- const steppedIn = path.some((step, i) => {
380
- const next = path[i + 1];
381
- return next !== undefined && distanceFeet(step, cell) > reach && distanceFeet(next, cell) <= reach;
597
+ const steppedIn = path3d.some((step, i) => {
598
+ const next = path3d[i + 1];
599
+ if (next === undefined || distanceFeet(step, cell) <= reach || distanceFeet(next, cell) > reach)
600
+ return false;
601
+ const sight = canReactorSeeAt(other, cell, next);
602
+ if (!sight.ok) {
603
+ if (sight.reason)
604
+ blockedSightNotes.add(sight.reason);
605
+ return false;
606
+ }
607
+ return true;
382
608
  });
383
609
  if (steppedIn)
384
610
  enters.push({ name: other.name, reach, reaction: r.name });
385
611
  }
386
612
  }
387
613
  }
388
- const to = { x: dest.x, y: dest.y, room: from.room };
614
+ const finalStep = path3d.at(-1);
615
+ const to = { x: finalStep.x, y: finalStep.y, ...(finalStep.z !== undefined && finalStep.z > 0 ? { z: finalStep.z } : {}), room: from.room };
389
616
  (state.positions ??= {})[ch.name] = to;
390
617
  let draggedTo;
391
618
  if (dragged !== undefined) {
392
619
  // 拖着的人落在你走过的最后一格(原地没动就不动他)
393
- const behind = path.length >= 2 ? path[path.length - 2] : undefined;
394
- if (behind !== undefined) {
395
- const cell = { x: behind.x, y: behind.y, room: from.room };
620
+ const behind = path3d.length >= 2 ? path3d[path3d.length - 2] : undefined;
621
+ if (behind !== undefined && (behind.x !== to.x || behind.y !== to.y || (behind.z ?? 0) !== (to.z ?? 0))) {
622
+ const cell = { x: behind.x, y: behind.y, ...(behind.z !== undefined && behind.z > 0 ? { z: behind.z } : {}), room: from.room };
396
623
  state.positions[dragged.name] = cell;
397
624
  draggedTo = { name: dragged.name, to: cell };
398
625
  }
399
626
  }
400
627
  const moved = state.moved ?? {};
628
+ const notes = [...moveInfo.notes, ...blockedSightNotes];
629
+ if (autoStandUp) {
630
+ changeCondition(c, ch.name, '倒地', false);
631
+ if (ts !== undefined && ts.actor === ch.name)
632
+ ts.stoodUp = true;
633
+ notes.push(`已自动花费 ${standCost} 尺移动力从倒地起身并解除「倒地」(若本意是保持倒地爬行,请 dnd_undo 后传 crawl=true)`);
634
+ }
635
+ else if (crawling) {
636
+ notes.push(`${ch.name} 保持倒地爬行(每格算双倍耗速)`);
637
+ }
401
638
  if (!reaction)
402
- moved[ch.name] = (moved[ch.name] ?? 0) + feet;
639
+ moved[ch.name] = (moved[ch.name] ?? 0) + standCost + feet;
403
640
  state.moved = moved;
404
- const notes = [];
405
- if (ch.conditions.includes('倒地'))
406
- notes.push(`${ch.name} 还倒地:爬行每尺算两尺;站起来花一半速度,再 dnd_apply 解除倒地`);
407
- const stuck = ch.conditions.filter((cond) => ['擒抱', '束缚', '麻痹', '石化', '昏迷'].includes(cond));
408
- if (stuck.length > 0)
409
- notes.push(`${ch.name} 处于${stuck.join('、')},速度应为 0`);
410
- const area = map === undefined ? undefined : areaAt(map, dest);
641
+ const hazardLines = settleMovementHazards(c, ch, path3d, options.roller ?? cryptoRoller, options.globalEffects);
642
+ notes.push(...hazardLines);
643
+ // 若沿途区域伤害已将角色击倒/击杀,不再保留借机恢复窗口
644
+ if (opportunity !== undefined && (ch.hp <= 0 || isOut(ch))) {
645
+ opportunity = undefined;
646
+ }
647
+ // 若区域伤害导致高空坠机(z 已清零),同步返回值中的 to
648
+ const postPos = state.positions[ch.name] ?? to;
649
+ if (moveInfo.hasUnboundFear)
650
+ notes.push(`${ch.name} 处于恐慌:不能主动移向恐惧源`);
651
+ if (moveInfo.zeroReasons.length > 0)
652
+ notes.push(`${ch.name} 处于${moveInfo.zeroReasons.join('、')},速度应为 0`);
653
+ const area = map === undefined || (postPos.z ?? 0) >= 15 ? undefined : areaAt(map, postPos);
411
654
  return {
412
655
  name: ch.name,
413
656
  from,
414
- to,
657
+ to: postPos,
415
658
  feet,
416
659
  totalFeet: moved[ch.name] ?? 0,
417
660
  speed,
@@ -420,9 +663,9 @@ export function moveOnGrid(c, name, request) {
420
663
  enters,
421
664
  disengaged,
422
665
  stayedIn,
423
- detour: feet > distanceFeet(from, dest) * factor,
666
+ detour: feet > distanceFeet(from, postPos) * factor,
424
667
  ...(area !== undefined && area.kind !== 'wall' ? { where: areaName(area) } : {}),
425
- adjacent: adjacentFoes(c, ch, to),
668
+ adjacent: adjacentFoes(c, ch, postPos),
426
669
  ...(draggedTo !== undefined ? { dragged: draggedTo } : {}),
427
670
  ...(short !== undefined ? { short } : {}),
428
671
  notes,
@@ -431,9 +674,13 @@ export function moveOnGrid(c, name, request) {
431
674
  }
432
675
  export function moveResultText(r) {
433
676
  const how = [r.detour ? '绕开挡路的' : '', r.dragged !== undefined ? `拖着 ${r.dragged.name},每格算双倍` : ''].filter(Boolean).join(',');
434
- const lines = [`${r.name} (${r.from.x},${r.from.y})→(${r.to.x},${r.to.y}),走 ${r.feet} 尺${how ? `(${how})` : ''},本回合累计 ${r.totalFeet}/${r.speed} 尺${r.dashed ? '(冲刺)' : ''}`];
435
- const now = [r.where !== undefined ? `站在${r.where}` : '', r.adjacent.length > 0 ? `贴身:${r.adjacent.join('、')}` : '没贴着敌人'].filter(Boolean);
436
- lines.push(`现在:${now.join(';')}${r.dragged !== undefined ? `;${r.dragged.name} 在 (${r.dragged.to.x},${r.dragged.to.y})` : ''}`);
677
+ const lines = [`${r.name} ${fmtCoord(r.from)}→${fmtCoord(r.to)},走 ${r.feet} 尺${how ? `(${how})` : ''},本回合累计 ${r.totalFeet}/${r.speed} 尺${r.dashed ? '(冲刺)' : ''}`];
678
+ const now = [
679
+ (r.to.z ?? 0) > 0 ? `离地 ${r.to.z} 尺` : '',
680
+ r.where !== undefined ? `站在${r.where}` : '',
681
+ r.adjacent.length > 0 ? `贴身:${r.adjacent.join('、')}` : '没贴着敌人',
682
+ ].filter(Boolean);
683
+ lines.push(`现在:${now.join(';')}${r.dragged !== undefined ? `;${r.dragged.name} 在 ${fmtCoord(r.dragged.to)}` : ''}`);
437
684
  if (r.short !== undefined)
438
685
  lines.push(`【DM】${r.short}。`);
439
686
  if (r.totalFeet > r.speed)
@@ -477,8 +724,9 @@ export function turnPositionNote(c, name) {
477
724
  const foes = placedIn(c, cell.room).filter(({ ch: other }) => isHostile(ch, other));
478
725
  const adjacent = adjacentFoes(c, ch, cell);
479
726
  const map = mapOf(c, cell.room);
480
- const area = map === undefined ? undefined : areaAt(map, cell);
481
- let where = `【站位】${ch.name}(${cell.x},${cell.y})${area !== undefined && area.kind !== 'wall' ? `(${areaName(area)})` : ''}`;
727
+ const area = map === undefined || (cell.z ?? 0) >= 15 ? undefined : areaAt(map, cell);
728
+ const zonesHere = zonesAtCell(c, cell.room, cell);
729
+ let where = `【站位】${ch.name}${fmtCoord(cell)}${area !== undefined && area.kind !== 'wall' ? `(${areaName(area)})` : ''}${zonesHere.length > 0 ? `(处于区域:${zonesHere.map((z) => z.name).join('、')})` : ''}`;
482
730
  if (adjacent.length > 0)
483
731
  where += `,贴身:${adjacent.join('、')}`;
484
732
  else if (foes.length > 0) {
@@ -489,16 +737,16 @@ export function turnPositionNote(c, name) {
489
737
  const noMap = map === undefined ? '这间还没有场地图:先 dnd_position terrain 照现有站位把墙、门、门外走廊、障碍画上。' : '';
490
738
  return `${where}。${hint}${noMap}`;
491
739
  }
492
- /** 玩家看站位时要藏起来的:隐形、躲着的怪。位置正是它们要瞒的东西 */
493
- const HIDDEN = ['隐形', '躲藏', '隐匿'];
740
+ /** 玩家看站位时要藏起来的:隐形、躲着的怪。位置正是它们要瞒的东西(被妖火照出形迹的不再藏) */
494
741
  export function hiddenFromPlayers(ch) {
495
- return ch.kind === 'monster' && ch.conditions.some((cond) => HIDDEN.includes(cond));
742
+ return ch.kind === 'monster' && ((isInvisibleState(ch) && !hasCondition(ch, '妖火')) || ch.conditions.some((cond) => cond === '躲藏' || cond === '隐匿'));
496
743
  }
744
+ const defaultVisible = () => true;
497
745
  /**
498
746
  * 团况和 show 用的全场站位,按房间分行:压缩之后靠这几行恢复现场。
499
747
  * visible 给玩家视角用:不列的人也不算进贴身。
500
748
  */
501
- export function battleLines(c, roomName, visible = () => true) {
749
+ export function battleLines(c, roomName, visible = defaultVisible) {
502
750
  const state = c.initiative;
503
751
  if (state === undefined)
504
752
  return [];
@@ -515,7 +763,11 @@ export function battleLines(c, roomName, visible = () => true) {
515
763
  for (const [, cell] of marks)
516
764
  if (!rooms.has(cell.room))
517
765
  rooms.set(cell.room, []);
766
+ for (const z of state.zones ?? [])
767
+ if (!rooms.has(z.room))
768
+ rooms.set(z.room, []);
518
769
  const lines = [];
770
+ const isDmView = visible === defaultVisible;
519
771
  for (const [room, members] of rooms) {
520
772
  const seen = new Set();
521
773
  const pairs = [];
@@ -529,12 +781,16 @@ export function battleLines(c, roomName, visible = () => true) {
529
781
  }
530
782
  }
531
783
  const roomMarks = marks.filter(([, cell]) => cell.room === room).map(([n, cell]) => `${n}(${cell.x},${cell.y})`);
532
- lines.push(`站位|${roomName(room)}(格=5尺,x东y南):${members.map(({ ch, cell }) => `${ch.name}(${cell.x},${cell.y})`).join('、') || '无'}`
784
+ lines.push(`站位|${roomName(room)}(格=5尺,x东y南):${members.map(({ ch, cell }) => `${ch.name}${fmtCoord(cell)}`).join('、') || '无'}`
533
785
  + `${pairs.length > 0 ? `;贴身:${pairs.join('、')}` : ''}`
534
786
  + `${roomMarks.length > 0 ? `;标记:${roomMarks.join('、')}` : ''}`);
535
787
  const map = mapOf(c, room);
536
788
  if (map !== undefined)
537
789
  lines.push(` ${terrainLine(map)}`);
790
+ const roomZones = zonesInRoom(c, room);
791
+ if (roomZones.length > 0) {
792
+ lines.push(` 持续区域:${roomZones.map(isDmView ? formatZoneSummary : formatZonePlayerLegend).join(';')}`);
793
+ }
538
794
  }
539
795
  const missing = unplaced(c).filter((n) => {
540
796
  const ch = findCharacter(c, n);
@@ -671,16 +927,40 @@ export function battleGridLines(c, roomName, visible = () => true) {
671
927
  for (const i of items.filter(inView))
672
928
  at.set(`${i.x},${i.y}`, [...(at.get(`${i.x},${i.y}`) ?? []), i]);
673
929
  const ground = (x, y) => {
674
- if (map === undefined)
930
+ const zHere = zonesAtCell(c, room, { x, y, z: 0 });
931
+ if (map === undefined) {
932
+ if (zHere.length > 0) {
933
+ if (!terrainNames.has('*'))
934
+ terrainNames.set('*', new Set());
935
+ for (const z of zHere)
936
+ terrainNames.get('*').add(z.name);
937
+ return '*';
938
+ }
675
939
  return '.';
940
+ }
676
941
  const area = areaAt(map, { x, y });
677
- if (area === undefined)
942
+ if (area === undefined) {
943
+ if (zHere.length > 0) {
944
+ if (!terrainNames.has('*'))
945
+ terrainNames.set('*', new Set());
946
+ for (const z of zHere)
947
+ terrainNames.get('*').add(z.name);
948
+ return '*';
949
+ }
678
950
  return '.';
951
+ }
679
952
  if (area.kind === 'object') {
680
953
  const g = glyph.get(`mark:${areaName(area)}`) ?? '?';
681
954
  shownGlyphs.add(`mark:${areaName(area)}`);
682
955
  return g;
683
956
  }
957
+ if (area.kind !== 'wall' && zHere.length > 0) {
958
+ if (!terrainNames.has('*'))
959
+ terrainNames.set('*', new Set());
960
+ for (const z of zHere)
961
+ terrainNames.get('*').add(z.name);
962
+ return '*';
963
+ }
684
964
  const g = TERRAIN_GLYPH[area.kind];
685
965
  if (!terrainNames.has(g))
686
966
  terrainNames.set(g, new Set());
@@ -707,11 +987,21 @@ export function battleGridLines(c, roomName, visible = () => true) {
707
987
  if (here.length > 1)
708
988
  stacked.push(`@=${here.map((i) => i.name).join('+')}`);
709
989
  }
710
- const legend = [...glyph].filter(([key]) => shownGlyphs.has(key)).map(([key, g]) => `${g}=${key.replace(/^mark:/, '')}`);
990
+ const altByKey = new Map(placed.filter((p) => (p.cell.z ?? 0) > 0).map((p) => [p.ch.name, p.cell.z]));
991
+ const legend = [...glyph]
992
+ .filter(([key]) => shownGlyphs.has(key))
993
+ .map(([key, g]) => {
994
+ const label = key.replace(/^mark:/, '');
995
+ const z = altByKey.get(key);
996
+ return `${g}=${label}${z !== undefined ? `(↑${z}尺)` : ''}`;
997
+ });
711
998
  const terrain = [...terrainNames].map(([g, names]) => `${g}=${[...names].join('/')}`);
712
999
  out.push([...legend, ...stacked].join(' '));
713
1000
  if (terrain.length > 0)
714
1001
  out.push(terrain.join(' '));
1002
+ const activeZones = rooms.flatMap((room) => zonesInRoom(c, room));
1003
+ if (activeZones.length > 0)
1004
+ out.push(`🌀 区域:${activeZones.map(formatZonePlayerLegend).join(';')}`);
715
1005
  if (offView.length > 0)
716
1006
  out.push(`图外:${offView.join('、')}`);
717
1007
  out.push('每格 5 尺,x 向东(右)、y 向南(下)');
@@ -737,7 +1027,7 @@ export function distancesFrom(c, name, visible = () => true) {
737
1027
  .filter(([, at]) => at.room === cell.room)
738
1028
  .map(([n, at]) => `${n} ${distanceFeet(cell, at)} 尺`);
739
1029
  const who = others.map((o) => `${o.foe ? '敌 ' : ''}${o.name} ${o.feet} 尺`).join('、') || '房间里没有别人';
740
- return `${ch.name}(${cell.x},${cell.y}) 到:${who}${marks.length > 0 ? `;标记:${marks.join('、')}` : ''}`;
1030
+ return `${ch.name}${fmtCoord(cell)} 到:${who}${marks.length > 0 ? `;标记:${marks.join('、')}` : ''}`;
741
1031
  }
742
1032
  /**
743
1033
  * 范围法术会罩到谁。11-08 的火球是 DM 凭眼睛摆的,说「三只都能罩住,队友一个都进不去」,