137 lines
4.4 KiB
TypeScript
137 lines
4.4 KiB
TypeScript
import { _decorator, resources, Sprite, SpriteAtlas, SpriteFrame, 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 { Hero } from "../hero/Hero";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { Timer } from "db://oops-framework/core/common/timer/Timer";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
import { HeroModelComp } from "../hero/HeroModelComp";
|
|
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
import { oops } from "db://oops-framework/core/Oops";
|
|
import { HeroPos } from "../common/config/heroSet";
|
|
import { FightSet } from "../common/config/Mission";
|
|
import { QualitySet } from "../common/config/BoxSet";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MissionHeroCompComp')
|
|
@ecs.register('MissionHeroComp', false)
|
|
export class MissionHeroCompComp extends CCComp {
|
|
timer:Timer=new Timer(2)
|
|
Friend_is_dead:boolean=false
|
|
current_hero_uuid:number=0
|
|
current_hero_num:number=-1
|
|
heros:any=[]
|
|
onLoad(){
|
|
this.on(GameEvent.UseHeroCard,this.call_hero,this)
|
|
this.on(GameEvent.FightReady,this.fight_ready,this)
|
|
this.on(GameEvent.Zhaohuan,this.zhao_huan,this)
|
|
this.on(GameEvent.FightEnd,this.clear_heros,this)
|
|
}
|
|
start() {
|
|
// this.test_call()
|
|
}
|
|
clear_heros(){
|
|
// console.log("[MissionHeroComp]: FightEnd clear heros")
|
|
|
|
}
|
|
fight_ready(){
|
|
// this.heros=[]
|
|
// for(let i=0;i<FightSet.HERO_MAX_NUM;i++){
|
|
// this.heros.push({
|
|
// uuid:0,
|
|
// count:0,
|
|
// quality:0,
|
|
// })
|
|
// }
|
|
// this.current_hero_num=-1
|
|
// this.current_hero_uuid=0
|
|
smc.vmdata.mission_data.hero_num=0
|
|
// console.log("[MissionHeroComp]:fight_ready",smc.fight_heros,Object.keys(smc.fight_heros).length)
|
|
let heros:any = smc.fight_heros
|
|
for(let i=0;i<Object.keys(heros).length;i++){
|
|
if(heros[i]!=0){
|
|
// console.log("[MissionHeroComp]:fight_ready",heros[i])
|
|
this.addHero(heros[i],false)
|
|
}
|
|
}
|
|
}
|
|
protected update(dt: number): void {
|
|
if(smc.mission.status != 1) return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private zhao_huan(event: string, args: any){
|
|
// console.log("[MissionHeroComp]:zhaohuan",args)
|
|
this.addHero(args.uuid,false)
|
|
}
|
|
|
|
|
|
|
|
|
|
call_hero(event: string, args: any){
|
|
// console.log("[MissionHeroComp]:call_hero",this.heros,this.current_hero_num,args)
|
|
|
|
// 尝试升级现有英雄
|
|
if (this.tryUpgradeExistingHero(args.uuid)) {
|
|
return
|
|
}
|
|
|
|
// 添加新英雄
|
|
this.addNewHero(args.uuid)
|
|
}
|
|
|
|
|
|
/**
|
|
* 尝试升级现有英雄
|
|
* @param uuid 英雄UUID
|
|
* @returns 是否成功升级
|
|
*/
|
|
private tryUpgradeExistingHero(uuid: number): boolean {
|
|
for (let i = 0; i < this.heros.length; i++) {
|
|
// console.log("[MissionHeroComp]:tryUpgradeExistingHero",this.heros,i,uuid)
|
|
if (this.heros[i].uuid === uuid) {
|
|
this.heros[i].count++
|
|
smc.vmdata[`hero${i+1}`].count=this.heros[i].count
|
|
oops.message.dispatchEvent(GameEvent.HeroLvUp, { uuid: uuid })
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
/**
|
|
* 添加新英雄到当前槽位
|
|
* @param uuid 英雄UUID
|
|
*/
|
|
private addNewHero(uuid: number) {
|
|
this.current_hero_num++
|
|
if(this.current_hero_num >= FightSet.HERO_MAX_NUM) return
|
|
this.current_hero_uuid = uuid
|
|
this.heros[this.current_hero_num].uuid = uuid
|
|
this.heros[this.current_hero_num].count = 1
|
|
this.heros[this.current_hero_num].quality = QualitySet.GREEN
|
|
this.addHero(uuid, false)
|
|
}
|
|
|
|
/** 添加英雄 */
|
|
private addHero(uuid:number=1001,is_zhaohuan:boolean=false) {
|
|
// console.log("[MissionHeroComp]:addHero",uuid,is_zhaohuan)
|
|
let hero_pos=0
|
|
let hero = ecs.getEntity<Hero>(Hero);
|
|
let scale = 1
|
|
let pos:Vec3 = HeroPos[hero_pos].pos;
|
|
hero.load(pos,scale,uuid);
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
// this.node.destroy();
|
|
}
|
|
} |