refactor(属性系统): 重构英雄属性系统,将属性定义移至HeroAttrs模块
- 将Attrs和DBuff相关定义从SkillSet迁移至HeroAttrs - 新增NeAttrs枚举用于管理负面状态 - 重构HeroViewComp中的buff/debuff处理逻辑 - 优化属性分类和分组,增加新属性类型 - 移除旧的DBuff相关代码,改用统一的负面状态管理
This commit is contained in:
@@ -5,13 +5,14 @@ import { HeroSpine } from "./HeroSpine";
|
||||
import { BoxSet, FacSet } from "../common/config/BoxSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||
import { Attrs, DBuff, SkillSet, BType, BuffConf, DbuffConf, TransformBuffs, AttrsType } from "../common/config/SkillSet";
|
||||
import { SkillSet,BuffConf,} from "../common/config/SkillSet";
|
||||
import { BuffComp } from "./BuffComp";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { FightSet, TooltipTypes } from "../common/config/Mission";
|
||||
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
|
||||
import { AttrSet, HeroInfo, HeroUpSet } from "../common/config/heroSet";
|
||||
import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
@@ -30,6 +31,11 @@ const { ccclass, property } = _decorator;
|
||||
*
|
||||
*/
|
||||
/** 角色显示组件 */
|
||||
export interface BuffInfo {
|
||||
attr: Attrs;
|
||||
value: number;
|
||||
remainTime?: number;
|
||||
}
|
||||
@ccclass('HeroViewComp') // 定义Cocos Creator 组件
|
||||
@ecs.register('HeroView', false) // 定义ECS 组件
|
||||
export class HeroViewComp extends CCComp {
|
||||
@@ -66,15 +72,12 @@ export class HeroViewComp extends CCComp {
|
||||
base_speed: number = 100; /** 角色移动速度 */
|
||||
base_dis: number = 100;
|
||||
Attrs:any=[]
|
||||
// Buff/Debuff 字典结构,通过属性索引直接访
|
||||
NeAttrs:any=[]
|
||||
// Buff debuff 统一管理, value是正,debuff 是负数
|
||||
// 结构: { [attrIndex: number]: { value: number, remainTime?: number } }
|
||||
DBUFF_V: Record<number, {value: number}> = {} // 持久型数debuff
|
||||
DBUFF_R: Record<number, {value: number}> = {} // 持久型百分比 debuff
|
||||
BUFF_V: Record<number, {value: number}> = {} // 持久型数buff
|
||||
BUFF_R: Record<number, {value: number}> = {} // 持久型百分比 buff
|
||||
|
||||
DBUFFS_V: Record<number, {value: number, remainTime: number}> = {} // 临时型数debuff
|
||||
DBUFFS_R: Record<number, {value: number, remainTime: number}> = {} // 临时型百分比 debuff
|
||||
BUFFS_V: Record<number, {value: number, remainTime: number}> = {} // 临时型数buff
|
||||
BUFFS_R: Record<number, {value: number, remainTime: number}> = {} // 临时型百分比 buff
|
||||
|
||||
@@ -82,8 +85,6 @@ export class HeroViewComp extends CCComp {
|
||||
atked_count: number = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
private damageQueue: Array<{
|
||||
damage: number,
|
||||
isCrit: boolean,
|
||||
@@ -126,14 +127,14 @@ export class HeroViewComp extends CCComp {
|
||||
*/
|
||||
initAttrs() {
|
||||
// 清空现有 buff/debuff
|
||||
this.BUFF_V = {};
|
||||
this.BUFFS_V = {};
|
||||
this.BUFF_R = {};
|
||||
this.BUFFS_R = {};
|
||||
this.DBUFF_V = {};
|
||||
this.DBUFFS_V = {};
|
||||
this.DBUFF_R = {};
|
||||
this.DBUFFS_R = {};
|
||||
this.BUFF_V = {
|
||||
};
|
||||
this.BUFFS_V = {
|
||||
};
|
||||
this.BUFF_R = {
|
||||
};
|
||||
this.BUFFS_R = {
|
||||
};
|
||||
// 获取英雄配置
|
||||
const heroInfo = HeroInfo[this.hero_uuid];
|
||||
if (!heroInfo) return;
|
||||
@@ -170,12 +171,6 @@ export class HeroViewComp extends CCComp {
|
||||
this.addBuff(buffConf);
|
||||
}
|
||||
}
|
||||
// 加载初始 debuff
|
||||
if (heroInfo.debuff && heroInfo.debuff.length > 0) {
|
||||
for (const dbuffConf of heroInfo.debuff) {
|
||||
this.addDebuff(dbuffConf);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ==================== BUFF管理 ====================
|
||||
/**
|
||||
@@ -238,76 +233,6 @@ export class HeroViewComp extends CCComp {
|
||||
this.recalculateSingleAttr(buffConf.buff);
|
||||
}
|
||||
|
||||
// ==================== DEBUFF管理 ====================
|
||||
/**
|
||||
* 添加 debuff 效果(智能覆盖)
|
||||
* @param dbuffConf debuff 配置 (来自 SkillSet.DbuffConf heroSet.debuff)
|
||||
*
|
||||
* 支持两种 debuff
|
||||
* 1. 属性型 debuff:直接修改属性值(有对应的 Attrs
|
||||
* 2. 状态型 debuff:只缓存状态(无对应的 Attrs,用于状态检查)
|
||||
*
|
||||
* 智能覆盖规则
|
||||
* 1. 值更小:不添
|
||||
* 2. 值相同且都是临时:叠加时
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间
|
||||
*/
|
||||
addDebuff(dbuffConf: DbuffConf) {
|
||||
// 获取 debuff 对应的属性字
|
||||
|
||||
const isValue = dbuffConf.BType === BType.VALUE;
|
||||
const isPermanent = dbuffConf.time === 0;
|
||||
|
||||
// 根据类型选择对应debuff 字典
|
||||
const permanentDebuffs = isValue ? this.DBUFF_V : this.DBUFF_R;
|
||||
const temporaryDebuffs = isValue ? this.DBUFFS_V : this.DBUFFS_R;
|
||||
// 状态类 debuff 使用 debuff 类型作为 key,属性类 debuff 使用 attrField 作为 key
|
||||
const key = dbuffConf.debuff;
|
||||
|
||||
if (isPermanent) {
|
||||
// 添加持久debuff
|
||||
const existing = permanentDebuffs[key];
|
||||
if (existing) {
|
||||
// 值更小,不添
|
||||
if (dbuffConf.value <= existing.value) {
|
||||
return;
|
||||
}
|
||||
// 值更大,更新
|
||||
existing.value = dbuffConf.value;
|
||||
} else {
|
||||
// 没有同类型,直接添加
|
||||
permanentDebuffs[key] = { value: dbuffConf.value };
|
||||
}
|
||||
} else {
|
||||
// 添加临时debuff
|
||||
const existing = temporaryDebuffs[key];
|
||||
if (existing) {
|
||||
if (dbuffConf.value < existing.value) {
|
||||
// 值更小,不添
|
||||
return;
|
||||
} else if (dbuffConf.value === existing.value) {
|
||||
// 值相同,叠加时间
|
||||
existing.remainTime += dbuffConf.time;
|
||||
return; // 时间叠加不需要重算属
|
||||
} else {
|
||||
// 值更大,更新值和时间
|
||||
existing.value = dbuffConf.value;
|
||||
existing.remainTime = dbuffConf.time;
|
||||
}
|
||||
} else {
|
||||
// 没有同类型,直接添加
|
||||
temporaryDebuffs[key] = {
|
||||
value: dbuffConf.value,
|
||||
remainTime: dbuffConf.time
|
||||
};
|
||||
}
|
||||
}
|
||||
let attrField = TransformBuffs(dbuffConf.debuff,true);
|
||||
// 只重新计算受影响的属性(状态类 debuff 不需要计算)
|
||||
if (attrField > 0 ) {
|
||||
this.recalculateSingleAttr(attrField);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 属性计算系====================
|
||||
/**
|
||||
@@ -343,16 +268,7 @@ export class HeroViewComp extends CCComp {
|
||||
totalValue += this.BUFFS_V[attrIndex].value;
|
||||
}
|
||||
|
||||
// Debuff:需要通过 DBuff key 查找
|
||||
const deKey = TransformBuffs(attrIndex, false);
|
||||
if (deKey !== -1) {
|
||||
if (this.DBUFF_V[deKey]) {
|
||||
totalValue -= this.DBUFF_V[deKey].value;
|
||||
}
|
||||
if (this.DBUFFS_V[deKey]) {
|
||||
totalValue -= this.DBUFFS_V[deKey].value;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 收集所有百分比型 buff/debuff
|
||||
let totalRatio = 0; // 总百分比(可正可负)
|
||||
|
||||
@@ -364,17 +280,7 @@ export class HeroViewComp extends CCComp {
|
||||
totalRatio += this.BUFFS_R[attrIndex].value;
|
||||
}
|
||||
|
||||
// Debuff:需要通过 DBuff key 查找
|
||||
if (deKey !== -1) {
|
||||
if (this.DBUFF_R[deKey]) {
|
||||
totalRatio -= this.DBUFF_R[deKey].value;
|
||||
}
|
||||
if (this.DBUFFS_R[deKey]) {
|
||||
totalRatio -= this.DBUFFS_R[deKey].value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 4. 根据属性类型计算最终值
|
||||
const attrType = AttrsType[attrIndex];
|
||||
const isRatioAttr = attrType === BType.RATIO;
|
||||
@@ -439,27 +345,12 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新临时型数debuff
|
||||
for (const key in this.DBUFFS_V) {
|
||||
const debuff = this.DBUFFS_V[key];
|
||||
// 负面状态更新
|
||||
for (const key in this.NeAttrs) {
|
||||
const debuff = this.NeAttrs[key];
|
||||
debuff.remainTime -= dt;
|
||||
if (debuff.remainTime <= 0) {
|
||||
delete this.DBUFFS_V[key];
|
||||
const keyNum = parseInt(key);
|
||||
const attrField = TransformBuffs(keyNum,true)
|
||||
if(attrField > 0) affectedAttrs.add(attrField);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新临时型百分比 debuff
|
||||
for (const key in this.DBUFFS_R) {
|
||||
const debuff = this.DBUFFS_R[key];
|
||||
debuff.remainTime -= dt;
|
||||
if (debuff.remainTime <= 0) {
|
||||
delete this.DBUFFS_R[key];
|
||||
const keyNum = parseInt(key);
|
||||
const attrField = TransformBuffs(keyNum,true)
|
||||
if(attrField > 0) affectedAttrs.add(attrField);
|
||||
debuff.remainTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,10 +361,10 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
|
||||
public isStun() {
|
||||
return this.DBUFFS_V[DBuff.STUN] !== undefined?true:false
|
||||
return this.NeAttrs[NeAttrs.IN_STUN].time > 0;
|
||||
}
|
||||
public isFrost() {
|
||||
return this.DBUFFS_V[DBuff.FROST] !== undefined?true:false
|
||||
return this.NeAttrs[NeAttrs.IN_FROST].time > 0;
|
||||
}
|
||||
|
||||
update(dt: number){
|
||||
|
||||
Reference in New Issue
Block a user