Files
gplan-2/game/core/run_ledger.gd
T

52 lines
2.5 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
class_name RunLedger
extends RefCounted
# 共享四本账显式承载(审计 P1-4「共享可变字典跨三层:所有权名义单点、实际三处
# 可写」收口 = 单类持四账)。
# 所有权:AdventureRunner 持有(开局构造、冒险全程唯一宿主);LevelRunner 经 set_run_ledger
# 下传并装配 encounter;战斗侧(BattleOrchestrator)经 encounter["ledger"] 拿本类引用,
# 只走下方 read/append 原语——战末 export/开局 seed 时点语义不变(确定性设计原样保留,
# 只把「函数签名上不可见的共享可变引用」换成签名可见的显式类)。
var attune_charges: Dictionary[Variant, Variant] = {} # 同调主动件充能账(use_treasure 扣减;断点随局回档)
var vision_counter: Dictionary[Variant, Variant] = {} # 真视类使用计数(冒险开始置 {"used":0};
# 缺省空 = 调试/单场战斗不计——enc 缺键守卫语义)
var adventure_counters: Dictionary[Variant, Variant] = {} # adventure 域效果计数器(rebuild 回灌/战末导出回写目标)
var bonus: Dictionary[Variant, Variant] = {} # 统一冒险加算区(冒险开始置四轴零账——商店购买/三选一属性件/战末 bonus_delta 汇入)
# ---- 战斗侧原语(裁点②甲:战斗侧只拿 read/append 两族;宿主侧冒险/关卡域直读字段域) ----
func attune_charge_has(item_id: String) -> bool:
return attune_charges.has(item_id)
func attune_charge_set(item_id: String, value: int) -> void:
attune_charges[item_id] = value
func attune_charge_consume(item_id: String) -> void:
# 原编排器 use_treasure 扣减语义逐字(has 闸 + maxi(0,·) 下限)
if attune_charges.has(item_id):
attune_charges[item_id] = maxi(0, int(attune_charges[item_id]) - 1)
func vision_count_add(n: int) -> void:
vision_counter["used"] = int(vision_counter.get("used", 0)) + n
func counters_seed_snapshot() -> Dictionary:
return adventure_counters # 回灌读面(时点 = begin_battle rebuild 后——语义不变)
func counters_merge_export(exported: Dictionary) -> void:
# 战末回写(原编排器逐字语义:仅非空账参与、逐键覆写)
if adventure_counters.is_empty():
return
for cid in exported.keys():
adventure_counters[cid] = int(exported[cid])
func bonus_add_axis(axis: String, delta: int) -> void:
# 原编排器战末汇入逐字语义(has 闸——账外轴丢弃)
if bonus.has(axis):
bonus[axis] = int(bonus.get(axis, 0)) + delta