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:
2025-10-17 22:02:23 +08:00
parent 94f83482fa
commit 2cdb25ac58
9 changed files with 280 additions and 276 deletions

View File

@@ -101,17 +101,18 @@ export enum DBuff {
SLOW = 2, //减速 - 对应Attrs.AS (攻击速度), BType.RATIO SLOW = 2, //减速 - 对应Attrs.AS (攻击速度), BType.RATIO
FROST = 3, //冰冻 - 对应Attrs.ICE_RES (冰冻抗性), BType.RATIO FROST = 3, //冰冻 - 对应Attrs.ICE_RES (冰冻抗性), BType.RATIO
BURN = 4, //易伤 - 对应Attrs.DEF/MDEF (防御/魔防), BType.RATIO, 默认次数是5, 技能配置的devC是额外次数 BURN = 4, //易伤 - 对应Attrs.DEF/MDEF (防御/魔防), BType.RATIO, 默认次数是5, 技能配置的devC是额外次数
DEAS = 5, //减速 - 对应Attrs.AS (攻击速度), BType.RATIO, 直接+技能cd AS = 5, //减速 - 对应Attrs.AS (攻击速度), BType.RATIO, 直接+技能cd
DEHP = 6, //减hp - 对应Attrs.HP_MAX (最大生命值), BType.RATIO HP_MAX = 6, //减hp - 对应Attrs.HP_MAX (最大生命值), BType.RATIO
DEAP = 7, //减atk - 对应Attrs.AP (攻击力), BType.RATIO AP = 7, //减atk - 对应Attrs.AP (攻击力), BType.RATIO
DEMGP = 8, //减魔法伤害 - 对应Attrs.MAP (魔法攻击力), BType.RATIO MGP = 8, //减魔法伤害 - 对应Attrs.MAP (魔法攻击力), BType.RATIO
BACK = 9, //击退概率 - 对应Attrs.KNOCKBACK (击退概率), BType.RATIO DEBACK = 9, //击退概率 - 对应Attrs.BACK (击退概率), BType.RATIO
CRITICAL = 10, //-暴击率 - 对应Attrs.CRITICAL (暴击率), BType.RATIO CRITICAL = 10, //-暴击率 - 对应Attrs.CRITICAL (暴击率), BType.RATIO
CRIT_DAMAGE = 11, //-暴击伤害 - 对应Attrs.CRITICAL_DMG (暴击伤害), BType.RATIO CRIT_DAMAGE = 11, //-暴击伤害 - 对应Attrs.CRITICAL_DMG (暴击伤害), BType.RATIO
DODGE = 12, //-闪避 - 对应Attrs.DODGE (闪避), BType.RATIO DODGE = 12, //-闪避 - 对应Attrs.DODGE (闪避), BType.RATIO
DBUFFUP=13, //edbuff效果提升 DBUFFUP=13, //edbuff效果提升
BUFF_DOWN = 14,// buff效果减弱 BUFF_DOWN = 14,// buff效果减弱
SPEED = 15, //移动速度下降 - 对应Attrs.MOVE_SPEED (移动速度), BType.RATIO SPEED = 15, //移动速度下降 - 对应Attrs.MOVE_SPEED (移动速度), BType.RATIO
DEBURN= 16, //被攻击带易伤
} }
@@ -131,19 +132,23 @@ export enum Attrs {
AS = 12, //攻击速度,直接减技能cd AS = 12, //攻击速度,直接减技能cd
REFLICT = 13, //反伤比率 REFLICT = 13, //反伤比率
LIFESTEAL = 14, //吸血比率 LIFESTEAL = 14, //吸血比率
KNOCKBACK = 15, //攻击带击退概率 BACK = 15, //攻击带击退概率
CON_RES = 16, //控制抗性 DEBACK = 16, //被攻击击退概率
ICE_RES = 17, //冰冻抗性 CON_RES = 17, //控制抗性
FIRE_RES = 18, //抗性 ICE_RES = 18, //冰冻抗性
WIND_RES = 19, //抗性 FIRE_RES = 19, //抗性
ICE_POWER = 20, //冰冻伤害效果提升 WIND_RES = 20, //风抗性
FIRE_POWER = 21,//伤害效果提升 ICE_POWER = 21, //冰冻伤害效果提升
WIND_POWER = 22,//伤害效果提升 FIRE_POWER = 22,//伤害效果提升
SHIELD_UP = 23, //护盾效果提升 WIND_POWER = 23,//风伤害效果提升
BUFF_UP = 24, //buff效果提升 BUFF_UP = 24, //buff效果提升
DBUFF_UP=25, //debuff效果提升 DBUFF_UP=25, //debuff效果提升
DIS=26, //攻击距离 DIS=26, //攻击距离
SPEED = 27, //移动速度加成,默认都是百分比 SPEED = 27, //移动速度加成,默认都是百分比
SHIELD_UP = 28, //护盾效果提升
BURN = 29, //攻击带易伤
DEBURN = 30, //被攻击易伤
} }
@@ -184,6 +189,8 @@ export const AttrsType: Record<Attrs, BType> = {
[Attrs.DEF]: BType.VALUE, // 防御 - 数值型 [Attrs.DEF]: BType.VALUE, // 防御 - 数值型
[Attrs.MDEF]: BType.VALUE, // 魔法防御 - 数值型 [Attrs.MDEF]: BType.VALUE, // 魔法防御 - 数值型
[Attrs.DIS]: BType.VALUE, // 攻击距离 - 数值型 [Attrs.DIS]: BType.VALUE, // 攻击距离 - 数值型
[Attrs.BURN]: BType.VALUE, // 易伤 - 数值型
[Attrs.DEBURN]: BType.VALUE, // 被攻击易伤 - 数值型
// ========== 百分比型属性 ========== // ========== 百分比型属性 ==========
[Attrs.CRITICAL]: BType.RATIO, // 暴击率 - 百分比型 [Attrs.CRITICAL]: BType.RATIO, // 暴击率 - 百分比型
@@ -194,7 +201,7 @@ export const AttrsType: Record<Attrs, BType> = {
[Attrs.AS]: BType.RATIO, // 攻击速度 - 百分比型 [Attrs.AS]: BType.RATIO, // 攻击速度 - 百分比型
[Attrs.REFLICT]: BType.RATIO, // 反伤比率 - 百分比型 [Attrs.REFLICT]: BType.RATIO, // 反伤比率 - 百分比型
[Attrs.LIFESTEAL]: BType.RATIO, // 吸血比率 - 百分比型 [Attrs.LIFESTEAL]: BType.RATIO, // 吸血比率 - 百分比型
[Attrs.KNOCKBACK]: BType.RATIO, // 击退概率 - 百分比型 [Attrs.BACK]: BType.RATIO, // 击退概率 - 百分比型
[Attrs.CON_RES]: BType.RATIO, // 控制抗性 - 百分比型 [Attrs.CON_RES]: BType.RATIO, // 控制抗性 - 百分比型
[Attrs.ICE_RES]: BType.RATIO, // 冰冻抗性 - 百分比型 [Attrs.ICE_RES]: BType.RATIO, // 冰冻抗性 - 百分比型
[Attrs.FIRE_RES]: BType.RATIO, // 火抗性 - 百分比型 [Attrs.FIRE_RES]: BType.RATIO, // 火抗性 - 百分比型
@@ -202,10 +209,11 @@ export const AttrsType: Record<Attrs, BType> = {
[Attrs.ICE_POWER]: BType.RATIO, // 冰冻伤害效果提升 - 百分比型 [Attrs.ICE_POWER]: BType.RATIO, // 冰冻伤害效果提升 - 百分比型
[Attrs.FIRE_POWER]: BType.RATIO, // 火伤害效果提升 - 百分比型 [Attrs.FIRE_POWER]: BType.RATIO, // 火伤害效果提升 - 百分比型
[Attrs.WIND_POWER]: BType.RATIO, // 风伤害效果提升 - 百分比型 [Attrs.WIND_POWER]: BType.RATIO, // 风伤害效果提升 - 百分比型
[Attrs.SHIELD_UP]: BType.RATIO, // 护盾效果提升 - 百分比型 [Attrs.DEBACK]:BType.RATIO,
[Attrs.BUFF_UP]: BType.RATIO, // buff效果提升 - 百分比型 [Attrs.BUFF_UP]: BType.RATIO, // buff效果提升 - 百分比型
[Attrs.DBUFF_UP]: BType.RATIO, // debuff效果提升 - 百分比型 [Attrs.DBUFF_UP]: BType.RATIO, // debuff效果提升 - 百分比型
[Attrs.SPEED]: BType.RATIO, // 移动速度加成 - 百分比型 [Attrs.SPEED]: BType.RATIO, // 移动速度加成 - 百分比型
[Attrs.SHIELD_UP]: BType.RATIO, // 护盾效果提升 - 百分比型
}; };
/** /**
@@ -227,61 +235,44 @@ export const getAttrType = (attrType: Attrs): BType => {
}; };
/** /**
* 获取 debuff 对应的属性字段 * DBuff 与 Attrs 的双向映射关系表
* @param debuffType DBuff 类型 * 格式:[DBuff, Attrs 或 -1状态类]
* @returns 对应的 Attrs 字段,如果是状态类 debuff只缓存返回 -1
*
* 扩展说明:
* 1. 普通 debuff返回 Attrs 值(会直接修改属性)
* 2. 状态类 debuff返回 -1只缓存不修改属性
*
* 新增 DBuff 时:
* - 如果需要修改属性,在 debuffAttrMap 中添加映射: [DBuff.NEW]: Attrs.ATTR
* - 如果只需缓存状态,在 stateDebuffSet 中添加: DBuff.NEW
*/ */
export const getAttrFieldFromDebuff = (debuffType: DBuff): number => { const DEBUFF_ATTR_MAP: [DBuff, number][] = [
// 状态类 debuff只需缓存不影响属性 [DBuff.STUN, -1], // 眩晕 - 状态类
const stateDebuffSet = new Set<DBuff>([ [DBuff.SLOW, Attrs.SPEED], // 减速 -> 速度
DBuff.STUN, [DBuff.FROST, -1], // 冰冻 - 状态类
DBuff.FROST, [DBuff.DEBURN, Attrs.DEBURN], // 被易伤 -> 被易伤
]); [DBuff.BURN, Attrs.BURN], // 易伤 -> 易伤效果
[DBuff.AS, Attrs.AS], // 减cd -> 攻击速度
[DBuff.HP_MAX, Attrs.HP_MAX], // 减hp -> 最大生命值
[DBuff.AP, Attrs.AP], // 减atk -> 攻击力
[DBuff.MGP, Attrs.MAP], // 减魔法 -> 魔法攻击力
[DBuff.DEBACK, Attrs.DEBACK], // 被击退 -> 被击退概率
[DBuff.CRITICAL, Attrs.CRITICAL], // -暴击率 -> 暴击率
[DBuff.CRIT_DAMAGE, Attrs.CRITICAL_DMG], // -暴击伤害 -> 暴击伤害
[DBuff.DODGE, Attrs.DODGE], // -闪避 -> 闪避
[DBuff.DBUFFUP, Attrs.DBUFF_UP], // debuff提升 -> debuff提升
[DBuff.BUFF_DOWN, Attrs.BUFF_UP], // buff减弱 -> buff效果
[DBuff.SPEED, Attrs.SPEED], // 移动速度下降 -> 移动速度
];
// 检查是否是状态类 debuff /**
if (stateDebuffSet.has(debuffType)) { * 双向转换DBuff ⇄ Attrs
return -1; // 表示只缓存,不影响属性 * @param key DBuff 或 Attrs 枚举值
* @param isDebuff true: key 是 DBuff, false: key 是 Attrs
* @returns 对应的转换值,未找到则返回 -1
*/
export const TransformBuffs = (key: number, isDebuff: boolean): number => {
if (isDebuff) {
// DBuff → Attrs
const found = DEBUFF_ATTR_MAP.find(([debuff]) => debuff === key);
return found ? found[1] : -1;
} else {
// Attrs → DBuff只返回第一个匹配
const found = DEBUFF_ATTR_MAP.find(([, attr]) => attr === key);
return found ? found[0] : -1;
} }
// ==================== 普通 Debuff 到 Attrs 的完整映射表 ====================
// 格式: [DBuff 类型]: Attrs 属性(会直接修改属性值)
// 注意:新增普通 debuff 时,在此添加映射关系即可
const debuffAttrMap: Record<DBuff, number> = {
[DBuff.STUN]: Attrs.CON_RES, // 眩晕 -> 控制抗性
[DBuff.SLOW]: Attrs.AS, // 减速 -> 攻击速度
[DBuff.FROST]: Attrs.ICE_RES, // 冰冻 -> 冰冻抗性
[DBuff.BURN]: Attrs.DEF, // 易伤 -> 防御
[DBuff.DEAS]: Attrs.AS, // 减cd -> 攻击速度
[DBuff.DEHP]: Attrs.HP_MAX, // 减hp -> 最大生命值
[DBuff.DEAP]: Attrs.AP, // 减atk -> 攻击力
[DBuff.DEMGP]: Attrs.MAP, // 减魔法 -> 魔法攻击力
[DBuff.BACK]: Attrs.KNOCKBACK, // 击退 -> 击退概率
[DBuff.CRITICAL]: Attrs.CRITICAL, // -暴击率 -> 暴击率
[DBuff.CRIT_DAMAGE]: Attrs.CRITICAL_DMG, // -暴击伤害 -> 暴击伤害
[DBuff.DODGE]: Attrs.DODGE, // -闪避 -> 闪避
[DBuff.DBUFFUP]: Attrs.DBUFF_UP, // debuff提升 -> debuff提升
[DBuff.BUFF_DOWN]: Attrs.BUFF_UP, // buff减弱 -> buff效果
[DBuff.SPEED]: Attrs.SPEED, // 移动速度下降 -> 移动速度
};
const attrField = debuffAttrMap[debuffType];
// 如果映射不存在,打印警告信息(方便开发调试)
if (attrField === undefined) {
console.warn(`[SkillSet] 未知的 DBuff 类型: ${debuffType},请在 getAttrFieldFromDebuff 添加映射关系或放入 stateDebuffSet`);
return -1;
}
return attrField;
}; };
/* /*

View File

@@ -26,7 +26,9 @@ import { debuff } from "../../skills/debuff"
* 0:战士 1:远程 2:法师 * 0:战士 1:远程 2:法师
* * */ * * */
export enum AttrSet {
ATTR_MAX = 85,
}
export enum HType { export enum HType {
warrior = 0, warrior = 0,
remote = 1, remote = 1,

View File

@@ -76,16 +76,19 @@ export class Hero extends ecs.Entity {
hv.base_def=hero.def hv.base_def=hero.def
hv.base_hp=hero.hp hv.base_hp=hero.hp
hv.base_mp=hero.mp hv.base_mp=hero.mp
hv.hp=hv.base_hp hv.base_dis=hero.dis
hv.mp=hv.base_mp hv.base_speed=hero.speed
hv.Attrs=getAttrs() hv.Attrs=getAttrs()
hv.Attrs[Attrs.HP_MAX]=hv.base_hp hv.hp=hv.Attrs[Attrs.HP_MAX]=hv.base_hp
hv.Attrs[Attrs.MP_MAX]=hv.base_mp hv.mp=hv.Attrs[Attrs.MP_MAX]=hv.base_mp
hv.Attrs[Attrs.DEF]=hv.base_def hv.Attrs[Attrs.DEF]=hv.base_def
hv.Attrs[Attrs.AP]=hv.base_ap hv.Attrs[Attrs.AP]=hv.base_ap
hv.Attrs[Attrs.MAP]=hv.base_map hv.Attrs[Attrs.MAP]=hv.base_map
hv.Attrs[Attrs.SPEED]=hero.speed
hv.Attrs[Attrs.DIS]=hero.dis
// 初始化 buff/debuff 系统 // 初始化 buff/debuff 系统
hv.initBuffsDebuffs(); hv.initAttrs();
return hv return hv
} }
} }

