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:
@@ -215,8 +215,8 @@ export class HeroBoxComp extends CCComp {
|
||||
// ---- 属性成长(固定基础值 + 成长类型指数递增 + 一次性加成) ----
|
||||
const attrLine = (lv: number): string => {
|
||||
const grow = calcGrowBonus(hero, lv);
|
||||
const ap = Math.floor(hero.ap + grow.ap + HeroBoxComp.sumBonus(hero.ap_bonus, lv));
|
||||
const hp = Math.floor(hero.hp + grow.hp + HeroBoxComp.sumBonus(hero.hp_bonus, lv));
|
||||
const ap = Math.floor(hero.ap + grow.ap + HeroBoxComp.sumBonusPct(hero.ap + grow.ap, hero.bonus, 'ap', lv));
|
||||
const hp = Math.floor(hero.hp + grow.hp + HeroBoxComp.sumBonusPct(hero.hp + grow.hp, hero.bonus, 'hp', lv));
|
||||
return `攻击 <color=#27AE60>${ap}</color> 生命 <color=#27AE60>${hp}</color>`;
|
||||
};
|
||||
|
||||
@@ -237,11 +237,12 @@ export class HeroBoxComp extends CCComp {
|
||||
}
|
||||
|
||||
/** 累加等级额外加成(≤目标等级的所有档位) */
|
||||
private static sumBonus(entries: { lv: number; value: number }[] | undefined, lv: number): number {
|
||||
/** 累加 bonus 中某百分比键的档位总量,并按"基础+成长"快照换算为固定增量(≤目标等级的所有档位) */
|
||||
private static sumBonusPct(snap: number, entries: HeroInfo[number]['bonus'], key: 'hp' | 'ap' | 'def', lv: number): number {
|
||||
if (!entries) return 0;
|
||||
let total = 0;
|
||||
for (const e of entries) { if (e.lv <= lv) total += e.value; }
|
||||
return total;
|
||||
let pct = 0;
|
||||
for (const e of entries) { if (e.lv <= lv) pct += e.attrs[key] ?? 0; }
|
||||
return Math.round(snap * pct / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -543,18 +544,18 @@ export class HeroBoxComp extends CCComp {
|
||||
}
|
||||
|
||||
// ---- AP / HP ----
|
||||
// plus(附加值)= 最终值 - 当前等级基础值;基础值 = 1 级原始 base + 等级成长 + ap/hp_bonus 一次性奖励。
|
||||
// plus(附加值)= 最终值 - 当前等级基础值;基础值 = 1 级原始 base + 等级成长 + bonus 百分比加成。
|
||||
// Why: base_ap/base_hp 是不含任何等级增长的原始值,直接用 final-base 会把升级带来的
|
||||
// 属性增长也计入增量。这里补齐等级增长作为基准,使 plus 仅反映 buff/光环等临时增益。
|
||||
const lv = Math.max(1, Math.floor(this.model.lv ?? 1));
|
||||
const grow = hero ? calcGrowBonus(hero, lv) : { ap: 0, hp: 0 };
|
||||
|
||||
const finalAp = Math.max(0, Math.floor(this.model.getFinalAp()));
|
||||
const lvBaseAp = Math.max(0, Math.floor((this.model.base_ap ?? 0) + grow.ap + HeroBoxComp.sumBonus(hero?.ap_bonus, lv)));
|
||||
const lvBaseAp = Math.max(0, Math.floor((this.model.base_ap ?? 0) + grow.ap + HeroBoxComp.sumBonusPct((this.model.base_ap ?? 0) + grow.ap, hero?.bonus, 'ap', lv)));
|
||||
this.setStatRow(this.ap_all_label, this.ap_plus_label, finalAp, finalAp - lvBaseAp);
|
||||
|
||||
const finalHp = Math.max(0, Math.floor(this.model.getFinalHpMax()));
|
||||
const lvBaseHp = Math.max(0, Math.floor((this.model.base_hp ?? 0) + grow.hp + HeroBoxComp.sumBonus(hero?.hp_bonus, lv)));
|
||||
const lvBaseHp = Math.max(0, Math.floor((this.model.base_hp ?? 0) + grow.hp + HeroBoxComp.sumBonusPct((this.model.base_hp ?? 0) + grow.hp, hero?.bonus, 'hp', lv)));
|
||||
this.setStatRow(this.hp_all_label, this.hp_plus_label, finalHp, finalHp - lvBaseHp);
|
||||
|
||||
// ---- 图标(UUID 变化时重新加载首帧动画) ----
|
||||
|
||||
@@ -2142,7 +2142,7 @@ export class MissionCardComp extends CCComp {
|
||||
* 1. 同步刷新 base_ap/base_hp 快照,下游 UI/复活读到当前 lv 的基础值
|
||||
* 2. 走 getRuntimeAp/getRuntimeHp 应用驻场光环乘区
|
||||
* 3. 重新解析 runtime_* 触发缓存与光环/复活,避免升级后停在旧等级快照
|
||||
* 4. 按 ≤nextLv 累加 hp_bonus/ap_bonus
|
||||
* 4. 按 ≤nextLv 累加 bonus 档位(hp/ap/def 百分比 + crt/frz/stun/para 百分点)
|
||||
*/
|
||||
public applyHeroLevel(model: HeroAttrsComp, targetLv: number) {
|
||||
const hero = HeroInfo[model.hero_uuid];
|
||||
@@ -2167,28 +2167,38 @@ export class MissionCardComp extends CCComp {
|
||||
model.hp_max = base_hp;
|
||||
}
|
||||
|
||||
// 按 ≤nextLv 累加:成长类型每级递增 + hp/ap/def_bonus 一次性奖励(沿用 Hero.load 的加法区规则)
|
||||
// 按 ≤nextLv 累加:成长类型每级递增 + bonus 档位(与 Hero.load 同口径:hp/ap 百分比、基数取"基础+成长"快照)
|
||||
const grow = calcGrowBonus(hero, nextLv);
|
||||
model.hp_max += grow.hp;
|
||||
model.ap += grow.ap;
|
||||
if (model.hp_bonus) {
|
||||
let hpExtra = 0;
|
||||
for (const e of model.hp_bonus) { if (e.lv <= nextLv) hpExtra += e.value; }
|
||||
model.hp_max += hpExtra;
|
||||
}
|
||||
if (model.ap_bonus) {
|
||||
let apExtra = 0;
|
||||
for (const e of model.ap_bonus) { if (e.lv <= nextLv) apExtra += e.value; }
|
||||
model.ap += apExtra;
|
||||
let bonusHpP = 0, bonusApP = 0, bonusDefP = 0;
|
||||
if (model.bonus) {
|
||||
for (const e of model.bonus) {
|
||||
if (e.lv > nextLv) continue;
|
||||
bonusHpP += e.attrs.hp ?? 0;
|
||||
bonusApP += e.attrs.ap ?? 0;
|
||||
bonusDefP += e.attrs.def ?? 0;
|
||||
}
|
||||
model.hp_max += Math.round((base_hp + grow.hp) * bonusHpP / 100);
|
||||
model.ap += Math.round((base_ap + grow.ap) * bonusApP / 100);
|
||||
}
|
||||
|
||||
// 天赋加成层(与 Hero.load 对齐):先重置天赋可能修改的字段,避免升级重算时重复叠加
|
||||
// Why: ap/hp_max 已由上方公式从 base 重算(天然幂等),但 defense 与概率类字段是累加语义,必须先归零再注入
|
||||
if (model.fac === FacSet.HERO) {
|
||||
// defense 从品质系数后的基础值重算,叠加 def 成长 + def_bonus + lv12 专项,幂等
|
||||
// defense 从品质系数后的基础值重算,叠加 def 成长 + def 百分比 bonus + lv12 专项,幂等
|
||||
let base_def = Math.round(hero.def * qualityCoef) + grow.def;
|
||||
if (model.def_bonus) {
|
||||
for (const e of model.def_bonus) { if (e.lv <= nextLv) base_def += e.value; }
|
||||
base_def += Math.round(base_def * bonusDefP / 100);
|
||||
// bonus 概率类:固定百分点累加(在下方归零后注入,避免重复叠加)
|
||||
let bonusCrt = 0, bonusFrz = 0, bonusStun = 0, bonusPara = 0;
|
||||
if (model.bonus) {
|
||||
for (const e of model.bonus) {
|
||||
if (e.lv > nextLv) continue;
|
||||
bonusCrt += e.attrs.crt ?? 0;
|
||||
bonusFrz += e.attrs.frz ?? 0;
|
||||
bonusStun += e.attrs.stun ?? 0;
|
||||
bonusPara += e.attrs.para ?? 0;
|
||||
}
|
||||
}
|
||||
// lv12 职业属性专项:达到 12 级时按职业对单项基础属性 +50%(基数为 lv11 有效值)
|
||||
if (nextLv >= HERO_LV12_SPECIAL_LV && model.role !== undefined) {
|
||||
@@ -2199,10 +2209,11 @@ export class MissionCardComp extends CCComp {
|
||||
else if (attr === "ap") model.ap += Math.round(lv11.ap * 0.5);
|
||||
}
|
||||
model.defense = base_def;
|
||||
model.critical = 0;
|
||||
model.critical = bonusCrt;
|
||||
model.critical_damage = 0;
|
||||
model.stun_chance = 0;
|
||||
model.freeze_chance = 0;
|
||||
model.stun_chance = bonusStun;
|
||||
model.freeze_chance = bonusFrz;
|
||||
model.paralyze_chance = bonusPara;
|
||||
// 风怒机制已停用: 升级重算不再重置风怒
|
||||
// model.wfuny = 0;
|
||||
model.puncture_chance = 0;
|
||||
|
||||
Reference in New Issue
Block a user