refactor(config): 修改 Buff/Debuff 接口字段命名

- 将 DbuffConf 中的属性 deV, deC, deR 重命名为 value, time, chance
- 将 BuffConf 中的属性 buV, buC, buR 重命名为 value, time, chance
- 统一代码中 Buff 和 Debuff 配置的字段命名,提升可读性和一致性
This commit is contained in:
walkpan
2025-10-17 19:46:31 +08:00
parent 4706a128f3
commit 94f83482fa
8 changed files with 276 additions and 2463 deletions

View File

@@ -17,62 +17,24 @@ const { ccclass, property } = _decorator;
/**
* ==================== BUFF 系统使用说明 ====================
*
* 1. 系统架构:
* - BUFF_V/BUFFS_V: 数值型 buff持久/临时)
* - BUFF_R/BUFFS_R: 百分比型 buff持久/临时)
* - DBUFF_V/DBUFFS_V: 数值型 debuff持久/临时)
* - DBUFF_R/DBUFFS_R: 百分比型 debuff持久/临时)
* 1. 系统架构�
* - BUFF_V/BUFFS_V: 数值型 buff(æŒ<C3A6>ï¿?临时ï¿?
* - BUFF_R/BUFFS_R: 百分比型 buff(æŒ<C3A6>ï¿?临时ï¿?
* - DBUFF_V/DBUFFS_V: 数值型 debuff(æŒ<C3A6>ï¿?临时ï¿?
* - DBUFF_R/DBUFFS_R: 百分比型 debuff(æŒ<C3A6>ï¿?临时ï¿?
*
* 2. 初始化(在英雄加载时自动调用):
* - initBuffsDebuffs(): 从 HeroInfo 读取初始配置
* 2. 智能覆盖规则�
* - 值æ´å°<EFBFBD>:ä¸<EFBFBD>添加(弱效果ä¸<EFBFBD>覆ç强效果)
* - 值ç¸å<C2B8>Œä¸”临时:å<C5A1> åŠ æ—¶ï¿?
* - 值更大:更新为新值(临时则更新值和时间�
*
* 3. 添加 buff技能调用:
* const buffConf: BuffConf = {
* buff: Attrs.AP, // 增加攻击力
* BType: BType.VALUE, // 数值型
* buV: 10, // 增加值
* buC: 0, // 持久(0=持久, >0=持续时间)
* buR: 100 // 触发概率(100%)
* };
* heroView.addBuff(buffConf);
*
* 4. 添加 debuff技能调用:
* const dbuffConf: DbuffConf = {
* debuff: DBuff.STUN, // 眩晕
* BType: BType.VALUE, // 数值型
* deV: 20, // 减少值
* deC: 3, // 持续3秒
* deR: 100 // 触发概率(100%)
* };
* heroView.addDebuff(dbuffConf);
*
* 5. 百分比型示例:
* // 增加20%攻击力
* heroView.addBuff({
* buff: Attrs.AP,
* BType: BType.RATIO, // 百分比型
* buV: 20, // 20%
* buC: 5, // 持续5秒
* buR: 100
* });
*
* 6. 移除 buff/debuff:
* heroView.removeBuff(Attrs.AP, false); // 移除持久 AP buff
* heroView.removeDebuff(DBuff.STUN, true); // 移除临时眩晕
*
* 7. 属性计算:
* - 每次 buff/debuff 变动时自动调用 recalculateAttrs()
* - 重新计算基础属性 + 所有 buff/debuff 的结果
* - 临时 buff/debuff 在 update 中按时间递减
*
* 8. 初始值属性:
* - base_hp, base_mp, base_def, base_ap, base_map 是初始值
* - 百分比 buff/debuff 基于这些初始值计算
* - 其他属性默认为 0无初始值
* 3. 性能优化�
* - 增é‡<C3A9>计算:添ï¿?删除时å<C2B6>ªé‡<C3A9>ç®—å<E28094>—å½±å“<C3A5>的属�?
* - 批é‡<C3A9>计算:initBuffsDebuffs() 中使ï¿?recalculateAttrs() 一次性计算所ï¿?
*/
/** 角色显示组件 */
@ccclass('HeroViewComp') // 定义为 Cocos Creator 组件
@ecs.register('HeroView', false) // 定义为 ECS 组件
@ccclass('HeroViewComp') // 定义�Cocos Creator 组件
@ecs.register('HeroView', false) // 定义�ECS 组件
export class HeroViewComp extends CCComp {
BUFFCOMP:BuffComp=null!
as: HeroSpine = null!
@@ -81,7 +43,7 @@ export class HeroViewComp extends CCComp {
hero_name : string = "hero";
lv:number =1;
scale: number = 1; /** è§è‰²é˜µè<C2B5>¥ 1:hero -1 :mon */
type: number = 0; /**角色类型 0近战-需要贴身 1远程-保持距离 2辅助 */
type: number = 0; /**角色类型 0è¿æˆ˜-需è¦<C3A8>è´´ï¿?1远ç¨-ä¿<C3A4>æŒ<C3A6>è·<C3A8>离 2辅助 */
fac:number=0; //阵è<C2B5>¥ 0:hero 1:monster
box_group:number = BoxSet.HERO;
is_dead:boolean = false; //是å<C2AF>¦æ§æ¯<C3A6>
@@ -96,10 +58,10 @@ export class HeroViewComp extends CCComp {
is_kalami:boolean =false;
mp: number = 100;
hp: number = 100; /** 血量 */
shield:number=0; //当前护甲值
/** 基础属性 有初始值的基础属性,后续Attrs 属性计算时用到*/
base_ap: number = 0; //基础攻击力
hp: number = 100; /** 血�*/
shield:number=0; //当å‰<EFBFBD>护甲ï¿?
/** 基础属�?有åˆ<C3A5>å§å€¼çš„基础属�?å<>Žç»­Attrs 属性计算时用到*/
base_ap: number = 0; //基础攻击�
base_map: number = 0;
base_def: number = 5;
base_hp: number = 100;
@@ -107,16 +69,17 @@ export class HeroViewComp extends CCComp {
base_speed: number = 100; /** 角色移动速度 */
Attrs:any=[]
//数值型debuff
DBUFF_V:any[]=[] //持久
DBUFF_R:any[]=[] //持久
BUFF_V:any[]=[] //持久
BUFF_R:any[]=[] //持久
// Buff/Debuff 字典结构,通过属性索引直接访�
// 结构: { [attrIndex: number]: { value: number, remainTime?: number } }
DBUFF_V: Record<number, {value: number}> = {} // æŒ<C3A6>ä¹…åžæ•°ï¿?debuff
DBUFF_R: Record<number, {value: number}> = {} // æŒ<C3A6>ä¹…åžç™¾åˆ†æ¯” debuff
BUFF_V: Record<number, {value: number}> = {} // æŒ<C3A6>ä¹…åžæ•°ï¿?buff
BUFF_R: Record<number, {value: number}> = {} // æŒ<C3A6>ä¹…åžç™¾åˆ†æ¯” buff
DBUFFS_V:any[]=[] //临时 带时间
DBUFFS_R:any[]=[] //临时 带时间
BUFFS_V:any[]=[] //临时 带时间
BUFFS_R:any[]=[] //临时 带时间
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
atk_count: number = 0;
atked_count: number = 0;
@@ -139,7 +102,7 @@ export class HeroViewComp extends CCComp {
this.on(GameEvent.FightEnd,this.do_fight_end,this)
const collider = this.node.getComponent(BoxCollider2D);
this.scheduleOnce(()=>{
if (collider) collider.enabled = true; // 先禁用
if (collider) collider.enabled = true; // å…ˆç¦<EFBFBD>ï¿?
},1)
// let anm = this.node.getChildByName("anm")
// anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8);
@@ -155,31 +118,47 @@ export class HeroViewComp extends CCComp {
if(this.is_boss){
this.node.getChildByName("top").position=v3(this.node.position.x,this.node.position.y+100,0)
}
/* 显示角色血量 */
/* 显示角色血�*/
this.node.getChildByName("top").getChildByName("hp").active = true;
this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
}
// ==================== BUFF系统初始化 ====================
// ==================== BUFF系统åˆ<EFBFBD>å§ï¿?====================
/**
* 初始化角色的 buff debuff
* HeroInfo 读取初始配置,建立属性系统
* åˆ<EFBFBD>å§åŒè§è‰²çš„ buff ï¿?debuff
* ï¿?HeroInfo 读å<EFBFBD>åˆ<EFBFBD>å§é…<EFBFBD>置,建ç«å±žæ€§ç³»ï¿?
*/
initBuffsDebuffs() {
// 清空现有 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 = {};
// 获å<C2B7>è±é„é…<C3A9>ç½®
const heroInfo = HeroInfo[this.hero_uuid];
if (!heroInfo) return;
// 清空现有 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 = [];
// 1. é‡<C3A9>置为基础ï¿?
this.Attrs[Attrs.HP_MAX] = this.base_hp;
this.Attrs[Attrs.MP_MAX] = this.base_mp;
this.Attrs[Attrs.DEF] = this.base_def;
this.Attrs[Attrs.AP] = this.base_ap;
this.Attrs[Attrs.MAP] = this.base_map;
this.Attrs[Attrs.SPEED] = this.base_speed;
this.Attrs[Attrs.SHIELD_MAX] = 0; // 护盾默认�0
// 2. åˆ<C3A5>å§åŒå…¶ä»å±žæ€§ï¼ˆæ— åˆ<C3A5>å§å€¼çš„ï¿?
for (const attrKey in this.Attrs) {
const attrIndex = parseInt(attrKey);
if(attrIndex !== Attrs.HP_MAX && attrIndex !== Attrs.MP_MAX && attrIndex !== Attrs.DEF && attrIndex !== Attrs.AP && attrIndex !== Attrs.MAP && attrIndex !== Attrs.SPEED) {
this.Attrs[attrIndex] = 0;
}
}
// 加载åˆ<C3A5>å§ buff
if (heroInfo.buff && heroInfo.buff.length > 0) {
for (const buffConf of heroInfo.buff) {
@@ -193,322 +172,280 @@ export class HeroViewComp extends CCComp {
this.addDebuff(dbuffConf);
}
}
// 重新计算所有属性
this.recalculateAttrs();
}
// ==================== BUFF管ç<C2A1>† ====================
/**
* 添加 buff 效果
* @param buffConf buff 配置 (来自 SkillSet.BuffConf heroSet.buff)
* 添加 buff 效果(智能覆盖)
* @param buffConf buff é…<EFBFBD>ç½® (æ<>¥è‡ª SkillSet.BuffConf ï¿?heroSet.buff)
*
* 智能覆盖规则�
* 1. 值æ´å°<C3A5>:ä¸<C3A4>æ·»ï¿?
* 2. 值ç¸å<C2B8>Œä¸”都是临时:å<C5A1> åŠ æ—¶ï¿?
* 3. 值更大:更新为新值(临时则更新值和时间�
*/
addBuff(buffConf: BuffConf) {
// 基于类型和持续时间分类存储
if (buffConf.BType === BType.VALUE) {
// 数值型 buff
if (buffConf.buC === 0) {
// 持久型
this.BUFF_V.push({...buffConf});
const isValue = buffConf.BType === BType.VALUE;
const isPermanent = buffConf.time === 0;
const attrIndex = buffConf.buff;
// æ ¹æ<EFBFBD>®ç±»åžé€‰æ©å¯¹åº”ï¿?buff å­—å…¸
const permanentBuffs = isValue ? this.BUFF_V : this.BUFF_R;
const temporaryBuffs = isValue ? this.BUFFS_V : this.BUFFS_R;
if (isPermanent) {
// 添加æŒ<C3A6>ä¹…ï¿?buff
const existing = permanentBuffs[attrIndex];
if (existing) {
// 值æ´å°<C3A5>,ä¸<C3A4>æ·»ï¿?
if (buffConf.value <= existing.value) {
return;
}
// 值更大,更新
existing.value = buffConf.value;
} else {
// 临时型 - 添加剩余时间属性
this.BUFFS_V.push({
...buffConf,
remainTime: buffConf.buC
});
// 没有å<EFBFBD>Œç±»åžï¼Œç´æŽ¥æ·»åŠ 
permanentBuffs[attrIndex] = { value: buffConf.value };
}
} else {
// 百分比型 buff
if (buffConf.buC === 0) {
// 持久型
this.BUFF_R.push({...buffConf});
// 添加临时�buff
const existing = temporaryBuffs[attrIndex];
if (existing) {
if (buffConf.value < existing.value) {
// 值æ´å°<C3A5>,ä¸<C3A4>æ·»ï¿?
return;
} else if (buffConf.value === existing.value) {
// 值ç¸å<C2B8>Œï¼Œå<C592> åŠ æ—¶é—´
existing.remainTime += buffConf.time;
return; // æ—¶é—´å<C2B4> åŠ ä¸<C3A4>需è¦<C3A8>é‡<C3A9>算属ï¿?
} else {
// 值更大,更新值和时间
existing.value = buffConf.value;
existing.remainTime = buffConf.time;
}
} else {
// 临时型 - 添加剩余时间属性
this.BUFFS_R.push({
...buffConf,
remainTime: buffConf.buC
});
// 没有å<EFBFBD>Œç±»åžï¼Œç´æŽ¥æ·»åŠ 
temporaryBuffs[attrIndex] = {
value: buffConf.value,
remainTime: buffConf.time
};
}
}
// 立即重新计算属性
this.recalculateAttrs();
// å<>ªé‡<C3A9>æ°è®¡ç®—å<E28094>—å½±å“<C3A5>的属ï¿?
this.recalculateSingleAttr(buffConf.buff);
}
// ==================== DEBUFF管ç<C2A1>† ====================
/**
* 添加 debuff 效果
* @param dbuffConf debuff 配置 (来自 SkillSet.DbuffConf heroSet.debuff)
* 添加 debuff 效果(智能覆盖)
* @param dbuffConf debuff é…<EFBFBD>ç½® (æ<>¥è‡ª SkillSet.DbuffConf ï¿?heroSet.debuff)
*
* 支持两种 debuff
* 1. 属性型 debuff直接修改属性值有对应的 Attrs
* 支æŒ<EFBFBD>两ç§<EFBFBD> debuffï¿?
* 1. 属性型 debuffï¼šç´æŽ¥ä¿®æ”¹å±žæ€§å€¼ï¼ˆæœ‰å¯¹åº”çš„ Attrsï¿?
* 2. 状æ€<C3A6>åž debuff:å<C5A1>ªç¼“存状æ€<C3A6>(无对应的 Attrs,用于状æ€<C3A6>检查)
*
* 智能覆盖规则�
* 1. 值æ´å°<C3A5>:ä¸<C3A4>æ·»ï¿?
* 2. 值ç¸å<C2B8>Œä¸”都是临时:å<C5A1> åŠ æ—¶ï¿?
* 3. 值更大:更新为新值(临时则更新值和时间�
*/
addDebuff(dbuffConf: DbuffConf) {
// 获取 debuff 对应的属性字段
// 获å<EFBFBD> debuff 对应的属性字ï¿?
// attrField = -1 表示状æ€<C3A6>ç±» debuff(å<CB86>ªç¼“存,ä¸<C3A4>修改属性)
// attrField >= 0 表示属性类 debuff(会修改属性)
const attrField = getAttrFieldFromDebuff(dbuffConf.debuff);
// 基于类型和持续时间分类存储
if (dbuffConf.BType === BType.VALUE) {
// 数值型 debuff
if (dbuffConf.deC === 0) {
// 持久型
this.DBUFF_V.push({
...dbuffConf,
attrField: attrField
});
const isValue = dbuffConf.BType === BType.VALUE;
const isPermanent = dbuffConf.time === 0;
// æ ¹æ<C2B9>®ç±»åžé€‰æ©å¯¹åº”ï¿?debuff å­—å…¸
const permanentDebuffs = isValue ? this.DBUFF_V : this.DBUFF_R;
const temporaryDebuffs = isValue ? this.DBUFFS_V : this.DBUFFS_R;
// 状æ€<C3A6>ç±» debuff 使用 debuff 类型作为 key,属性类 debuff 使用 attrField 作为 key
const key = attrField >= 0 ? attrField : dbuffConf.debuff;
if (isPermanent) {
// 添加æŒ<C3A6>ä¹…ï¿?debuff
const existing = permanentDebuffs[key];
if (existing) {
// 值æ´å°<C3A5>,ä¸<C3A4>æ·»ï¿?
if (dbuffConf.value <= existing.value) {
return;
}
// 值更大,更新
existing.value = dbuffConf.value;
} else {
// 临时型 - 添加剩余时间属性
this.DBUFFS_V.push({
...dbuffConf,
attrField: attrField,
remainTime: dbuffConf.deC
});
// 没有å<EFBFBD>Œç±»åžï¼Œç´æŽ¥æ·»åŠ 
permanentDebuffs[key] = { value: dbuffConf.value };
}
} else {
// 百分比型 debuff
if (dbuffConf.deC === 0) {
// 持久型
this.DBUFF_R.push({
...dbuffConf,
attrField: attrField
});
// 添加临时�debuff
const existing = temporaryDebuffs[key];
if (existing) {
if (dbuffConf.value < existing.value) {
// 值æ´å°<C3A5>,ä¸<C3A4>æ·»ï¿?
return;
} else if (dbuffConf.value === existing.value) {
// 值ç¸å<C2B8>Œï¼Œå<C592> åŠ æ—¶é—´
existing.remainTime += dbuffConf.time;
return; // æ—¶é—´å<C2B4> åŠ ä¸<C3A4>需è¦<C3A8>é‡<C3A9>算属ï¿?
} else {
// 值更大,更新值和时间
existing.value = dbuffConf.value;
existing.remainTime = dbuffConf.time;
}
} else {
// 临时型 - 添加剩余时间属性
this.DBUFFS_R.push({
...dbuffConf,
attrField: attrField,
remainTime: dbuffConf.deC
});
// 没有å<EFBFBD>Œç±»åžï¼Œç´æŽ¥æ·»åŠ 
temporaryDebuffs[key] = {
value: dbuffConf.value,
remainTime: dbuffConf.time
};
}
}
// 立即重新计算属性
this.recalculateAttrs();
}
// ==================== 属性计算系统 ====================
/**
* 重新计算所有角色属性
* 基于基础属性 + 所有有效的 buff/debuff 计算
* 注意某些属性有初始值HP_MAX, MP_MAX, DEF, AP, MAP
*/
recalculateAttrs() {
// 1. 重置为基础值
this.Attrs[Attrs.HP_MAX] = this.base_hp;
this.Attrs[Attrs.MP_MAX] = this.base_mp;
this.Attrs[Attrs.DEF] = this.base_def;
this.Attrs[Attrs.AP] = this.base_ap;
this.Attrs[Attrs.MAP] = this.base_map;
this.Attrs[Attrs.SPEED] = this.base_speed;
this.Attrs[Attrs.SHIELD_MAX] = 0; // 护盾默认为 0
// 2. 初始化其他属性(无初始值的)
let length = Object.keys(this.Attrs).length;
for (let i = 0; i < length; i++) {
if (!(i in this.Attrs) ||
(i !== Attrs.HP_MAX && i !== Attrs.MP_MAX && i !== Attrs.DEF &&
i !== Attrs.AP && i !== Attrs.MAP && i !== Attrs.SHIELD_MAX&&13 && i !== Attrs.SPEED)) {
this.Attrs[i] = 0;
}
}
// 3. 应用数值型 buff (持久 + 临时)
this.applyValueBuffs();
// 4. 应用百分比型 buff (持久 + 临时)
this.applyRatioBuffs();
// 5. 应用数值型 debuff (持久 + 临时)
this.applyValueDebuffs();
// 6. 应用百分比型 debuff (持久 + 临时)
this.applyRatioDebuffs();
// 7. 确保关键属性不为负数
this.clampAttrs();
}
/**
* 应用数值型 buff
*/
private applyValueBuffs() {
// 持久型 buff
for (const buff of this.BUFF_V) {
if (buff.buff !== undefined) {
this.Attrs[buff.buff] += buff.buV;
}
}
// 临时型 buff
for (const buff of this.BUFFS_V) {
if (buff.buff !== undefined) {
this.Attrs[buff.buff] += buff.buV;
}
// å<>ªé‡<C3A9>æ°è®¡ç®—å<E28094>—å½±å“<C3A5>的属性(状æ€<C3A6>ç±» debuff ä¸<C3A4>需è¦<C3A8>计算)
if (attrField >= 0) {
this.recalculateSingleAttr(attrField);
}
}
// ==================== 属性计算系�====================
/**
* 应用百分比型 buff
* 百分比型 buff 是基于基础属性的百分比增加
* é‡<EFBFBD>æ°è®¡ç®—å<EFBFBD>•个属�?
* @param attrIndex 属性索�
*/
private applyRatioBuffs() {
// 获取基础值映射
const baseValues: Record<number, number> = {};
baseValues[Attrs.HP_MAX] = this.base_hp;
baseValues[Attrs.MP_MAX] = this.base_mp;
baseValues[Attrs.DEF] = this.base_def;
baseValues[Attrs.AP] = this.base_ap;
baseValues[Attrs.MAP] = this.base_map;
baseValues[Attrs.SPEED] = this.base_speed;
private recalculateSingleAttr(attrIndex: number) {
// 1. é‡<C3A9>置为基础ï¿?
const baseValues: Record<number, number> = {
[Attrs.HP_MAX]: this.base_hp,
[Attrs.MP_MAX]: this.base_mp,
[Attrs.DEF]: this.base_def,
[Attrs.AP]: this.base_ap,
[Attrs.MAP]: this.base_map,
[Attrs.SPEED]: this.base_speed,
[Attrs.SHIELD_MAX]: 0
};
this.Attrs[attrIndex] = baseValues[attrIndex] !== undefined ? baseValues[attrIndex] : 0;
// 持久型 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));
}
// 2. 应用数值型 buff - 直接访问
if (this.BUFF_V[attrIndex]) {
this.Attrs[attrIndex] += this.BUFF_V[attrIndex].value;
}
if (this.BUFFS_V[attrIndex]) {
this.Attrs[attrIndex] += this.BUFFS_V[attrIndex].value;
}
// 临时型 buff
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));
}
// 3. 应用百分比型 buff - 直接访问
const baseVal = baseValues[attrIndex] !== undefined ? baseValues[attrIndex] : this.Attrs[attrIndex];
if (this.BUFF_R[attrIndex]) {
this.Attrs[attrIndex] += Math.floor(baseVal * (this.BUFF_R[attrIndex].value / 100));
}
if (this.BUFFS_R[attrIndex]) {
this.Attrs[attrIndex] += Math.floor(baseVal * (this.BUFFS_R[attrIndex].value / 100));
}
// 4. 应用数值型 debuff - 直接访问
if (this.DBUFF_V[attrIndex]) {
this.Attrs[attrIndex] -= this.DBUFF_V[attrIndex].value;
}
if (this.DBUFFS_V[attrIndex]) {
this.Attrs[attrIndex] -= this.DBUFFS_V[attrIndex].value;
}
// 5. 应用百分比型 debuff - 直接访问
if (this.DBUFF_R[attrIndex]) {
this.Attrs[attrIndex] -= Math.floor(baseVal * (this.DBUFF_R[attrIndex].value / 100));
}
if (this.DBUFFS_R[attrIndex]) {
this.Attrs[attrIndex] -= Math.floor(baseVal * (this.DBUFFS_R[attrIndex].value / 100));
}
// 6. ç¡®ä¿<C3A4>属性值å<C2BC>ˆï¿?
this.clampSingleAttr(attrIndex);
}
/**
* 应用数值型 debuff
* ç¡®ä¿<EFBFBD>å<EFBFBD>•个属性值å<EFBFBD>ˆï¿?
*/
private applyValueDebuffs() {
// 持久型 debuff
for (const debuff of this.DBUFF_V) {
// 跳过状态类 debuffattrField === -1
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
this.Attrs[debuff.attrField] -= debuff.deV;
}
private clampSingleAttr(attrIndex: number) {
switch(attrIndex) {
case Attrs.HP_MAX:
case Attrs.MP_MAX:
this.Attrs[attrIndex] = Math.max(1, this.Attrs[attrIndex]);
break;
case Attrs.DEF:
case Attrs.AP:
case Attrs.MAP:
this.Attrs[attrIndex] = Math.max(0, this.Attrs[attrIndex]);
break;
case Attrs.CRITICAL:
case Attrs.DODGE:
case Attrs.HIT:
this.Attrs[attrIndex] = Math.max(0, Math.min(85, this.Attrs[attrIndex]));
break;
}
// 临时型 debuff
for (const debuff of this.DBUFFS_V) {
// 跳过状态类 debuffattrField === -1
if (debuff.attrField !== undefined && debuff.attrField >= 0) {
this.Attrs[debuff.attrField] -= debuff.deV;
}
}
}
/**
* 应用百分比型 debuff
* 百分比型 debuff 是基于基础属性的百分比减少
*/
private applyRatioDebuffs() {
// 获取基础值映射
const baseValues: Record<number, number> = {};
baseValues[Attrs.HP_MAX] = this.base_hp;
baseValues[Attrs.MP_MAX] = this.base_mp;
baseValues[Attrs.DEF] = this.base_def;
baseValues[Attrs.AP] = this.base_ap;
baseValues[Attrs.MAP] = this.base_map;
this.Attrs[Attrs.SPEED] = this.base_speed;
// 持久型 debuff
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];
this.Attrs[debuff.attrField] -= Math.floor(baseVal * (debuff.deV / 100));
}
}
// 临时型 debuff
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];
this.Attrs[debuff.attrField] -= Math.floor(baseVal * (debuff.deV / 100));
}
}
}
/**
* 确保关键属性不为负数
*/
private clampAttrs() {
// HP_MAX 最少 1
this.Attrs[Attrs.HP_MAX] = Math.max(1, this.Attrs[Attrs.HP_MAX]);
// MP_MAX 最少 1
this.Attrs[Attrs.MP_MAX] = Math.max(1, this.Attrs[Attrs.MP_MAX]);
// DEF 最少 0
this.Attrs[Attrs.DEF] = Math.max(0, this.Attrs[Attrs.DEF]);
// AP 最少 0
this.Attrs[Attrs.AP] = Math.max(0, this.Attrs[Attrs.AP]);
// MAP 最少 0
this.Attrs[Attrs.MAP] = Math.max(0, this.Attrs[Attrs.MAP]);
// 百分比属性限制在 0-100 之间
this.Attrs[Attrs.CRITICAL] = Math.max(0, Math.min(85, this.Attrs[Attrs.CRITICAL]));
this.Attrs[Attrs.DODGE] = Math.max(0, Math.min(85, this.Attrs[Attrs.DODGE]));
this.Attrs[Attrs.HIT] = Math.max(0, Math.min(85, this.Attrs[Attrs.HIT]));
}
// ==================== 临时 BUFF/DEBUFF 更新 ====================
/**
* 更新临时 buff/debuff 的剩余时间
* 应在 update 中定期调用
* @param dt 时间差
* 更新临时 buff/debuff 的剩余时�
* 应在 update 中定期调�
* @param dt æ—¶é—´ï¿?
*/
updateTemporaryBuffsDebuffs(dt: number) {
let needRecalculate = false;
const affectedAttrs = new Set<number>();
// 更新临时型数值 buff
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 (const attrIndex in this.BUFFS_V) {
const buff = this.BUFFS_V[attrIndex];
buff.remainTime -= dt;
if (buff.remainTime <= 0) {
delete this.BUFFS_V[attrIndex];
affectedAttrs.add(parseInt(attrIndex));
}
}
// 更新临时型百分比 buff
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;
for (const attrIndex in this.BUFFS_R) {
const buff = this.BUFFS_R[attrIndex];
buff.remainTime -= dt;
if (buff.remainTime <= 0) {
delete this.BUFFS_R[attrIndex];
affectedAttrs.add(parseInt(attrIndex));
}
}
// 更新临时型数值 debuff
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 (const key in this.DBUFFS_V) {
const debuff = this.DBUFFS_V[key];
debuff.remainTime -= dt;
if (debuff.remainTime <= 0) {
delete this.DBUFFS_V[key];
affectedAttrs.add(parseInt(key));
}
}
// 更新临时型百分比 debuff
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;
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];
affectedAttrs.add(parseInt(key));
}
}
// 如果有 buff/debuff 过期,重新计算属性
if (needRecalculate) {
this.recalculateAttrs();
}
// å<EFBFBD>ªé‡<EFBFBD>æ°è®¡ç®—å<EFBFBD>—å½±å“<EFBFBD>的属ï¿?
affectedAttrs.forEach(attrIndex => {
this.recalculateSingleAttr(attrIndex);
});
}
public isStun() {
return this.DBUFF_V.some(d => d.debuff === DBuff.STUN)
return this.DBUFF_V[DBuff.STUN] !== undefined || this.DBUFFS_V[DBuff.STUN] !== undefined
}
public isFrost() {
return this.DBUFF_V.some(d => d.debuff === DBuff.FROST)
return this.DBUFF_V[DBuff.FROST] !== undefined || this.DBUFFS_V[DBuff.FROST] !== undefined
}
update(dt: number){
@@ -538,7 +475,7 @@ export class HeroViewComp extends CCComp {
get isActive() {
return this.ent.has(HeroViewComp) && this.node?.isValid;
}
//状态切换
//状æ€<EFBFBD>切ï¿?
status_change(type:string){
this.status=type
if(type == "idle"){
@@ -806,7 +743,7 @@ export class HeroViewComp extends CCComp {
this.showDamageImmediate(damageInfo.damage, damageInfo.isCrit,damageInfo.anm);
// 设置延时处理下一个伤害
// 设置延时处ç<EFBFBD>†ä¸ä¸€ä¸ªä¼¤ï¿?
this.scheduleOnce(() => {
this.isProcessingDamage = false;
}, this.damageInterval);
@@ -820,10 +757,10 @@ export class HeroViewComp extends CCComp {
this.atked_count++;
if (isCrit) {
this.BUFFCOMP.hp_tip(TooltipTypes.crit, damage.toFixed(0), damage);
// //console.log("暴击伤害:" + damage);
// //console.log("暴击伤害� + damage);
} else {
this.BUFFCOMP.hp_tip(TooltipTypes.life, damage.toFixed(0), damage);
// //console.log("普通伤害:" + damage);
}
}
}
}