132 lines
4.8 KiB
TypeScript
132 lines
4.8 KiB
TypeScript
import { _decorator,v3,Vec3 ,Label} 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/SkillSet";
|
|
import { Monster } from "./Monster";
|
|
import { MonsterModelComp } from "./MonsterModelComp";
|
|
import { MonsterViewComp } from "./MonsterViewComp";
|
|
import { BoxSet } from "../common/config/BoxSet";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { HeroModelComp } from "./HeroModelComp";
|
|
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;
|
|
time:number = 0;
|
|
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(smc.skills[this.skill_uuid].sd)
|
|
this.cd = new Timer(smc.skills[this.skill_uuid].cd)
|
|
this.time =smc.skills[this.skill_uuid].sd
|
|
this.node.getChildByName("time").getComponent(Label).string = this.time.toString()
|
|
|
|
}
|
|
protected update(dt: number): void {
|
|
if (this.sd.update(dt)) {
|
|
if (this.is_destroy) {
|
|
return
|
|
}
|
|
this.to_destroy()
|
|
}
|
|
if (this.cd.update(dt)) {
|
|
this.time -=1
|
|
this.node.getChildByName("time").getComponent(Label).string = this.time.toString()
|
|
if(smc.skills[this.skill_uuid].type == 1){
|
|
this.shoot()
|
|
}
|
|
if(smc.skills[this.skill_uuid].type == 9){
|
|
this.add_buff()
|
|
}
|
|
|
|
}
|
|
}
|
|
shoot() {
|
|
let skill = ecs.getEntity<Skill>(Skill);
|
|
let pos = v3(0,0)
|
|
let t_pos = v3(0,0)
|
|
let angle = 0
|
|
let m_pos=v3(0,0)
|
|
let monsters:any = ecs.query(ecs.allOf(MonsterModelComp));
|
|
if (monsters.length > 0) {
|
|
m_pos = monsters[0].MonsterView.get_monster_pos()
|
|
|
|
}else{
|
|
m_pos = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
|
|
}
|
|
t_pos = v3(m_pos.x-this.node.position.x,m_pos.y-this.node.position.y) // 目标增量
|
|
// console.log("m_pos",m_pos);
|
|
// console.log("pos",this.node.position);
|
|
// console.log("t_pos",t_pos);
|
|
let dx=m_pos.x-this.node.position.x
|
|
let dy=m_pos.y-this.node.position.y
|
|
let dir=v3(dx,dy,0)
|
|
let randian=Math.atan2(dir.y,dir.x)
|
|
angle = randian * (180 / Math.PI);
|
|
// console.log("angle",angle);
|
|
let scale = this.scale
|
|
let dis = smc.skills[this.skill_uuid].dis+this.dis;
|
|
let atk = smc.skills[this.skill_uuid].atk+this.atk;
|
|
let speed = smc.skills[this.skill_uuid].speed+this.speed;
|
|
skill.load(pos,speed,dis,scale,this.node,this.skill_uuid,atk,angle,t_pos);
|
|
}
|
|
add_buff(){
|
|
let uuid= this.skill_uuid;
|
|
let eid = 0
|
|
let group = BoxSet.HERO;
|
|
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
|
|
if (heros.length > 0) {
|
|
for (let i = 0; i < heros.length; i++) {
|
|
let hero = heros[i];
|
|
hero.MonsterBuff.add_buff(uuid,eid,group);
|
|
}
|
|
}
|
|
// oops.message.dispatchEvent("add_buff",{uuid:this.skill_uuid,eid:0,group:BoxSet.HERO})
|
|
}
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
to_destroy() {
|
|
this.is_destroy = true
|
|
this.remove_buff()
|
|
// console.log("CSkillComp toDestroy");
|
|
if (this.node.isValid) {
|
|
// console.log("CSkillComp.node.isValid");
|
|
// console.log("CSkillComp.node.destroy",this);
|
|
this.ent.destroy()
|
|
}
|
|
}
|
|
remove_buff(){
|
|
for (let index = 0; index < 8; index++) {
|
|
if(smc.player_buffs[index].eid == this.ent.eid){
|
|
smc.player_buffs[index].eid=0
|
|
break
|
|
}
|
|
}
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.sd.reset()
|
|
this.cd.reset()
|
|
this.node.destroy();
|
|
}
|
|
} |