refactor(field): 重构驻场光环数据结构,分离元数据与数值
1. 新增FieldEntry类型,将驻场词条的uuid与生效数值分离 2. 重构FieldSkillSet,移除各档位重复配置,仅保留基础元数据 3. 更新所有使用驻场词条的业务代码,适配新的数据结构 4. 修复数值渲染逻辑,使用词条携带的实际数值而非配置固化值
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
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 {
|
||||
/** 获取指定驻场技能类型的总加成值(计算存活的友方英雄 + 场上的驻场技能卡) */
|
||||
@@ -27,47 +31,37 @@ export class FieldSkillHelper {
|
||||
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 的 uuid 列表)
|
||||
// 读 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;
|
||||
const fields = model.runtime_field;
|
||||
if (fields) {
|
||||
for (const skillUuid of fields) {
|
||||
const skillConfig = FieldSkillSet[skillUuid];
|
||||
if (skillConfig && skillConfig.type === type) {
|
||||
total += skillConfig.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
accumulate(model.runtime_field);
|
||||
});
|
||||
|
||||
// 2. 统计技能盒子(技能卡)带来的驻场技能加成(仅英雄阵营)
|
||||
// 2. 统计技能盒子(技能卡)与装备盒(装备卡)带来的驻场技能加成(仅英雄阵营)
|
||||
if (fac === FacSet.HERO) {
|
||||
ecs.query(ecs.allOf(SkillBoxComp)).forEach((entity: ecs.Entity) => {
|
||||
const skillBox = entity.get(SkillBoxComp);
|
||||
if (!skillBox || !skillBox.field || skillBox.field.length === 0) return;
|
||||
|
||||
for (const skillUuid of skillBox.field) {
|
||||
const skillConfig = FieldSkillSet[skillUuid];
|
||||
if (skillConfig && skillConfig.type === type) {
|
||||
total += skillConfig.value;
|
||||
}
|
||||
}
|
||||
if (!skillBox) return;
|
||||
accumulate(skillBox.field);
|
||||
});
|
||||
|
||||
// 3. 统计装备盒(装备卡)带来的驻场技能加成(仅英雄阵营)
|
||||
ecs.query(ecs.allOf(EquipBoxComp)).forEach((entity: ecs.Entity) => {
|
||||
const equipBox = entity.get(EquipBoxComp);
|
||||
if (!equipBox || !equipBox.field || equipBox.field.length === 0) return;
|
||||
|
||||
for (const skillUuid of equipBox.field) {
|
||||
const skillConfig = FieldSkillSet[skillUuid];
|
||||
if (skillConfig && skillConfig.type === type) {
|
||||
total += skillConfig.value;
|
||||
}
|
||||
}
|
||||
if (!equipBox) return;
|
||||
accumulate(equipBox.field);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user