import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween, math, RigidBody2D, Animation, sp, Tween} 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 { smc } from "../common/SingletonModuleComp"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { GameEvent } from "../common/config/GameEvent"; import { AType, DTType, EType, SkillSet, SType, TGroup } from "../common/config/SkillSet"; import { BoxSet, FacSet } from "../common/config/BoxSet"; import { HeroViewComp } from "../hero/HeroViewComp"; import { BezierMove } from "../BezierMove/BezierMove"; import { MonModelComp } from "../hero/MonModelComp"; import { FightSet } from "../common/config/Mission"; import { HeroModelComp } from "../hero/HeroModelComp"; import { Skill } from "./Skill"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('SkillCom') @ecs.register('SkillCom') export class SkillCom extends CCComp { s_uuid:number = 0; s_name:string = ""; hero:number = 0; speed:number = 200; scale:number = 1; angle:number = 0; atk_count:number = 0; is_destroy:boolean = false; enemys:any = []; AType: number = 0; // 运动类型 startPos: Vec3 = v3(); // 起始位置 targetPos: Vec3 = v3(); // 目标位置 duration: number = 0; // 技能持续时间 prefabName: string = ""; // 预制体名称 animName: string = ""; group:number = 0; //阵营 fac:number=0; //阵营 caster:any=null; distance_x:number=0; distance_y:number=0; ap:number=0; buV:number=0; buC:number=0; buR:number=0; burn_count:number=0; burn_value:number=0; stun_time:number=0; stun_ratto:number=0; frost_ratto:number=0; frost_time:number=0; run_time:number=0; hited_time:number=0; hit_count:number=0; spine:sp.Skeleton=null; anim:Animation=null; tweenInstance:Tween = null; t_end_x:number=0; caster_crit:number=0; caster_crit_d:number=0; puncture:number=0; puncture_damage:number=0; EType:any=null private moveDirection: Vec3 | null = null; // 添加一个属性来存储移动方向 protected onLoad(): void { } start() { this.EType=SkillSet[this.s_uuid].EType this.node.setPosition(this.startPos.x,this.startPos.y,0) if(this.node.getChildByName('anm')){ this.spine=this.node.getChildByName('anm').getComponent('sp.Skeleton') as sp.Skeleton; }else{ this.anim=this.node.getComponent(Animation) } this.on(GameEvent.MissionEnd, this.doDestroy, this); this.node.active = true; //console.log("[SkillCom]:caster",this.caster) let collider = this.getComponent(Collider2D); if(collider) { collider.group = this.group; collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); } let bm=this.node.getComponent(BezierMove) // //console.log(this.group +"技能 collider ",collider); switch(SkillSet[this.s_uuid].AType){ case AType.parabolic: this.node.angle +=10 // bm.speed=700 if(this.group==BoxSet.MONSTER) {bm.controlPointSide=-1 } bm.rotationSmoothness=0.6 bm.moveTo(this.targetPos) break; case AType.linear: let s_x=this.startPos.x let s_y=this.startPos.y let t_x=this.targetPos.x let t_y=this.targetPos.y // 设定目标x this.targetPos.x = 400; if(this.group == BoxSet.MONSTER) { bm.controlPointSide = -1; this.targetPos.x = -400; } // 计算斜率 const k = (t_y - s_y) / (t_x - s_x); // 按直线公式计算新的y this.targetPos.y = k * (this.targetPos.x - s_x) + s_y; bm.controlPointOffset=0 bm.rotationSmoothness=0.6 bm.moveTo(this.targetPos); break; case AType.StartEnd: // 2段位移:先升高,然后移到目的地 this.node.setPosition(this.startPos.x > 360?300:this.startPos.x,0,0) this.do_anim() break; case AType.fixedEnd: this.node.setPosition(this.targetPos.x > 360?300:this.targetPos.x,0,0) this.do_anim() break; case AType.fixedStart: // this.node.setPosition(this.startPos.x > 360?300:this.startPos.x,0,0) this.do_anim() break; } } do_anim(){ if(this.node.getComponent(Animation)){ let anim = this.node.getComponent(Animation); //console.log("[SkillCom]:has anim",anim) anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this); } if(this.node.getChildByName('anm')){ if(this.node.getChildByName('anm').getComponent('sp.Skeleton')){ //console.log("[SkillCom]:has spine",this.spine) this.spine.setCompleteListener((trackEntry) => { this.onAnimationFinished() //console.log("[SkillCom]:[track %s][animation %s] complete: %s", trackEntry.trackIndex); }); } } } onAnimationFinished(){ console.log("[SkillCom]:onAnimationFinished",this.s_uuid) if(SkillSet[this.s_uuid].EType==EType.timeEnd) return if(SkillSet[this.s_uuid].SType!=SType.damage){ this.to_do_buff() } this.is_destroy=true } to_do_buff(){ switch(SkillSet[this.s_uuid].SType){ case SType.shield: this.caster.add_shield(SkillSet[this.s_uuid].buV) break; } } //单体伤害 single_damage(target:HeroViewComp,is_range:boolean=false){ // //console.log("[SkillCom]:onBeginContact hit_count:",this.hit_count,SkillSet[this.s_uuid].hit) // if(this.hit_count > 0&&!is_range) this.ap=this.ap*(50+this.puncture_damage)/100 // 穿刺后 伤害减半,过滤范围伤害 if(target == null) return; let ap=this.ap if(this.hit_count > 0 &&!is_range ){ ap=ap*(50+this.puncture_damage)/100 } target.do_atked(ap,this.caster_crit,this.caster_crit_d, this.burn_count,this.burn_value, this.stun_time,this.stun_ratto, this.frost_time,this.frost_ratto) // ap 及暴击 属性已经在skill.ts 处理 // console.log("[SkillCom]:single_damage t:tp:rtp",this.node.position,this.targetPos,target.node.position) if(SkillSet[this.s_uuid].debuff>0){ let debuff=SkillSet[this.s_uuid] let dev=debuff.deV*(100+this.caster.DEBUFF_VALUE)/100 let deR=debuff.deR+this.caster.DEBUFF_UP dev=Math.round(dev*100)/100 let deC=debuff.deC+this.caster.DEBUFF_COUNT //dec只作为次数叠加 // //console.log("[SkillCom]:debuff",SkillSet[this.s_uuid].name,debuff.debuff,deUP.deV,deUP.deC) target.add_debuff(debuff.debuff,dev,deC,deR) } this.hit_count++ // console.log("[SkillCom]:碰撞次数:技能次数:穿刺次数",this.hit_count,SkillSet[this.s_uuid].hit,this.puncture) if(this.hit_count>=(SkillSet[this.s_uuid].hit+this.puncture)&&(SkillSet[this.s_uuid].DTType!=DTType.range)&&(SkillSet[this.s_uuid].EType!=EType.animationEnd)&&(SkillSet[this.s_uuid].EType!=EType.timeEnd)) this.is_destroy=true // 技能命中次数 } onBeginContact (seCol: Collider2D, oCol: Collider2D) { // console.log(this.scale+"碰撞开始 ",seCol,oCol); if(seCol.node.position.x-oCol.node.position.x > 100 ) return let target = oCol.getComponent(HeroViewComp) if(oCol.group!=this.group){ if(target == null) return; // console.log("[SkillCom]:onBeginContact oCol||seCol",oCol.node.position,seCol.node.position) this.single_damage(target,SkillSet[this.s_uuid].DTType==DTType.range?true:false) // this.ent.destroy() } } update(deltaTime: number) { let config=SkillSet[this.s_uuid] if(smc.mission.pause) { if(this.spine) this.spine.paused=true if(this.anim) this.anim.pause() return; } if(this.anim) this.anim.resume() if(this.spine) this.spine.paused=false if (!this.node || !this.node.isValid) return; if(config.EType==EType.timeEnd){ this.run_time+=deltaTime if(this.run_time>config.in){ // //console.log("[SkillCom]: timeEnd destroy",this.s_uuid,this.run_time) this.is_destroy=true } } //直线移动 // if(this.AType == AType.linear) this.startLinearMove(deltaTime); this.toDestroy(); } toDestroy() { if(this.is_destroy){ if (this.ent) { this.ent.destroy(); } else { // 如果ent不存在,直接销毁节点 if (this.node && this.node.isValid) { this.node.destroy(); } } } } doDestroy(){ // //console.log("[SkillCom]:doDestroy") this.is_destroy=true } to_console(value:any,value2:any=null,value3:any=null){ //console.log("[SkillCom]:["+this.s_name+this.s_uuid+"]:",value,value2,value3) } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.is_destroy = false; this.AType = 0; this.speed = 0; this.startPos.set(); this.targetPos.set(); this.moveDirection = null; // 重置移动方向 // 先移除所有碰撞回调 const collider = this.getComponent(Collider2D); if (collider) { collider.off(Contact2DType.BEGIN_CONTACT); } this.scheduleOnce(() => { this.node.destroy(); }, 0); } }