View File

@@ -5,36 +5,36 @@ import { HeroSpine } from "./HeroSpine";
import { BoxSet, FacSet } from "../common/config/BoxSet"; import { BoxSet, FacSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp"; import { smc } from "../common/SingletonModuleComp";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer"; 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 { BuffComp } from "./BuffComp";
import { oops } from "db://oops-framework/core/Oops"; import { oops } from "db://oops-framework/core/Oops";
import { GameEvent } from "../common/config/GameEvent"; import { GameEvent } from "../common/config/GameEvent";
import { FightSet, TooltipTypes } from "../common/config/Mission"; import { FightSet, TooltipTypes } from "../common/config/Mission";
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager"; 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; const { ccclass, property } = _decorator;
/** /**
* ==================== BUFF 系统使用说明 ==================== * ==================== BUFF 系统使用说明 ====================
* *
* 1. 系统架构<EFBFBD><EFBFBD>? * 1. 系统架构
* - BUFF_V/BUFFS_V: 数值型 buff<EFBFBD><EFBFBD>?临时<E4B8B4><E697B6>? * - BUFF_V/BUFFS_V: 数值型 buff临时
* - BUFF_R/BUFFS_R: 百分比型 buff<EFBFBD><EFBFBD>?临时<E4B8B4><E697B6>? * - BUFF_R/BUFFS_R: 百分比型 buff临时
* - DBUFF_V/DBUFFS_V: 数值型 debuff<EFBFBD><EFBFBD>?临时<E4B8B4><E697B6>? * - DBUFF_V/DBUFFS_V: 数值型 debuff临时
* - DBUFF_R/DBUFFS_R: 百分比型 debuff<EFBFBD><EFBFBD>?临时<E4B8B4><E697B6>? * - DBUFF_R/DBUFFS_R: 百分比型 debuff临时
* *
* 2. 智能覆盖规则<EFBFBD><EFBFBD>? * 2. 智能覆盖规则
* - 值更小:不添加(弱效果不覆盖强效果) * - 值更小:不添加(弱效果不覆盖强效果)
* - 值相同且临时:叠加时<EFBFBD><EFBFBD>? * - 值相同且临时:叠加时
* - 值更大:更新为新值(临时则更新值和时间<EFBFBD><EFBFBD>? * - 值更大:更新为新值(临时则更新值和时间
* *
* 3. 性能优化<EFBFBD><EFBFBD>? * 3. 性能优化
* - 增量计算:添<EFBFBD><EFBFBD>?删除时只重算受影响的属<EFBFBD>? * - 增量计算:添删除时只重算受影响的属
* - 批量计算initBuffsDebuffs() 中使<EFBFBD><EFBFBD>?recalculateAttrs() 一次性计算所<EFBFBD><EFBFBD>? * - 批量计算initBuffsDebuffs() 中使recalculateAttrs() 一次性计算所
*/ */
/** 角色显示组件 */ /** 角色显示组件 */
@ccclass('HeroViewComp') // 定义<EFBFBD><EFBFBD>?Cocos Creator 组件 @ccclass('HeroViewComp') // 定义Cocos Creator 组件
@ecs.register('HeroView', false) // 定义<EFBFBD><EFBFBD>?ECS 组件 @ecs.register('HeroView', false) // 定义ECS 组件
export class HeroViewComp extends CCComp { export class HeroViewComp extends CCComp {
BUFFCOMP:BuffComp=null! BUFFCOMP:BuffComp=null!
as: HeroSpine = null! as: HeroSpine = null!
@@ -43,7 +43,7 @@ export class HeroViewComp extends CCComp {
hero_name : string = "hero"; hero_name : string = "hero";
lv:number =1; lv:number =1;
scale: number = 1; /** 角色阵营 1hero -1 :mon */ scale: number = 1; /** 角色阵营 1hero -1 :mon */
type: number = 0; /**角色类型 0近战-需要贴<EFBFBD><EFBFBD>?1远程-保持距离 2辅助 */ type: number = 0; /**角色类型 0近战-需要贴1远程-保持距离 2辅助 */
fac:number=0; //阵营 0hero 1monster fac:number=0; //阵营 0hero 1monster
box_group:number = BoxSet.HERO; box_group:number = BoxSet.HERO;
is_dead:boolean = false; //是否摧毁 is_dead:boolean = false; //是否摧毁
@@ -58,27 +58,27 @@ export class HeroViewComp extends CCComp {
is_kalami:boolean =false; is_kalami:boolean =false;
mp: number = 100; mp: number = 100;
hp: number = 100; /** 血<EFBFBD><EFBFBD>?*/ hp: number = 100; /** 血*/
shield:number=0; //当前护甲<EFBFBD><EFBFBD>? shield:number=0; //当前护甲
/** 基础属<EFBFBD>?有初始值的基础属<EFBFBD>?后续Attrs 属性计算时用到*/ /** 基础属有初始值的基础属后续Attrs 属性计算时用到*/
base_ap: number = 0; //基础攻击<EFBFBD><EFBFBD>? base_ap: number = 0; //基础攻击
base_map: number = 0; base_map: number = 0;
base_def: number = 5; base_def: number = 5;
base_hp: number = 100; base_hp: number = 100;
base_mp: number = 100; base_mp: number = 100;
base_speed: number = 100; /** 角色移动速度 */ base_speed: number = 100; /** 角色移动速度 */
base_dis: number = 100;
Attrs:any=[] Attrs:any=[]
// Buff/Debuff 字典结构,通过属性索引直接访<EFBFBD><EFBFBD>? // Buff/Debuff 字典结构,通过属性索引直接访
// 结构: { [attrIndex: number]: { value: number, remainTime?: number } } // 结构: { [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 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 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 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 BUFFS_R: Record<number, {value: number, remainTime: number}> = {} // 临时型百分比 buff
atk_count: number = 0; atk_count: number = 0;
@@ -102,7 +102,7 @@ export class HeroViewComp extends CCComp {
this.on(GameEvent.FightEnd,this.do_fight_end,this) this.on(GameEvent.FightEnd,this.do_fight_end,this)
const collider = this.node.getComponent(BoxCollider2D); const collider = this.node.getComponent(BoxCollider2D);
this.scheduleOnce(()=>{ this.scheduleOnce(()=>{
if (collider) collider.enabled = true; // 先禁<EFBFBD><EFBFBD>? if (collider) collider.enabled = true; // 先禁
},1) },1)
// let anm = this.node.getChildByName("anm") // let anm = this.node.getChildByName("anm")
// anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8); // 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){ if(this.is_boss){
this.node.getChildByName("top").position=v3(this.node.position.x,this.node.position.y+100,0) 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.node.getChildByName("top").getChildByName("hp").active = true;
this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX]) this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
} }
// ==================== BUFF系统初始<EFBFBD><EFBFBD>?==================== // ==================== BUFF系统初始====================
/** /**
* 初始化角色的 buff <EFBFBD><EFBFBD>?debuff * 初始化角色的 buff debuff
* <EFBFBD><EFBFBD>?HeroInfo 读取初始配置,建立属性系<EFBFBD><EFBFBD>? * HeroInfo 读取初始配置,建立属性系
*/ */
initBuffsDebuffs() { initAttrs() {
// 清空现有 buff/debuff // 清空现有 buff/debuff
this.BUFF_V = {}; this.BUFF_V = {};
this.BUFFS_V = {}; this.BUFFS_V = {};
@@ -143,19 +143,28 @@ export class HeroViewComp extends CCComp {
if (!heroInfo) return; if (!heroInfo) return;
// 1. 重置为基础<EFBFBD><EFBFBD>? // 1. 重置为基础
this.Attrs[Attrs.HP_MAX] = this.base_hp; this.Attrs[Attrs.HP_MAX] = this.base_hp;
this.Attrs[Attrs.MP_MAX] = this.base_mp; this.Attrs[Attrs.MP_MAX] = this.base_mp;
this.Attrs[Attrs.DEF] = this.base_def; this.Attrs[Attrs.DEF] = this.base_def;
this.Attrs[Attrs.AP] = this.base_ap; this.Attrs[Attrs.AP] = this.base_ap;
this.Attrs[Attrs.MAP] = this.base_map; this.Attrs[Attrs.MAP] = this.base_map;
this.Attrs[Attrs.SPEED] = this.base_speed; 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) { for (const attrKey in this.Attrs) {
const attrIndex = parseInt(attrKey); 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; this.Attrs[attrIndex] = 0;
} }
} }
@@ -165,7 +174,6 @@ export class HeroViewComp extends CCComp {
this.addBuff(buffConf); this.addBuff(buffConf);
} }
} }
// 加载初始 debuff // 加载初始 debuff
if (heroInfo.debuff && heroInfo.debuff.length > 0) { if (heroInfo.debuff && heroInfo.debuff.length > 0) {
for (const dbuffConf of heroInfo.debuff) { for (const dbuffConf of heroInfo.debuff) {
@@ -176,27 +184,27 @@ export class HeroViewComp extends CCComp {
// ==================== BUFF管理 ==================== // ==================== BUFF管理 ====================
/** /**
* 添加 buff 效果(智能覆盖) * 添加 buff 效果(智能覆盖)
* @param buffConf buff 配置 (来自 SkillSet.BuffConf <EFBFBD><EFBFBD>?heroSet.buff) * @param buffConf buff 配置 (来自 SkillSet.BuffConf heroSet.buff)
* *
* 智能覆盖规则<EFBFBD><EFBFBD>? * 智能覆盖规则
* 1. 值更小:不添<EFBFBD><EFBFBD>? * 1. 值更小:不添
* 2. 值相同且都是临时:叠加时<EFBFBD><EFBFBD>? * 2. 值相同且都是临时:叠加时
* 3. 值更大:更新为新值(临时则更新值和时间<EFBFBD><EFBFBD>? * 3. 值更大:更新为新值(临时则更新值和时间
*/ */
addBuff(buffConf: BuffConf) { addBuff(buffConf: BuffConf) {
const isValue = buffConf.BType === BType.VALUE; const isValue = buffConf.BType === BType.VALUE;
const isPermanent = buffConf.time === 0; const isPermanent = buffConf.time === 0;
const attrIndex = buffConf.buff; const attrIndex = buffConf.buff;
// 根据类型选择对应<EFBFBD><EFBFBD>?buff 字典 // 根据类型选择对应buff 字典
const permanentBuffs = isValue ? this.BUFF_V : this.BUFF_R; const permanentBuffs = isValue ? this.BUFF_V : this.BUFF_R;
const temporaryBuffs = isValue ? this.BUFFS_V : this.BUFFS_R; const temporaryBuffs = isValue ? this.BUFFS_V : this.BUFFS_R;
if (isPermanent) { if (isPermanent) {
// 添加持久<EFBFBD><EFBFBD>?buff // 添加持久buff
const existing = permanentBuffs[attrIndex]; const existing = permanentBuffs[attrIndex];
if (existing) { if (existing) {
// 值更小,不添<EFBFBD><EFBFBD>? // 值更小,不添
if (buffConf.value <= existing.value) { if (buffConf.value <= existing.value) {
return; return;
} }
@@ -207,16 +215,16 @@ export class HeroViewComp extends CCComp {
permanentBuffs[attrIndex] = { value: buffConf.value }; permanentBuffs[attrIndex] = { value: buffConf.value };
} }
} else { } else {
// 添加临时<EFBFBD><EFBFBD>?buff // 添加临时buff
const existing = temporaryBuffs[attrIndex]; const existing = temporaryBuffs[attrIndex];
if (existing) { if (existing) {
if (buffConf.value < existing.value) { if (buffConf.value < existing.value) {
// 值更小,不添<EFBFBD><EFBFBD>? // 值更小,不添
return; return;
} else if (buffConf.value === existing.value) { } else if (buffConf.value === existing.value) {
// 值相同,叠加时间 // 值相同,叠加时间
existing.remainTime += buffConf.time; existing.remainTime += buffConf.time;
return; // 时间叠加不需要重算属<EFBFBD><EFBFBD>? return; // 时间叠加不需要重算属
} else { } else {
// 值更大,更新值和时间 // 值更大,更新值和时间
existing.value = buffConf.value; existing.value = buffConf.value;
@@ -231,44 +239,40 @@ export class HeroViewComp extends CCComp {
} }
} }
// 只重新计算受影响的属<E79A84><E5B19E>?
this.recalculateSingleAttr(buffConf.buff); this.recalculateSingleAttr(buffConf.buff);
} }
// ==================== DEBUFF管理 ==================== // ==================== DEBUFF管理 ====================
/** /**
* 添加 debuff 效果(智能覆盖) * 添加 debuff 效果(智能覆盖)
* @param dbuffConf debuff 配置 (来自 SkillSet.DbuffConf <EFBFBD><EFBFBD>?heroSet.debuff) * @param dbuffConf debuff 配置 (来自 SkillSet.DbuffConf heroSet.debuff)
* *
* 支持两种 debuff<EFBFBD><EFBFBD>? * 支持两种 debuff
* 1. 属性型 debuff直接修改属性值有对应的 Attrs<EFBFBD><EFBFBD>? * 1. 属性型 debuff直接修改属性值有对应的 Attrs
* 2. 状态型 debuff只缓存状态无对应的 Attrs用于状态检查 * 2. 状态型 debuff只缓存状态无对应的 Attrs用于状态检查
* *
* 智能覆盖规则<EFBFBD><EFBFBD>? * 智能覆盖规则
* 1. 值更小:不添<EFBFBD><EFBFBD>? * 1. 值更小:不添
* 2. 值相同且都是临时:叠加时<EFBFBD><EFBFBD>? * 2. 值相同且都是临时:叠加时
* 3. 值更大:更新为新值(临时则更新值和时间<EFBFBD><EFBFBD>? * 3. 值更大:更新为新值(临时则更新值和时间
*/ */
addDebuff(dbuffConf: DbuffConf) { addDebuff(dbuffConf: DbuffConf) {
// 获取 debuff 对应的属性字<EFBFBD><EFBFBD>? // 获取 debuff 对应的属性字
// attrField = -1 表示状态类 debuff只缓存不修改属性
// attrField >= 0 表示属性类 debuff会修改属性
const attrField = getAttrFieldFromDebuff(dbuffConf.debuff);
const isValue = dbuffConf.BType === BType.VALUE; const isValue = dbuffConf.BType === BType.VALUE;
const isPermanent = dbuffConf.time === 0; const isPermanent = dbuffConf.time === 0;
// 根据类型选择对应<EFBFBD><EFBFBD>?debuff 字典 // 根据类型选择对应debuff 字典
const permanentDebuffs = isValue ? this.DBUFF_V : this.DBUFF_R; const permanentDebuffs = isValue ? this.DBUFF_V : this.DBUFF_R;
const temporaryDebuffs = isValue ? this.DBUFFS_V : this.DBUFFS_R; const temporaryDebuffs = isValue ? this.DBUFFS_V : this.DBUFFS_R;
// 状态类 debuff 使用 debuff 类型作为 key属性类 debuff 使用 attrField 作为 key // 状态类 debuff 使用 debuff 类型作为 key属性类 debuff 使用 attrField 作为 key
const key = attrField >= 0 ? attrField : dbuffConf.debuff; const key = dbuffConf.debuff;
if (isPermanent) { if (isPermanent) {
// 添加持久<EFBFBD><EFBFBD>?debuff // 添加持久debuff
const existing = permanentDebuffs[key]; const existing = permanentDebuffs[key];
if (existing) { if (existing) {
// 值更小,不添<EFBFBD><EFBFBD>? // 值更小,不添
if (dbuffConf.value <= existing.value) { if (dbuffConf.value <= existing.value) {
return; return;
} }
@@ -279,16 +283,16 @@ export class HeroViewComp extends CCComp {
permanentDebuffs[key] = { value: dbuffConf.value }; permanentDebuffs[key] = { value: dbuffConf.value };
} }
} else { } else {
// 添加临时<EFBFBD><EFBFBD>?debuff // 添加临时debuff
const existing = temporaryDebuffs[key]; const existing = temporaryDebuffs[key];
if (existing) { if (existing) {
if (dbuffConf.value < existing.value) { if (dbuffConf.value < existing.value) {
// 值更小,不添<EFBFBD><EFBFBD>? // 值更小,不添
return; return;
} else if (dbuffConf.value === existing.value) { } else if (dbuffConf.value === existing.value) {
// 值相同,叠加时间 // 值相同,叠加时间
existing.remainTime += dbuffConf.time; existing.remainTime += dbuffConf.time;
return; // 时间叠加不需要重算属<EFBFBD><EFBFBD>? return; // 时间叠加不需要重算属
} else { } else {
// 值更大,更新值和时间 // 值更大,更新值和时间
existing.value = dbuffConf.value; existing.value = dbuffConf.value;
@@ -302,20 +306,24 @@ export class HeroViewComp extends CCComp {
}; };
} }
} }
let attrField = TransformBuffs(dbuffConf.debuff,true);
// 只重新计算受影响的属性(状态类 debuff 不需要计算) // 只重新计算受影响的属性(状态类 debuff 不需要计算)
if (attrField >= 0) { if (attrField > 0 ) {
this.recalculateSingleAttr(attrField); 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) { private recalculateSingleAttr(attrIndex: number) {
// 1. 重置为基础<EFBFBD><EFBFBD>? // 1. 获取基础值
const baseValues: Record<number, number> = { const baseValues: Record<number, number> = {
[Attrs.HP_MAX]: this.base_hp, [Attrs.HP_MAX]: this.base_hp,
[Attrs.MP_MAX]: this.base_mp, [Attrs.MP_MAX]: this.base_mp,
@@ -326,46 +334,68 @@ export class HeroViewComp extends CCComp {
[Attrs.SHIELD_MAX]: 0 [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]) { if (this.BUFF_V[attrIndex]) {
this.Attrs[attrIndex] += this.BUFF_V[attrIndex].value; totalValue += this.BUFF_V[attrIndex].value;
} }
if (this.BUFFS_V[attrIndex]) { if (this.BUFFS_V[attrIndex]) {
this.Attrs[attrIndex] += this.BUFFS_V[attrIndex].value; totalValue += this.BUFFS_V[attrIndex].value;
} }
// 3. 应用百分比型 buff - 直接访问 // Debuff需要通过 DBuff key 查找
const baseVal = baseValues[attrIndex] !== undefined ? baseValues[attrIndex] : this.Attrs[attrIndex]; 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]) { 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]) { if (this.BUFFS_R[attrIndex]) {
this.Attrs[attrIndex] += Math.floor(baseVal * (this.BUFFS_R[attrIndex].value / 100)); totalRatio += this.BUFFS_R[attrIndex].value;
} }
// 4. 应用数值型 debuff - 直接访问 // Debuff需要通过 DBuff key 查找
if (this.DBUFF_V[attrIndex]) { if (deKey !== -1) {
this.Attrs[attrIndex] -= this.DBUFF_V[attrIndex].value; if (this.DBUFF_R[deKey]) {
totalRatio -= this.DBUFF_R[deKey].value;
}
if (this.DBUFFS_R[deKey]) {
totalRatio -= this.DBUFFS_R[deKey].value;
} }
if (this.DBUFFS_V[attrIndex]) {
this.Attrs[attrIndex] -= this.DBUFFS_V[attrIndex].value;
} }
// 5. 应用百分比型 debuff - 直接访问
if (this.DBUFF_R[attrIndex]) { // 4. 根据属性类型计算最终值
this.Attrs[attrIndex] -= Math.floor(baseVal * (this.DBUFF_R[attrIndex].value / 100)); const attrType = AttrsType[attrIndex];
} const isRatioAttr = attrType === BType.RATIO;
if (this.DBUFFS_R[attrIndex]) {
this.Attrs[attrIndex] -= Math.floor(baseVal * (this.DBUFFS_R[attrIndex].value / 100)); if (isRatioAttr) {
// 百分比型属性:直接加减
this.Attrs[attrIndex] = totalValue + totalRatio;
} else {
// 数值型属性:(基础值+数值) × (1 + 百分比/100)
this.Attrs[attrIndex] = Math.floor(totalValue * (1 + totalRatio / 100));
} }
// 6. 确保属性值合<EFBFBD><EFBFBD>? // 5. 确保属性值合
this.clampSingleAttr(attrIndex); this.clampSingleAttr(attrIndex);
} }
/** /**
* 确保单个属性值合<EFBFBD><EFBFBD>? * 确保单个属性值合
*/ */
private clampSingleAttr(attrIndex: number) { private clampSingleAttr(attrIndex: number) {
switch(attrIndex) { switch(attrIndex) {
@@ -376,26 +406,25 @@ export class HeroViewComp extends CCComp {
case Attrs.DEF: case Attrs.DEF:
case Attrs.AP: case Attrs.AP:
case Attrs.MAP: case Attrs.MAP:
this.Attrs[attrIndex] = Math.max(0, this.Attrs[attrIndex]); this.Attrs[attrIndex] = Math.max(1, this.Attrs[attrIndex]);
break; break;
case Attrs.CRITICAL: case Attrs.CRITICAL:
case Attrs.DODGE: case Attrs.DODGE:
case Attrs.HIT: 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; break;
} }
} }
// ==================== 临时 BUFF/DEBUFF 更新 ==================== // ==================== 临时 BUFF/DEBUFF 更新 ====================
/** /**
* 更新临时 buff/debuff 的剩余时<EFBFBD><EFBFBD>? * 更新临时 buff/debuff 的剩余时
* 应在 update 中定期调<EFBFBD><EFBFBD>? * 应在 update 中定期调
* @param dt 时间<EFBFBD><EFBFBD>? * @param dt 时间
*/ */
updateTemporaryBuffsDebuffs(dt: number) { updateTemporaryBuffsDebuffs(dt: number) {
const affectedAttrs = new Set<number>(); const affectedAttrs = new Set<number>();
// 更新临时型数buff
// 更新临时型数<E59E8B><E695B0>?buff
for (const attrIndex in this.BUFFS_V) { for (const attrIndex in this.BUFFS_V) {
const buff = this.BUFFS_V[attrIndex]; const buff = this.BUFFS_V[attrIndex];
buff.remainTime -= dt; buff.remainTime -= dt;
@@ -404,7 +433,6 @@ export class HeroViewComp extends CCComp {
affectedAttrs.add(parseInt(attrIndex)); affectedAttrs.add(parseInt(attrIndex));
} }
} }
// 更新临时型百分比 buff // 更新临时型百分比 buff
for (const attrIndex in this.BUFFS_R) { for (const attrIndex in this.BUFFS_R) {
const buff = this.BUFFS_R[attrIndex]; 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) { for (const key in this.DBUFFS_V) {
const debuff = this.DBUFFS_V[key]; const debuff = this.DBUFFS_V[key];
debuff.remainTime -= dt; debuff.remainTime -= dt;
if (debuff.remainTime <= 0) { if (debuff.remainTime <= 0) {
delete this.DBUFFS_V[key]; 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; debuff.remainTime -= dt;
if (debuff.remainTime <= 0) { if (debuff.remainTime <= 0) {
delete this.DBUFFS_R[key]; 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 => { affectedAttrs.forEach(attrIndex => {
this.recalculateSingleAttr(attrIndex); this.recalculateSingleAttr(attrIndex);
}); });
} }
public isStun() { public isStun() {
return this.DBUFF_V[DBuff.STUN] !== undefined || this.DBUFFS_V[DBuff.STUN] !== undefined this.DBUFFS_V[DBuff.STUN] !== undefined
} }
public isFrost() { public isFrost() {
return this.DBUFF_V[DBuff.FROST] !== undefined || this.DBUFFS_V[DBuff.FROST] !== undefined this.DBUFFS_V[DBuff.FROST] !== undefined
} }
update(dt: number){ update(dt: number){
@@ -475,7 +507,7 @@ export class HeroViewComp extends CCComp {
get isActive() { get isActive() {
return this.ent.has(HeroViewComp) && this.node?.isValid; return this.ent.has(HeroViewComp) && this.node?.isValid;
} }
//状态切<EFBFBD><EFBFBD>? //状态切
status_change(type:string){ status_change(type:string){
this.status=type this.status=type
if(type == "idle"){ if(type == "idle"){
@@ -743,7 +775,7 @@ export class HeroViewComp extends CCComp {
this.showDamageImmediate(damageInfo.damage, damageInfo.isCrit,damageInfo.anm); this.showDamageImmediate(damageInfo.damage, damageInfo.isCrit,damageInfo.anm);
// 设置延时处理下一个伤<EFBFBD><EFBFBD>? // 设置延时处理下一个伤
this.scheduleOnce(() => { this.scheduleOnce(() => {
this.isProcessingDamage = false; this.isProcessingDamage = false;
}, this.damageInterval); }, this.damageInterval);
@@ -757,7 +789,7 @@ export class HeroViewComp extends CCComp {
this.atked_count++; this.atked_count++;
if (isCrit) { if (isCrit) {
this.BUFFCOMP.hp_tip(TooltipTypes.crit, damage.toFixed(0), damage); this.BUFFCOMP.hp_tip(TooltipTypes.crit, damage.toFixed(0), damage);
// //console.log("暴击伤害<EFBFBD><EFBFBD>? + damage); // //console.log("暴击伤害 + damage);
} else { } else {
this.BUFFCOMP.hp_tip(TooltipTypes.life, damage.toFixed(0), damage); this.BUFFCOMP.hp_tip(TooltipTypes.life, damage.toFixed(0), damage);
// //console.log("普通伤害:" + damage); // //console.log("普通伤害:" + damage);

View File

@@ -8,7 +8,7 @@ import { HeroInfo } from "../common/config/heroSet";
import { MonModelComp } from "./MonModelComp"; import { MonModelComp } from "./MonModelComp";
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp"; import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
import { SkillConComp } from "./SkillConComp"; import { SkillConComp } from "./SkillConComp";
import { BuffAttr, getBuffNum, SkillSet } from "../common/config/SkillSet"; import { Attrs, getAttrs, SkillSet } from "../common/config/SkillSet";
/** 角色实体 */ /** 角色实体 */
@ecs.register(`Monster`) @ecs.register(`Monster`)
export class Monster extends ecs.Entity { export class Monster extends ecs.Entity {
@@ -64,9 +64,11 @@ export class Monster extends ecs.Entity {
} }
hero_init(uuid:number=1001,node:Node,scale:number=1,box_group=BoxSet.HERO,is_boss:boolean=false,is_call:boolean=false,enhancement?: any, stageMultipliers?: any) { hero_init(uuid:number=1001,node:Node,scale:number=1,box_group=BoxSet.HERO,is_boss:boolean=false,is_call:boolean=false,enhancement?: any, stageMultipliers?: any) {
var hv = node.getComponent(HeroViewComp)!; var hv = node.getComponent(HeroViewComp)!;
hv.hide_info()
// console.log("hero_init",buff) // console.log("hero_init",buff)
let hero= HeroInfo[uuid] // 共用英雄数据 let hero= HeroInfo[uuid] // 共用英雄数据
hv.scale = scale; hv.scale = scale;
hv.fac = FacSet.MON; hv.fac = FacSet.MON;
hv.type = hero.type; hv.type = hero.type;
@@ -78,10 +80,8 @@ export class Monster extends ecs.Entity {
hv.hero_uuid= uuid; hv.hero_uuid= uuid;
hv.hero_name= hero.name; hv.hero_name= hero.name;
// 初始化Attrs属性系统参考Hero.ts的实 // 初始化Attrs属性系统参考Hero.ts的实
hv.Attrs = getBuffNum(); // 计算基础属性(使用关卡倍数)
// 计算基础属性(使用关卡倍数)
const baseHp = hero.hp; const baseHp = hero.hp;
const baseAp = hero.ap; const baseAp = hero.ap;
@@ -93,46 +93,29 @@ export class Monster extends ecs.Entity {
finalHp = Math.floor(baseHp * stageMultipliers.hp); finalHp = Math.floor(baseHp * stageMultipliers.hp);
finalAp = Math.floor(baseAp * stageMultipliers.attack); finalAp = Math.floor(baseAp * stageMultipliers.attack);
// console.log(`[Monster]: 怪物${hero.name} 关卡倍数 - HP: ${baseHp} x ${stageMultipliers.hp.toFixed(2)} = ${finalHp}, AP: ${baseAp} x ${stageMultipliers.attack.toFixed(2)} = ${finalAp}`); // console.log(`[Monster]: 怪物${hero.name} 关卡倍数 - HP: ${baseHp} x ${stageMultipliers.hp.toFixed(2)} = ${finalHp}, AP: ${baseAp} x ${stageMultipliers.attack.toFixed(2)} = ${finalAp}`);
} else {
// console.log(`[Monster]: 怪物${hero.name} 使用基础属性 - HP: ${finalHp}, AP: ${finalAp}`);
} }
hv.hp = hv.hp_max = finalHp; hv.base_ap=finalAp
hv.ap = finalAp; hv.base_map=hero.mp
hv.ap_base = finalAp; hv.base_def=hero.def
hv.base_hp=finalHp
hv.base_mp=hero.mp
hv.hp=hv.base_hp
hv.mp=hv.base_mp
hv.Attrs=getAttrs()
hv.Attrs[Attrs.HP_MAX]=hv.base_hp
hv.Attrs[Attrs.MP_MAX]=hv.base_mp
hv.Attrs[Attrs.DEF]=hv.base_def
hv.Attrs[Attrs.AP]=hv.base_ap
hv.Attrs[Attrs.MAP]=hv.base_map
hv.Attrs[Attrs.SPEED]=hero.speed
hv.Attrs[Attrs.DIS]=hero.dis
// 初始化 buff/debuff 系统
hv.initAttrs();
// 设置基础属性到Attrs系统
hv.Attrs[BuffAttr.SPEED] = hv.speed = hv.speed_base = hero.speed;
hv.Attrs[BuffAttr.DIS] = hv.dis = hero.dis;
hv.Attrs[BuffAttr.ATK_CD] = hv.cd = hero.cd;
hv.Attrs[BuffAttr.HP_MAX] = hv.hp_max;
hv.Attrs[BuffAttr.AP] = hv.ap;
hv.Attrs[BuffAttr.DEF] = hv.def;
// 处理原有Buff使用统一的apply_buff方法
hero.buff.forEach((buff:any)=>{
hv.apply_buff(buff.type, buff.value);
})
// 处理肉鸽模式的增强属性
if (enhancement && enhancement.buffList && enhancement.buffList.length > 0) {
// console.log(`[Monster]: 怪物${hero.name}应用增强属性:`, enhancement.buffList.map((buff: any) => `${buff.name}:+${buff.value}`));
enhancement.buffList.forEach((buff:any)=>{
hv.apply_buff(buff.buffType, buff.value);
})
}
// 重新计算最终HP因为buff可能修改了hp_max
hv.hp = hv.hp_max;
for(let i=0;i<hero.skills.length;i++){
hv.skills.push({
cd:0,
uuid:hero.skills[i],
cd_max:i==0?hero.cd:SkillSet[hero.skills[i]].cd
})
}
this.add(hv); this.add(hv);
} }
} }

View File

@@ -32,9 +32,8 @@ export class SkillConComp extends CCComp {
update(dt: number) { update(dt: number) {
if(!smc.mission.play||smc.mission.pause) return if(!smc.mission.play||smc.mission.pause) return
const hasStun = this.HeroView.V_DBUFF.some(d => d.debuff === DBuff.STUN);
const hasFrost = this.HeroView.V_DBUFF.some(d => d.debuff === DBuff.FROST); if(!this.HeroView.isStun() && !this.HeroView.isFrost()) {
if(!hasStun && !hasFrost) {
let skills=this.HeroView.skills let skills=this.HeroView.skills
for(let i=0;i<skills.length;i++){ for(let i=0;i<skills.length;i++){
skills[i].cd += dt; skills[i].cd += dt;
@@ -49,7 +48,6 @@ export class SkillConComp extends CCComp {
} }
} }
} }

View File

@@ -3,7 +3,7 @@
* *
* 功能说明: * 功能说明:
* - 提供基于怪物类型的属性加成配置 * - 提供基于怪物类型的属性加成配置
* - 使用BuffAttr枚举定义属性增强 * - 使用Attrs枚举定义属性增强
* - 供游戏系统调用获取怪物增强数据 * - 供游戏系统调用获取怪物增强数据
* *
* @author 游戏开发团队 * @author 游戏开发团队
@@ -12,7 +12,7 @@
*/ */
import { QualitySet } from "../common/config/BoxSet"; import { QualitySet } from "../common/config/BoxSet";
import { BuffAttr } from "../common/config/SkillSet"; import { Attrs } from "../common/config/SkillSet";
import { getMonList } from "../common/config/heroSet"; import { getMonList } from "../common/config/heroSet";
/** /**
@@ -92,16 +92,14 @@ export const StageConfigRules = {
* 按权重排序,数值越大优先级越高 * 按权重排序,数值越大优先级越高
*/ */
export const AvailableEnhancementPool = [ export const AvailableEnhancementPool = [
{ buffType: BuffAttr.HP, weight: 10, baseValue: 80, name: "生命值增强" }, { buffType: Attrs.HP_MAX, weight: 10, baseValue: 80, name: "生命值增强" },
{ buffType: BuffAttr.ATK, weight: 9, baseValue: 50, name: "攻击力增强" }, { buffType: Attrs.AP, weight: 9, baseValue: 50, name: "攻击力增强" },
{ buffType: BuffAttr.CRITICAL, weight: 8, baseValue: 30, name: "暴击率增强" }, { buffType: Attrs.CRITICAL, weight: 8, baseValue: 30, name: "暴击率增强" },
{ buffType: BuffAttr.DEF, weight: 7, baseValue: 40, name: "防御增强" }, { buffType: Attrs.DEF, weight: 7, baseValue: 40, name: "防御增强" },
{ buffType: BuffAttr.CRITICAL_DMG, weight: 6, baseValue: 60, name: "暴击伤害增强" }, { buffType: Attrs.CRITICAL_DMG, weight: 6, baseValue: 60, name: "暴击伤害增强" },
{ buffType: BuffAttr.DODGE, weight: 5, baseValue: 25, name: "闪避增强" }, { buffType: Attrs.DODGE, weight: 5, baseValue: 25, name: "闪避增强" },
{ buffType: BuffAttr.ATK_CD, weight: 4, baseValue: 20, name: "攻击速度增强" }, { buffType: Attrs.AS, weight: 4, baseValue: 20, name: "攻击速度增强" },
{ buffType: BuffAttr.LIFESTEAL, weight: 3, baseValue: 15, name: "吸血" }, { buffType: Attrs.LIFESTEAL, weight: 3, baseValue: 15, name: "吸血" },
{ buffType: BuffAttr.DMG_RED, weight: 2, baseValue: 20, name: "免伤" },
{ buffType: BuffAttr.PUNCTURE, weight: 1, baseValue: 2, name: "穿刺" }
]; ];
/** /**
@@ -128,8 +126,8 @@ export const MonsterTypeBaseConfig = {
export interface MonsterEnhancementData { export interface MonsterEnhancementData {
name: string; name: string;
description: string; description: string;
buffs: { [key in BuffAttr]?: number }; buffs: { [key in Attrs]?: number };
buffList: Array<{ buffType: BuffAttr; value: number; name: string }>; buffList: Array<{ buffType: Attrs; value: number; name: string }>;
} }
/** /**
@@ -138,7 +136,7 @@ export interface MonsterEnhancementData {
* @param excludeTypes 排除的属性类型 * @param excludeTypes 排除的属性类型
* @returns 选中的增强属性数组 * @returns 选中的增强属性数组
*/ */
export function selectRandomEnhancements(count: number, excludeTypes: BuffAttr[] = []): Array<{buffType: BuffAttr, weight: number, baseValue: number, name: string}> { export function selectRandomEnhancements(count: number, excludeTypes: Attrs[] = []): Array<{buffType: Attrs, weight: number, baseValue: number, name: string}> {
if (count <= 0) return []; if (count <= 0) return [];
// 过滤掉排除的属性类型 // 过滤掉排除的属性类型
@@ -147,7 +145,7 @@ export function selectRandomEnhancements(count: number, excludeTypes: BuffAttr[]
if (availablePool.length === 0) return []; if (availablePool.length === 0) return [];
const selectedEnhancements = []; const selectedEnhancements = [];
const usedTypes = new Set<BuffAttr>(); const usedTypes = new Set<Attrs>();
for (let i = 0; i < count && i < availablePool.length; i++) { for (let i = 0; i < count && i < availablePool.length; i++) {
// 计算权重总和 // 计算权重总和
@@ -185,7 +183,7 @@ export function getMonsterEnhancement(monsterType: MonsterType, useRandom: boole
const baseConfig = MonsterTypeBaseConfig[monsterType]; const baseConfig = MonsterTypeBaseConfig[monsterType];
const enhancementCount = MonsterEnhancementCountConfig[monsterType]; const enhancementCount = MonsterEnhancementCountConfig[monsterType];
let selectedEnhancements: Array<{buffType: BuffAttr, weight: number, baseValue: number, name: string}> = []; let selectedEnhancements: Array<{buffType: Attrs, weight: number, baseValue: number, name: string}> = [];
if (useRandom) { if (useRandom) {
// 随机生成增强属性 // 随机生成增强属性
@@ -198,8 +196,8 @@ export function getMonsterEnhancement(monsterType: MonsterType, useRandom: boole
} }
// 构建buffs对象 // 构建buffs对象
const buffs: { [key in BuffAttr]?: number } = {}; const buffs: { [key in Attrs]?: number } = {};
const buffList: Array<{ buffType: BuffAttr; value: number; name: string }> = []; const buffList: Array<{ buffType: Attrs; value: number; name: string }> = [];
selectedEnhancements.forEach(enhancement => { selectedEnhancements.forEach(enhancement => {
buffs[enhancement.buffType] = enhancement.baseValue; buffs[enhancement.buffType] = enhancement.baseValue;

View File

@@ -38,7 +38,6 @@ load(startPos: Vec3, parent: Node, uuid: number, targetPos: any[], caster:Hero
node.setPosition(startPos); node.setPosition(startPos);
if(caster.fac==FacSet.MON){ if(caster.fac==FacSet.MON){
node.scale=v3(node.scale.x*-1,1,1) node.scale=v3(node.scale.x*-1,1,1)
}else{ }else{
if(caster.type==HType.warrior){ if(caster.type==HType.warrior){
if(caster.node.scale.x<0){ if(caster.node.scale.x<0){
@@ -49,21 +48,18 @@ load(startPos: Vec3, parent: Node, uuid: number, targetPos: any[], caster:Hero
// 添加技能组件 // 添加技能组件
const SComp = node.getComponent(SkillViewCom); // 初始化技能参数 const SComp = node.getComponent(SkillViewCom); // 初始化技能参数
// 只设置必要的运行时属性,配置信息通过 SkillSet[uuid] 访问 // 只设置必要的运行时属性,配置信息通过 SkillSet[uuid] 访问
Object.assign(SComp, {
// 核心标识 // 核心标识
s_uuid: uuid, SComp.s_uuid= uuid
cName:caster.hero_name, SComp.cName=caster.hero_name
scale: caster.node.scale.x, SComp.scale= caster.node.scale.x
// 位置和施法者信息 // 位置和施法者信息
startPos: startPos, SComp.startPos= startPos
targetPos: targetPos, SComp.targetPos= targetPos
group: caster.box_group, SComp.group= caster.box_group
fac: caster.fac, SComp.fac= caster.fac,
// 技能数值 // 技能数值
ap: caster.Attrs[Attrs.AP], SComp.Attrs= caster.Attrs
caster: caster, SComp.caster= caster,
});
this.add(SComp); this.add(SComp);
} }

View File

@@ -40,11 +40,12 @@ export class SkillViewCom extends CCComp {
target:HeroViewComp=null; target:HeroViewComp=null;
parent:Node=null; parent:Node=null;
target_postions:any[]=null target_postions:any[]=null
group:0 group:number=0
fac: 0 fac:number=0
// 战斗相关运行时数据 // 战斗相关运行时数据
Attrs:any=null Attrs:any=null
targetPos:any[]=null startPos:any=null
targetPos:any=null
start() { start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象 // var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
this.node.getChildByName("ready").active = this.hasReady this.node.getChildByName("ready").active = this.hasReady