- 调整了英雄角色top.prefab节点结构和组件关联,优化层级关系和属性值 - 修改pow、mpb等子节点的组件及位置,提升表现效果 - 更新技能atk_fires.prefab增加了ReadyLoop、SkillTime等新属性 - 调整攻击技能atk_s1.prefab的运行类型及相关时间与计数参数 - 修正atk_s1.prefab目标覆盖配置,完善prefab实例结构 - 精简atk_s_1.prefab的子节点引用,去除冗余id链接,简化资源结构
164 lines
6.2 KiB
TypeScript
164 lines
6.2 KiB
TypeScript
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
|
|
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
|
|
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 >= this.SkillTime) {
|
|
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();
|
|
}
|
|
} |