5.8 KiB
5.8 KiB
M4 Module Progression SpacetimeDB 基座记录(2026-04-21)
更新时间:2026-04-21
0. 文档目标
本文件只记录一件事:
把 module-progression 从“只有 README 占位”推进到“SpacetimeDB 侧已有最小可编译成长真相基座”的真实落地结果。
本轮先落等级/经验/章节计划与记账的最小领域骨架,并补上任务交付与战斗胜利的自动联动;不扩到完整 custom-world 章节蓝图编译或 Axum facade 全链迁移。
1. 本轮落地范围
本轮按 LEVEL_PROGRESS_AND_CHAPTER_NPC_AUTO_SCALING_DESIGN_2026-04-20.md 与 SPACETIMEDB_AXUM_OSS_BACKEND_REWRITE_DESIGN_2026-04-20.md 的交叉口径,只落实下面 6 件事:
- 新增
server-rs/crates/module-progression/真实 crate,而不是继续停留在 README 占位。 - 在
module-progression中冻结LevelBenchmark、PlayerProgressionSnapshot、ChapterProgressionSnapshot、RuntimeEntityLevelProfile的首版领域类型。 - 在
module-progression中落地与当前 Node 版一致的等级经验曲线、参考强度曲线、章节 pseudo level 曲线与敌对战斗 fallback 规则。 - 在
server-rs/crates/spacetime-module/中新增player_progression、chapter_progression两张表。 - 在
spacetime-module中新增get_player_progression_or_default、grant_player_progression_experience、upsert_chapter_progression、apply_chapter_progression_ledger_entry及对应 procedure。 - 用
module-story / module-quest同口径方式,把成长状态固定成“单用户成长表 + 单章节计划/记账表”的最小可编译基座。
2. 本轮新增的真实工程落点
2.1 新增 crate
server-rs/crates/module-progression/Cargo.tomlserver-rs/crates/module-progression/src/lib.rs
2.2 workspace 与主工程聚合
server-rs/Cargo.toml- 已把
crates/module-progression纳入 workspace members
- 已把
server-rs/crates/spacetime-module/Cargo.toml- 已接入
module-progression依赖
- 已接入
server-rs/crates/spacetime-module/src/lib.rs- 已接入
module-progression类型 - 已新增
player_progression - 已新增
chapter_progression - 已新增成长相关 reducer / procedure
- 已接入
3. 当前冻结的数据口径
3.1 player_progression
当前首版字段冻结为:
user_idlevelcurrent_level_xptotal_xpxp_to_next_levelpending_level_upslast_granted_sourcecreated_atupdated_at
当前策略:
player_progression保持 private 真相表口径。- 当前统一按
user_id单行持久化,不在本轮拆历史 grant 日志表。 - 若记录不存在,
procedure返回Lv.1 / 0 XP默认快照,但不额外写库。
3.2 chapter_progression
当前首版字段冻结为:
chapter_progression_iduser_idchapter_idchapter_indextotal_chaptersentry_pseudo_level_millisexit_pseudo_level_millisentry_levelexit_levelplanned_total_xpplanned_quest_xpplanned_hostile_xpactual_quest_xpactual_hostile_xpexpected_hostile_defeat_countactual_hostile_defeat_countlevel_at_entrylevel_at_exitpace_bandcreated_atupdated_at
当前策略:
chapter_progression先用一张表同时承接ChapterProgressionPlan与ChapterExperienceLedger。- 当前不再额外拆计划表和记账表,避免首轮 schema 还没稳定就二次改表。
- 主键固定为
user_id + chapter_id组合衍生 ID,保证同一玩家每章只有一条真相记录。
4. 当前 reducer / procedure 口径
4.1 get_player_progression_or_default
当前负责:
- 按
user_id读取player_progression - 若不存在则返回默认
Lv.1 / 0 XP - 不产生额外写入
4.2 grant_player_progression_experience
当前负责:
- 读取当前
player_progression,不存在则按默认成长态开始 - 根据
PlayerProgressionGrantInput发放经验 - 统一更新
level / current_level_xp / total_xp / xp_to_next_level / pending_level_ups - 固定
last_granted_source
4.3 upsert_chapter_progression
当前负责:
- 写入或覆盖某玩家某章节的计划快照
- 固定章节预算、目标等级带与预期击杀数
- 把实际记账字段初始化为
0
4.4 apply_chapter_progression_ledger_entry
当前负责:
- 在已存在的章节计划上累计
actual_quest_xp - 累计
actual_hostile_xp - 累计
actual_hostile_defeat_count - 可选更新
level_at_exit
5. 当前刻意未做
本轮明确没有扩到以下范围:
- 还没有把
sceneChapterBlueprints的完整编译逻辑迁到 Rust。 - 还没有落
repeatPenalty、超预算衰减与章节偏差评级输出。 - 还没有把完整章节蓝图、掉落和全量 quest signal 都自动串进
player_progression / chapter_progression。 - 还没有新增 Axum 的 progression facade。
- 还没有把前端
Lv.展示、任务奖励经验提示或敌对等级徽标切到 Rust 后端真相源。
也就是说,本轮只是把 module-progression 的 SpacetimeDB 成长基座立起来,不宣称已经完成成长系统迁移。
6. 验证要求
本轮工程变更完成后,至少执行下面两类验证:
npm run check:encodingcargo test -p module-progressioncargo check -p spacetime-module
7. 下一步建议
按当前节奏,后续应继续按下面顺序推进:
- 先把章节预算编译从 Node
chapterProgressionPlanner平移到 Rust 领域层。 - 再把
npc/combat入口改为消费RuntimeEntityLevelProfile和chapter_progression。 - 再把掉落、任务物品、好感奖励并入统一奖励结算。
- 最后再接 Axum facade、兼容 DTO 与前端成长主链。