refactor(skillSet): 基本功完成 新buff系统 优化DBuff与Attrs映射及转换逻辑
- 规范化DBuff的枚举命名,修正属性对应关系 - 统一DBuff与Attrs的双向映射,通过TransformBuffs函数处理转换 - 移除旧的getAttrFieldFromDebuff方法,改用更灵活的映射数组 - 更新Attrs枚举,增加被易伤、防护盾等新属性 - 重新调整AttrsType映射,保证属性类型一致性 refactor(hero): 重构Hero和Monster初始化属性及buff系统 - Hero初始化时完善基础属性赋值,新增基础移动速度与攻击距离 - Hero使用initAttrs替代initBuffsDebuffs,重构buff/debuff初始化流程 - Monster初始化简化,统一按Hero写法初始化基础属性和Attrs - 实现buff/debuff属性智能覆盖与叠加时长的改进逻辑 - 属性计算改用统一逻辑,支持数值型和百分比型准确计算 - 增加属性值范围限制,确保部分属性在合理区间内 refactor(heroViewComp): 优化buff/debuff管理及状态判断 - 统一buff和debuff的持久与临时管理字典及更新方法 - 优化临时buff/debuff的更新时间处理,自动触发属性重新计算 - 提供isStun和isFrost接口简化眩晕、冰冻状态判断 - 规范注释及代码格式,提升可读性和维护性 refactor(skillConComp): 优化眩晕与冰冻状态判断逻辑 - 移除遍历判断,改用HeroViewComp的isStun和isFrost方法 - 简化技能冷却更新逻辑,提升性能 chore(heroSet): 添加AttrSet枚举定义属性最大值限制 docs(rogueConfig): 更新说明文档中的属性枚举定义说明 - 将属性增强枚举由BuffAttr修改为Attrs,以保持一致性
This commit is contained in:
@@ -5,36 +5,36 @@ 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, getAttrFieldFromDebuff } from "../common/config/SkillSet";
|
||||
import { Attrs, DBuff, SkillSet, BType, BuffConf, DbuffConf, TransformBuffs, AttrsType } 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 { HeroInfo, HeroUpSet } from "../common/config/heroSet";
|
||||
import { AttrSet, HeroInfo, HeroUpSet } from "../common/config/heroSet";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* ==================== BUFF 系统使用说明 ====================
|
||||
*
|
||||
* 1. 系统架构<EFBFBD><EFBFBD>?
|
||||
* - BUFF_V/BUFFS_V: 数值型 buff(持<EFBFBD><EFBFBD>?临时<E4B8B4><E697B6>?
|
||||
* - BUFF_R/BUFFS_R: 百分比型 buff(持<EFBFBD><EFBFBD>?临时<E4B8B4><E697B6>?
|
||||
* - DBUFF_V/DBUFFS_V: 数值型 debuff(持<EFBFBD><EFBFBD>?临时<E4B8B4><E697B6>?
|
||||
* - DBUFF_R/DBUFFS_R: 百分比型 debuff(持<EFBFBD><EFBFBD>?临时<E4B8B4><E697B6>?
|
||||
* 1. 系统架构
|
||||
* - BUFF_V/BUFFS_V: 数值型 buff(持临时
|
||||
* - BUFF_R/BUFFS_R: 百分比型 buff(持临时
|
||||
* - DBUFF_V/DBUFFS_V: 数值型 debuff(持临时
|
||||
* - DBUFF_R/DBUFFS_R: 百分比型 debuff(持临时
|
||||
*
|
||||
* 2. 智能覆盖规则<EFBFBD><EFBFBD>?
|
||||
* 2. 智能覆盖规则
|
||||
* - 值更小:不添加(弱效果不覆盖强效果)
|
||||
* - 值相同且临时:叠加时<EFBFBD><EFBFBD>?
|
||||
* - 值更大:更新为新值(临时则更新值和时间<EFBFBD><EFBFBD>?
|
||||
* - 值相同且临时:叠加时
|
||||
* - 值更大:更新为新值(临时则更新值和时间
|
||||
*
|
||||
* 3. 性能优化<EFBFBD><EFBFBD>?
|
||||
* - 增量计算:添<EFBFBD><EFBFBD>?删除时只重算受影响的属<EFBFBD>?
|
||||
* - 批量计算:initBuffsDebuffs() 中使<EFBFBD><EFBFBD>?recalculateAttrs() 一次性计算所<EFBFBD><EFBFBD>?
|
||||
* 3. 性能优化
|
||||
* - 增量计算:添删除时只重算受影响的属
|
||||
* - 批量计算:initBuffsDebuffs() 中使recalculateAttrs() 一次性计算所
|
||||
*/
|
||||
/** 角色显示组件 */
|
||||
@ccclass('HeroViewComp') // 定义<EFBFBD><EFBFBD>?Cocos Creator 组件
|
||||
@ecs.register('HeroView', false) // 定义<EFBFBD><EFBFBD>?ECS 组件
|
||||
@ccclass('HeroViewComp') // 定义Cocos Creator 组件
|
||||
@ecs.register('HeroView', false) // 定义ECS 组件
|
||||
export class HeroViewComp extends CCComp {
|
||||
BUFFCOMP:BuffComp=null!
|
||||
as: HeroSpine = null!
|
||||
@@ -43,7 +43,7 @@ export class HeroViewComp extends CCComp {
|
||||
hero_name : string = "hero";
|
||||
lv:number =1;
|
||||
scale: number = 1; /** 角色阵营 1:hero -1 :mon */
|
||||
type: number = 0; /**角色类型 0近战-需要贴<EFBFBD><EFBFBD>?1远程-保持距离 2辅助 */
|
||||
type: number = 0; /**角色类型 0近战-需要贴1远程-保持距离 2辅助 */
|
||||
fac:number=0; //阵营 0:hero 1:monster
|
||||
box_group:number = BoxSet.HERO;
|
||||
is_dead:boolean = false; //是否摧毁
|
||||
@@ -58,27 +58,27 @@ export class HeroViewComp extends CCComp {
|
||||
is_kalami:boolean =false;
|
||||
|
||||
mp: number = 100;
|
||||
hp: number = 100; /** 血<EFBFBD><EFBFBD>?*/
|
||||
shield:number=0; //当前护甲<EFBFBD><EFBFBD>?
|
||||
/** 基础属<EFBFBD>?有初始值的基础属<EFBFBD>?后续Attrs 属性计算时用到*/
|
||||
base_ap: number = 0; //基础攻击<EFBFBD><EFBFBD>?
|
||||
hp: number = 100; /** 血*/
|
||||
shield:number=0; //当前护甲
|
||||
/** 基础属有初始值的基础属后续Attrs 属性计算时用到*/
|
||||
base_ap: number = 0; //基础攻击
|
||||
base_map: number = 0;
|
||||
base_def: number = 5;
|
||||
base_hp: number = 100;
|
||||
base_mp: number = 100;
|
||||
base_speed: number = 100; /** 角色移动速度 */
|
||||
|
||||
base_dis: number = 100;
|
||||
Attrs:any=[]
|
||||
// Buff/Debuff 字典结构,通过属性索引直接访<EFBFBD><EFBFBD>?
|
||||
// Buff/Debuff 字典结构,通过属性索引直接访
|
||||
// 结构: { [attrIndex: number]: { value: number, remainTime?: number } }
|
||||
DBUFF_V: Record<number, {value: number}> = {} // 持久型数<EFBFBD><EFBFBD>?debuff
|
||||
DBUFF_V: Record<number, {value: number}> = {} // 持久型数debuff
|
||||
DBUFF_R: Record<number, {value: number}> = {} // 持久型百分比 debuff
|
||||
BUFF_V: Record<number, {value: number}> = {} // 持久型数<EFBFBD><EFBFBD>?buff
|
||||
BUFF_V: Record<number, {value: number}> = {} // 持久型数buff
|
||||
BUFF_R: Record<number, {value: number}> = {} // 持久型百分比 buff
|
||||
|
||||
DBUFFS_V: Record<number, {value: number, remainTime: number}> = {} // 临时型数<EFBFBD><EFBFBD>?debuff
|
||||
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}> = {} // 临时型数<EFBFBD><EFBFBD>?buff
|
||||
BUFFS_V: Record<number, {value: number, remainTime: number}> = {} // 临时型数buff
|
||||
BUFFS_R: Record<number, {value: number, remainTime: number}> = {} // 临时型百分比 buff
|
||||
|
||||
atk_count: number = 0;
|
||||
@@ -102,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; // 先禁<EFBFBD><EFBFBD>?
|
||||
if (collider) collider.enabled = true; // 先禁
|
||||
},1)
|
||||
// let anm = this.node.getChildByName("anm")
|
||||
// anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8);
|
||||
@@ -118,17 +118,17 @@ 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)
|
||||
}
|
||||
/* 显示角色血<EFBFBD><EFBFBD>?*/
|
||||
/* 显示角色血*/
|
||||
this.node.getChildByName("top").getChildByName("hp").active = true;
|
||||
this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
|
||||
}
|
||||
|
||||
// ==================== BUFF系统初始<EFBFBD><EFBFBD>?====================
|
||||
// ==================== BUFF系统初始====================
|
||||
/**
|
||||
* 初始化角色的 buff <EFBFBD><EFBFBD>?debuff
|
||||
* <EFBFBD><EFBFBD>?HeroInfo 读取初始配置,建立属性系<EFBFBD><EFBFBD>?
|
||||
* 初始化角色的 buff debuff
|
||||
* HeroInfo 读取初始配置,建立属性系
|
||||
*/
|
||||
initBuffsDebuffs() {
|
||||
initAttrs() {
|
||||
// 清空现有 buff/debuff
|
||||
this.BUFF_V = {};
|
||||
this.BUFFS_V = {};
|
||||
@@ -143,19 +143,28 @@ export class HeroViewComp extends CCComp {
|
||||
if (!heroInfo) return;
|
||||
|
||||
|
||||
// 1. 重置为基础<EFBFBD><EFBFBD>?
|
||||
// 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; // 护盾默认<E9BB98><E8AEA4>?0
|
||||
this.Attrs[Attrs.DIS] = this.base_dis;
|
||||
|
||||
// 2. 初始化其他属性(无初始值的<EFBFBD><EFBFBD>?
|
||||
// 2. 初始化其他属性(无初始值的
|
||||
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) {
|
||||
if(
|
||||
attrIndex !== Attrs.HP_MAX &&
|
||||
attrIndex !== Attrs.MP_MAX&&
|
||||
attrIndex !== Attrs.DEF &&
|
||||
attrIndex !== Attrs.AP &&
|
||||
attrIndex !== Attrs.MAP &&
|
||||
attrIndex !== Attrs.SPEED &&
|
||||
attrIndex !== Attrs.DIS
|
||||
|
||||
) {
|
||||
this.Attrs[attrIndex] = 0;
|
||||
}
|
||||
}
|
||||
@@ -165,7 +174,6 @@ export class HeroViewComp extends CCComp {
|
||||
this.addBuff(buffConf);
|
||||
}
|
||||
}
|
||||
|
||||
// 加载初始 debuff
|
||||
if (heroInfo.debuff && heroInfo.debuff.length > 0) {
|
||||
for (const dbuffConf of heroInfo.debuff) {
|
||||
@@ -176,27 +184,27 @@ export class HeroViewComp extends CCComp {
|
||||
// ==================== BUFF管理 ====================
|
||||
/**
|
||||
* 添加 buff 效果(智能覆盖)
|
||||
* @param buffConf buff 配置 (来自 SkillSet.BuffConf <EFBFBD><EFBFBD>?heroSet.buff)
|
||||
* @param buffConf buff 配置 (来自 SkillSet.BuffConf heroSet.buff)
|
||||
*
|
||||
* 智能覆盖规则<EFBFBD><EFBFBD>?
|
||||
* 1. 值更小:不添<EFBFBD><EFBFBD>?
|
||||
* 2. 值相同且都是临时:叠加时<EFBFBD><EFBFBD>?
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间<EFBFBD><EFBFBD>?
|
||||
* 智能覆盖规则
|
||||
* 1. 值更小:不添
|
||||
* 2. 值相同且都是临时:叠加时
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间
|
||||
*/
|
||||
addBuff(buffConf: BuffConf) {
|
||||
const isValue = buffConf.BType === BType.VALUE;
|
||||
const isPermanent = buffConf.time === 0;
|
||||
const attrIndex = buffConf.buff;
|
||||
|
||||
// 根据类型选择对应<EFBFBD><EFBFBD>?buff 字典
|
||||
// 根据类型选择对应buff 字典
|
||||
const permanentBuffs = isValue ? this.BUFF_V : this.BUFF_R;
|
||||
const temporaryBuffs = isValue ? this.BUFFS_V : this.BUFFS_R;
|
||||
|
||||
if (isPermanent) {
|
||||
// 添加持久<EFBFBD><EFBFBD>?buff
|
||||
// 添加持久buff
|
||||
const existing = permanentBuffs[attrIndex];
|
||||
if (existing) {
|
||||
// 值更小,不添<EFBFBD><EFBFBD>?
|
||||
// 值更小,不添
|
||||
if (buffConf.value <= existing.value) {
|
||||
return;
|
||||
}
|
||||
@@ -207,16 +215,16 @@ export class HeroViewComp extends CCComp {
|
||||
permanentBuffs[attrIndex] = { value: buffConf.value };
|
||||
}
|
||||
} else {
|
||||
// 添加临时<EFBFBD><EFBFBD>?buff
|
||||
// 添加临时buff
|
||||
const existing = temporaryBuffs[attrIndex];
|
||||
if (existing) {
|
||||
if (buffConf.value < existing.value) {
|
||||
// 值更小,不添<EFBFBD><EFBFBD>?
|
||||
// 值更小,不添
|
||||
return;
|
||||
} else if (buffConf.value === existing.value) {
|
||||
// 值相同,叠加时间
|
||||
existing.remainTime += buffConf.time;
|
||||
return; // 时间叠加不需要重算属<EFBFBD><EFBFBD>?
|
||||
return; // 时间叠加不需要重算属
|
||||
} else {
|
||||
// 值更大,更新值和时间
|
||||
existing.value = buffConf.value;
|
||||
@@ -231,44 +239,40 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
// 只重新计算受影响的属<E79A84><E5B19E>?
|
||||
this.recalculateSingleAttr(buffConf.buff);
|
||||
}
|
||||
|
||||
// ==================== DEBUFF管理 ====================
|
||||
/**
|
||||
* 添加 debuff 效果(智能覆盖)
|
||||
* @param dbuffConf debuff 配置 (来自 SkillSet.DbuffConf <EFBFBD><EFBFBD>?heroSet.debuff)
|
||||
* @param dbuffConf debuff 配置 (来自 SkillSet.DbuffConf heroSet.debuff)
|
||||
*
|
||||
* 支持两种 debuff<EFBFBD><EFBFBD>?
|
||||
* 1. 属性型 debuff:直接修改属性值(有对应的 Attrs<EFBFBD><EFBFBD>?
|
||||
* 支持两种 debuff
|
||||
* 1. 属性型 debuff:直接修改属性值(有对应的 Attrs
|
||||
* 2. 状态型 debuff:只缓存状态(无对应的 Attrs,用于状态检查)
|
||||
*
|
||||
* 智能覆盖规则<EFBFBD><EFBFBD>?
|
||||
* 1. 值更小:不添<EFBFBD><EFBFBD>?
|
||||
* 2. 值相同且都是临时:叠加时<EFBFBD><EFBFBD>?
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间<EFBFBD><EFBFBD>?
|
||||
* 智能覆盖规则
|
||||
* 1. 值更小:不添
|
||||
* 2. 值相同且都是临时:叠加时
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间
|
||||
*/
|
||||
addDebuff(dbuffConf: DbuffConf) {
|
||||
// 获取 debuff 对应的属性字<EFBFBD><EFBFBD>?
|
||||
// attrField = -1 表示状态类 debuff(只缓存,不修改属性)
|
||||
// attrField >= 0 表示属性类 debuff(会修改属性)
|
||||
const attrField = getAttrFieldFromDebuff(dbuffConf.debuff);
|
||||
// 获取 debuff 对应的属性字
|
||||
|
||||
const isValue = dbuffConf.BType === BType.VALUE;
|
||||
const isPermanent = dbuffConf.time === 0;
|
||||
|
||||
// 根据类型选择对应<EFBFBD><EFBFBD>?debuff 字典
|
||||
// 根据类型选择对应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 = attrField >= 0 ? attrField : dbuffConf.debuff;
|
||||
const key = dbuffConf.debuff;
|
||||
|
||||
if (isPermanent) {
|
||||
// 添加持久<EFBFBD><EFBFBD>?debuff
|
||||
// 添加持久debuff
|
||||
const existing = permanentDebuffs[key];
|
||||
if (existing) {
|
||||
// 值更小,不添<EFBFBD><EFBFBD>?
|
||||
// 值更小,不添
|
||||
if (dbuffConf.value <= existing.value) {
|
||||
return;
|
||||
}
|
||||
@@ -279,16 +283,16 @@ export class HeroViewComp extends CCComp {
|
||||
permanentDebuffs[key] = { value: dbuffConf.value };
|
||||
}
|
||||
} else {
|
||||
// 添加临时<EFBFBD><EFBFBD>?debuff
|
||||
// 添加临时debuff
|
||||
const existing = temporaryDebuffs[key];
|
||||
if (existing) {
|
||||
if (dbuffConf.value < existing.value) {
|
||||
// 值更小,不添<EFBFBD><EFBFBD>?
|
||||
// 值更小,不添
|
||||
return;
|
||||
} else if (dbuffConf.value === existing.value) {
|
||||
// 值相同,叠加时间
|
||||
existing.remainTime += dbuffConf.time;
|
||||
return; // 时间叠加不需要重算属<EFBFBD><EFBFBD>?
|
||||
return; // 时间叠加不需要重算属
|
||||
} else {
|
||||
// 值更大,更新值和时间
|
||||
existing.value = dbuffConf.value;
|
||||
@@ -302,20 +306,24 @@ export class HeroViewComp extends CCComp {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let attrField = TransformBuffs(dbuffConf.debuff,true);
|
||||
// 只重新计算受影响的属性(状态类 debuff 不需要计算)
|
||||
if (attrField >= 0) {
|
||||
if (attrField > 0 ) {
|
||||
this.recalculateSingleAttr(attrField);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 属性计算系<EFBFBD><EFBFBD>?====================
|
||||
// ==================== 属性计算系====================
|
||||
/**
|
||||
* 重新计算单个属<EFBFBD>?
|
||||
* @param attrIndex 属性索<EFBFBD><EFBFBD>?
|
||||
* 重新计算单个属性
|
||||
* @param attrIndex 属性索引
|
||||
*
|
||||
* 计算公式:
|
||||
* - 数值型属性:最终值 = (基础值 + 数值型buff - 数值型debuff) × (1 + 百分比buff/100 - 百分比debuff/100)
|
||||
* - 百分比型属性:最终值 = 基础值 + 数值型buff - 数值型debuff + 百分比buff - 百分比debuff
|
||||
*/
|
||||
private recalculateSingleAttr(attrIndex: number) {
|
||||
// 1. 重置为基础<EFBFBD><EFBFBD>?
|
||||
// 1. 获取基础值
|
||||
const baseValues: Record<number, number> = {
|
||||
[Attrs.HP_MAX]: this.base_hp,
|
||||
[Attrs.MP_MAX]: this.base_mp,
|
||||
@@ -326,46 +334,68 @@ export class HeroViewComp extends CCComp {
|
||||
[Attrs.SHIELD_MAX]: 0
|
||||
};
|
||||
|
||||
this.Attrs[attrIndex] = baseValues[attrIndex] !== undefined ? baseValues[attrIndex] : 0;
|
||||
const baseVal = baseValues[attrIndex] !== undefined ? baseValues[attrIndex] : 0;
|
||||
|
||||
// 2. 应用数值型 buff - 直接访问
|
||||
// 2. 收集所有数值型 buff/debuff
|
||||
let totalValue = baseVal;
|
||||
|
||||
// Buff:直接使用 Attrs 索引
|
||||
if (this.BUFF_V[attrIndex]) {
|
||||
this.Attrs[attrIndex] += this.BUFF_V[attrIndex].value;
|
||||
totalValue += this.BUFF_V[attrIndex].value;
|
||||
}
|
||||
if (this.BUFFS_V[attrIndex]) {
|
||||
this.Attrs[attrIndex] += this.BUFFS_V[attrIndex].value;
|
||||
totalValue += this.BUFFS_V[attrIndex].value;
|
||||
}
|
||||
|
||||
// 3. 应用百分比型 buff - 直接访问
|
||||
const baseVal = baseValues[attrIndex] !== undefined ? baseValues[attrIndex] : this.Attrs[attrIndex];
|
||||
|
||||
// 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; // 总百分比(可正可负)
|
||||
|
||||
// Buff:直接使用 Attrs 索引
|
||||
if (this.BUFF_R[attrIndex]) {
|
||||
this.Attrs[attrIndex] += Math.floor(baseVal * (this.BUFF_R[attrIndex].value / 100));
|
||||
totalRatio += this.BUFF_R[attrIndex].value;
|
||||
}
|
||||
if (this.BUFFS_R[attrIndex]) {
|
||||
this.Attrs[attrIndex] += Math.floor(baseVal * (this.BUFFS_R[attrIndex].value / 100));
|
||||
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;
|
||||
|
||||
if (isRatioAttr) {
|
||||
// 百分比型属性:直接加减
|
||||
this.Attrs[attrIndex] = totalValue + totalRatio;
|
||||
} else {
|
||||
// 数值型属性:(基础值+数值) × (1 + 百分比/100)
|
||||
this.Attrs[attrIndex] = Math.floor(totalValue * (1 + totalRatio / 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. 确保属性值合<E580BC><E59088>?
|
||||
// 5. 确保属性值合理
|
||||
this.clampSingleAttr(attrIndex);
|
||||
}
|
||||
/**
|
||||
* 确保单个属性值合<EFBFBD><EFBFBD>?
|
||||
* 确保单个属性值合
|
||||
*/
|
||||
private clampSingleAttr(attrIndex: number) {
|
||||
switch(attrIndex) {
|
||||
@@ -376,26 +406,25 @@ export class HeroViewComp extends CCComp {
|
||||
case Attrs.DEF:
|
||||
case Attrs.AP:
|
||||
case Attrs.MAP:
|
||||
this.Attrs[attrIndex] = Math.max(0, this.Attrs[attrIndex]);
|
||||
this.Attrs[attrIndex] = Math.max(1, 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]));
|
||||
this.Attrs[attrIndex] = Math.max(0, Math.min(AttrSet.ATTR_MAX, this.Attrs[attrIndex])); //AttrSet.ATTR_MAX =85
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 临时 BUFF/DEBUFF 更新 ====================
|
||||
/**
|
||||
* 更新临时 buff/debuff 的剩余时<EFBFBD><EFBFBD>?
|
||||
* 应在 update 中定期调<EFBFBD><EFBFBD>?
|
||||
* @param dt 时间<EFBFBD><EFBFBD>?
|
||||
* 更新临时 buff/debuff 的剩余时
|
||||
* 应在 update 中定期调
|
||||
* @param dt 时间
|
||||
*/
|
||||
updateTemporaryBuffsDebuffs(dt: number) {
|
||||
const affectedAttrs = new Set<number>();
|
||||
|
||||
// 更新临时型数<E59E8B><E695B0>?buff
|
||||
// 更新临时型数buff
|
||||
for (const attrIndex in this.BUFFS_V) {
|
||||
const buff = this.BUFFS_V[attrIndex];
|
||||
buff.remainTime -= dt;
|
||||
@@ -404,7 +433,6 @@ export class HeroViewComp extends CCComp {
|
||||
affectedAttrs.add(parseInt(attrIndex));
|
||||
}
|
||||
}
|
||||
|
||||
// 更新临时型百分比 buff
|
||||
for (const attrIndex in this.BUFFS_R) {
|
||||
const buff = this.BUFFS_R[attrIndex];
|
||||
@@ -415,13 +443,15 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新临时型数<EFBFBD><EFBFBD>?debuff
|
||||
// 更新临时型数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));
|
||||
const keyNum = parseInt(key);
|
||||
const attrField = TransformBuffs(keyNum,true)
|
||||
if(attrField > 0) affectedAttrs.add(attrField);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,21 +461,23 @@ export class HeroViewComp extends CCComp {
|
||||
debuff.remainTime -= dt;
|
||||
if (debuff.remainTime <= 0) {
|
||||
delete this.DBUFFS_R[key];
|
||||
affectedAttrs.add(parseInt(key));
|
||||
const keyNum = parseInt(key);
|
||||
const attrField = TransformBuffs(keyNum,true)
|
||||
if(attrField > 0) affectedAttrs.add(attrField);
|
||||
}
|
||||
}
|
||||
|
||||
// 只重新计算受影响的属<EFBFBD><EFBFBD>?
|
||||
// 只重新计算受影响的属
|
||||
affectedAttrs.forEach(attrIndex => {
|
||||
this.recalculateSingleAttr(attrIndex);
|
||||
});
|
||||
}
|
||||
|
||||
public isStun() {
|
||||
return this.DBUFF_V[DBuff.STUN] !== undefined || this.DBUFFS_V[DBuff.STUN] !== undefined
|
||||
this.DBUFFS_V[DBuff.STUN] !== undefined
|
||||
}
|
||||
public isFrost() {
|
||||
return this.DBUFF_V[DBuff.FROST] !== undefined || this.DBUFFS_V[DBuff.FROST] !== undefined
|
||||
this.DBUFFS_V[DBuff.FROST] !== undefined
|
||||
}
|
||||
|
||||
update(dt: number){
|
||||
@@ -475,7 +507,7 @@ export class HeroViewComp extends CCComp {
|
||||
get isActive() {
|
||||
return this.ent.has(HeroViewComp) && this.node?.isValid;
|
||||
}
|
||||
//状态切<EFBFBD><EFBFBD>?
|
||||
//状态切
|
||||
status_change(type:string){
|
||||
this.status=type
|
||||
if(type == "idle"){
|
||||
@@ -743,7 +775,7 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
this.showDamageImmediate(damageInfo.damage, damageInfo.isCrit,damageInfo.anm);
|
||||
|
||||
// 设置延时处理下一个伤<EFBFBD><EFBFBD>?
|
||||
// 设置延时处理下一个伤
|
||||
this.scheduleOnce(() => {
|
||||
this.isProcessingDamage = false;
|
||||
}, this.damageInterval);
|
||||
@@ -757,7 +789,7 @@ export class HeroViewComp extends CCComp {
|
||||
this.atked_count++;
|
||||
if (isCrit) {
|
||||
this.BUFFCOMP.hp_tip(TooltipTypes.crit, damage.toFixed(0), damage);
|
||||
// //console.log("暴击伤害<EFBFBD><EFBFBD>? + damage);
|
||||
// //console.log("暴击伤害 + damage);
|
||||
} else {
|
||||
this.BUFFCOMP.hp_tip(TooltipTypes.life, damage.toFixed(0), damage);
|
||||
// //console.log("普通伤害:" + damage);
|
||||
|
||||
Reference in New Issue
Block a user