140 lines
4.5 KiB
TypeScript
140 lines
4.5 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 { FriendModelComp } from "../hero/FriendModel";
|
|
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
|
|
onLoad(){
|
|
this.on(GameEvent.UseHeroCard,this.call_hero,this)
|
|
this.on(GameEvent.ChangeATK_EQUIP_SPECIAL_ATTR,this.change_equip_qpecial_attr,this)
|
|
this.on(GameEvent.FightReady,this.fight_ready,this)
|
|
this.on(GameEvent.Zhaohuan,this.zhao_huan,this)
|
|
|
|
}
|
|
start() {
|
|
// this.test_call()
|
|
}
|
|
fight_ready(){
|
|
}
|
|
protected update(dt: number): void {
|
|
if(smc.mission.status != 1) return
|
|
|
|
|
|
}
|
|
|
|
change_equip_qpecial_attr(e:GameEvent,data:any){
|
|
|
|
}
|
|
private zhao_huan(event: string, args: any){
|
|
console.log("[MissionHeroComp]:zhaohuan",args)
|
|
this.addHero(args.uuid,false,true)
|
|
}
|
|
|
|
private call_friend(event: string, args: any,is_master:boolean=false){
|
|
console.log("[MissionHeroComp]:call_hero addHero",args.uuid,is_master)
|
|
let hero_pos=1
|
|
if(is_master){
|
|
hero_pos=0
|
|
}
|
|
let info:any={ap:0,hp:0,lv:0}
|
|
let hero = ecs.getEntity<Hero>(Hero);
|
|
let scale = 1
|
|
let heros=ecs.query(ecs.allOf(HeroViewComp))
|
|
for(let hero of heros){
|
|
let hv = hero.get(HeroViewComp)
|
|
if(hv.fight_pos==hero_pos){
|
|
hero_pos=2
|
|
break
|
|
}
|
|
}
|
|
console.log("[MissionHeroComp]:call_friend",heros)
|
|
let pos:Vec3 = HeroPos[hero_pos].pos;
|
|
if(is_master){
|
|
hero.hart_load(args.uuid)
|
|
}else{
|
|
hero.load(pos,scale,args.uuid,info,hero_pos);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
call_hero(event: string, args: any){
|
|
// console.log("call_hero",args)
|
|
// let fight_pos=args
|
|
// 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(args.uuid,args.is_master)
|
|
}
|
|
|
|
/** 添加英雄 */
|
|
private addHero(uuid:number=1001,is_master:boolean=false,is_zhaohuan:boolean=false) {
|
|
let hero_pos=1
|
|
if(is_master){
|
|
hero_pos=0
|
|
}
|
|
if(is_zhaohuan){
|
|
hero_pos=2
|
|
}
|
|
let info:any=this.get_info_and_remove(hero_pos,uuid)
|
|
// let info:any={ap:0,hp:0,lv:0}
|
|
let hero = ecs.getEntity<Hero>(Hero);
|
|
let scale = 1
|
|
let pos:Vec3 = HeroPos[hero_pos].pos;
|
|
if(is_master){
|
|
hero.hart_load(uuid)
|
|
}else{
|
|
hero.load(pos,scale,uuid,info,hero_pos);
|
|
}
|
|
}
|
|
|
|
get_info_and_remove(fight_pos:number,uuid:number){
|
|
let info:any={ap:0,hp:0,lv:1,crit:0,crit_d:0,dod:0,dod_no:false,crit_no:false}
|
|
let heros=ecs.query(ecs.allOf(FriendModelComp))
|
|
if(heros.length>0){
|
|
let hero = heros[0]
|
|
let hv = hero.get(HeroViewComp)
|
|
info.ap=hv.ap
|
|
info.hp=hv.hp_max
|
|
info.lv=hv.lv
|
|
info.crit=hv.crit
|
|
info.crit_d=hv.crit_d
|
|
info.dod=hv.dod
|
|
info.dod_no=hv.dod_no
|
|
info.crit_no=hv.crit_no
|
|
hero.destroy()
|
|
return info
|
|
|
|
}
|
|
return info
|
|
}
|
|
|
|
do_hero_change(){
|
|
//金币加1
|
|
smc.vmdata.mission_data.gold+=1
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
// this.node.destroy();
|
|
}
|
|
} |