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:
@@ -76,16 +76,19 @@ export class Hero extends ecs.Entity {
|
||||
hv.base_def=hero.def
|
||||
hv.base_hp=hero.hp
|
||||
hv.base_mp=hero.mp
|
||||
hv.hp=hv.base_hp
|
||||
hv.mp=hv.base_mp
|
||||
hv.base_dis=hero.dis
|
||||
hv.base_speed=hero.speed
|
||||
hv.Attrs=getAttrs()
|
||||
hv.Attrs[Attrs.HP_MAX]=hv.base_hp
|
||||
hv.Attrs[Attrs.MP_MAX]=hv.base_mp
|
||||
hv.hp=hv.Attrs[Attrs.HP_MAX]=hv.base_hp
|
||||
hv.mp=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.initBuffsDebuffs();
|
||||
hv.initAttrs();
|
||||
return hv
|
||||
}
|
||||
}
|
||||
@@ -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. 系统架构�
|
||||
* - BUFF_V/BUFFS_V: 数值型 buff(æŒ<C3A6>ï¿?临时ï¿?
|
||||
* - BUFF_R/BUFFS_R: 百分比型 buff(æŒ<C3A6>ï¿?临时ï¿?
|
||||
* - DBUFF_V/DBUFFS_V: 数值型 debuff(æŒ<C3A6>ï¿?临时ï¿?
|
||||
* - DBUFF_R/DBUFFS_R: 百分比型 debuff(æŒ<C3A6>ï¿?临时ï¿?
|
||||
* 1. 系统架构
|
||||
* - BUFF_V/BUFFS_V: 数值型 buff(持临时
|
||||
* - BUFF_R/BUFFS_R: 百分比型 buff(持临时
|
||||
* - DBUFF_V/DBUFFS_V: 数值型 debuff(持临时
|
||||
* - DBUFF_R/DBUFFS_R: 百分比型 debuff(持临时
|
||||
*
|
||||
* 2. 智能覆盖规则�
|
||||
* 2. 智能覆盖规则
|
||||
* - 值更小:不添加(弱效果不覆盖强效果)
|
||||
* - 值相å<EFBFBD>Œä¸”临时:å<EFBFBD> åŠ æ—¶ï¿?
|
||||
* - 值更大:更新为新值(临时则更新值和时间�
|
||||
* - 值相同且临时:叠加时
|
||||
* - 值更大:更新为新值(临时则更新值和时间
|
||||
*
|
||||
* 3. 性能优化�
|
||||
* - 增é‡<EFBFBD>计算:添ï¿?åˆ é™¤æ—¶å<C2B6>ªé‡<C3A9>ç®—å<E28094>—å½±å“<C3A5>的属�?
|
||||
* - 批é‡<EFBFBD>计算:initBuffsDebuffs() ä¸ä½¿ï¿?recalculateAttrs() 一次性计算所ï¿?
|
||||
* 3. 性能优化
|
||||
* - 增量计算:添删除时只重算受影响的属
|
||||
* - 批量计算: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!
|
||||
@@ -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近战-需è¦<C3A8>è´´ï¿?1远程-ä¿<C3A4>æŒ<C3A6>è·<C3A8>离 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; /** 血�*/
|
||||
shield:number=0; //当å‰<EFBFBD>护甲ï¿?
|
||||
/** 基础属�?有åˆ<C3A5>始值的基础属�?å<>Žç»Attrs 属性计算时用到*/
|
||||
base_ap: number = 0; //基础攻击�
|
||||
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 å—典结构,通过属性索引直接访ï¿?
|
||||
// Buff/Debuff 字典结构,通过属性索引直接访
|
||||
// 结构: { [attrIndex: number]: { value: number, remainTime?: number } }
|
||||
DBUFF_V: Record<number, {value: number}> = {} // æŒ<EFBFBD>久型数ï¿?debuff
|
||||
DBUFF_V: Record<number, {value: number}> = {} // 持久型数debuff
|
||||
DBUFF_R: Record<number, {value: number}> = {} // 持久型百分比 debuff
|
||||
BUFF_V: Record<number, {value: number}> = {} // æŒ<EFBFBD>久型数ï¿?buff
|
||||
BUFF_V: Record<number, {value: number}> = {} // 持久型数buff
|
||||
BUFF_R: Record<number, {value: number}> = {} // 持久型百分比 buff
|
||||
|
||||
DBUFFS_V: Record<number, {value: number, remainTime: number}> = {} // 临时型数�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}> = {} // 临时型数�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>ï¿?
|
||||
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)
|
||||
}
|
||||
/* 显示角色血�*/
|
||||
/* 显示角色血*/
|
||||
this.node.getChildByName("top").getChildByName("hp").active = true;
|
||||
this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
|
||||
}
|
||||
|
||||
// ==================== BUFF系统åˆ<EFBFBD>å§‹ï¿?====================
|
||||
// ==================== BUFF系统初始====================
|
||||
/**
|
||||
* åˆ<EFBFBD>始化角色的 buff ï¿?debuff
|
||||
* ï¿?HeroInfo 读å<EFBFBD>–åˆ<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>置为基础ï¿?
|
||||
// 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
|
||||
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 é…<EFBFBD>ç½® (æ<>¥è‡ª SkillSet.BuffConf ï¿?heroSet.buff)
|
||||
* @param buffConf buff 配置 (来自 SkillSet.BuffConf heroSet.buff)
|
||||
*
|
||||
* 智能覆盖规则�
|
||||
* 1. 值更å°<EFBFBD>:ä¸<EFBFBD>æ·»ï¿?
|
||||
* 2. 值相å<EFBFBD>Œä¸”都是临时:å<EFBFBD> åŠ æ—¶ï¿?
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间�
|
||||
* 智能覆盖规则
|
||||
* 1. 值更小:不添
|
||||
* 2. 值相同且都是临时:叠加时
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间
|
||||
*/
|
||||
addBuff(buffConf: BuffConf) {
|
||||
const isValue = buffConf.BType === BType.VALUE;
|
||||
const isPermanent = buffConf.time === 0;
|
||||
const attrIndex = buffConf.buff;
|
||||
|
||||
// æ ¹æ<EFBFBD>®ç±»åž‹é€‰æ‹©å¯¹åº”ï¿?buff å—å…¸
|
||||
// 根据类型选择对应buff 字典
|
||||
const permanentBuffs = isValue ? this.BUFF_V : this.BUFF_R;
|
||||
const temporaryBuffs = isValue ? this.BUFFS_V : this.BUFFS_R;
|
||||
|
||||
if (isPermanent) {
|
||||
// æ·»åŠ æŒ<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 {
|
||||
// æ·»åŠ ä¸´æ—¶ï¿?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>需è¦<EFBFBD>é‡<EFBFBD>算属ï¿?
|
||||
return; // 时间叠加不需要重算属
|
||||
} else {
|
||||
// 值更大,更新值和时间
|
||||
existing.value = buffConf.value;
|
||||
@@ -231,44 +239,40 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
// å<>ªé‡<C3A9>新计算å<E28094>—å½±å“<C3A5>的属ï¿?
|
||||
this.recalculateSingleAttr(buffConf.buff);
|
||||
}
|
||||
|
||||
// ==================== DEBUFF管理 ====================
|
||||
/**
|
||||
* 添加 debuff 效果(智能覆盖)
|
||||
* @param dbuffConf debuff é…<EFBFBD>ç½® (æ<>¥è‡ª SkillSet.DbuffConf ï¿?heroSet.debuff)
|
||||
* @param dbuffConf debuff 配置 (来自 SkillSet.DbuffConf heroSet.debuff)
|
||||
*
|
||||
* 支æŒ<EFBFBD>两ç§<EFBFBD> debuffï¿?
|
||||
* 1. 属性型 debuff:直接修改属性值(有对应的 Attrs�
|
||||
* 支持两种 debuff
|
||||
* 1. 属性型 debuff:直接修改属性值(有对应的 Attrs
|
||||
* 2. 状态型 debuff:只缓存状态(无对应的 Attrs,用于状态检查)
|
||||
*
|
||||
* 智能覆盖规则�
|
||||
* 1. 值更å°<EFBFBD>:ä¸<EFBFBD>æ·»ï¿?
|
||||
* 2. 值相å<EFBFBD>Œä¸”都是临时:å<EFBFBD> åŠ æ—¶ï¿?
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间�
|
||||
* 智能覆盖规则
|
||||
* 1. 值更小:不添
|
||||
* 2. 值相同且都是临时:叠加时
|
||||
* 3. 值更大:更新为新值(临时则更新值和时间
|
||||
*/
|
||||
addDebuff(dbuffConf: DbuffConf) {
|
||||
// 获å<EFBFBD>– debuff 对应的属性å—ï¿?
|
||||
// attrField = -1 表示状æ€<C3A6>ç±» debuff(å<CB86>ªç¼“å˜ï¼Œä¸<C3A4>修改属性)
|
||||
// attrField >= 0 表示属性类 debuff(会修改属性)
|
||||
const attrField = getAttrFieldFromDebuff(dbuffConf.debuff);
|
||||
// 获取 debuff 对应的属性字
|
||||
|
||||
const isValue = dbuffConf.BType === BType.VALUE;
|
||||
const isPermanent = dbuffConf.time === 0;
|
||||
|
||||
// æ ¹æ<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>ä¹…ï¿?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 {
|
||||
// æ·»åŠ ä¸´æ—¶ï¿?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>需è¦<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>•个属�?
|
||||
* @param attrIndex 属性索�
|
||||
* 重新计算单个属性
|
||||
* @param attrIndex 属性索引
|
||||
*
|
||||
* 计算公式:
|
||||
* - 数值型属性:最终值 = (基础值 + 数值型buff - 数值型debuff) × (1 + 百分比buff/100 - 百分比debuff/100)
|
||||
* - 百分比型属性:最终值 = 基础值 + 数值型buff - 数值型debuff + 百分比buff - 百分比debuff
|
||||
*/
|
||||
private recalculateSingleAttr(attrIndex: number) {
|
||||
// 1. é‡<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. ç¡®ä¿<C3A4>属性值å<C2BC>ˆï¿?
|
||||
// 5. 确保属性值合理
|
||||
this.clampSingleAttr(attrIndex);
|
||||
}
|
||||
/**
|
||||
* ç¡®ä¿<EFBFBD>å<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 的剩余时�
|
||||
* 应在 update ä¸å®šæœŸè°ƒï¿?
|
||||
* @param dt æ—¶é—´ï¿?
|
||||
* 更新临时 buff/debuff 的剩余时
|
||||
* 应在 update 中定期调
|
||||
* @param dt 时间
|
||||
*/
|
||||
updateTemporaryBuffsDebuffs(dt: number) {
|
||||
const affectedAttrs = new Set<number>();
|
||||
|
||||
// 更新临时型数�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 {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新临时型数�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>新计算å<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>切ï¿?
|
||||
//状态切
|
||||
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>†ä¸‹ä¸€ä¸ªä¼¤ï¿?
|
||||
// 设置延时处理下一个伤
|
||||
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("暴击伤害� + damage);
|
||||
// //console.log("暴击伤害 + damage);
|
||||
} else {
|
||||
this.BUFFCOMP.hp_tip(TooltipTypes.life, damage.toFixed(0), damage);
|
||||
// //console.log("普通伤害:" + damage);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { HeroInfo } from "../common/config/heroSet";
|
||||
import { MonModelComp } from "./MonModelComp";
|
||||
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
||||
import { SkillConComp } from "./SkillConComp";
|
||||
import { BuffAttr, getBuffNum, SkillSet } from "../common/config/SkillSet";
|
||||
import { Attrs, getAttrs, SkillSet } from "../common/config/SkillSet";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Monster`)
|
||||
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) {
|
||||
var hv = node.getComponent(HeroViewComp)!;
|
||||
hv.hide_info()
|
||||
|
||||
|
||||
// console.log("hero_init",buff)
|
||||
let hero= HeroInfo[uuid] // 共用英雄数据
|
||||
|
||||
hv.scale = scale;
|
||||
hv.fac = FacSet.MON;
|
||||
hv.type = hero.type;
|
||||
@@ -77,11 +79,9 @@ export class Monster extends ecs.Entity {
|
||||
hv.box_group = box_group;
|
||||
hv.hero_uuid= uuid;
|
||||
hv.hero_name= hero.name;
|
||||
|
||||
// 初始化Attrs属性系统,参考Hero.ts的实现
|
||||
hv.Attrs = getBuffNum();
|
||||
|
||||
// 计算基础属性(使用关卡倍数)
|
||||
|
||||
// 初始化Attrs属性系统,参考Hero.ts的实
|
||||
// 计算基础属性(使用关卡倍数)
|
||||
const baseHp = hero.hp;
|
||||
const baseAp = hero.ap;
|
||||
|
||||
@@ -93,46 +93,29 @@ export class Monster extends ecs.Entity {
|
||||
finalHp = Math.floor(baseHp * stageMultipliers.hp);
|
||||
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}`);
|
||||
} else {
|
||||
// console.log(`[Monster]: 怪物${hero.name} 使用基础属性 - HP: ${finalHp}, AP: ${finalAp}`);
|
||||
}
|
||||
|
||||
hv.base_ap=finalAp
|
||||
hv.base_map=hero.mp
|
||||
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();
|
||||
|
||||
hv.hp = hv.hp_max = finalHp;
|
||||
hv.ap = finalAp;
|
||||
hv.ap_base = finalAp;
|
||||
|
||||
// 设置基础属性到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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,9 +32,8 @@ export class SkillConComp extends CCComp {
|
||||
|
||||
update(dt: number) {
|
||||
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(!hasStun && !hasFrost) {
|
||||
|
||||
if(!this.HeroView.isStun() && !this.HeroView.isFrost()) {
|
||||
let skills=this.HeroView.skills
|
||||
for(let i=0;i<skills.length;i++){
|
||||
skills[i].cd += dt;
|
||||
@@ -49,7 +48,6 @@ export class SkillConComp extends CCComp {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user