865 lines
50 KiB
GDScript
865 lines
50 KiB
GDScript
# VERTICAL SLICE - NOT FOR PRODUCTION
|
||
# Validation Question: 玩家能否无指导在一场完整战斗中经历「开战→挖掘规划→轮末结算逐行兑现→胜/负」并逐行归因(P2)
|
||
# Date: 2026-09-10
|
||
# 战斗结算编排中枢:轮次生命周期唯一 owner · 五段结算(授予→增益/减益→战斗→衰减→判定——2026-09-15
|
||
# 格面资源批,道具窗口/道具段随可选类删除下线)· 授予段极性路由(「动作 × 格型」矩阵:开安全格/标中旗
|
||
# = 正向,开雷格/标错旗 = 负向;结算队列 + 抵消过滤——标旗后被撤旗以轮末在场旗为基线不判)·
|
||
# 10 类行协议可回放步骤流(零 await;随机消费三处皆封闭流——开战遭遇骰〔初始化随机〕+ 技能摇号
|
||
# behavior_roll〔回合内、开轮时点、步骤流之外——敌人技能池批 2026-09-16〕+ 护甲等级掷点〔回合内、
|
||
# 步骤流之内〕;同种子同输入逐位复现)· 高光双落(完美排雷 ×2 / 标中旗 highlight)·
|
||
# Waiting 相位结算触发(不依赖事件到达序)。
|
||
# GP+商店房实施批(2026-09-21):授予段极性路由增 GP 型兑付(effect_id gp_gain/gp_loss → 战斗内缓冲
|
||
# escrow 记账,不入钱包不入增益容器);战斗结束分支掷 gp_drop 封闭流(每战斗末恰一 scope)出
|
||
# gp_dropped = 掷定 + level_gp_bonus + escrow 随 battle_finished 上抛——战斗域零 GP 状态持久。
|
||
# 伤害管线单据化批(2026-09-24 用户三裁决,06 台账 148):伤害兑付全部收口 伤害控制器(DamageController
|
||
# 单点管线)——本类六调用点(主角先手/敌方伤害技/棋盘克制直伤/群伤/反噬/地形变异)退化为开单点
|
||
# (流程决定何时开单给谁开单;单据怎么算归控制器)。结账时机开关在控制器 policy:IMMEDIATE(A=开单
|
||
# 即结,逐位等价迁移前行为——回切位)/ SEGMENT(B=攒批到段界 flush:授予段尾〔含清图批前〕+ 战斗段尾)。
|
||
# 死亡事件 = 单位容器 unit_died(单位自行宣布)→ 控制器作废该敌未结单据〔死亡即不动手〕/ 主角死终止兑付。
|
||
# 切片登记:① 事件总线载体 = 直连信号(实现期 ADR 项,provisional)② Waiting 相位刷新通道 2026-09-15 用户拍板整体
|
||
# 拆除(仅 Active 挖掘期受理)③ 效果行协议 = 授予段逐 grant 行 + 增益/减益段续存实例组合行。
|
||
# 实现 GDD:design/gdd/systems/战斗循环/战斗结算.md(v0.7 格面资源批——registry 追溯锚)
|
||
class_name BattleOrchestrator
|
||
extends RefCounted
|
||
|
||
signal step_row(row: Dictionary)
|
||
signal battle_finished(payload: Dictionary) # {result, hero_hp, gp_dropped}——hero 在 despawn 前捕获(呈现层销毁后读状态的时序防护);gp_dropped = 战斗掉落合计(GP+商店房实施批 2026-09-21)
|
||
signal round_started(round_index: int)
|
||
signal board_changed()
|
||
signal settlement_snapshot(snap: Dictionary) # 每结算末尾的全量状态快照(playtest_logger 消费——JSONL 数值分析)
|
||
|
||
# 明细流水行型协议(战斗结算 Core Rule;9 类——2026-09-20 伏击单轮上限退役,溢出未生效行 overflow 随之下线;
|
||
# 2026-09-15 格面资源批由 15 类收拢,清单改动须同步 battle_log_view 的 _format_row 与本文档头注):
|
||
# 效果行 effect · 伤害行 damage · 治疗行 heal ·
|
||
# 奖励未生效行 reward_ineffective · 标旗未中行 flag_miss · 施放行 cast(敌人技能池批由蓄力行 charge 改型)· 衰减行 decay ·
|
||
# 判定行 verdict · 高光行 highlight
|
||
# 行来源断言豁免集合(行型层)——判定段 / 衰减段本就无棋盘来源,勿一刀切误炸
|
||
const SOURCE_EXEMPT_TYPES := ["decay", "verdict"]
|
||
# 行来源断言豁免集合(来源类别层)——事实来源是单位 / 清图而非棋盘格
|
||
const SOURCE_EXEMPT_CLASSES := ["hero_attack", "enemy_action", "clear_reward"]
|
||
|
||
var db
|
||
var rng
|
||
# E1 封装收口(2026-09-13):协作对象 board_generator/enemy_system/status_effects/reward_economy 私有化——跨层读取一律经 presentation_snapshot()/
|
||
# diagnostic_snapshot() 成文出口(呈现层链式穿透 settlement._enemy_system.hero_unit() 的根因收口)。
|
||
# minesweeper/action_economy 保持公有 = 架构文档 API Boundaries 的 HUD框架消费面(意图提交 settle_batch + compute_move_path
|
||
# 只读;ap/rap/相位读取)——非本文档登记的契约面,勿增新用途。
|
||
var _board_generator: BoardGenerator
|
||
var minesweeper: MinesweeperRules
|
||
var action_economy: ActionEconomy
|
||
var _enemy_system: UnitContainer
|
||
var _status_effects: StatusContainer
|
||
var _reward_economy: RewardEconomy
|
||
var _damage: DamageController # 伤害控制器(伤害管线单据化批 2026-09-24——单据唯一兑付管线)
|
||
|
||
var encounter: Dictionary = {}
|
||
var round_index := 0
|
||
var battle_result := "" # "" / "victory" / "defeat"
|
||
var escrow := 0 # 战斗内 GP 缓冲(战斗域中间态——begin_battle 清零;gp_gain/gp_loss 兑付累记;随 gp_dropped 上抛即弃,不入钱包)
|
||
|
||
var _facts_reveals: Array = []
|
||
var _facts_flags: Array = []
|
||
var _facts_path := ""
|
||
var _settling := false
|
||
var _refresh_used_this_round := 0 # 每轮刷新计数(Active 相位合计,兜底上限 = ActionEconomyTable.refresh_cap_per_round)
|
||
var _board_seq := 0 # 板序号(本战斗第几张板——快照归因用)
|
||
var _board_from_midround_refresh := false # 装板 provenance:轮内刷新换来的图 = true(清图奖励守卫——刷新图不发清图奖励)
|
||
var _flag_consumed := {} # 兑付资格以雷格实例为键(板级;换图重置)
|
||
var _flag_miss_seen := {} # 标旗未中行去重(每安全格实例一次)
|
||
var _perfect_hit_true := 0 # 板级完美排雷计数(install 重置)
|
||
var _perfect_hit_false := 0
|
||
var _hero_atk := 0 # 主角攻击基值快照(encounter.hero_atk;E4 收口——表值运行期不可变)
|
||
|
||
|
||
func _init(db_ref, rng_ref) -> void:
|
||
db = db_ref
|
||
rng = rng_ref
|
||
_board_generator = BoardGenerator.new()
|
||
action_economy = ActionEconomy.new(db)
|
||
minesweeper = MinesweeperRules.new(db, action_economy)
|
||
_enemy_system = UnitContainer.new(db)
|
||
_status_effects = StatusContainer.new(db)
|
||
_reward_economy = RewardEconomy.new(db, rng)
|
||
_damage = DamageController.new(db, rng, _enemy_system, _status_effects)
|
||
_damage.emit_row_cb = _emit_row # 行协议归属本类(9 类行协议 + 来源断言不外泄)
|
||
minesweeper.cell_revealed.connect(_on_cell_revealed)
|
||
minesweeper.flag_judged.connect(_on_flag_judged)
|
||
minesweeper.round_end_board.connect(_on_round_end)
|
||
action_economy.round_end_stopped.connect(_on_round_end)
|
||
|
||
|
||
# ---- 战斗开始序列(编排专章①:门 → 增益状态 → 敌人系统 → install+roll → 行动经济)----
|
||
|
||
func begin_battle(enc: Dictionary) -> bool:
|
||
if round_index != 0:
|
||
push_warning("[战斗结算] begin_battle 重复受理")
|
||
return false
|
||
encounter = enc
|
||
escrow = 0 # 战斗域零 GP 持久(GP+商店房实施批——每场战斗缓冲从零起算)
|
||
_damage.set_hero_ac_override(int(enc.get("hero_armor_class", -1))) # 主角护甲合流入参(伤害控制器 defender_ac 消费——口径同原 _defender_ac)
|
||
db.set_reload_gate(true)
|
||
if not _status_effects.notify_battle_start():
|
||
_fatal("增益状态 开域被拒(编排违例)")
|
||
return false
|
||
# 遭遇骰(难度曲线与Boss GDD Core Rule 8——2026-09-12 用户拍板):行有 unit_count_max 时按 [unit_count, max] 均匀骰;
|
||
# 2026-09-14 敌方攻击区间批扩展:行有 atk_min 时按 [atk_min, atk_max] 骰 spawn 期整战持久值
|
||
# (每拍抖动否决——数字可读性锚;中点 = 行值)。encounter 封闭流恰一 scope(数量骰先、atk 骰后);
|
||
# 挖掘决策域之外——P1 合规;敌人系统 零随机纪律保持(收 override 即确定值)。
|
||
var erow_pre: Dictionary = db.resolve_enemy_rowset(int(enc.level_index), int(enc.node_depth))
|
||
var roll_lo: int = int(erow_pre.get("unit_count", 1))
|
||
var roll_hi: int = int(erow_pre.get("unit_count_max", roll_lo))
|
||
var needs_count: bool = roll_hi > roll_lo
|
||
var needs_atk: bool = erow_pre.has("atk_min")
|
||
var rolled := roll_lo
|
||
var rolled_atk := -1
|
||
if needs_count or needs_atk:
|
||
var estream: RandomNumberGenerator = rng.open_stream("encounter")
|
||
if needs_count:
|
||
rolled = roll_lo + estream.randi_range(0, roll_hi - roll_lo)
|
||
if needs_atk:
|
||
rolled_atk = int(erow_pre.atk_min) + estream.randi_range(0, int(erow_pre.atk_max) - int(erow_pre.atk_min))
|
||
# E4 收口:加成经 encounter 显式携带(hero_atk/hero_max_hp;缺省 = 表值——冒烟/工具直呼路径)
|
||
_hero_atk = int(enc.get("hero_atk", int(db.hero.atk)))
|
||
if not _enemy_system.spawn(int(enc.level_index), int(enc.node_depth), int(enc.hero_hp), rolled,
|
||
_hero_atk, int(enc.get("hero_max_hp", -1)), rolled_atk):
|
||
_fatal("敌人系统 spawn 被拒")
|
||
return false
|
||
var erow: Dictionary = db.resolve_enemy_rowset(int(enc.level_index), int(enc.node_depth))
|
||
if not _install_new_board():
|
||
return false
|
||
_reset_round_facts() # 首板 install 的初始展开事件不入轮 facts(resource 恒 false 的双保险)
|
||
if not action_economy.notify_round_start():
|
||
_fatal("行动经济 首轮 notify_round_start 被拒")
|
||
return false
|
||
round_index = 1
|
||
_roll_round_actions() # 开轮摇号(敌人技能池批——首轮同样摇;先于 round_started,挖掘期动画位可读)
|
||
round_started.emit(round_index)
|
||
return true
|
||
|
||
|
||
func _install_new_board(during_round := false) -> bool:
|
||
var stream: RandomNumberGenerator = rng.open_stream("board_gen")
|
||
var board: BoardData = _board_generator.generate(int(encounter.level_index), int(encounter.node_depth), stream, db)
|
||
if board == null:
|
||
return false
|
||
var res: Dictionary = minesweeper.install_board(board, during_round)
|
||
if not res.accepted:
|
||
_fatal("排雷玩法 install 拒绝(不变式违例): %s" % str(res))
|
||
return false
|
||
# 地图战斗资源 义务⑥:roll_board 恰一次(install 后、挖掘前);资格格 = 全部非封锁格(安全格 + 雷格,雷安同池)
|
||
var r0 := {}
|
||
for c in board.compute_r0():
|
||
r0[c] = true
|
||
var eligible: Array = []
|
||
for c in board.safe_cells():
|
||
if not r0.has(c):
|
||
eligible.append({"cell": c})
|
||
for c in board.mines.keys():
|
||
if not r0.has(c):
|
||
eligible.append({"cell": c})
|
||
if not _reward_economy.roll_board(eligible):
|
||
_fatal("地图战斗资源 roll_board 被拒")
|
||
return false
|
||
# 地形变异 布置段(2026-09-19 用户拍板棋盘设置顺序第 4 步:生成棋盘 → 打开状态初始化 →
|
||
# 战斗资源格设置 → 变异格设置)——布置在初始展开与资源格之后,变异天然不落已开区
|
||
_place_variants(board)
|
||
_flag_consumed.clear() # 换图新雷 = 新实例,资格自然重置(行动经济 Rule 8)
|
||
_flag_miss_seen.clear()
|
||
_perfect_hit_true = 0 # 板级完美计数随 install 重置
|
||
_perfect_hit_false = 0
|
||
_board_from_midround_refresh = during_round # 轮内刷新装板 = 刷新图(清图奖励不发);常规换图/开战装板 = false
|
||
_board_seq += 1
|
||
board_changed.emit()
|
||
return true
|
||
|
||
|
||
# ---- 地形变异 布置段(首批类型定稿批 2026-09-19——棋盘设置顺序第 4 步)----
|
||
# 候选池门控(unlock_level ≤ 关卡序号 + board_types 与本地形交集,∅ 通配)经 config_db.variant_pool;
|
||
# 池空 = 合法态,静默零布置(框架 P0 口径不变)。零特判:本段只写格子变异数据快照,不改扫雷规则本体。
|
||
# 候选格域 = 安全格 − 初始展开区(伤害型 placement=closed_only 的结构保障——布置发生在初始展开之后,
|
||
# 已开格天然排除);雷格不吃变异(挖雷一层惩罚 + 变异伤害双层叠罚污染逐行归因,首版排除——provisional)。
|
||
# 每图至多一种类型(候选池内均匀选一,混型布置归因复杂留待后续批);数量 = round(候选池格数×percent) +
|
||
# (关卡序号−1)×per_level_bonus——基数为候选池而非总格数(2026-09-21 用户拍板基数修正批:初始展开
|
||
# 占全板 56–67%,总格数基数使有效密度膨胀 4–6 倍、L1 小板极端全池覆盖;percent 语义 = 占可挖格比例,
|
||
# 关卡递增由 per_level_bonus 绝对格数承载);连通片生长(8 邻),单片 ≤ pack_max(2×2 / 1×4 / 1×3+1 等形)。
|
||
func _place_variants(board: BoardData) -> void:
|
||
var pool: Array = db.variant_pool(int(encounter.level_index), String(board.board_type))
|
||
if pool.is_empty():
|
||
return
|
||
var r0 := {}
|
||
for c in board.compute_r0():
|
||
r0[c] = true
|
||
var candidates: Array = []
|
||
for c in board.safe_cells():
|
||
if not r0.has(c):
|
||
candidates.append(c)
|
||
if candidates.is_empty():
|
||
return
|
||
var stream: RandomNumberGenerator = rng.open_stream("variant_place") # 一板恰一 scope(换图/刷新图各取号一次)
|
||
var vrow: Dictionary = pool[stream.randi_range(0, pool.size() - 1)]
|
||
var total: int = int(round(float(candidates.size()) * float(db.variation.percent_of_cells) / 100.0)) \
|
||
+ (int(encounter.level_index) - 1) * int(db.variation.per_level_bonus)
|
||
total = mini(total, candidates.size())
|
||
var placed := {}
|
||
while placed.size() < total:
|
||
var pack_size: int = mini(total - placed.size(), stream.randi_range(2, int(db.variation.pack_max)))
|
||
var free: Array = []
|
||
for c in candidates:
|
||
# 新片种子/生长格禁与其他已布片 8 邻贴接——否则两片粘连成一个超 pack_max 的连通分量
|
||
# (R3 随机流下实测暴露:独立生长的相邻片合流击穿单片上限断言)
|
||
if placed.has(c) or _adjacent_to_packs(board, placed, c):
|
||
continue
|
||
free.append(c)
|
||
if free.is_empty():
|
||
break
|
||
var seed_c: Vector2i = free[stream.randi_range(0, free.size() - 1)]
|
||
placed[seed_c] = true
|
||
var pack: Array = [seed_c]
|
||
var pack_set := {seed_c: true}
|
||
while pack.size() < pack_size:
|
||
var fringe: Array = []
|
||
for c in pack:
|
||
for n in board.neighbors8(c):
|
||
if candidates.has(n) and not placed.has(n) and not fringe.has(n) \
|
||
and not _adjacent_to_packs(board, placed, n, pack_set):
|
||
fringe.append(n)
|
||
if fringe.is_empty():
|
||
break # 生长域耗尽——该片就地收束(数量不足总目标为合法态,候选域碎片化时触发)
|
||
var nxt: Vector2i = fringe[stream.randi_range(0, fringe.size() - 1)]
|
||
placed[nxt] = true
|
||
pack_set[nxt] = true
|
||
pack.append(nxt)
|
||
for c in placed.keys():
|
||
board.variants[c] = [String(vrow.variant_id)]
|
||
|
||
|
||
# 候选格是否与其他已布片(own_pack 之外的 placed 格)8 邻贴接——片间隔离保证连通分量 = 单片 ≤ pack_max
|
||
func _adjacent_to_packs(board: BoardData, placed: Dictionary, c: Vector2i, own_pack: Dictionary = {}) -> bool:
|
||
for m in board.neighbors8(c):
|
||
if placed.has(m) and not own_pack.has(m):
|
||
return true
|
||
return false
|
||
|
||
|
||
# ---- 事件缓冲(轮 facts 收集;结算触发 = Waiting 相位编排点,不依赖到达序)----
|
||
|
||
func _on_cell_revealed(evt: Dictionary) -> void:
|
||
# 轮 facts 缓冲不设相位守卫——轮末最后一挖的揭示事件在 request_dig 翻相之后才到(事件序:
|
||
# cell_revealed 批 → flag_judged 批 → round_end),phase==Active 守卫会丢最后一挖的事实;
|
||
# initial 通道事件(install 初始展开——封锁格)resource=false,进入授予段被资格检查自然跳过。
|
||
if battle_result == "":
|
||
if bool(evt.get("resource", false)):
|
||
# 身份快照随缓冲捕获(批次隔离——轮内刷新后 mapping 已换批,授予必须用缓冲期身份,
|
||
# 防旧图已挖格在轮末错拿新图同坐标身份)。雷格同样携带(雷安同池——负向兑付的来源格)
|
||
var snap = _reward_economy.query_full_snapshot(evt.cell)
|
||
if snap != null:
|
||
evt = evt.duplicate()
|
||
evt["reward_snapshot"] = snap
|
||
_facts_reveals.append(evt)
|
||
|
||
|
||
func _on_flag_judged(evt: Dictionary) -> void:
|
||
_facts_flags.append(evt)
|
||
|
||
|
||
func _on_round_end(_payload: Dictionary) -> void:
|
||
_facts_path = String(_payload.get("path_tag", ""))
|
||
_maybe_settle()
|
||
|
||
|
||
func _maybe_settle() -> void:
|
||
if _settling or battle_result != "":
|
||
return
|
||
if action_economy.phase != action_economy.PHASE_WAITING:
|
||
return
|
||
_settle()
|
||
|
||
|
||
# ---- 每轮结算序列(五段——段序骨架冻结于 SettlementTable.segment_order)----
|
||
|
||
func _settle() -> void:
|
||
_settling = true
|
||
var ri := round_index
|
||
# ① 授予段:结算队列(开格/旗判定/清图)→ 极性路由逐批兑付。
|
||
# 判定基线 = 轮末在场旗(发射面已过滤——被挖开的旗已随挖掘擦除零兑付,插旗不可逆批 2026-09-19;
|
||
# 开格事实不可撤)。
|
||
for evt in _facts_reveals:
|
||
if not bool(evt.get("resource", false)):
|
||
continue # 封锁格(initial 通道)恒无资源——不入账(战斗结算 义务②)
|
||
var snap = evt.get("reward_snapshot")
|
||
if not (snap is Dictionary):
|
||
continue
|
||
if evt.kind == "safe":
|
||
if bool(evt.get("dug_under_flag", false)):
|
||
# 插旗不可逆四情况④(2026-09-19 用户拍板):插安全格再挖开 = 零惩罚零奖励——正向兑付
|
||
# 作废(归因行在案);标空判定已随旗擦除自然缺席(被挖的旗不在轮末在场基线)。
|
||
_emit_row("reward_ineffective", "safe_cell", evt.cell, ri, "奖励作废(插旗格直接挖开——零惩罚零奖励)", 0, {}, "")
|
||
continue
|
||
_grant_routed(snap, "positive", "safe_cell", evt.cell, ri, "")
|
||
elif evt.kind == "mine":
|
||
# 插旗不可逆四情况②:插雷格再挖开 = 只受挖雷一层惩罚(mine_hit 照常兑付——惊动巢穴),
|
||
# 标中不发(旗已随挖掘擦除、不入轮末判定基线)。
|
||
_grant_routed(snap, "negative", "mine_hit", evt.cell, ri, "")
|
||
# 地形变异 兑付段(授予段尾——触发枚举 on_open:挖开即伤、chain 通道同口径,轮末结算逐行兑现;
|
||
# 信息型 hide_number 不进结算——呈现层读取,见 board_view 数字遮蔽;雷格恒无变异——布置段排除,
|
||
# 双层叠罚不存在;插旗格直挖照吃变异伤害——地形后果同 mine_hit 口径,非奖励不作废)
|
||
for evt in _facts_reveals:
|
||
var vids: Array = evt.get("variant_ids", [])
|
||
for vid in vids:
|
||
var vrow: Dictionary = db.variation.row_by_id(String(vid))
|
||
if String(vrow.get("effect", "")) != "flat_damage":
|
||
continue # 触发词表按 effect 路由:flat_damage=on_open 兑现;hide_number/on_open 外组合 = 数据行新词表未接线(显式忽略面)
|
||
# 地形变异伤害单据(伤害管线单据化批 2026-09-24)——无类型必中,下限保底在控制器管线内
|
||
var vt := _damage.open_ticket(DamageController.KIND_BOARD_FLAT_HERO, "地形变异", String(vrow.get("display_name", vid)), "board", \
|
||
int(vrow.get("effect_value", 0)), DamageController.TARGET_HERO, ri, evt.cell, "", 0, "", {"variant_id": String(vid)})
|
||
_damage.submit(vt)
|
||
for evt in _facts_flags:
|
||
_judge_flag(evt, ri)
|
||
if _facts_path == "cleared":
|
||
_grant_clear_reward(ri)
|
||
_damage.flush() # 授予段界结账(B 模式——段内开单攒批到此统一兑现;A 模式 no-op;清图批前另有同步结账点)
|
||
# ② 增益/减益段(续存实例组合行;本结算新授予的已在授予段逐 grant 出行——增益状态 义务⑦)
|
||
_emit_composition_effects("hero", ri)
|
||
_emit_composition_effects("enemy", ri)
|
||
# ③ 战斗段(调用序:掷点判定 → apply_damage → commit_action;hero hp=0 短路)
|
||
_combat_segment(ri)
|
||
# ④ 衰减段(恰一次恒执行含末轮——先兑付后衰减)
|
||
var k: int = _status_effects.decay_round()
|
||
_emit_row("decay", "", Vector2i(-1, -1), ri, "状态衰减", k, {}, "")
|
||
# ⑤ 判定段(防御性优先级 hero 先判——双死结构不可达的纵深防御)
|
||
var verdict := "continue"
|
||
if int(_enemy_system.hero_unit().get("hp", 0)) <= 0:
|
||
verdict = "defeat"
|
||
elif _enemy_system.query_alive("enemy").is_empty():
|
||
verdict = "victory"
|
||
_emit_settlement_snapshot(verdict) # 全量状态快照(despawn 前组装——终局含 result)
|
||
if verdict == "defeat":
|
||
_emit_row("verdict", "", Vector2i(-1, -1), ri, "战斗失败", 0, {}, "")
|
||
_battle_over("defeat")
|
||
return
|
||
if verdict == "victory":
|
||
_emit_row("verdict", "", Vector2i(-1, -1), ri, "战斗胜利", 1, {}, "")
|
||
_battle_over("victory")
|
||
return
|
||
_emit_row("verdict", "", Vector2i(-1, -1), ri, "下一轮次", 0, {}, "")
|
||
_exit_distribution()
|
||
_settling = false
|
||
|
||
|
||
# ---- 授予段 helpers(极性路由)----
|
||
|
||
# 「动作 × 格型」矩阵的执行面:snap = 缓冲期冻结身份快照(cell_type = 该格装板期摇定的类型身份),
|
||
# polarity 由动作决定(开安全格/标中旗 = positive,开雷格/标错旗 = negative),
|
||
# 兑付行 = 奖励字典(类型, 极性)行。返回 true = percent 行实际生效(flat 行恒 false——兑付结果由行协议承载)。
|
||
func _grant_routed(snap: Dictionary, polarity: String, source_class: String, cell: Vector2i, ri: int, highlight: String = "", label_suffix: String = "") -> bool:
|
||
var row: Dictionary = _reward_economy.polarity_row(String(snap.get("cell_type", "")), polarity)
|
||
if row.is_empty():
|
||
_fatal("极性字典缺行: %s %s" % [String(snap.get("cell_type", "")), polarity])
|
||
return false
|
||
if polarity == "positive":
|
||
row["power"] = int(snap.get("power", int(row.power))) # 区间行快照 power(身份批 roll 值)覆盖表值——授予期零随机口径(E14)
|
||
return _dispatch_row(row, source_class, cell, ri, highlight, label_suffix)
|
||
|
||
|
||
# 兑付形态分派:effect_id 非空 = percent 行(进增益状态容器);空 = flat 行(当场兑付)
|
||
func _dispatch_row(row: Dictionary, source_class: String, cell: Vector2i, ri: int, highlight: String = "", label_suffix: String = "") -> bool:
|
||
var eff := String(row.get("effect_id", ""))
|
||
if eff != "":
|
||
return _apply_percent_row(row, source_class, cell, ri, highlight, label_suffix)
|
||
_apply_flat_row(row, source_class, cell, ri, highlight, label_suffix)
|
||
return false
|
||
|
||
|
||
# percent 行兑付:GP 型行走战斗内缓冲记账(GP+商店房实施批);其余 apply_effect 入容器;
|
||
# 满层拒收 = "奖励未生效"行(零静默)
|
||
func _apply_percent_row(row: Dictionary, source_class: String, cell: Vector2i, ri: int, highlight: String = "", label_suffix: String = "") -> bool:
|
||
var eff := String(row.effect_id)
|
||
if eff == "gp_gain" or eff == "gp_loss":
|
||
return _apply_gp_row(row, source_class, cell, ri, highlight, label_suffix)
|
||
var ok: bool = _status_effects.apply_effect(eff, {"source_class": source_class, "origin_cell": cell, "round_index": ri})
|
||
if ok:
|
||
var srow: Dictionary = db.status_effect_row(eff)
|
||
_emit_row("effect", source_class, cell, ri, String(srow.display_name) + label_suffix, int(srow.magnitude), {"effect_id": eff, "pool_value": _pool_effective(eff)}, highlight)
|
||
return true
|
||
_emit_row("reward_ineffective", source_class, cell, ri, "奖励未生效(满层)%s" % label_suffix, 0, {"batch_key": eff}, highlight)
|
||
return false
|
||
|
||
|
||
# GP 型行兑付(GP+商店房实施批 2026-09-21):战斗内缓冲 escrow 记账——不入钱包不入增益容器。
|
||
# 正向(gp_gain)= 挖开金币安全格/标中旗;负向(gp_loss)= 挖雷格/标错旗。兑付行经既有 effect 行
|
||
# 通道外发(escrow 随行——归因可读),战斗结束随 gp_dropped 一次上抛后即弃。
|
||
func _apply_gp_row(row: Dictionary, source_class: String, cell: Vector2i, ri: int, highlight: String = "", label_suffix: String = "") -> bool:
|
||
var eff := String(row.effect_id)
|
||
var delta: int = int(row.power) if eff == "gp_gain" else -int(row.power)
|
||
escrow += delta
|
||
_emit_row("effect", source_class, cell, ri, "%s %+d%s" % [String(row.display_name), delta, label_suffix], delta, {"effect_id": eff, "escrow": escrow}, highlight)
|
||
return true
|
||
|
||
|
||
# flat 行兑付(负向恒即时,无库存语义):伤害型分支全部改开单据(伤害管线单据化批 2026-09-24——
|
||
# 管线/下限/目标解析归 伤害控制器,本函数只保留非伤害分支与单据装配):
|
||
# action = 行动点排队(非伤害);blast 正向 = 群伤单据(无类型恒定表值打全体存活敌;负向 = 警觉 percent 行走 _apply_percent_row);
|
||
# heal 正向 = 主角回复 clamp(满血 → 奖励未生效行);heal 负向 = 主角直伤单据(不经增益状态);
|
||
# pierce/magic 正向 = 单目标克制直伤单据(attack_type 查克制矩阵,必中全额不掷点);负向 = 主角直伤单据。
|
||
# 返回 "redeemed" = 实际有效兑付 / "zero" = 零兑付(行已自记)——读数 = 控制器结账 outcome(A 模式提交即结)。
|
||
# sync = 同步开单(清图批——流程依赖完美第二份/高光份数读数,无视结账政策当场结账)。
|
||
func _apply_flat_row(row: Dictionary, source_class: String, cell: Vector2i, ri: int, highlight: String = "", label_suffix: String = "", sync := false) -> String:
|
||
var ctype := String(row.cell_type)
|
||
var power := int(row.power)
|
||
var display := String(row.display_name) + label_suffix
|
||
if ctype == "action":
|
||
var delta: int = power if String(row.get("polarity", "positive")) == "positive" else -power
|
||
action_economy.queue_ap_delta(delta)
|
||
_emit_row("effect", source_class, cell, ri, "%s(下轮行动点 %+d)" % [display, delta], delta, {"effect_id": "ap_delta", "pool_value": action_economy.pending_ap_delta()}, highlight)
|
||
return "redeemed"
|
||
if ctype == "blast":
|
||
var t := _damage.open_ticket(DamageController.KIND_BOARD_BLAST, source_class, display, "board", power, \
|
||
DamageController.TARGET_ALL_ALIVE, ri, cell, "", 0, highlight, {"batch_key": String(row.reward_id)})
|
||
return _damage.outcome(_submit(t, sync))
|
||
if ctype == "pierce" or ctype == "magic":
|
||
# 伤害道具批(2026-09-18)语义不变:正向 = 单目标克制直伤(必中全额不掷点——棋盘来源伤害既有口径);
|
||
# 负向 = 主角直伤(复用反噬通道)。
|
||
if String(row.get("polarity", "positive")) == "negative":
|
||
return _submit_flat_hero(source_class, display, power, cell, ri, highlight, sync)
|
||
var atk_type: String = String(row.get("attack_type", ctype))
|
||
var t2 := _damage.open_ticket(DamageController.KIND_BOARD_TYPED, source_class, display, "board", power, \
|
||
DamageController.TARGET_FRONT_ALIVE, ri, cell, atk_type, 0, highlight, {"batch_key": String(row.reward_id)})
|
||
return _damage.outcome(_submit(t2, sync))
|
||
if ctype == "heal":
|
||
if String(row.get("polarity", "positive")) == "negative":
|
||
return _submit_flat_hero(source_class, display, power, cell, ri, highlight, sync)
|
||
if int(_enemy_system.hero_unit().get("hp", 0)) <= 0:
|
||
# 主角已倒下(同轮更早的负向直伤致死)——治疗不再合法作用,按"奖励未生效"留痕
|
||
_emit_row("reward_ineffective", source_class, cell, ri, "%s 未生效(主角已倒下)" % display, 0, {"batch_key": String(row.reward_id)}, highlight)
|
||
return "zero"
|
||
if int(_enemy_system.hero_unit().hp) >= int(_enemy_system.hero_unit().max_hp):
|
||
_emit_row("reward_ineffective", source_class, cell, ri, "%s 未生效(满血)" % display, 0, {"batch_key": String(row.reward_id)}, highlight)
|
||
return "zero"
|
||
var healed: int = _enemy_system.heal(_enemy_system.hero_unit(), power) # clamp 归 战斗结算
|
||
_emit_row("heal", source_class, cell, ri, "%s 回复" % display, healed, {"target": "hero"}, highlight)
|
||
return "redeemed"
|
||
_fatal("flat 行未知类型: %s" % ctype)
|
||
return "zero"
|
||
|
||
|
||
# 开单分流:sync(清图批)走控制器同步开单——先按序结清段内排队单据、再当场兑现本单;
|
||
# 常规开单按结账时机政策(A 即结 / B 入队)。
|
||
func _submit(t: Dictionary, sync: bool) -> int:
|
||
return _damage.flush_submit(t) if sync else _damage.submit(t)
|
||
|
||
|
||
# 主角直伤单据(反噬/治疗包负向——无类型必中,下限保底在控制器管线内)
|
||
func _submit_flat_hero(source_class: String, display: String, power: int, cell: Vector2i, ri: int, highlight: String, sync := false) -> String:
|
||
var t := _damage.open_ticket(DamageController.KIND_BOARD_FLAT_HERO, source_class, display, "board", power, \
|
||
DamageController.TARGET_HERO, ri, cell, "", 0, highlight, {})
|
||
return _damage.outcome(_submit(t, sync))
|
||
|
||
|
||
# 旗判定批:标中 = 该雷格资源的正向兑付(每雷实例一次;高光 = 强制检查点);
|
||
# 标空 = "标旗未中"归因行 + 该安全格资源的负向兑付(同键去重——每格实例一次)。
|
||
func _judge_flag(evt: Dictionary, ri: int) -> void:
|
||
var cell: Vector2i = evt.cell
|
||
if evt.hit:
|
||
if _flag_consumed.has(cell):
|
||
return # 去重跳过(资格以雷格实例为键——排雷玩法 诚实重复上报的对侧);零明细行
|
||
_flag_consumed[cell] = true
|
||
_perfect_hit_true += 1
|
||
var snap = _reward_economy.grant(cell)
|
||
if not (snap is Dictionary):
|
||
return
|
||
_grant_routed(snap, "positive", "flag_hit", cell, ri, "flag_hit")
|
||
else:
|
||
_perfect_hit_false += 1
|
||
if _flag_miss_seen.has(cell):
|
||
return # 每格实例一次去重(归因行与负向兑付同键——防逐轮惩罚轰炸)
|
||
_flag_miss_seen[cell] = true
|
||
var hl := ""
|
||
if _perfect_hit_false == 1:
|
||
hl = "perfect_broken" # 本板完美谓词已破的归因锚
|
||
_emit_row("flag_miss", "flag_miss", cell, ri, "标旗未中", 0, {}, hl)
|
||
var snap = _reward_economy.grant(cell)
|
||
if not (snap is Dictionary):
|
||
return
|
||
_grant_routed(snap, "negative", "flag_miss", cell, ri, "")
|
||
|
||
|
||
# 清图批:清图奖励对象恰好发一次;完美排雷追加第二份同身份兑付(grant_clear 本身恰一次)。
|
||
# 高光行 value = 实际有效兑付份数(禁记名义值;首份零兑付 → 降级不发)。
|
||
func _grant_clear_reward(ri: int) -> void:
|
||
if _board_from_midround_refresh:
|
||
return # 轮内刷新换来的新图不发清图奖励(行动经济/战斗结算 明文——刷新图不是清图挣来的)
|
||
var snap = _reward_economy.grant_clear()
|
||
if not (snap is Dictionary):
|
||
return
|
||
var perfect: bool = _perfect_hit_false == 0 and _perfect_hit_true >= 1
|
||
var first_ok := _grant_clear_identity(snap, ri, "(清图奖励)")
|
||
var second_ok := false
|
||
if perfect and first_ok:
|
||
second_ok = _grant_clear_identity(snap, ri, "(完美第二份)")
|
||
if perfect and first_ok:
|
||
_emit_row("highlight", "clear_reward", Vector2i(-1, -1), ri, "完美排雷!清图奖励 ×2", (2 if second_ok else 1), {}, "perfect_sweep")
|
||
|
||
|
||
# 清图奖励 = 板级独立对象(不属于任何一格):兑付形态按其 cell_type 的正向字典形态走,
|
||
# 行值全部取快照(身份批 roll 值)。返回实际有效兑付。
|
||
# 同步开单(sync)——完美第二份与高光份数的流程依赖需要同步读数(开单权归流程 用户裁决③);
|
||
# 同步路径内先按序结清段内排队单据(B 模式保序),随后本批无视结账政策当场兑现。
|
||
func _grant_clear_identity(snap: Dictionary, ri: int, suffix: String) -> bool:
|
||
var row := {
|
||
"reward_id": String(snap.get("reward_id", "")),
|
||
"cell_type": String(snap.get("cell_type", "")),
|
||
"polarity": "positive",
|
||
"display_name": String(snap.get("display_name", "")),
|
||
"power": int(snap.get("power", 0)),
|
||
"effect_id": String(snap.get("effect_id", "")),
|
||
"stacks": int(snap.get("stacks", 1)),
|
||
}
|
||
var eff := String(row.effect_id)
|
||
if eff != "":
|
||
return _apply_percent_row(row, "clear_reward", Vector2i(-1, -1), ri, "clear_reward_h2", suffix)
|
||
return _apply_flat_row(row, "clear_reward", Vector2i(-1, -1), ri, "clear_reward_h2", suffix, true) == "redeemed"
|
||
|
||
|
||
# ---- 开轮摇号(敌人技能池批——共识点 B:技能选择前置到轮次开始,数值计算留结算段)----
|
||
# 每实例:保底判定(连续执行普攻 ≥ M → 必出特殊技、特殊技内按权重、不受冷却限制)→ 排除冷却中技能
|
||
# (中签率 = 权重 ÷ 可摇权重合计——份额归一)→ 按行序逐敌从统一流顺序取号摇定本拍动作。
|
||
# 随机消费只在换算层(本方法 + SkillLottery);单位容器收确定值(零随机纪律——armor_roll 先例同构)。
|
||
# 并流批(ADR-0007 裁丙 2026-09-27):behavior_roll 子流派生向量(spawn_index×STRIDE+序)退役——
|
||
# 「单敌轨迹独立复放」前提随之移除(位置交错,单点定位由事件日志承载)。摇定后、兑现前死亡 → 本拍技能作废。
|
||
func _roll_round_actions() -> void:
|
||
var pity_m: int = int(db.skill.pity_threshold)
|
||
for u in _enemy_system.query_alive("enemy"):
|
||
var entries: Array = _enemy_system.rollable_skills(u)
|
||
if _enemy_system.basic_streak(u) >= pity_m:
|
||
var specials: Array = _enemy_system.special_skills(u)
|
||
if not specials.is_empty():
|
||
entries = specials # 保底命中——普攻恒可摇 → 非保底路径池恒非空,此为唯一替代集合
|
||
var stream: RandomNumberGenerator = rng.open_stream("behavior_roll")
|
||
_enemy_system.set_pending_action(u, SkillLottery.draw(entries, stream))
|
||
_enemy_system.tick_cooldowns() # 递减在摇号读值之后——"施放后连续 N 拍不可摇中"的等价实现(单位容器 注记)
|
||
|
||
|
||
# ---- 战斗段 ----
|
||
# 伤害管线单据化批(2026-09-24):本段只开单——主角先手单 + 敌方伤害技单;掷点/折扣/暴击/克制/
|
||
# 池乘区/下限/交付/commit 全部收口 伤害控制器(A 模式提交即结=与迁移前逐位一致;B 模式段尾 flush)。
|
||
# 开单守卫归流程(用户裁决③——流程决定给谁开单):主角存活+目标存在才开先手单;hero hp=0 立即
|
||
# 停开(B 模式下若 flush 中主角倒下,由控制器死亡事件终止余单——两模式同一结果)。
|
||
|
||
func _combat_segment(ri: int) -> void:
|
||
# ⓪ 主角先手攻击(基础攻击恒存在——2026-09-11 用户裁决;先于敌方行动;授予段负向直伤致死 → 致电短路不先手)。
|
||
# 单分量伤害构成(2026-09-19 充能退役批·用户拍板):主角攻击 = 唯一基础分量(atk,吃掷点含暴击;
|
||
# 类型 = 主角 attack_type 表值——2026-09-18 营地扩展前置批:量与类型抽象分离;查甲效矩阵对应行取克制修正)。
|
||
# 原"基础 + 穿刺/魔法充能三分量"模型随充能系统整体退役——克制策略归冒险前配置(营地换型 / 未来冒险前参数面),
|
||
# 局内不再有挖掘攒弹药的第二伤害供给。attack_up 增益经 hero_offense 池乘攻击合计(见池乘区注记)。
|
||
# 护甲等级掷点批(2026-09-16):基础分量吃掷点判定(含暴击);棋盘来源伤害不掷不折;
|
||
# 任何伤害落地 ≥ damage_floor(全局 max(1,·)——2026-09-20 用户拍板扩全来源,下限在控制器管线单点收口)。
|
||
var hero_alive: bool = int(_enemy_system.hero_unit().get("hp", 0)) > 0
|
||
var hero_target = _enemy_system.default_target()
|
||
if hero_alive and hero_target != null:
|
||
var ht := _damage.open_ticket(DamageController.KIND_HERO_ATTACK, "hero_attack", "主角攻击", "combat", _hero_atk, \
|
||
DamageController.TARGET_FRONT_ALIVE, ri, Vector2i(-1, -1), String(_enemy_system.hero_unit().get("attack_type", "normal")))
|
||
_damage.submit(ht)
|
||
# 敌方行动(敌人技能池批——本拍动作开轮已摇定,此处按技能行兑现;行序 = 生成序)。
|
||
# 死亡即不动手:摇定后、兑现前死亡的敌不在存活序中——本拍技能作废,不 commit、不进冷却。
|
||
for u in _enemy_system.query_alive("enemy"):
|
||
if int(_enemy_system.hero_unit().hp) <= 0:
|
||
break # hero hp=0 立即短路(死尸挨打行是归因噪音——用户拍板)
|
||
var skill_id := _enemy_system.pending_action(u)
|
||
var srow: Dictionary = db.skill_row(skill_id)
|
||
if srow.is_empty():
|
||
_fatal("敌实例待发动作悬空: %s" % skill_id)
|
||
continue
|
||
if String(srow.type) == "buff" or String(srow.type) == "debuff":
|
||
# 增益/妨害技(新效应词汇批 2026-09-19)= 0 伤害施放行:不掷不折;状态授予即数值兑现,技能冷却与增益持续两计时器分账。
|
||
# (原"本轮喂的伏击逢施放拍不兑现"读怪奖励随伏击退役一并作废——2026-09-20 八型批)
|
||
# 落点由状态行 target_side 路由(buff → 敌方侧 / debuff → 主角侧——容器零改动,proposal-status-vocabulary §1)。
|
||
var dur: int = int(srow.get("buff_duration", 1))
|
||
_status_effects.apply_effect(String(srow.buff_ref), {"source_class": "enemy_action", "origin_cell": Vector2i(-1, -1), "round_index": ri}, dur)
|
||
_emit_row("cast", "enemy_action", Vector2i(-1, -1), ri, "%s 施放 %s" % [u.display_name, String(srow.display_name)], 0, {"skill_id": skill_id, "effect_id": String(srow.buff_ref), "duration": dur})
|
||
_enemy_system.commit_action(u)
|
||
continue
|
||
# 伤害技(含普攻——倍率恒 1)= 敌方伤害技单据:基线 = round(atk×倍率)、rider 预计算归开单侧
|
||
# (表值算术零随机),掷点/克制恒中性/hero_defense×enemy_output 池乘区/下限/rider 后置/commit
|
||
# 全归控制器管线(兑现序 = 开单序;来源敌已死在兑现时作废——死亡即不动手)。
|
||
var baseline: int = int(round(float(u.atk) * float(srow.get("damage_mult", 1.0))))
|
||
var rider := 0
|
||
if srow.has("rider_mult"):
|
||
rider = maxi(int(db.settlement.damage_floor), int(floor(float(u.atk) * float(srow.rider_mult))))
|
||
var et := _damage.open_ticket(DamageController.KIND_ENEMY_SKILL, "enemy_action", "%s %s" % [u.display_name, String(srow.display_name)], "combat", \
|
||
baseline, DamageController.TARGET_HERO, ri, Vector2i(-1, -1), "", rider)
|
||
et["source_unit"] = u
|
||
et["context"] = {"skill_id": skill_id, "baseline": baseline}
|
||
_damage.submit(et)
|
||
_damage.flush() # 战斗段界结账(B 模式——段内开单攒批到此统一兑现;A 模式 no-op)
|
||
|
||
|
||
# ---- 算术读数(伤害管线单据化批 2026-09-24 迁移注记)----
|
||
# 掷点/折扣/克制点数/池乘区/攻击行文本已全部迁入 伤害控制器(damage_controller.gd 管线单点);
|
||
# 本类仅保留两处薄委托——_defender_ac(快照面消费)/ _clamped_pool(冒烟白盒断言直呼面 smoke_all 沿用)。
|
||
|
||
# 防守方护甲等级读数——实现归 伤害控制器 defender_ac(本委托供结算快照/呈现快照)
|
||
func _defender_ac(unit: Dictionary) -> int:
|
||
return _damage.defender_ac(unit)
|
||
|
||
|
||
# 池内加算 → clamp——实现归 伤害控制器 clamped_pool(本委托供冒烟白盒断言 smoke_all 直呼兼容)
|
||
func _clamped_pool(pool: String) -> int:
|
||
return _damage.clamped_pool(pool)
|
||
|
||
|
||
func _pool_effective(effect_id: String) -> int:
|
||
var side := "hero"
|
||
var row: Dictionary = db.status_effect_row(effect_id)
|
||
if not row.is_empty():
|
||
side = String(row.target_side)
|
||
for eff in _status_effects.query_active(side):
|
||
if eff.effect_id == effect_id:
|
||
return eff.effective_value
|
||
return 0
|
||
|
||
|
||
func _emit_composition_effects(side: String, ri: int) -> void:
|
||
for eff in _status_effects.query_active(side):
|
||
if eff.round_index < ri:
|
||
# 续存实例(前轮授予)——每结算兑付一次的可见面(合并实例只持首授归因——增益状态 义务⑦)
|
||
_emit_row("effect", eff.source_class, eff.origin_cell, ri, eff.display_name, eff.snap_magnitude, {"effect_id": eff.effect_id, "pool_value": eff.effective_value})
|
||
|
||
|
||
# ---- 结算快照(playtest 数值分析数据面——每次结算全量状态;运行时零决策读取)----
|
||
|
||
func _emit_settlement_snapshot(verdict: String) -> void:
|
||
var enemies: Array = []
|
||
for u in _enemy_system.query_alive("enemy"):
|
||
enemies.append({"id": String(u.enemy_id), "hp": int(u.hp), "max_hp": int(u.max_hp), "atk": int(u.atk), "pending_skill": _enemy_system.pending_action(u), "armor": String(u.get("armor_type", "light")), "armor_class": int(u.get("armor_class", 0))})
|
||
var buffs: Array = []
|
||
for eff in _status_effects.query_active("hero"):
|
||
buffs.append({"id": eff.effect_id, "side": "hero", "layers": eff.layers, "left": eff.remaining_settlements})
|
||
for eff in _status_effects.query_active("enemy"):
|
||
buffs.append({"id": eff.effect_id, "side": "enemy", "layers": eff.layers, "left": eff.remaining_settlements})
|
||
var mines_hit := 0
|
||
var safe_n := 0
|
||
for evt in _facts_reveals:
|
||
if evt.kind == "mine":
|
||
mines_hit += 1
|
||
elif evt.kind == "safe":
|
||
safe_n += 1
|
||
var board_stats := {"seq": _board_seq}
|
||
if minesweeper.current_board() != null:
|
||
board_stats["w"] = minesweeper.current_board().width
|
||
board_stats["h"] = minesweeper.current_board().height
|
||
board_stats["revealed"] = minesweeper.revealed_cells().size()
|
||
board_stats["flags"] = minesweeper.flag_count()
|
||
settlement_snapshot.emit({
|
||
"kind": "settlement",
|
||
"level": int(encounter.get("level_index", 0)),
|
||
"depth": int(encounter.get("node_depth", 0)),
|
||
"round": round_index,
|
||
"verdict": verdict,
|
||
"unit_count": enemies.size(),
|
||
"spawn_count": _enemy_system.all_enemies().size(), # 本战斗实例化总数(含死亡残位)——unit_count=0 时区分「首轮全灭」vs「空场」(playtest-2026-09-12 报告 Bug#1 误读教训)
|
||
"hero": {"hp": int(_enemy_system.hero_unit().get("hp", 0)), "max_hp": int(_enemy_system.hero_unit().get("max_hp", 0)), "atk": int(_enemy_system.hero_unit().get("atk", 0)), "armor_class": _defender_ac(_enemy_system.hero_unit())},
|
||
"economy": {"phase": String(action_economy.phase), "ap": int(action_economy.ap), "rap": int(action_economy.rap), "refresh_used": _refresh_used_this_round},
|
||
"board": board_stats,
|
||
"enemies": enemies,
|
||
"buffs": buffs,
|
||
"round_facts": {"path": _facts_path, "safe": safe_n, "mines": mines_hit, "flag_events": _facts_flags.size(), },
|
||
})
|
||
|
||
|
||
# ---- 出口分发与战斗结束序列 ----
|
||
|
||
func _exit_distribution() -> void:
|
||
var mode := "same_board"
|
||
if _facts_path == "cleared":
|
||
mode = "new_board" # cleared 轮恒走 new_board(契约义务);非清图轮恒同图(等待期刷新通道已移除)
|
||
if mode == "new_board":
|
||
_reward_economy.retire_mapping()
|
||
minesweeper.retire_board()
|
||
if not _install_new_board():
|
||
_fatal("换图编排失败")
|
||
return
|
||
action_economy.notify_settlement_done(mode)
|
||
action_economy.notify_round_start()
|
||
_reset_round_facts()
|
||
_refresh_used_this_round = 0
|
||
round_index += 1
|
||
_roll_round_actions() # 开轮摇号——每轮恰摇一次(轮内刷新换图不重摇:refresh 不走本通道)
|
||
round_started.emit(round_index)
|
||
|
||
|
||
# 呈现层查询面(HUD 刷新按钮可用性)——挖掘期唯一通道
|
||
func can_refresh() -> bool:
|
||
return battle_result == "" \
|
||
and _refresh_used_this_round < int(db.action_economy.refresh_cap_per_round) \
|
||
and action_economy.phase == action_economy.PHASE_ACTIVE \
|
||
and action_economy.rap >= int(db.action_economy.rap_refresh_cost)
|
||
|
||
|
||
# 玩家经 HUD框架发起、战斗结算 代理调用(禁止 RAP 满自动刷)。
|
||
# 挖掘期唯一通道(2026-09-12 方案 A 拍板 + 2026-09-15 等待期通道整体移除):Active 相位立即换图
|
||
# 继续挖(RAP -8;AP 保留、相位不动、不触发结算);非挖掘期请求一律拒绝——非清图轮恒同图。
|
||
func player_request_refresh() -> bool:
|
||
if not can_refresh():
|
||
return false
|
||
if not action_economy.request_refresh():
|
||
return false
|
||
_refresh_used_this_round += 1
|
||
_reward_economy.retire_mapping() # 旧图批次退役(地图战斗资源 Ready→retired;E6 新批重置前提)
|
||
minesweeper.retire_board(true) # 旧板退役(轮内通道)
|
||
return _install_new_board(true) # 当场换图——失败即编排违例 fail-fast
|
||
|
||
|
||
func _battle_over(result: String) -> void:
|
||
battle_result = result
|
||
# 映射随战斗结束退役(地图战斗资源 义务④——下一场战斗 = 新板新 scope 批,roll_board 相位守卫的前提)
|
||
var hero_hp_left := int(_enemy_system.hero_unit().get("hp", 0)) # despawn 前捕获(信号载荷供呈现层"HP 带入下一层")
|
||
var gp_dropped := _roll_gp_drop() # 战斗掉落(GP+商店房实施批——escrow 随此值上抛即弃)
|
||
_reward_economy.retire_mapping()
|
||
_enemy_system.despawn_all()
|
||
_status_effects.notify_battle_end()
|
||
action_economy.notify_combat_end() # → Idle,RAP 清零
|
||
db.set_reload_gate(false)
|
||
_reset_round_facts()
|
||
battle_finished.emit({"result": result, "hero_hp": hero_hp_left, "gp_dropped": gp_dropped})
|
||
|
||
|
||
# 战斗掉落掷定(GP+商店房实施批 2026-09-21):tier = Boss 节点 ? "boss" : "normal"(elite 留分支位);
|
||
# gp_dropped = gp_drop 封闭流掷定(tier 行的 roll_min..roll_max 均匀整数——每战斗末恰一 scope)
|
||
# + level_gp_bonus(level_index) + escrow。掷定行缺位 = 数据面缺行(fail 报错按 0 兑付——不哑掉)。
|
||
func _roll_gp_drop() -> int:
|
||
var tier := "boss" if String(encounter.get("node_type", "")) == "boss" else "normal"
|
||
var drops: Dictionary = db.shop_gp_drop_row(tier)
|
||
var roll := 0
|
||
if drops.is_empty():
|
||
push_error("[战斗结算] gp_drops 缺行 tier=%s——掉落掷定按 0 兑付" % tier)
|
||
else:
|
||
var stream: RandomNumberGenerator = rng.open_stream("gp_drop")
|
||
roll = stream.randi_range(int(drops.get("roll_min", 0)), int(drops.get("roll_max", 0)))
|
||
return roll + db.shop_level_gp_bonus(int(encounter.get("level_index", 0))) + escrow
|
||
|
||
|
||
# ---- 呈现状态面(E1 封装收口 2026-09-13):呈现层 / headless 自动玩家的唯一读取出口——
|
||
# 协作对象(_enemy_system/_status_effects/_reward_economy)私有化后,跨层读取一律经本快照或下列命名面(diagnostic_snapshot 同款模式,
|
||
# 禁再链式穿透 settlement.enemy_system.hero 一类路径)。载荷 schema 成文(code-conventions 2.1):
|
||
# round / battle_result / phase / ap / rap / can_refresh / hero{hp,max_hp,atk,alive,armor_class} /
|
||
# enemies[{order,display_name,hp,max_hp,enemy_id,armor_type,armor_class,pending_skill,pending_type,pending_name,effects[],alive}] /
|
||
# (敌人技能池批批 2 定稿:beat/ring_size/ring_index 拆除 → pending_* 三字段 + 敌方增益 effects 投影;池与权重不公开;
|
||
# 八型批 2026-09-20:ambush_layers 拆除——伏击退役,警觉并入 effects 投影)hero_effects[](增益状态 query_active 投影)
|
||
func presentation_snapshot() -> Dictionary:
|
||
var enemies: Array = []
|
||
var all: Array = _enemy_system.all_enemies()
|
||
# 敌方增益投影(side-wide 状态——蓄力/硬化/削弱/暴走 percent 行 + 警觉 ac 行,八型批 2026-09-20)
|
||
var enemy_effects: Array = []
|
||
for eff in _status_effects.query_active("enemy"):
|
||
var erow: Dictionary = db.status_effect_row(eff.effect_id)
|
||
if not erow.is_empty() and String(erow.unit) in ["percent", "ac"]:
|
||
enemy_effects.append({"effect_id": eff.effect_id, "display_name": String(eff.display_name), "layers": int(eff.layers)})
|
||
for i in all.size():
|
||
var u: Dictionary = all[i]
|
||
var alive: bool = bool(u.get("alive", false))
|
||
var pending: String = String(u.get("pending_skill", "")) if alive else ""
|
||
var pending_row: Dictionary = db.skill_row(pending)
|
||
enemies.append({
|
||
"order": i + 1,
|
||
"display_name": String(u.display_name),
|
||
"hp": int(u.hp), "max_hp": int(u.max_hp),
|
||
"enemy_id": String(u.enemy_id),
|
||
"armor_type": String(u.get("armor_type", "light")),
|
||
"armor_class": int(u.get("armor_class", 0)),
|
||
# 敌人技能池批(批 2 定稿):摇定动作三字段——普通攻击零表示 / 特殊技类型级动画占位。
|
||
# 池与权重不公开(proposal D4/D5)——实例池的权重/冷却不投影,实例池可见面 = 摇定结果本身。
|
||
"pending_skill": pending,
|
||
"pending_type": String(pending_row.get("type", "")) if not pending_row.is_empty() else "",
|
||
"pending_name": String(pending_row.get("display_name", "")) if not pending_row.is_empty() else "",
|
||
"effects": enemy_effects,
|
||
"alive": alive,
|
||
})
|
||
var hero := {}
|
||
var h: Dictionary = _enemy_system.hero_unit()
|
||
if not h.is_empty():
|
||
hero = {"hp": int(h.hp), "max_hp": int(h.max_hp), "atk": int(h.atk), "alive": bool(h.get("alive", false)), "armor_class": _defender_ac(h)}
|
||
return {
|
||
"round": round_index,
|
||
"battle_result": battle_result,
|
||
"phase": String(action_economy.phase),
|
||
"ap": int(action_economy.ap), "rap": int(action_economy.rap),
|
||
"can_refresh": can_refresh(),
|
||
"hero": hero,
|
||
"enemies": enemies,
|
||
"hero_effects": _status_effects.query_active("hero"),
|
||
}
|
||
|
||
|
||
# 战斗进行中谓词(hero 在场且存活)——组合根高频相位判断的低成本面
|
||
func is_battle_live() -> bool:
|
||
return battle_result == "" and not _enemy_system.hero_unit().is_empty()
|
||
|
||
|
||
# 奖励身份解析(组合根注入 BoardView 徽章回调的只读代理——Ready 相位守卫归 地图战斗资源)
|
||
func query_reward_identity(cell: Vector2i):
|
||
return _reward_economy.query_identity(cell)
|
||
|
||
|
||
# 诊断观测面(组合根诊断转储 / 行为探针消费):私有编排状态的成文只读出口——
|
||
# 消费方禁止再直读本类下划线字段(code-review 2026-09-12 封装收口批)
|
||
func diagnostic_snapshot() -> Dictionary: return {
|
||
"battle_result": battle_result,
|
||
"round": round_index,
|
||
"settling": _settling,
|
||
"refresh_used_round": _refresh_used_this_round,
|
||
"board_seq": _board_seq,
|
||
"facts_path": _facts_path,
|
||
"facts_reveals": _facts_reveals.size(),
|
||
"facts_flags": _facts_flags.size(),
|
||
"action_economy": {"phase": String(action_economy.phase), "ap": action_economy.ap, "rap": action_economy.rap},
|
||
"minesweeper_board_installed": minesweeper.current_board() != null,
|
||
"minesweeper_revealed": minesweeper.revealed_cells().size() if minesweeper.current_board() != null else 0,
|
||
"minesweeper_flags": minesweeper.flag_count() if minesweeper.current_board() != null else 0,
|
||
"reward_economy_phase": _reward_economy.phase(),
|
||
"enemies_alive": _enemy_system.query_alive("enemy").size(),
|
||
"hero_hp": int(_enemy_system.hero_unit().get("hp", -1)) if not _enemy_system.hero_unit().is_empty() else -1,
|
||
}
|
||
|
||
|
||
func _reset_round_facts() -> void:
|
||
_facts_reveals.clear()
|
||
_facts_flags.clear()
|
||
_facts_path = ""
|
||
|
||
|
||
# ---- 行协议(Core Rule:公共字段 + 行类型特有字段)----
|
||
|
||
func _emit_row(type: String, source_class: String, origin_cell: Vector2i, ri: int, display: String, value: int, extra: Dictionary, highlight: String = "") -> void:
|
||
_assert_row_source(type, source_class, origin_cell)
|
||
var row := {
|
||
"type": type,
|
||
"source_class": source_class,
|
||
"origin_cell": [origin_cell.x, origin_cell.y],
|
||
"round_index": ri,
|
||
"display_name": display,
|
||
"value": value,
|
||
}
|
||
if highlight != "":
|
||
row["highlight"] = highlight
|
||
for k in extra.keys():
|
||
row[k] = extra[k]
|
||
step_row.emit(row)
|
||
|
||
|
||
# 行来源断言(战斗结算 明细流水:"任何一行找不到来源即断言失败——宁可报错"):
|
||
# 来源字段 = source_class(公共字段)+ origin_cell(棋盘来源行的真实格)。
|
||
# 豁免按两层成文(见 SOURCE_EXEMPT_TYPES / SOURCE_EXEMPT_CLASSES 常量注释),其余行必须带真实棋盘格。
|
||
func _assert_row_source(type: String, source_class: String, origin_cell: Vector2i) -> void:
|
||
if SOURCE_EXEMPT_TYPES.has(type):
|
||
return
|
||
assert(source_class != "", "[战斗结算] 明细行缺来源类别(type=%s)——任何一行找不到来源即断言失败" % type)
|
||
if SOURCE_EXEMPT_CLASSES.has(source_class):
|
||
return
|
||
assert(origin_cell.x >= 0 and origin_cell.y >= 0,
|
||
"[战斗结算] 明细行来源格越界(type=%s source=%s cell=%s)——棋盘来源行必须指回真实格" % [type, source_class, str(origin_cell)])
|
||
|
||
|
||
func _fatal(msg: String) -> void:
|
||
push_error("[战斗结算/fatal] " + msg)
|
||
assert(false, msg)
|