refactor(hero): 重构额外属性加成系统,统一为bonus字段

1.  将原ap_bonus/hp_bonus/def_bonus三个字段合并为通用的bonus数组结构
2.  新增多属性同时配置能力,支持hp/ap/def百分比加成与crt/frz/stun/para固定百分点加成
3.  更新所有前端编辑器、服务端渲染与游戏运行时逻辑适配新配置格式
4.  添加数据兼容迁移逻辑,自动处理旧版英雄配置数据
This commit is contained in:
panFD
2026-09-07 23:05:30 +08:00
parent a1c8f46c50
commit ed738d2e30
10 changed files with 180 additions and 94 deletions

View File

@@ -173,12 +173,8 @@
<!-- 额外加成 -->
<div class="panel">
<h3>额外属性加成</h3>
<el-tabs>
<el-tab-pane label="ap_bonus"><BonusEditor :model="current.ap_bonus" /></el-tab-pane>
<el-tab-pane label="hp_bonus"><BonusEditor :model="current.hp_bonus" /></el-tab-pane>
<el-tab-pane label="def_bonus"><BonusEditor :model="current.def_bonus" /></el-tab-pane>
</el-tabs>
<h3>额外属性加成(hp/ap/def 百分比,crt/frz/stun/para 百分点)</h3>
<BonusEditor :model="current.bonus" />
</div>
<!-- 描述 -->
@@ -363,9 +359,9 @@ function fieldSummary(h) {
return `lv${f.lv} · ${auras}`
})
}
// 额外加成条目总数(ap/hp/def_bonus 之和)
// 额外加成档位总数(bonus 数组长度)
function bonusCount(h) {
return (h.ap_bonus?.length || 0) + (h.hp_bonus?.length || 0) + (h.def_bonus?.length || 0)
return h.bonus?.length || 0
}
async function loadMeta() {
@@ -439,6 +435,11 @@ async function loadHeroes() {
try {
const r = await api.fetchHeroes()
if (Array.isArray(r.heroes) && r.heroes.length) {
// 兼容旧数据:ap_bonus/hp_bonus/def_bonus 已废弃,统一迁移为空 bonus
for (const h of r.heroes) {
if (!Array.isArray(h.bonus)) h.bonus = []
delete h.ap_bonus; delete h.hp_bonus; delete h.def_bonus
}
heroes.value = r.heroes
}
} catch (e) {

View File

@@ -1,14 +1,61 @@
<template>
<div>
<div v-for="(b, idx) in model" :key="idx" style="display: flex; gap: 8px; margin-bottom: 6px">
<el-input-number v-model="b.lv" :min="1" :max="20" :controls="false" style="width: 100px" placeholder="lv" />
<el-input-number v-model="b.value" :controls="false" style="width: 140px" placeholder="value" />
<el-button type="danger" size="small" text @click="model.splice(idx, 1)">删除</el-button>
<div v-for="(b, idx) in model" :key="idx" class="skill-block">
<div class="head">
<span>加成档位 lv {{ b.lv }}</span>
<el-button type="danger" size="small" text @click="model.splice(idx, 1)">删除档位</el-button>
</div>
<div class="form-grid">
<el-form-item label="等级 lv">
<el-input-number v-model="b.lv" :min="1" :max="20" :controls="false" style="width: 100%" />
</el-form-item>
</div>
<el-form-item label="属性加成">
<div style="width: 100%">
<div v-for="(a, i) in attrList(b)" :key="i" style="display: flex; gap: 8px; margin-bottom: 6px">
<el-select :model-value="a.key" placeholder="属性" style="width: 220px" @update:model-value="(k) => renameKey(b, a.key, k)">
<el-option v-for="opt in BONUS_ATTR_KEYS" :key="opt.key" :label="opt.label" :value="opt.key" :disabled="hasKey(b, opt.key, a.key)" />
</el-select>
<el-input-number v-model="b.attrs[a.key]" :controls="false" style="width: 140px" placeholder="value" />
<el-button type="danger" size="small" text @click="removeKey(b, a.key)">删除</el-button>
</div>
<el-button size="small" @click="addKey(b)">+ 添加属性</el-button>
</div>
</el-form-item>
</div>
<el-button size="small" @click="model.push({ lv: 12, value: 0 })">+ 添加</el-button>
<el-button size="small" type="primary" @click="model.push({ lv: 9, attrs: {} })">+ 添加加成档位</el-button>
</div>
</template>
<script setup>
import { BONUS_ATTR_KEYS } from '../constants'
defineProps({ model: { type: Array, required: true } })
// attrs 对象为键值对,转列表渲染(保持键序稳定)
function attrList(b) {
return Object.keys(b.attrs).map((key) => ({ key }))
}
function hasKey(b, key, except) {
return key !== except && b.attrs[key] !== undefined
}
function addKey(b) {
const free = BONUS_ATTR_KEYS.find((o) => b.attrs[o.key] === undefined)
if (free) b.attrs[free.key] = 0
}
function removeKey(b, key) {
delete b.attrs[key]
}
// 换键:删旧键、写新键(保留原值)
function renameKey(b, oldKey, newKey) {
const v = b.attrs[oldKey]
delete b.attrs[oldKey]
b.attrs[newKey] = v
}
</script>
<style scoped>
.skill-block { border: 1px solid var(--el-border-color); border-radius: 4px; padding: 10px; margin-bottom: 10px; }
.head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
</style>

View File

@@ -76,9 +76,7 @@ export function defaultHero() {
dead: {},
field: [], // [{lv,uuids:[{uuid,value,name}],desc}]
// revive 已纳入 dead 触发组,通过 overrides.revive_hp / revive_count 配置
ap_bonus: [],
hp_bonus: [],
def_bonus: [],
bonus: [], // [{lv, attrs:{hp?,ap?,def?,crt?,frz?,stun?,para?}}] hp/ap/def 为百分比,概率类为固定百分点
info: '',
}
}
@@ -143,6 +141,17 @@ export const OVERRIDE_KEYS = [
{ key: 'icon', label: 'icon 英雄语境图标(覆写 SkillSet.icon)', type: 'string' },
]
// bonus attrs 可用键:hp/ap/def 按"基础+成长"快照百分比加成;crt/frz/stun/para 为固定百分点累加
export const BONUS_ATTR_KEYS = [
{ key: 'hp', label: 'hp 生命%' },
{ key: 'ap', label: 'ap 攻击%' },
{ key: 'def', label: 'def 防御%' },
{ key: 'crt', label: 'crt 暴击率(百分点)' },
{ key: 'frz', label: 'frz 冰冻(百分点)' },
{ key: 'stun', label: 'stun 击晕(百分点)' },
{ key: 'para', label: 'para 麻痹(百分点)' },
]
// icon 覆写常用候选(SkillSet 各底座图标 + 通用图标),可在输入框直接键入其他帧名
export const SKILL_ICON_OPTIONS = [
'Stat_Attack_01', 'Stat_RangedAttack', 'Stat_Tripleshot',