把「内容的效果行为」从结算代码硬编码分支搬进数据行的第一步:通用解释器 EffectEngine 落地。 本提交=框架与埋点,双轨过渡期——发射点仅观测命中、施加面仍走旧消费点,行为与迁移前逐位一致 (冒烟 783 项 0 失败实证、单元 17 套全绿)。 新增 game/core/effect_engine.gd: - 事件词汇 16 个(任务书 §3.1 定稿)+扫雷侧事件集(流派扫雷触发铁律新形态) - 效果类型词汇 24 型(任务书 §3.3 定稿 19 行;标题计 23 系笔误按行内容全收,代拍板留痕) - fact 条件词汇 9 项+when 算子词汇封闭(mod_zero/advantageous/gte_ref/lt_ref/ends_with 系现状条件装进 9 项 fact 的查询面落法——代拍板白名单覆盖:掘进蓄能取模、淬毒克制正面、 深挖配额计数器比较、对某甲族泛条件) - 订阅装载 rebuild(每战 begin_battle 重建——中途获得下一战生效,同战内不热载; 装载序=feats 表序→treasure 表序→树规则合成行,写死保种子复放) - 计数器账本(counter_add/counter_spend/reset_at=round_start 重置点声明) - 组合规则六族(加法/乘法/任意真/按序改写/按序消耗/即时执行——发射点施加面引用) 16 发射点埋点(订阅空=零循环零扰动): - 战斗编排器:dig_reveal/mine_hit/flag_hit/flag_settle/round_end/enemy_hp_threshold/ treasure_used/damage_taken(kind=terrain)/round_start×2 - 伤害控制器:attack_commit(hero_attack 单算术前)/clamp_check×2(主角攻击+棋盘克制面)/ armor_roll/kill/damage_taken(kind=enemy_skill) - 行动经济:dig_paid(对价闸前)/charge_full(转蓄力满层沿——R6 框架先行,现无订阅者) - 地图战斗资源:reward_roll(摇号前权重合成层) 行为等价细节(本批预演、T3 落地): - 停手转存改记账制:request_stop 记剩余 AP 后清零,转存决策移至 round_end 发射点 finish_round_stop(grant_ap(mode:transfer) 订阅定夺;双轨期旧旗并行,缺省 RAP 转存不变) - attack_commit 发射点=管线算术前(载荷含 matchup/dig_streak/nest_count——连珠矢/执拗/ 猎巢人/淬毒订阅事实源) 设计权威:design/research/研究-内容数据驱动扩展架构-2026-10-06.md(案乙)。 任务书:design/research/任务书-内容数据驱动扩展批-2026-10-06.md §六 T1。
263 lines
11 KiB
GDScript
263 lines
11 KiB
GDScript
# VERTICAL SLICE - NOT FOR PRODUCTION
|
||
# Validation Question: 玩家能否无指导在一场完整战斗中经历「开战→挖掘规划→轮末结算逐行兑现→胜/负」并逐行归因(P2)
|
||
# Date: 2026-09-10
|
||
# 行动经济:被动账本(AP 硬重置 / 统一价目 / 三路径结束仲裁 cleared > stopped > ap_exhausted /
|
||
# RAP 池战斗域 / 双发射源之 stopped 直发)。相位域 = {Idle, Active, Waiting}。
|
||
# 实现 GDD:design/archive/gdd-2026-09-14/a3-action-economy.md(系统 ID A3·行动经济——registry 追溯锚,命名规范见 CLAUDE.md)
|
||
class_name ActionEconomy
|
||
extends RefCounted
|
||
|
||
signal round_end_stopped(payload: Dictionary) # 双发射源之停手路径(行动经济 直发;payload 与 排雷玩法 棋盘路径同构)
|
||
|
||
const PHASE_IDLE := "Idle"
|
||
const PHASE_ACTIVE := "Active"
|
||
const PHASE_WAITING := "Waiting"
|
||
|
||
# 相位轴(P6 状态机——code-review 2026-09-29 P2-2):内部 enum + match,外部 phase getter 保持
|
||
# String 面(presentation_snapshot 与冒烟链的 "Idle"/"Active"/"Waiting" 对照契约零变化)。
|
||
enum Phase { IDLE, ACTIVE, WAITING }
|
||
|
||
var db: ConfigDb
|
||
# 相位与账本只读出口(E5 封装收口 2026-09-13):外部读取经 getter-only 属性(架构文档
|
||
# "ap/rap/phase 只读" 的机制化),写入只经 notify_* / request_* 方法通道。
|
||
var _phase: int = Phase.IDLE
|
||
var phase: String:
|
||
get: return _phase_text(_phase)
|
||
var _ap := 0
|
||
var ap: int:
|
||
get: return _ap
|
||
var _rap := 0
|
||
var rap: int:
|
||
get: return _rap
|
||
var _last_round_end: Dictionary[String, String] = {} # {path_tag, continuation_hint}——排雷玩法 组包 round_end 的合法数据源
|
||
var last_round_end: Dictionary:
|
||
get: return _last_round_end
|
||
var _settlement_consumed := false # AC-14 门:notify_settlement_done 消费后才受理 round_start
|
||
var _next_round_mode := "" # 调试观测量(同板续轮 / 换新图)
|
||
var _pending_ap_delta := 0 # 下轮行动点修正排队(格面资源八型批 2026-09-20——action 型 ±1 排队,轮开始兑现后清零)
|
||
# 蓄力流运行态(迭代 12 T5——relic 件注入面;false=关着零扰动):
|
||
# feat_ap_carry=整备军备(轮末剩余 AP 转蓄力层替代 RAP 转存——cleared 作废口径改写的停手侧承载);
|
||
# feat_dig_extra=深挖钻头付费开掘对价(R4 甲非信息税形态;2026-10-04 试玩缺陷修复——对价挂付费
|
||
# 开掘侧:AP 富余时挖掘付全价 1+extra 积付费计数、AP 不足时降级只付基础 1 照常开格不积计数——
|
||
# 原「持有期所有挖掘无条件 +1」实现把对价错挂成普通挖掘税,AP=1 锁死开格);charge_layers=蓄力层账本。
|
||
var feat_ap_carry := false
|
||
var feat_dig_extra := 0
|
||
var _charge_layers := 0
|
||
var charge_layers: int:
|
||
get: return _charge_layers
|
||
var _deep_paid_count := 0
|
||
var deep_paid_count: int:
|
||
get: return _deep_paid_count
|
||
# 效果引擎(内容数据驱动扩展批 T1——dig_paid/charge_full 发射面;round_end 转存决策面)
|
||
var _fx: EffectEngine = null
|
||
var _last_stop_ap := 0 # 停手侧剩余 AP 记账(转存决策移至 round_end 发射点——grant_ap(transfer) 订阅定夺)
|
||
|
||
|
||
func set_fx(fx: EffectEngine) -> void:
|
||
_fx = fx
|
||
|
||
|
||
func _init(db_ref: ConfigDb) -> void:
|
||
db = db_ref
|
||
|
||
|
||
func _phase_text(p: int) -> String:
|
||
match p:
|
||
Phase.ACTIVE:
|
||
return PHASE_ACTIVE
|
||
Phase.WAITING:
|
||
return PHASE_WAITING
|
||
return PHASE_IDLE
|
||
|
||
|
||
func _cost(kind: String) -> int:
|
||
var ae = db.action_economy
|
||
match kind:
|
||
"dig":
|
||
return ae.dig_ap_cost # 基础挖格成本恒表值(钻头对价挂付费开掘侧——2026-10-04 缺陷修复)
|
||
"flag_place":
|
||
return ae.flag_place_ap_cost
|
||
"move":
|
||
return ae.move_ap_cost
|
||
"chain":
|
||
return ae.chain_ap_cost
|
||
assert(false, "未知动作价目: " + kind)
|
||
return 0
|
||
|
||
|
||
# 通用扣减(排雷玩法 用于旗动作;挖握走 request_dig——cleared 仲裁需要 clears_map 参数)
|
||
func try_spend(action_kind: String) -> bool:
|
||
if _phase != Phase.ACTIVE:
|
||
_reject("phase")
|
||
return false
|
||
return _spend_and_arbitrate(action_kind, false)
|
||
|
||
|
||
# 排雷玩法 挖掘专用:chain_size = 连锁附加格数(不含首格);clears_map = 本次动作后全图安全格开完。
|
||
# 深挖钻头付费开掘(2026-10-04 缺陷修复——对价挂付费侧):AP 富余(≥基础+extra)时本动作付全价
|
||
# 并积付费开掘计数(orchestrator 深层产出配额取数面);AP 不足全价时**降级只付基础 1 照常开格**、
|
||
# 不积计数——持有钻头永不锁死普通挖格(散件保底 B-2)。
|
||
func request_dig(chain_size: int, clears_map: bool) -> bool:
|
||
if _phase != Phase.ACTIVE:
|
||
_reject("phase")
|
||
return false
|
||
var cost := _cost("dig")
|
||
if feat_dig_extra > 0 and _ap >= cost + feat_dig_extra:
|
||
cost += feat_dig_extra
|
||
_deep_paid_count += 1
|
||
# dig_paid 发射点(内容数据驱动扩展批 T1——付费开掘发起、动作经济闸收对价前;
|
||
# 深挖钻头 counter_spend 对价订阅面。双轨期对价仍走 feat_dig_extra 旧面)
|
||
if _fx != null:
|
||
_fx.dispatch("dig_paid", {"ap_cost": cost, "ap_surplus": _ap - cost})
|
||
if _ap < cost:
|
||
_reject("resource_face")
|
||
return false
|
||
return _spend_cost_and_arbitrate(cost, clears_map)
|
||
|
||
|
||
func _spend_cost_and_arbitrate(cost: int, clears_map: bool) -> bool:
|
||
if _ap < cost:
|
||
_reject("resource_face")
|
||
return false
|
||
_ap -= cost
|
||
if clears_map:
|
||
# cleared 胜出(同帧仲裁 cleared > ap_exhausted);剩余 AP 当场清零作废、不进 RAP(EC7/EC10)
|
||
_ap = 0
|
||
_finish_round("cleared", "new_board")
|
||
elif _ap == 0:
|
||
# AP 归 0 瞬间轮次结束——不存在 0-AP 操作窗口
|
||
_finish_round("ap_exhausted", "same_board")
|
||
return true
|
||
|
||
|
||
func _spend_and_arbitrate(action_kind: String, clears_map: bool) -> bool:
|
||
var cost := _cost(action_kind)
|
||
if _ap < cost:
|
||
_reject("resource_face")
|
||
return false
|
||
_ap -= cost
|
||
if clears_map:
|
||
# cleared 胜出(同帧仲裁 cleared > ap_exhausted);剩余 AP 当场清零作废、不进 RAP(EC7/EC10)
|
||
_ap = 0
|
||
_finish_round("cleared", "new_board")
|
||
elif _ap == 0:
|
||
# AP 归 0 瞬间轮次结束——不存在 0-AP 操作窗口
|
||
_finish_round("ap_exhausted", "same_board")
|
||
return true
|
||
|
||
|
||
# 停手:剩余 AP 1:1 转存 RAP;行动经济 直发 stopped 路径 round_end(双发射源)。
|
||
# 整备军备改写(迭代 12 T5——feat_ap_carry=true 时剩余 AP 转蓄力层〔上限 3〕替代 RAP 转存:
|
||
# 「不动也是行动」——cleared 作废口径改写的停手侧承载;cleared 分支 AP 恒清零维持既有作废语义)。
|
||
# 内容数据驱动扩展批 T1:本方法改记账制——剩余 AP 存 _last_stop_ap 后清零,转存决策移至
|
||
# round_end 发射点 finish_round_stop(grant_ap(mode:transfer) 订阅定夺;双轨期旧旗 feat_ap_carry
|
||
# 并行生效,行为与迁移前逐位一致)。
|
||
func request_stop() -> bool:
|
||
if _phase != Phase.ACTIVE:
|
||
_reject("phase")
|
||
return false
|
||
_last_stop_ap = _ap
|
||
_ap = 0
|
||
_finish_round("stopped", "same_board")
|
||
round_end_stopped.emit({"path_tag": "stopped", "continuation_hint": "same_board"})
|
||
return true
|
||
|
||
|
||
# 轮末停手转存决策(round_end 发射点调用——编排器授予段尾):transfer=true=剩余 AP 转蓄力层
|
||
# (上限 3,整备军备面);false=1:1 转存 RAP(缺省)。非停手轮(cleared/耗尽)_last_stop_ap=0
|
||
# 两分支均零操作。转蓄后达上限的沿发 charge_full(R6 框架先行——现无订阅者)。
|
||
func finish_round_stop(transfer: bool) -> void:
|
||
if transfer:
|
||
var prev_layers := _charge_layers
|
||
_charge_layers = mini(3, _charge_layers + _last_stop_ap)
|
||
if _fx != null and _charge_layers >= 3 and prev_layers < 3:
|
||
_fx.dispatch("charge_full", {"layers": _charge_layers})
|
||
else:
|
||
_rap += _last_stop_ap
|
||
_last_stop_ap = 0
|
||
|
||
|
||
# 轮内刷新(2026-09-12 方案 A 用户拍板;等待期通道 2026-09-15 用户拍板整体移除):唯一入口 =
|
||
# Active 相位——仅扣 RAP,相位与 AP 均不动。刷新不打断轮次、不触发结算;换图编排归 战斗结算
|
||
# (retire + install 立即执行,玩家同轮继续挖新图)。决策主体 = 玩家(经 HUD框架发起)纪律不变。
|
||
func request_refresh() -> bool:
|
||
if _phase != Phase.ACTIVE:
|
||
_reject("phase")
|
||
return false
|
||
if _rap < db.action_economy.rap_refresh_cost:
|
||
return false # EC13 资源不足拒绝——合法相位内资源拒绝,非编排错误
|
||
_rap -= db.action_economy.rap_refresh_cost
|
||
return true
|
||
|
||
|
||
# 战斗结算 回发:结算完成(仅记录编排意图;phase 停留 Waiting——AC-14 门不被绕过)
|
||
func notify_settlement_done(next_round_mode: String) -> bool:
|
||
if _phase != Phase.WAITING:
|
||
_reject("phase")
|
||
return false
|
||
_settlement_consumed = true
|
||
_next_round_mode = next_round_mode
|
||
return true
|
||
|
||
|
||
# 下轮行动点修正排队(格面资源八型批 2026-09-20):action 型正负行结算期调用,同轮多次授予累加;
|
||
# 相位无关(授予发生在结算段,此时本类可能处于 ACTIVE/WAITING 任一相位)
|
||
# 第 9 API(registry 行动经济×① 接口漂移预授权——迭代 7 T2 秘宝内容批落位):ap_grant 道具的
|
||
# 当轮行动点加量(GDD「加行动点效果给当轮」——区别于 queue_ap_delta 的下轮排队语义)。Active 受理、
|
||
# 无上限域、零随机;使用道具本身零扣费(成本在获取时已付——捡道具格不出战斗奖励)。
|
||
func grant_ap(amount: int) -> bool:
|
||
if amount <= 0 or _phase != Phase.ACTIVE:
|
||
_reject("grant_ap")
|
||
return false
|
||
_ap += amount
|
||
return true
|
||
|
||
|
||
func queue_ap_delta(delta: int) -> void:
|
||
_pending_ap_delta += delta
|
||
|
||
|
||
func pending_ap_delta() -> int:
|
||
return _pending_ap_delta
|
||
|
||
|
||
func notify_round_start() -> bool:
|
||
if _phase == Phase.IDLE:
|
||
pass # 战斗首轮唯一出口
|
||
elif _phase == Phase.WAITING and _settlement_consumed:
|
||
pass
|
||
else:
|
||
_reject("phase")
|
||
return false
|
||
_ap = maxi(0, db.action_economy.ap_per_round + _pending_ap_delta) # 每轮基线 + 排队修正(下限 0)
|
||
_pending_ap_delta = 0
|
||
_phase = Phase.ACTIVE
|
||
_settlement_consumed = false
|
||
return true
|
||
|
||
|
||
func notify_combat_end() -> bool:
|
||
if _phase != Phase.WAITING:
|
||
_reject("phase")
|
||
return false
|
||
_phase = Phase.IDLE
|
||
_rap = 0 # RAP 战斗域清零(用户拍板;HUD框架可见反馈义务)
|
||
_ap = 0
|
||
return true
|
||
|
||
|
||
func _finish_round(path_tag: String, continuation_hint: String) -> void:
|
||
# 实现层断言兜底(行动经济 轮次结束仲裁表):耗尽轮剩余恒为 0;清图轮剩余已当场清零(不进储备池)。
|
||
# 两断言守在唯一仲裁出口,未来若在扣费与仲裁之间挪动 AP 写入在此红灯。
|
||
assert(path_tag != "ap_exhausted" or _ap == 0, "耗尽轮剩余行动点恒为 0(实现层断言兜底)")
|
||
assert(path_tag != "cleared" or _ap == 0, "清图轮剩余行动点当场清零(不进储备池)")
|
||
_last_round_end = {"path_tag": path_tag, "continuation_hint": continuation_hint}
|
||
_phase = Phase.WAITING
|
||
|
||
|
||
func _reject(source: String) -> void:
|
||
if source == "phase":
|
||
push_warning("[行动经济] 动作被拒(%s 相位守卫/资源)" % source)
|
||
else:
|
||
push_warning("[行动经济] 资源不足拒绝")
|