Files
pixelheros/assets/script/game/hero/FieldSkillHelper.ts
panFD 450a8b81e5 refactor(field): 重构驻场光环数据结构,分离元数据与数值
1.  新增FieldEntry类型,将驻场词条的uuid与生效数值分离
2.  重构FieldSkillSet,移除各档位重复配置,仅保留基础元数据
3.  更新所有使用驻场词条的业务代码,适配新的数据结构
4.  修复数值渲染逻辑,使用词条携带的实际数值而非配置固化值
2026-08-11 22:36:28 +08:00

71 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { FacSet } from "../common/config/GameSet";
import { FieldSkillSet, FieldSkillType } from "../common/config/SkillSet";
import { FieldEntry } from "../common/config/heroSet";
import { HeroAttrsComp } from "./HeroAttrsComp";
import { SkillBoxComp } from "../map/SkillBoxComp";
import { EquipBoxComp } from "../map/EquipBoxComp";
/**
* 驻场技能(光环属性)计算辅助类
*
* 核心职责:
* 统一管理全场存活英雄带来的全局加成属性计算。
* 解耦原先写在 HeroAttrsComp 中的静态计算逻辑,符合单一职责原则。
*
* 数据结构field 列表元素为 FieldEntry{uuid,value}uuid 仅用于查 FieldSkillSet
* 的类型元数据,实际加成数值取自词条自身的 value。
*/
export class FieldSkillHelper {
/** 获取指定驻场技能类型的总加成值(计算存活的友方英雄 + 场上的驻场技能卡) */
public static getFieldSkillTotalValue(type: FieldSkillType): number {
return FieldSkillHelper.getFieldSkillTotalValueForFac(type, FacSet.HERO);
}
/**
* 获取指定阵营的驻场技能总加成值
* @param type 驻场技能类型
* @param fac 阵营FacSet.HERO / FacSet.MON默认 HERO
* @returns 总加成值
*/
public static getFieldSkillTotalValueForFac(type: FieldSkillType, fac: number = FacSet.HERO): number {
let total = 0;
// 累加一组驻场词条中匹配类型的数值
const accumulate = (fields: FieldEntry[] | undefined): void => {
if (!fields) return;
for (const entry of fields) {
const fs = FieldSkillSet[entry.uuid];
if (fs && fs.type === type) {
total += entry.value;
}
}
};
// 1. 统计英雄/怪物带来的驻场技能加成
// 读 model.runtime_field已按当前等级 resolve 的词条列表)
ecs.query(ecs.allOf(HeroAttrsComp)).forEach((entity: ecs.Entity) => {
const model = entity.get(HeroAttrsComp);
if (!model || model.is_dead || model.fac !== fac) return;
accumulate(model.runtime_field);
});
// 2. 统计技能盒子(技能卡)与装备盒(装备卡)带来的驻场技能加成(仅英雄阵营)
if (fac === FacSet.HERO) {
ecs.query(ecs.allOf(SkillBoxComp)).forEach((entity: ecs.Entity) => {
const skillBox = entity.get(SkillBoxComp);
if (!skillBox) return;
accumulate(skillBox.field);
});
ecs.query(ecs.allOf(EquipBoxComp)).forEach((entity: ecs.Entity) => {
const equipBox = entity.get(EquipBoxComp);
if (!equipBox) return;
accumulate(equipBox.field);
});
}
return total;
}
}