185 lines
6.8 KiB
TypeScript
185 lines
6.8 KiB
TypeScript
import { _decorator, CCBoolean, 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 { BuffAttr, 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({ type: CCInteger })
|
|
ReadyTime: number = 0
|
|
@property({ type: CCInteger })
|
|
runType: number = 0
|
|
@property({ type: CCInteger })
|
|
ready_y: number = 0
|
|
@property({ type: CCInteger })
|
|
atk_x: number = 0
|
|
@property({ type: CCInteger })
|
|
atk_y: number = 0
|
|
|
|
endTime: number = 0;
|
|
readyFinish: boolean = false;
|
|
caster:HeroViewComp=null!;
|
|
s_uuid:number=0;
|
|
s_count:number=1;
|
|
s_interval:number=0.2;
|
|
s_cd:number=0;
|
|
scale: number = 0;
|
|
cName:string="";
|
|
target:HeroViewComp=null;
|
|
parent:Node=null;
|
|
target_postions:any[]=null
|
|
group:0
|
|
fac: 0
|
|
// 战斗相关运行时数据
|
|
ap:number=0;
|
|
burn_count:number=0;
|
|
burn_value:number=0;
|
|
stun_time:number=0;
|
|
stun_ratio:number=0;
|
|
frost_ratio:number=0;
|
|
frost_time:number=0;
|
|
run_time:number=0;
|
|
hited_time:number=0;
|
|
hit_count:number=0;
|
|
caster_crit:number=0;
|
|
caster_crit_d:number=0;
|
|
puncture:number=0;
|
|
puncture_damage:number=0;
|
|
debuff_up:number=0;
|
|
debuff_value:number=0;
|
|
debuff_count:number=0;
|
|
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 >= SkillSet[this.s_uuid].in) {
|
|
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,
|
|
// 技能数值
|
|
ap: this.ap,
|
|
caster_crit: this.caster_crit,
|
|
caster_crit_d: this.caster_crit_d,
|
|
puncture: this.puncture,
|
|
puncture_damage: this.puncture_damage,
|
|
burn_count: this.burn_count,
|
|
burn_value: this.burn_value,
|
|
stun_time: this.stun_time,
|
|
stun_ratio: this.stun_ratio,
|
|
frost_time: this.frost_time,
|
|
frost_ratio: this.frost_ratio,
|
|
debuff_up: this.debuff_up,
|
|
debuff_value: this.debuff_value,
|
|
debuff_count: this.debuff_count,
|
|
});
|
|
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();
|
|
}
|
|
} |