Files
heros/assets/script/game/skill/SkillViewCom.ts
walkpan 2cdb25ac58 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,以保持一致性
2025-10-17 22:02:23 +08:00

158 lines
5.9 KiB
TypeScript

import { _decorator, CCBoolean, CCInteger, instantiate, Node, Prefab, v3, Vec3 } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { HeroViewComp } from "../hero/HeroViewComp";
import { getAttrs, RType, SkillSet } from "../common/config/SkillSet";
import { AtkConCom } from "./AtkConCom";
import { BoxSet } from "../common/config/BoxSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('SkillViewCom')
@ecs.register('SkillView', false)
export class SkillViewCom extends CCComp {
/** 视图层逻辑代码分离演示 */
@property({ type: Prefab })
atkPrefab: Prefab = null!
@property
hasReady: boolean = false;
@property({ type: CCInteger })
ReadyTime: number = 0
@property({ type: CCInteger })
runType: number = 0
@property({ type: CCInteger })
ready_y: number = 0
@property({ type: CCInteger })
atk_x: number = 0
@property({ type: CCInteger })
atk_y: number = 0
endTime: number = 0;
readyFinish: boolean = false;
caster:HeroViewComp=null!;
s_uuid:number=0;
s_count:number=1;
s_interval:number=0.2;
s_cd:number=0;
scale: number = 0;
cName:string="";
target:HeroViewComp=null;
parent:Node=null;
target_postions:any[]=null
group:number=0
fac:number=0
// 战斗相关运行时数据
Attrs:any=null
startPos:any=null
targetPos:any=null
start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
this.node.getChildByName("ready").active = this.hasReady
console.log("[skillView] start ",this.hasReady)
}
protected update(dt: number): void {
this.doTimer(dt)
this.move(dt)
this.doEnd(dt)
this.do_cd(dt)
if(this.readyFinish) this.doAtk(dt)
}
doEnd(dt: number) {
this.endTime += dt
if(this.endTime >= SkillSet[this.s_uuid].in) {
this.ent.destroy()
}
}
doTimer(dt: number){
console.log('[skillview]:doTimer',this.ReadyTime,this.readyFinish)
if(this.ReadyTime > 0) this.ReadyTime -= dt
if(this.ReadyTime <=0) this.readyFinish=true
}
doAtk(dt:number): void {
console.log(`${this.cName}_[SkillViewCom] doAtkC`,this.s_cd,this.s_count)
if(this.s_cd <= 0&&this.s_count > 0) {
console.log(`${this.cName}_[SkillViewCom] doAtk 2`)
this.doSkill()
this.s_count--
this.s_cd = this.s_interval
}
}
do_cd(dt:number){
if(this.s_cd > 0) this.s_cd -= dt
}
doSkill(){
console.log(`${this.cName}_[SkillViewCom] atkPrefab`,this.atkPrefab)
if(this.atkPrefab!=null){
let atkNode:Node = instantiate(this.atkPrefab)
atkNode.parent = this.node.parent
if(this.node.scale.x < 0){
atkNode.setScale(v3(atkNode.scale.x*-1,atkNode.scale.y,atkNode.scale.z))
}
atkNode.setPosition(v3(this.node.position.x + this.atk_x*atkNode.scale.x, this.node.position.y + this.atk_y))
console.log(`${this.cName}_[SkillViewCom] doSkill atkNode`,this.node.position,atkNode.position)
let atkCom=atkNode.getComponent(AtkConCom)
// 计算延长后的目标点坐标
const originalStart = v3(this.node.position.x + this.atk_x, this.node.position.y + this.atk_y);
const originalTarget = v3(this.targetPos[0].x, this.targetPos[0].y + BoxSet.ATK_Y);
const direction = new Vec3();
Vec3.subtract(direction, originalTarget, originalStart);
const distance = direction.length();
direction.normalize();
const extendedTarget = new Vec3();
Vec3.scaleAndAdd(extendedTarget, originalTarget, direction, 720);
Object.assign(atkCom, {
// 核心标识
s_uuid: this.s_uuid,
// 位置和施法者信息
startPos: originalStart,
targetPos: extendedTarget,
group: this.group,
fac: this.fac,
// 技能数值
Attrs:this.Attrs
});
switch(this.runType){
case RType.linear:
this.do_linear(atkNode)
break
case RType.bezier:
this.do_bezier(atkNode)
break
case RType.fixed:
this.do_fixed(atkNode)
break
case RType.fixedEnd:
this.do_fixedEnd(atkNode)
break
}
}
}
do_linear(atkNode:any): void {
console.log(`${this.cName}_[SkillViewCom] skille run type: linear`,this.node.position,atkNode.position)
atkNode.getComponent(AtkConCom).do_line()
}
do_bezier(atkNode:any): void {
console.log(`${this.cName}_[SkillViewCom] skille run type: bezier`)
atkNode.getComponent(AtkConCom).do_parabolic()
}
do_fixed(atkNode:any): void {
console.log(`${this.cName}_[SkillViewCom] skille run type: fixed`)
atkNode.getComponent(AtkConCom).do_fixedStart()
}
do_fixedEnd(atkNode:any): void {
console.log(`${this.cName}_[SkillViewCom] skille run type: fixedEnd`)
atkNode.getComponent(AtkConCom).do_fixedEnd()
}
move(dt: number): void {
// console.log(`${this.cName}_[SkillViewCom] move`)
if(this.caster != null&&this.caster.node!=null) this.node.setPosition(this.caster.node.position.x,this.caster.node.position.y+this.ready_y)
// console.log(`${this.cName}_[skillview]move`,this.caster.node.position,this.node.position)
}
reset() {
this.node.destroy();
}
}