import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,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 { smc } from "../common/SingletonModuleComp"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager"; import { MSkills, MSkillset, MSlist, SkillSet } from "../common/config/SkillSet"; import { HeroModelComp } from "../hero/HeroModelComp"; import { RewardSet } from "../common/config/RewardSet"; import { BoxSet, GameSet } from "../common/config/BoxSet"; import { GameMap } from "./GameMap"; import { MapModelComp } from "./model/MapModelComp"; import { Talent } from "../Role/Talent"; import { Talents } from "../common/config/TalentSet"; import { MonViewComp } from "../mon/MonViewComp"; import { HeroViewComp } from "../hero/HeroViewComp"; import { RoleViewComp } from "../Role/RoleViewComp"; import { BossViewComp } from "../Boss/BossViewComp"; import { Hero } from "../hero/Hero"; import { HeroSet } from "../common/config/heroSet"; import { Boss } from "../Boss/Boss"; import { MonModelComp } from "../mon/MonModelComp"; import { BossList, MissionNum, MissionSet, MonsetList } from "../common/config/MissionSet"; import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer"; import { HCard } from "./HCard"; import { HCardComp } from "./HCardComp"; import { MSkill } from "../skills/MSkill"; import { MSkillComp } from "../skills/MSkillComp"; import { VictoryComp } from "./VictoryComp"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('MissionComp') @ecs.register('Mission', false) export class MissionComp extends CCComp { VictoryComp:any = null; mon_list:any = [] call_hero_timer: Timer = new Timer(0.3); target_timer: Timer = new Timer(0.1); reward:number = 0; reward_num:number = 0; game_over:boolean = false; fight_start:boolean = false; msk:any={ on :false, uuid:1001, type:1, lv: 1 } mmsk:any={ on :false, uuid:1001, type:1, lv: 1 } onLoad(){ } start() { this.VictoryComp=this.node.getChildByName("victory").getComponent(VictoryComp) } protected update(dt: number): void { if(!smc.vmdata.mission.play||smc.vmdata.pause){ return } if(this.fight_start){ this.check_mon_num() } this.count_hero_pos() this.count_mon_pos() this.check_buff() // if (this.game_timer.update(dt)) { // smc.vmdata.game.g_time += 1; // } // this.shuaxin(dt) } mission_start(){ /* todo 关卡设定完善*/ let mon_set=RandomManager.instance.getRandomByObjectList(MissionSet,1) this.mon_list=mon_set[0] console.log("mission_start:",this.mon_list) //局内数据初始化 this.fight_start=false smc.vmdata.mission.is_victory=false smc.vmdata.mission.is_defeat=false smc.vmdata.mission.a_exp=0 //近战经验 smc.vmdata.mission.h_exp=0 //远程经验 smc.vmdata.mission.ma_exp=0 //敌方近战经验 smc.vmdata.mission.mh_exp=0 //敌方远程经验 this.msk={ on :false, uuid:1001,type:1,lv: 1} this.mmsk={ on :false, uuid:1001,type:1,lv: 1} this.node.getChildByName("exp").getChildByName("ap").active = true this.node.getChildByName("exp").getChildByName("hp").active = true this.node.getChildByName("mexp").getChildByName("ap").active = true this.node.getChildByName("mexp").getChildByName("hp").active = true this.mon_refresh() this.heros_call() } mission_end(){ smc.vmdata.mission.play=false let heros:any= this.get_heros();; let monsters:any= this.get_mons(); let hcards:any= ecs.query(ecs.allOf(HCardComp)); let mska:any= ecs.query(ecs.allOf(MSkillComp)); for(let i=0;i= smc.vmdata.mission.a_up_exp){ smc.vmdata.mission.ap+=smc.vmdata.mission.a_up smc.vmdata.mission.a_exp-=smc.vmdata.mission.a_up_exp this.node.getChildByName("exp").getChildByName("ap").setScale(1.2,1) this.scheduleOnce(function(){ this.node.getChildByName("exp").getChildByName("ap").setScale(1,1) },0.1) } if(smc.vmdata.mission.h_exp >= smc.vmdata.mission.h_up_exp){ smc.vmdata.mission.hp+=smc.vmdata.mission.h_up smc.vmdata.mission.h_exp-=smc.vmdata.mission.h_up_exp this.node.getChildByName("exp").getChildByName("hp").setScale(1.2,1) this.scheduleOnce(function(){ this.node.getChildByName("exp").getChildByName("hp").setScale(1,1) },0.1) } if(smc.vmdata.mission.ma_exp >= smc.vmdata.mission.ma_up_exp){ smc.vmdata.mission.map+=smc.vmdata.mission.ma_up smc.vmdata.mission.ma_exp-=smc.vmdata.mission.ma_up_exp this.node.getChildByName("mexp").getChildByName("ap").setScale(1.2,1) this.scheduleOnce(function(){ this.node.getChildByName("mexp").getChildByName("ap").setScale(1,1) },0.1) } if(smc.vmdata.mission.mh_exp >= smc.vmdata.mission.mh_up_exp){ smc.vmdata.mission.mhp+=smc.vmdata.mission.mh_up smc.vmdata.mission.mh_exp-=smc.vmdata.mission.mh_up_exp this.node.getChildByName("mexp").getChildByName("hp").setScale(1.2,1) this.scheduleOnce(function(){ this.node.getChildByName("mexp").getChildByName("hp").setScale(1,1) },0.1) } } do_reward(){ console.log("do_reward") } check_mon_num(){ let mons:any = this.get_mons() let heros:any= this.get_heros() let h_alive=false let m_alive=false for (let i = 0; i < heros.length; i++) { if ( !heros[i].HeroView.is_dead) { h_alive=true } } for (let i = 0; i < mons.length; i++) { if ( !mons[i].HeroView.is_dead) { m_alive=true } } if (!m_alive) smc.vmdata.mission.is_victory = true if (!h_alive) smc.vmdata.mission.is_defeat = true this.to_end_mission() } to_end_mission(){ if (smc.vmdata.mission.is_victory){ this.VictoryComp.do_victiry() } if (smc.vmdata.mission.is_defeat){ this.VictoryComp.do_defeat() } } get_mons(){ return ecs.query(ecs.allOf(MonModelComp)); } get_heros(){ return ecs.query(ecs.allOf(HeroModelComp)) } count_mon_pos(){ let monsters:any= this.get_mons() for(let i=0;i(HCard) // console.log("hcard:",hcard) hcard.load(1001,i,node) } this.fight_start= true } /** 添加玩家 */ private addHero(uuid:number=1001,i:number=0) { let hero = ecs.getEntity(Hero); let scale = 1 let pos:Vec3 = v3(HeroSet.StartPos[smc.heros[uuid].type]-i*15,BoxSet.GAME_LINE); // console.log("addHero:",pos) hero.load(pos,scale,uuid); } private addMonster(uuid:number=1001,i:number=0) { let monster = ecs.getEntity(Hero); let scale = -1 let pos:Vec3 = v3(-1*HeroSet.StartPos[smc.heros[uuid].type]+i*15,BoxSet.GAME_LINE); console.log("addMonster:",pos) monster.load(pos,scale,uuid,false); } /** 视图层逻辑代码分离演示 */ /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } }