81 lines
2.8 KiB
TypeScript
81 lines
2.8 KiB
TypeScript
import { _decorator,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 { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
import { Skill } from "../skills/Skill";
|
|
import { SkillSet } from "../common/config/CardSet";
|
|
import { Monster } from "./Monster";
|
|
import { MonsterModelComp } from "./MonsterModelComp";
|
|
import { MonsterViewComp } from "./MonsterViewComp";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('CSkillComp')
|
|
@ecs.register('CSkill', false)
|
|
export class CSkillComp extends CCComp {
|
|
//持续时间
|
|
private sd:Timer = new Timer(5)
|
|
private cd:Timer = new Timer(1)
|
|
private is_destroy:boolean = false;
|
|
scale:number = 1;
|
|
speed:number = 0;
|
|
dis:number = 0;
|
|
atk:number = 0;
|
|
skill_uuid:number = 1001;
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
this.sd =new Timer(SkillSet[this.skill_uuid].sd)
|
|
this.cd = new Timer(SkillSet[this.skill_uuid].cd)
|
|
|
|
}
|
|
protected update(dt: number): void {
|
|
if (this.sd.update(dt)) {
|
|
if (this.is_destroy) {
|
|
return
|
|
}
|
|
this.to_destroy()
|
|
}
|
|
if (this.cd.update(dt)) {
|
|
this.shoot()
|
|
}
|
|
}
|
|
shoot() {
|
|
let skill = ecs.getEntity<Skill>(Skill);
|
|
let pos = v3(0,0)
|
|
let t_pos:Vec3=null
|
|
let monsters:any = ecs.query(ecs.allOf(MonsterModelComp));
|
|
for (const monster of monsters) {
|
|
t_pos= monster.getComponent(MonsterViewComp).get_monster_pos()
|
|
}
|
|
let scale = this.scale
|
|
let dis = SkillSet[this.skill_uuid].dis+this.dis;
|
|
let atk = SkillSet[this.skill_uuid].atk+this.atk;
|
|
let speed = SkillSet[this.skill_uuid].speed+this.speed;
|
|
let sp_name = SkillSet[this.skill_uuid].sp_name
|
|
skill.load(pos,speed,dis,scale,this.node,sp_name,atk,t_pos);
|
|
}
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
to_destroy() {
|
|
this.is_destroy = true
|
|
// console.log("CSkillComp toDestroy");
|
|
if (this.node.isValid) {
|
|
// console.log("CSkillComp.node.isValid");
|
|
setTimeout(() => {
|
|
// console.log("CSkillComp.node.destroy",this);
|
|
this.ent.destroy()
|
|
}, 10);
|
|
}
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |