6.4 KiB
Executable File
6.4 KiB
Executable File
Task 7: 角色属性系统(探索力/智慧/勇气/灵感)
Agent: full-stack-developer
完成状态: ✅ 全部完成
创建的文件
/home/z/my-project/src/lib/game/attributes.ts— 属性逻辑层(~330 行)/home/z/my-project/src/components/game/AttributesPanel.tsx— 属性 UI 面板(~330 行)
修改的文件
/home/z/my-project/src/lib/game/types.ts— GameState 新增 attributes/attributeProgress/pendingAttrPoints/home/z/my-project/src/lib/game/config.ts— INITIAL_STATE 补全新字段默认值/home/z/my-project/src/lib/game/engine.ts— recomputeStats 聚合属性加成;performPrestige 发放属性点/home/z/my-project/src/store/gameStore.ts— 新增 allocateAttribute/gainAttributeExp action;pulse/clickNode/autoDecodeTick/resolveCurrentNode/grantCruiseReward/tickTide/init 接入属性逻辑;旧存档兼容/home/z/my-project/src/lib/game/achievements.ts— 新增 2 项属性成就/home/z/my-project/src/app/page.tsx— 新增第 8 个「角色」标签页 + grid-cols-7→8 + 红点提示 + 统计面板新增属性行 + 版本号 v0.6→v0.7
关键实现细节
attributes.ts 逻辑层
- 类型系统:AttributeKey(4 个键)/ CharacterAttributes(0-100 数值)/ AttributeProgressEntry(exp + level)
- 加成公式:
- 0-50 线性区:每点 +0.5% 加成(0..50 → 0..25%)
- 50-100 递减区:每点 +0.2% 加成(50..100 → 25..35%)
- 超过 100 仍按 100 计算加成(软上限)
- getAttributeBonus(attr) 单属性加成百分比
- getAllBonuses(attrs) 返回 12 个修饰器:探险力倍率/巡航速度/解码步数/洞见倍率/自动解码周期/探险生命/BOSS 胜率/巡航护盾/接触率/星潮触发/脉冲连击/产能加成
- levelUpCheck(progress) 自动跨多级升级,安全上限 200 次循环
- expRequiredForLevel(level) = 10 × level(最低 10)
- computePrestigeAttrPoints(ascensions) = ascensions × 2 + 1(飞升前次数计算)
- migrateAttributes(state) 旧存档兼容:补全缺失字段、夹紧越界值、同步 level 与 attributes
engine.ts 改造
- recomputeStats 末尾追加
getAllBonuses(state.attributes ?? {})聚合:crystalsPerSec *= am.crystalsPerSecMultinsightMult += am.insightMultAddcontactRateMult *= am.contactRateMultdecodeStepsBonus += am.decodeStepsBonus
- performPrestige:
- 保留 attributes 数值(跨周目永久)
- 清空 attributeProgress(新周目重新累积经验)
- pendingAttrPoints += computePrestigeAttrPoints(ascensions) = ascensions × 2 + 1
- createInitialState:每次返回全新 attributes/attributeProgress 对象,避免引用共享
gameStore.ts 集成(核心)
- pulse:连击 ≥3 给灵感经验(expGain = 1 + floor(combo/2));脉冲威力乘以灵感连击加成
- clickNode 完成:给智慧经验(expGain = puzzle.tier × 2)
- autoDecodeTick:自动解码也给智慧经验 +1;自动解码周期受智慧 am.autoDecodeIntervalMult 影响
- startExpedition:探险力乘 am.expeditionPowerMult;探险生命加 am.expeditionHpBonus
- resolveCurrentNode:
- BOSS 节点用包装 RNG 提升 +am.bossWinRateBonus 胜率(单次 rng 调用,B% 概率返回 0,其余返回 r-B 保持均匀分布)
- 战斗胜利给勇气+探索力经验(中途战斗 +2/+1,BOSS 击破 +8/+6,探险胜利 +4)
- grantCruiseReward:按总奖励量缩放给探索力+勇气经验(expBase = max(2, totalReward/30))
- tickTide:灵感 am.tideTriggerBonus 缩短星潮间隙(gap × (1 - bonus)),上限 30%
- doPrestige:performPrestige 后用 next.attributes 重算 stats
- allocateAttribute(attr, points=1):分配属性点,同步 attributeProgress[attr].level
- gainAttributeExp(attr, amount):通用经验获取(自动升级)
- init():调用 migrateAttributes 补全旧存档字段,并传 attributes 到 syncStats
- 所有 syncStats 调用点(10+ 处)都补充
attributes: ...参数
AttributesPanel.tsx UI
- 四维属性卡片网格(小屏 2×2,大屏 1×4):
- 图标(Compass/Brain/Swords/Sparkles)+ 中文名 + 英文名 + Lv.{value} badge
- 数值 /100 + 加成百分比
- 经验进度条(gradient + glow)+ "递减区"标记
- 加成影响列表(3 条)
- 「+分配」按钮(pendingAttrPoints > 0 时可点,hover scale 105)
- 顶部:标题 + 待分配点数 badge(pendingAttrPoints > 0 时 echo-pending-pulse 动画)
- 底部:总等级 + 总加成概览 + 12 个修饰器明细行
- 配色:4 色全息(emerald/fuchsia/amber/rose),辉光边框 + 顶角光晕装饰
- 完全响应式(2 列 → 4 列),overflow-y-auto + 自定义 scrollbar
page.tsx 集成
- 新增
User图标导入 - 新增
pendingAttrPointsstore selector - TabsList: grid-cols-7 → grid-cols-8
- 新增第 8 个 TabsTrigger「角色」(value="attributes"),主题色用 emerald→fuchsia→rose 渐变
- pendingAttrPoints > 0 时显示 rose 红点
- 新增 TabsContent 渲染 AttributesPanel
- StatsPanel 新增 5 行属性行(探索力/智慧/勇气/灵感/待分配属性点)
- 版本号 v0.6 → v0.7
achievements.ts 新增
ach_attr_total_50(四维觉醒):四维属性总和 ≥ 50 → 产能+6%/洞见+6%ach_attr_max_100(维度精通):任一属性 ≥ 100 → 产能+12%/洞见+10%
QA 验证结果
- ✅
bun run lint零错误 - ✅ dev 服务器 HTTP 200
- ✅ 编译 < 250ms(177ms 实测)
- ✅ 7 标签页 + 巡航按钮完好保留,新增第 8 个「角色」标签页
- ✅ data-tut 锚点(tab-expedition/tab-tech/prestige-btn/crystal-orb/decode-panel)保留
- ✅ 色彩规范:严格 emerald/fuchsia/amber/rose 四色全息,零蓝色/靛色
- ✅ 旧存档兼容:migrateAttributes 补全 attributes/attributeProgress/pendingAttrPoints 字段
- ✅ 飞升后 pendingAttrPoints = ascensions × 2 + 1(飞升前次数)
- ✅ pulse/clickNode/resolveCurrentNode/grantCruiseReward/autoDecodeTick 均接入属性经验获取
注意事项
- BOSS 胜率 RNG 包装:仅在 boss 节点生效,单次 rng 调用保持均匀分布;+am.bossWinRateBonus 上限 +30%
- 灵感星潮触发:通过缩短 gap 间接提升触发频率(上限 30%)
- 属性加成与现有所有系统(技术树/蓝图/成就/星图/星潮)叠加,不冲突
- migrateAttributes 同步 attributeProgress[attr].level 与 attributes[attr] 数值,避免漂移