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, GameSet } from "../common/config/BoxSet"; import { HeroInfo, HeroList, HeroPos, HeroSet, HeroUpInfo } 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"; import { HeroModelComp } from "../hero/HeroModelComp"; import { HeroViewComp } from "../hero/HeroViewComp"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('MissionHeroCompComp') @ecs.register('MissionHeroComp', false) export class MissionHeroCompComp extends CCComp { timer:Timer=new Timer(2) start_pos:any={ 0:{pos:v3(-140,135,0),has:false}, 1:{pos:v3(-270,205,0),has:false}, 2:{pos:v3(-270,65,0),has:false}, } onLoad(){ this.on(GameEvent.UserHeroCard,this.call_hero,this) } start() { // this.test_call() } protected update(dt: number): void { if(smc.mission.status != 1) return } init(){ this.start_pos[0].has=false this.start_pos[1].has=false this.start_pos[2].has=false } test_call(){ this.addHero(5010) } 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) { console.log("call_hero addHero",uuid) let info:any={ap:0,hp:0} if(this.start_pos[HeroInfo[uuid].type].has){ info=this.get_info_and_remove(HeroInfo[uuid].type,uuid) } let hero = ecs.getEntity(Hero); let scale = 1 let pos:Vec3 = this.start_pos[HeroInfo[uuid].type].pos; console.log("hero load0",pos,this.start_pos) hero.load(pos,scale,uuid,info); this.start_pos[HeroInfo[uuid].type].has=true } get_info_and_remove(type:number,uuid:number){ let info:any={ap:0,hp:0} let heros=ecs.query(ecs.allOf(HeroModelComp)) for(let hero of heros){ if(hero.get(HeroViewComp).type==type){ let hv = hero.get(HeroViewComp) let AP_UP_RATE = hv.hero_uuid === uuid ? GameSet.AP_UPDATE_RATE : GameSet.AP_CHANGE_RATE; let heroUpData = HeroUpInfo[hv.hero_uuid] || {} let o_ap_rate = heroUpData.ap_up_rate || 0 //被替换 升级的英雄额外被替换攻击增长比率 let o_ap = heroUpData.ap_up || 0 //被替换 升级的英雄额外被替换攻击增长值 let s_ap_rate = (HeroUpInfo[uuid] || {}).ap_up_rate || 0 //替换 升级的英雄额外替换攻击增长比率 let s_ap = (HeroUpInfo[uuid] || {}).ap_up || 0 //替换 升级的英雄额外替换攻击增长值 let o_hp_up = heroUpData.hp_up || 0 //被替换 升级的英雄额外被替换血量增长值 let s_hp_up = (HeroUpInfo[uuid] || {}).hp_up || 0 //替换 升级的英雄额外替换血量增长值 info.ap=Math.floor(hv.ap*(AP_UP_RATE+o_ap_rate+s_ap_rate)/100+o_ap+s_ap) info.hp=Math.floor(o_hp_up+s_hp_up) hero.destroy() return info } } return info } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } }