refactor(skill): 重构伤害计算逻辑
- 删除SkillEnt.ts及其meta文件,简化技能实体管理 - 将SDataCom重命名为更清晰的DmgDataCom和SDataCom - 重构伤害计算系统,增加命中检测和伤害类型处理 - 优化技能碰撞检测逻辑,支持范围伤害和数量限制
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import { _decorator, Animation, CCInteger, Collider2D, Contact2DType, v3, Vec3 } from "cc";
|
||||
import { _decorator, Animation, CCInteger, Collider2D, Contact2DType, UITransform, 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 { DTType, RType, SkillSet } from "../common/config/SkillSet";
|
||||
import { DTType, EType, RType, SkillSet } from "../common/config/SkillSet";
|
||||
import { BezierMove } from "../BezierMove/BezierMove";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { SDataCom } from "./SDataCom";
|
||||
import { DmgDataCom, SDataCom } from "./SDataCom";
|
||||
import { SMoveDataComp } from "./SMoveComp";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
import { MonMoveComp } from "../hero/MonMove";
|
||||
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -108,6 +111,71 @@ export class SkillView extends CCComp {
|
||||
}
|
||||
onAnimationFinished(){
|
||||
|
||||
}
|
||||
//动画帧事件 atk 触发
|
||||
public atk(args:any){
|
||||
let dis=this.node.getComponent(UITransform).width/2
|
||||
let sData=this.ent.get(SDataCom)
|
||||
let fac=sData.fac
|
||||
let enemys:any=[]
|
||||
if(fac==BoxSet.HERO){
|
||||
enemys=ecs.query(ecs.allOf(MonMoveComp))
|
||||
}else{
|
||||
enemys=ecs.query(ecs.allOf(HeroViewComp))
|
||||
}
|
||||
let IRTargets: HeroViewComp[] = []
|
||||
// 收集范围内所有敌方目标
|
||||
enemys.some(e => {
|
||||
const view = e.get(HeroViewComp);
|
||||
const distance = Math.abs(this.node.position.x - view.node.position.x);
|
||||
if(distance <= dis) {
|
||||
IRTargets.push(view);
|
||||
}
|
||||
|
||||
});
|
||||
// 根据配置的hit_num决定攻击模式
|
||||
const hitNum = SkillSet[this.s_uuid].hit_num || 0;
|
||||
if(hitNum > 0) {
|
||||
// 限制目标数量:按距离排序,选择最近的N个目标
|
||||
if(IRTargets.length > 0) {
|
||||
// 按距离排序(从近到远)
|
||||
IRTargets.sort((a, b) => {
|
||||
const distanceA = Math.abs(this.node.position.x - a.node.position.x);
|
||||
const distanceB = Math.abs(this.node.position.x - b.node.position.x);
|
||||
return distanceA - distanceB;
|
||||
});
|
||||
|
||||
// 限制目标数量
|
||||
const maxTargets = Math.min(hitNum, IRTargets.length);
|
||||
const sTargets = IRTargets.slice(0, maxTargets);
|
||||
|
||||
sTargets.forEach(target => {
|
||||
this.apply_damage(target, false);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 范围伤害:对所有范围内目标造成伤害
|
||||
if(IRTargets.length > 0) {
|
||||
IRTargets.forEach(target => {
|
||||
this.apply_damage(target, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
//伤害应用
|
||||
apply_damage(target:HeroViewComp,is_range:boolean=false){
|
||||
if(target == null) return;
|
||||
if (!this.SConf) return;
|
||||
let sData=this.ent.get(SDataCom)
|
||||
//伤害处理
|
||||
let dmgData=target.ent.add(DmgDataCom)
|
||||
dmgData.Attrs=sData.Attrs
|
||||
dmgData.caster=sData.caster
|
||||
dmgData.s_uuid=sData.s_uuid
|
||||
|
||||
sData.hit_count++
|
||||
// console.log("[SkillCom]:碰撞次数:技能次数:穿刺次数",this.hit_count,this.Config.hit,this.puncture)
|
||||
if(sData.hit_count>=(this.SConf.hit+sData.Attrs[Attrs.PUNCTURE])&&(this.SConf.DTType!=DTType.range)&&(this.SConf.EType!=EType.animationEnd)&&(this.SConf.EType!=EType.timeEnd)) this.ent.destroy// 技能命中次数
|
||||
}
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
|
||||
Reference in New Issue
Block a user