import { _decorator, CCBoolean, CCFloat, 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 withHero: boolean = true @property ReadyLoop: boolean = false // 预备是否循环 @property({ type: CCFloat }) SkillTime: number = 0 // 技能控制存续时间时间 @property({ type: CCFloat }) ReadyTime: number = 0 // 技能前摇时间 @property({ type: CCInteger }) runType: number = 0 //技能运行类型 0-线性 1-贝塞尔 2-开始位置固定 3-目标位置固定 @property({ type: CCInteger }) ready_y: number = 0 @property({ type: CCInteger }) atk_x: number = 0 @property({ type: CCInteger }) atk_y: number = 0 @property({ type: CCInteger }) s_count:number=1; @property({ type: CCFloat }) s_interval:number=0.2; endTime: number = 0; readyFinish: boolean = false; caster:HeroViewComp=null!; s_uuid:number=0; 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 this.node.setPosition(this.caster.node.position.x,this.caster.node.position.y+this.ready_y) } 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 >= this.SkillTime) { this.ent.destroy() } } doTimer(dt: number){ if(this.ReadyTime > 0) this.ReadyTime -= dt if(this.ReadyTime <=0) this.readyFinish=true } doAtk(dt:number): void { if(this.s_cd <= 0&&this.s_count > 0) { 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(){ if(this.atkPrefab!=null){ let atkNode:Node = instantiate(this.atkPrefab) atkNode.parent = this.node.parent atkNode.setPosition(v3(this.node.position.x + this.atk_x*atkNode.scale.x, this.node.position.y + this.atk_y)) if(this.node.scale.x < 0){ atkNode.setScale(v3(atkNode.scale.x*-1,atkNode.scale.y,atkNode.scale.z)) } 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 { atkNode.getComponent(AtkConCom).do_line() } do_bezier(atkNode:any): void { atkNode.getComponent(AtkConCom).do_parabolic() } do_fixed(atkNode:any): void { atkNode.getComponent(AtkConCom).do_fixedStart() } do_fixedEnd(atkNode:any): void { atkNode.getComponent(AtkConCom).do_fixedEnd() } move(dt: number): void { // console.log(`${this.cName}_[SkillViewCom] move`) if(this.caster != null&&this.caster.node!=null&&this.withHero) 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(); } }