refactor(buff): 统一buff和debuff属性结构及类型区分

- 新增Buff类型枚举BType,区分数值型与百分比型属性
- 定义AttrsType,映射每个属性的类型(数值或百分比)
- 添加辅助方法isRatioAttr和getAttrType用于属性类型判断
- HeroViewComp中buff和debuff相关属性名称重新命名,区分持久型和临时型及属性类型
- 修改buff/debuff的加载、应用、更新逻辑,适配新的属性结构
- 新增HeroViewComp的isStun和isFrost方法判断状态
- BattleMoveSystem中使用新判断方法替代旧列表遍历
- 移除SkillCom中未使用的BuffAttr导入项,优化依赖关系
This commit is contained in:
2025-10-17 18:41:54 +08:00
parent 13874f3618
commit 4706a128f3
4 changed files with 131 additions and 68 deletions

View File

@@ -18,10 +18,10 @@ const { ccclass, property } = _decorator;
* ==================== BUFF 系统使用说明 ====================
*
* 1. 系统架构:
* - V_BUFF/V_BUFFS: 数值型 buff持久/临时)
* - R_BUFF/R_BUFFS: 百分比型 buff持久/临时)
* - V_DBUFF/V_DBUFFS: 数值型 debuff持久/临时)
* - R_DBUFF/R_DBUFFS: 百分比型 debuff持久/临时)
* - BUFF_V/BUFFS_V: 数值型 buff持久/临时)
* - BUFF_R/BUFFS_R: 百分比型 buff持久/临时)
* - DBUFF_V/DBUFFS_V: 数值型 debuff持久/临时)
* - DBUFF_R/DBUFFS_R: 百分比型 debuff持久/临时)
*
* 2. 初始化(在英雄加载时自动调用):
* - initBuffsDebuffs(): 从 HeroInfo 读取初始配置
@@ -108,17 +108,15 @@ export class HeroViewComp extends CCComp {
Attrs:any=[]
//数值型debuff
V_DBUFF:any[]=[] //持久
V_DBUFFS:any[]=[] //临时 带时间
//百分比型debuff
R_DBUFF:any[]=[] //持久
R_DBUFFS:any[]=[] //临时 带时间
//数值型buff
V_BUFF:any[]=[] //持久
V_BUFFS:any[]=[] //临时 带时间
//百分比型buff
R_BUFF:any[]=[] //持久
R_BUFFS:any[]=[] //临时 带时间
DBUFF_V:any[]=[] //持久
DBUFF_R:any[]=[] //持久
BUFF_V:any[]=[] //持久
BUFF_R:any[]=[] //持久
DBUFFS_V:any[]=[] //临时 带时间
DBUFFS_R:any[]=[] //临时 带时间
BUFFS_V:any[]=[] //临时 带时间
BUFFS_R:any[]=[] //临时 带时间
atk_count: number = 0;
atked_count: number = 0;
@@ -173,14 +171,14 @@ export class HeroViewComp extends CCComp {
if (!heroInfo) return;
// 清空现有 buff/debuff
this.V_BUFF = [];
this.V_BUFFS = [];
this.R_BUFF = [];
this.R_BUFFS = [];
this.V_DBUFF = [];
this.V_DBUFFS = [];
this.R_DBUFF = [];
this.R_DBUFFS = [];
this.BUFF_V = [];
this.BUFFS_V = [];
this.BUFF_R = [];
this.BUFFS_R = [];
this.DBUFF_V = [];
this.DBUFFS_V = [];
this.DBUFF_R = [];
this.DBUFFS_R = [];
// 加载初始 buff
if (heroInfo.buff && heroInfo.buff.length > 0) {
@@ -211,10 +209,10 @@ export class HeroViewComp extends CCComp {
// 数值型 buff
if (buffConf.buC === 0) {
// 持久型
this.V_BUFF.push({...buffConf});
this.BUFF_V.push({...buffConf});
} else {
// 临时型 - 添加剩余时间属性
this.V_BUFFS.push({
this.BUFFS_V.push({
...buffConf,
remainTime: buffConf.buC
});
@@ -223,10 +221,10 @@ export class HeroViewComp extends CCComp {
// 百分比型 buff
if (buffConf.buC === 0) {
// 持久型
this.R_BUFF.push({...buffConf});
this.BUFF_R.push({...buffConf});
} else {
// 临时型 - 添加剩余时间属性
this.R_BUFFS.push({
this.BUFFS_R.push({
...buffConf,
remainTime: buffConf.buC
});
@@ -256,13 +254,13 @@ export class HeroViewComp extends CCComp {
// 数值型 debuff
if (dbuffConf.deC === 0) {
// 持久型
this.V_DBUFF.push({
this.DBUFF_V.push({
...dbuffConf,
attrField: attrField
});
} else {
// 临时型 - 添加剩余时间属性
this.V_DBUFFS.push({
this.DBUFFS_V.push({
...dbuffConf,
attrField: attrField,
remainTime: dbuffConf.deC
@@ -272,13 +270,13 @@ export class HeroViewComp extends CCComp {
// 百分比型 debuff
if (dbuffConf.deC === 0) {
// 持久型
this.R_DBUFF.push({
this.DBUFF_R.push({
...dbuffConf,
attrField: attrField
});
} else {
// 临时型 - 添加剩余时间属性
this.R_DBUFFS.push({
this.DBUFFS_R.push({
...dbuffConf,
attrField: attrField,
remainTime: dbuffConf.deC
@@ -336,14 +334,14 @@ export class HeroViewComp extends CCComp {
*/
private applyValueBuffs() {
// 持久型 buff
for (const buff of this.V_BUFF) {
for (const buff of this.BUFF_V) {
if (buff.buff !== undefined) {
this.Attrs[buff.buff] += buff.buV;
}
}
// 临时型 buff
for (const buff of this.V_BUFFS) {
for (const buff of this.BUFFS_V) {
if (buff.buff !== undefined) {
this.Attrs[buff.buff] += buff.buV;
}
@@ -365,7 +363,7 @@ export class HeroViewComp extends CCComp {
baseValues[Attrs.SPEED] = this.base_speed;
// 持久型 buff
for (const buff of this.R_BUFF) {
for (const buff of this.BUFF_R) {
if (buff.buff !== undefined) {
const baseVal = baseValues[buff.buff] || this.Attrs[buff.buff];
this.Attrs[buff.buff] += Math.floor(baseVal * (buff.buV / 100));
@@ -373,7 +371,7 @@ export class HeroViewComp extends CCComp {
}
// 临时型 buff
for (const buff of this.R_BUFFS) {
for (const buff of this.BUFFS_R) {
if (buff.buff !== undefined) {
const baseVal = baseValues[buff.buff] || this.Attrs[buff.buff];
this.Attrs[buff.buff] += Math.floor(baseVal * (buff.buV / 100));
@@ -386,7 +384,7 @@ export class HeroViewComp extends CCComp {
*/
private applyValueDebuffs() {
// 持久型 debuff
for (const debuff of this.V_DBUFF) {
for (const debuff of this.DBUFF_V) {
// 跳过状态类 debuffattrField === -1
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
this.Attrs[debuff.attrField] -= debuff.deV;
@@ -394,7 +392,7 @@ export class HeroViewComp extends CCComp {
}
// 临时型 debuff
for (const debuff of this.V_DBUFFS) {
for (const debuff of this.DBUFFS_V) {
// 跳过状态类 debuffattrField === -1
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
this.Attrs[debuff.attrField] -= debuff.deV;
@@ -417,7 +415,7 @@ export class HeroViewComp extends CCComp {
this.Attrs[Attrs.SPEED] = this.base_speed;
// 持久型 debuff
for (const debuff of this.R_DBUFF) {
for (const debuff of this.DBUFF_R) {
// 跳过状态类 debuffattrField === -1
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
const baseVal = baseValues[debuff.attrField] || this.Attrs[debuff.attrField];
@@ -426,7 +424,7 @@ export class HeroViewComp extends CCComp {
}
// 临时型 debuff
for (const debuff of this.R_DBUFFS) {
for (const debuff of this.DBUFFS_R) {
// 跳过状态类 debuffattrField === -1
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
const baseVal = baseValues[debuff.attrField] || this.Attrs[debuff.attrField];
@@ -465,37 +463,37 @@ export class HeroViewComp extends CCComp {
let needRecalculate = false;
// 更新临时型数值 buff
for (let i = this.V_BUFFS.length - 1; i >= 0; i--) {
this.V_BUFFS[i].remainTime -= dt;
if (this.V_BUFFS[i].remainTime <= 0) {
this.V_BUFFS.splice(i, 1);
for (let i = this.BUFFS_V.length - 1; i >= 0; i--) {
this.BUFFS_V[i].remainTime -= dt;
if (this.BUFFS_V[i].remainTime <= 0) {
this.BUFFS_V.splice(i, 1);
needRecalculate = true;
}
}
// 更新临时型百分比 buff
for (let i = this.R_BUFFS.length - 1; i >= 0; i--) {
this.R_BUFFS[i].remainTime -= dt;
if (this.R_BUFFS[i].remainTime <= 0) {
this.R_BUFFS.splice(i, 1);
for (let i = this.BUFFS_R.length - 1; i >= 0; i--) {
this.BUFFS_R[i].remainTime -= dt;
if (this.BUFFS_R[i].remainTime <= 0) {
this.BUFFS_R.splice(i, 1);
needRecalculate = true;
}
}
// 更新临时型数值 debuff
for (let i = this.V_DBUFFS.length - 1; i >= 0; i--) {
this.V_DBUFFS[i].remainTime -= dt;
if (this.V_DBUFFS[i].remainTime <= 0) {
this.V_DBUFFS.splice(i, 1);
for (let i = this.DBUFFS_V.length - 1; i >= 0; i--) {
this.DBUFFS_V[i].remainTime -= dt;
if (this.DBUFFS_V[i].remainTime <= 0) {
this.DBUFFS_V.splice(i, 1);
needRecalculate = true;
}
}
// 更新临时型百分比 debuff
for (let i = this.R_DBUFFS.length - 1; i >= 0; i--) {
this.R_DBUFFS[i].remainTime -= dt;
if (this.R_DBUFFS[i].remainTime <= 0) {
this.R_DBUFFS.splice(i, 1);
for (let i = this.DBUFFS_R.length - 1; i >= 0; i--) {
this.DBUFFS_R[i].remainTime -= dt;
if (this.DBUFFS_R[i].remainTime <= 0) {
this.DBUFFS_R.splice(i, 1);
needRecalculate = true;
}
}
@@ -506,6 +504,12 @@ export class HeroViewComp extends CCComp {
}
}
public isStun() {
return this.DBUFF_V.some(d => d.debuff === DBuff.STUN)
}
public isFrost() {
return this.DBUFF_V.some(d => d.debuff === DBuff.FROST)
}
update(dt: number){
if(!smc.mission.play||smc.mission.pause) return