refactor(战斗系统): 优化伤害计算与技能释放逻辑,下一步 将伤害信标处理,改为队列处理
- 移除HeroViewComp中的调试日志 - 缩短技能释放前摇时间从0.3秒到0.1秒 - 重构Skill类,清理无用导入并优化属性传递 - 改进HeroAtkSystem,添加伤害数据深拷贝避免重复处理 - 完善SkillView,增加技能结束类型处理并优化伤害应用逻辑
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import { instantiate, Node, Prefab, v3, Vec3 } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { Hero } from "../hero/Hero";
|
||||
import { Monster } from "../hero/Mon";
|
||||
import { ECSEntity } from "db://oops-framework/libs/ecs/ECSEntity";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { AtkConCom } from "./AtkConCom";
|
||||
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
||||
import { BoxSet, FacSet } from "../common/config/BoxSet";
|
||||
import { HType } from "../common/config/heroSet";
|
||||
|
||||
import { SkillView } from "./SkillView";
|
||||
import { SDataCom } from "./SDataCom";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
import { SMoveDataComp } from "../skill/SMoveComp";
|
||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
|
||||
@@ -75,13 +69,14 @@ export class Skill extends ecs.Entity {
|
||||
sMoveCom.s_uuid=s_uuid
|
||||
sMoveCom.scale=caster.node.scale.x < 0 ? -1 : 1
|
||||
|
||||
let casterAttrs=caster.ent.get(HeroAttrsComp).Attrs
|
||||
let cAttrsComp=caster.ent.get(HeroAttrsComp)
|
||||
// 初始化数据组件
|
||||
const sDataCom = this.get(SDataCom);
|
||||
sDataCom.group=caster.box_group
|
||||
sDataCom.caster=caster
|
||||
sDataCom.Attrs=casterAttrs
|
||||
sDataCom.Attrs=cAttrsComp.Attrs
|
||||
sDataCom.s_uuid=s_uuid
|
||||
sDataCom.fac=cAttrsComp.fac
|
||||
}
|
||||
|
||||
/** 模块资源释放 */
|
||||
|
||||
@@ -2,14 +2,15 @@ import { _decorator, Animation, CCInteger, Collider2D, Contact2DType, UITransfor
|
||||
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, EType, RType, SkillSet } from "../common/config/SkillSet";
|
||||
import { DTType, EType, RType, SkillConfig, SkillSet } from "../common/config/SkillSet";
|
||||
import { BezierMove } from "../BezierMove/BezierMove";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { BoxSet, FacSet } from "../common/config/BoxSet";
|
||||
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";
|
||||
import { HeroMoveComp } from "../hero/HeroMove";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -23,15 +24,18 @@ export class SkillView extends CCComp {
|
||||
@property({ type: CCInteger })
|
||||
atk_y: number = 0
|
||||
@property({ type: CCInteger })
|
||||
runType: number = 0 //技能运行类型 0-线性 1-贝塞尔 2-开始位置固定 3-目标位置固定
|
||||
runType: RType = 0 //技能运行类型 0-线性 1-贝塞尔 2-开始位置固定 3-目标位置固定
|
||||
@property({ type: CCInteger })
|
||||
endType: EType = 0 //
|
||||
|
||||
anim:Animation=null;
|
||||
group:number=0;
|
||||
SConf:any=null;
|
||||
SConf:SkillConfig=null;
|
||||
sData:SDataCom=null;
|
||||
s_uuid:number=1001
|
||||
start() {
|
||||
console.log("SkillView start scale",this.node.scale)
|
||||
this.SConf = SkillSet[this.s_uuid]
|
||||
this.sData=this.ent.get(SDataCom)
|
||||
this.anim=this.node.getComponent(Animation)
|
||||
this.node.active = true;
|
||||
let collider = this.getComponent(Collider2D);
|
||||
@@ -67,11 +71,13 @@ export class SkillView extends CCComp {
|
||||
if(oCol.group!=this.group){
|
||||
if(target == null) return;
|
||||
if (!this.SConf) return;
|
||||
if(this.endType==EType.collision){
|
||||
this.apply_damage(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_bezier(startPos:Vec3,targetPos:Vec3){
|
||||
console.log("do_bezier",startPos,targetPos)
|
||||
let bm=this.node.getComponent(BezierMove)
|
||||
this.node.angle +=10
|
||||
// bm.speed=700
|
||||
@@ -80,7 +86,6 @@ export class SkillView extends CCComp {
|
||||
bm.moveTo(targetPos)
|
||||
}
|
||||
do_linear(startPos:Vec3,targetPos:Vec3){
|
||||
console.log("do_linear",startPos,targetPos)
|
||||
let bm=this.node.getComponent(BezierMove)
|
||||
let s_x=startPos.x
|
||||
let s_y=startPos.y
|
||||
@@ -101,12 +106,11 @@ export class SkillView extends CCComp {
|
||||
bm.moveTo(targetPos);
|
||||
}
|
||||
do_fixedEnd(startPos:Vec3,targetPos:Vec3){
|
||||
console.log("do_fixedEnd",startPos,targetPos)
|
||||
this.node.setPosition(targetPos.x > 360?300:targetPos.x,this.node.position.y,0)
|
||||
this.do_anim()
|
||||
}
|
||||
do_fixedStart(startPos:Vec3,targetPos:Vec3){
|
||||
console.log("do_fixedStart",startPos,targetPos)
|
||||
// console.log("do_fixedStart",startPos,targetPos)
|
||||
this.node.setPosition(startPos.x,this.node.position.y,0)
|
||||
this.do_anim()
|
||||
}
|
||||
@@ -118,18 +122,18 @@ export class SkillView extends CCComp {
|
||||
}
|
||||
}
|
||||
onAnimationFinished(){
|
||||
|
||||
if(this.endType==EType.animationEnd){
|
||||
this.ent.destroy()
|
||||
}
|
||||
}
|
||||
//动画帧事件 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){
|
||||
if( this.sData.fac==FacSet.HERO){
|
||||
enemys=ecs.query(ecs.allOf(MonMoveComp))
|
||||
}else{
|
||||
enemys=ecs.query(ecs.allOf(HeroViewComp))
|
||||
enemys=ecs.query(ecs.allOf(HeroMoveComp))
|
||||
}
|
||||
let IRTargets: HeroViewComp[] = []
|
||||
// 收集范围内所有敌方目标
|
||||
@@ -174,17 +178,15 @@ export class SkillView extends CCComp {
|
||||
apply_damage(target:HeroViewComp,is_range:boolean=false){
|
||||
if(target == null) return;
|
||||
if (!this.SConf) return;
|
||||
let sData=this.ent.get(SDataCom)
|
||||
//伤害处理
|
||||
target.ent.add(DmgDataCom)
|
||||
target.ent.addComponents<DmgDataCom>(DmgDataCom)
|
||||
let dmgData=target.ent.get(DmgDataCom)
|
||||
dmgData.Attrs=sData.Attrs
|
||||
dmgData.caster=sData.caster
|
||||
dmgData.s_uuid=sData.s_uuid
|
||||
console.log("[SkillCom]:apply_damage",target,sData,dmgData)
|
||||
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// 技能命中次数
|
||||
dmgData.Attrs= this.sData.Attrs
|
||||
dmgData.caster= this.sData.caster
|
||||
dmgData.s_uuid= this.sData.s_uuid
|
||||
// console.log(`[SkillCom]: ${this.sData.caster.ent.get(HeroAttrsComp).hero_name}[${this.sData.caster.ent.get(HeroAttrsComp).fac}:${ this.sData.fac}:${target.ent.get(HeroAttrsComp).fac}] 对 ${target.ent.get(HeroAttrsComp).hero_name} 释放技能 ${this.SConf.name}`)
|
||||
this.sData.hit_count++
|
||||
if( this.sData.hit_count>=(this.SConf.hit+ this.sData.Attrs[Attrs.PUNCTURE])&&(this.SConf.DTType!=DTType.range)&&(this.endType!=EType.animationEnd)&&(this.endType!=EType.timeEnd)) this.ent.destroy// 技能命中次数
|
||||
}
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
|
||||
Reference in New Issue
Block a user