import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,v3, Vec3,Animation, UI } 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 { Missions} from "../common/config/Mission"; import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer"; import { VictoryComp } from "./VictoryComp"; import { CardControllerComp } from "./CardController"; import { GameEvent } from "../common/config/GameEvent"; import { HeroSkillsComp } from "../skill/heroSkillsComp"; import { HeroViewComp } from "../hero/HeroViewComp"; import { Hero } from "../hero/Hero"; import { HartModelComp } from "../hero/HartModelComp"; 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; heros_node:any=null heros_node_pos:any=v3(0,0,0) herosc_node:any=null hero_args:any=null mission_data:any={ gold:10,//金币 refresh_gold:1,//刷新金币 call_gold:3,//召唤金币 exp:0,//经验 skp:0,//技能点 box:0,//宝箱 energy:0,//能量 hp:0,//血量 ap:0,//攻击 } onLoad(){ this.on(GameEvent.MissionLoss,this.mission_end,this) this.on(GameEvent.MissionWin,this.mission_end,this) } start() { } protected update(dt: number): void { if(!smc.mission.play||smc.mission.pause){ return } // if (this.game_timer.update(dt)) { // smc.vmdata.game.g_time += 1; // } } call_hero(event: string, args: any){ console.log("call_hero",args) oops.message.dispatchEvent(GameEvent.CallHero,{uuid:this.hero_args.uuid,pos:args}) this.hero_args=null } mission_start(){ /* todo 关卡设定完善*/ console.log("战斗开始 Missions mons:",Missions[smc.mission.lv]) smc.mission.status=1 this.colose_victory() this.mission_init() } mission_end(){ oops.message.dispatchEvent(GameEvent.MissionEnd) smc.mission.play=false smc.mission.pause=false this.cleanComponents() // this.to_mission_home() this.open_victory() } private cleanComponents() { ecs.query(ecs.allOf(HeroSkillsComp)).forEach(entity => {entity.remove(HeroSkillsComp);entity.destroy()}); ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {entity.remove(HeroViewComp);entity.destroy()}); } open_victory(){ this.node.getChildByName("victory").active=true this.node.getChildByName("victory").getComponent(VictoryComp).open() } colose_victory(){ this.node.getChildByName("victory").active=false } to_mission_home(){ this.colose_victory() let home =this.node.parent.getComponent(CardControllerComp); home.mission_to_mission_home() } mission_init(){ //局内数据初始化 this.fight_start=false smc.mission.is_victory=false smc.mission.is_defeat=false smc.vmdata.mission_data ={ gold:10,//金币 refresh_gold:1,//刷新金币 call_gold:3,//召唤金币 exp:0,//经验 skp:0,//技能点 box:0,//宝箱 energy:0,//能量 hp:0,//血量 ap:0,//攻击 } let hero = ecs.getEntity(Hero); hero.hart_load() } card_refresh(){ oops.message.dispatchEvent(GameEvent.CardRefresh) } /** 视图层逻辑代码分离演示 */ /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } }