151 lines
7.1 KiB
TypeScript
151 lines
7.1 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";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MissionHeroCompComp')
|
|
@ecs.register('MissionHeroComp', false)
|
|
export class MissionHeroCompComp extends CCComp {
|
|
timer:Timer=new Timer(2)
|
|
Friend_alive_cd:Timer=new Timer(10)
|
|
Friend_is_dead:boolean=false
|
|
current_hero_uuid:number=0
|
|
onLoad(){
|
|
this.on(GameEvent.UseHeroCard,this.call_hero,this)
|
|
this.on(GameEvent.ChangeATK_FRIEND_LIVE_CD,this.change_friend_alive_cd,this)
|
|
|
|
}
|
|
start() {
|
|
// this.test_call()
|
|
this.node.getChildByName("location").active=false
|
|
}
|
|
protected update(dt: number): void {
|
|
if(smc.mission.status != 1) return
|
|
if(this.Friend_is_dead){
|
|
if(this.Friend_alive_cd.update(dt)){
|
|
console.log("alive friend")
|
|
}
|
|
}
|
|
|
|
}
|
|
change_friend_alive_cd(e:GameEvent,data:any){
|
|
console.log("change_friend_alive_cd",data)
|
|
this.Friend_alive_cd=new Timer(FightSet.FRIEND_LIVE_CD-data)
|
|
}
|
|
|
|
init(){
|
|
|
|
}
|
|
test_call(){
|
|
this.addHero(5010)
|
|
}
|
|
// show_heros_pos(event: string, args: any){
|
|
// console.log("show_heros_pos",args)
|
|
// this.current_hero_uuid=args.uuid
|
|
// this.update_fight_hero_info()
|
|
// this.node.getChildByName("location").active=true
|
|
// }
|
|
// update_fight_hero_info(){
|
|
// var icon_path = "game/heros/herois"
|
|
// this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos1").getChildByName("hero").active=false
|
|
// this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos2").getChildByName("hero").active=false
|
|
// this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos3").getChildByName("hero").active=false
|
|
|
|
// let heros=ecs.query(ecs.allOf(HeroModelComp))
|
|
// for(let hero of heros){
|
|
// let hv = hero.get(HeroViewComp)
|
|
// if(hv.fight_pos==0){
|
|
// this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos1").getChildByName("hero").active=true
|
|
// resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
// const sprite = this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos1").getChildByName("hero").getChildByName("icon").getComponent(Sprite);
|
|
// sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[hv.hero_uuid].path);
|
|
// });
|
|
// }
|
|
// if(hv.fight_pos==1){
|
|
// this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos2").getChildByName("hero").active=true
|
|
// resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
// const sprite = this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos2").getChildByName("hero").getChildByName("icon").getComponent(Sprite);
|
|
// sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[hv.hero_uuid].path);
|
|
// });
|
|
// }
|
|
// if(hv.fight_pos==2){
|
|
// this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos3").getChildByName("hero").active=true
|
|
// resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
|
// const sprite = this.node.getChildByName("location").getChildByName("herospos").getChildByName("heropos3").getChildByName("hero").getChildByName("icon").getComponent(Sprite);
|
|
// sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[hv.hero_uuid].path);
|
|
// });
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
call_hero(event: string, args: any){
|
|
// this.node.getChildByName("location").active=false
|
|
// 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)
|
|
}
|
|
|
|
/** 添加英雄 */
|
|
private addHero(uuid:number=1001,freind_pos:number=0) {
|
|
console.log("call_hero addHero",uuid)
|
|
let info:any=this.get_info_and_remove(freind_pos,uuid)
|
|
// let info:any={ap:0,hp:0,lv:0}
|
|
let hero = ecs.getEntity<Hero>(Hero);
|
|
let scale = 1
|
|
let pos:Vec3 = HeroPos[freind_pos].pos;
|
|
hero.load(pos,scale,uuid,info,freind_pos);
|
|
oops.message.dispatchEvent(GameEvent.HeroSelectEnd)
|
|
this.current_hero_uuid=0
|
|
}
|
|
|
|
get_info_and_remove(fight_pos:number,uuid:number){
|
|
let info:any={ap:0,hp:0,lv:0}
|
|
let heros=ecs.query(ecs.allOf(HeroModelComp))
|
|
for(let hero of heros){
|
|
let hv = hero.get(HeroViewComp)
|
|
if(hv.fight_pos==fight_pos&&!hv.is_master){
|
|
// let AP_UP_RATE = hv.hero_uuid === uuid ? FightSet.AP_UPDATE_RATE : FightSet.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)
|
|
info.ap=hv.ap
|
|
info.hp=hv.hp_max
|
|
info.lv=hv.lv
|
|
hero.destroy()
|
|
return info
|
|
}
|
|
}
|
|
return info
|
|
}
|
|
|
|
do_hero_change(){
|
|
//金币加1
|
|
smc.vmdata.mission_data.gold+=1
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
// this.node.destroy();
|
|
}
|
|
} |