refactor(skill/hero): 重构技能buff系统,优化属性处理与技能加成逻辑
- 新增HeroAttrsComp的add_special_attr方法,实现动态累加任意数字类型的英雄属性 - 废弃旧的BuffConf数组配置格式,改用单一buff_type字段简化技能buff配置 - 修复金币类技能加成未随技能等级提升的问题,调整计算逻辑为baseGold + sUp.ap * skillLv - 重构applyActualFriendlyEffect方法,添加技能等级参数,按buff类型匹配对应升级加成 - 更新所有内置技能配置为新的格式规范
This commit is contained in:
@@ -6,6 +6,7 @@ import { FacSet, FightSet } from "../common/config/GameSet";
|
||||
import { FieldSkillSet, FieldSkillType, SkillOverrides } from "../common/config/SkillSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { TalentConfig, TalentType } from "../common/config/TalentSet";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
import { FieldSkillHelper } from "./FieldSkillHelper";
|
||||
@ecs.register('HeroAttrs')
|
||||
export class HeroAttrsComp extends ecs.Comp {
|
||||
@@ -135,6 +136,25 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一的特殊/固定属性数值增加方法
|
||||
* @param attr_type 属性类型枚举
|
||||
* @param value 增加的数值
|
||||
*/
|
||||
add_special_attr(attr_type: Attrs, value: number) {
|
||||
// 利用枚举值(字符串)与类属性名一致的特性,动态访问并累加属性
|
||||
const key = attr_type as keyof this;
|
||||
|
||||
// 确保目标属性存在且类型为数字,避免运行时错误
|
||||
if (typeof this[key] === 'number') {
|
||||
(this as any)[key] += value;
|
||||
} else {
|
||||
if (this.debugMode) {
|
||||
mLogger.log(this.debugMode, 'HeroAttrs', `未找到对应数字属性或无法累加: attr_type=${attr_type}, value=${value}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
toFrost(time: number=1) {
|
||||
const frostTime = FightSet.FROST_TIME * time;
|
||||
|
||||
@@ -412,13 +412,13 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
: this.pickRandomFriendlyTargets(targets, sHit);
|
||||
|
||||
for (const target of applyTargets) {
|
||||
this.applyActualFriendlyEffect(target, kind, sAp, _cAttrsComp, config, sUp);
|
||||
this.applyActualFriendlyEffect(target, kind, sAp, _cAttrsComp, config, sUp, _skillLv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private applyActualFriendlyEffect(target: HeroViewComp, kind: SkillKind, sAp: number, _cAttrsComp: HeroAttrsComp, config: SkillConfig, sUp: any) {
|
||||
private applyActualFriendlyEffect(target: HeroViewComp, kind: SkillKind, sAp: number, _cAttrsComp: HeroAttrsComp, config: SkillConfig, sUp: any, _skillLv: number = 1) {
|
||||
if (!target.ent) return;
|
||||
const model = target.ent.get(HeroAttrsComp);
|
||||
if (!model || model.is_dead) return;
|
||||
@@ -440,23 +440,35 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
model.add_shield(addShield);
|
||||
} else if (kind === SkillKind.Gold) {
|
||||
const baseGold = config.gold ?? config.ap;
|
||||
const addGold = baseGold + (sUp.ap);
|
||||
const addGold = baseGold + (sUp.ap * _skillLv);
|
||||
if (addGold > 0) {
|
||||
MissionEconomy.addCoin(addGold);
|
||||
}
|
||||
}
|
||||
if (!config.buffs || config.buffs.length === 0) return;
|
||||
for (const buffConf of config.buffs) {
|
||||
if (!buffConf) continue;
|
||||
const sBuffAp=buffConf.value+sUp.buff_ap
|
||||
const sBuffHp=buffConf.value+sUp.buff_hp
|
||||
switch (buffConf.buff){
|
||||
|
||||
if (config.buff_type !== undefined) {
|
||||
const baseValue = config.ap;
|
||||
let upgradeValue = 0;
|
||||
|
||||
// 根据 buff 类型选择对应的升级加成
|
||||
if (config.buff_type === Attrs.ap) upgradeValue = sUp.buff_ap || 0;
|
||||
else if (config.buff_type === Attrs.hp_max) upgradeValue = sUp.buff_hp || 0;
|
||||
else if (config.buff_type === Attrs.critical) upgradeValue = sUp.crt || 0;
|
||||
// 如果后续有冰冻等,在这里加上对应的 sUp 字段即可,如 sUp.frz
|
||||
|
||||
const totalBuffValue = baseValue + upgradeValue;
|
||||
|
||||
switch (config.buff_type){
|
||||
case Attrs.ap:
|
||||
model.add_ap(sBuffAp)
|
||||
break
|
||||
model.add_ap(totalBuffValue);
|
||||
break;
|
||||
case Attrs.hp_max:
|
||||
model.add_hp_max(sBuffHp)
|
||||
break
|
||||
model.add_hp_max(totalBuffValue);
|
||||
break;
|
||||
default:
|
||||
// 除了 hp_max 和 ap,其他固定属性走统一的 add_special_attr 方法
|
||||
model.add_special_attr(config.buff_type, totalBuffValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user