Files
heros/assets/script/game/map/MissionHeroComp.ts
2025-03-25 16:34:09 +08:00

48 lines
1.7 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 { BoxSet } from "../common/config/BoxSet";
import { HeroList, HeroSet } from "../common/config/heroSet";
import { Hero } from "../hero/Hero";
import { smc } from "../common/SingletonModuleComp";
import { Timer } from "db://oops-framework/core/common/timer/Timer";
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
import { GameEvent } from "../common/config/GameEvent";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('MissionHeroCompComp')
@ecs.register('MissionHeroComp', false)
export class MissionHeroCompComp extends CCComp {
timer:Timer=new Timer(2)
onLoad(){
this.on(GameEvent.UserHeroCard,this.call_hero,this)
}
start() {
}
protected update(dt: number): void {
if(smc.mission.status != 1) return
}
call_hero(event: string, args: any){
this.timer.reset()
let hero_list =HeroList
let x=RandomManager.instance.getRandomInt(0,hero_list.length,1)
let uuid=args.uuid
console.log("call_hero",uuid)
this.addHero(uuid)
}
/** 添加玩家 */
private addHero(uuid:number=1001,i:number=0) {
let hero = ecs.getEntity<Hero>(Hero);
let scale = 1
let pos:Vec3 = v3(HeroSet.StartPos[1]-i*10,BoxSet.GAME_LINE);
hero.load(pos,scale,uuid);
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}