// -------------------------------------------------------------------- // @author: xxx@syg.com(必填, 创建模块的人员) // @description: // 冒险主控制器 //
Create: 2019-05-09 14:14:52 // -------------------------------------------------------------------- const BridgeController = require( "bridge.controller" ); var AdventureEvent = require("adventure_event"); const ADVCONST = require("adventure_const"); var BattleConst = require("battle_const"); var BattleController = require("battle_controller"); var AdventureController = cc.Class({ extends: BridgeController, ctor: function () { }, // 初始化配置数据 initConfig: function () { var AdventureModel = require("adventure_model"); this.model = new AdventureModel(); this.model.initConfig(); this.model_type = 1; this.id_dead = false;//是否死亡 this.cur_evt_type = null; this.npc_event_data = null; this.weekly_heros = null; this.is_open_endlesshero = false; this.is_init = false;//true 时不需要请求基础数据 this.partners = {};//分模式,模式下分bid }, // 返回当前的model getModel: function () { return this.model; }, // 注册协议接受事件 registerProtocals: function () { this.RegisterProtocal(29500, this.handle29500);//模式地图初始化 this.RegisterProtocal(29501, this.handle29501);//buff信息詳情 this.RegisterProtocal(29502, this.handle29502);//探索房间信息 this.RegisterProtocal(29503, this.handle29503);//房间信息更新 this.RegisterProtocal(29504, this.handle29504);//当前英雄的信息数据 this.RegisterProtocal(29505, this.handle29505);//无尽模式选择上阵英雄 this.RegisterProtocal(29506, this.handle29506);//背包内容 this.RegisterProtocal(29507, this.handle29507);//使用道具 this.RegisterProtocal(29508, this.handle29508);//使用正确路径探索指定房间 this.RegisterProtocal(29509, this.handle29509);//模式英雄列表 this.RegisterProtocal(29510, this.handle29510);//切換英雄 this.RegisterProtocal(29512, this.handle29512);//游戲結束 this.RegisterProtocal(29513, this.handle29513);//購買體力 this.RegisterProtocal(29520, this.handle29520);//事件操作 this.RegisterProtocal(29524, this.handle29524);//戰鬥事件 this.RegisterProtocal(29527, this.handle29527);//NPC事件 this.RegisterProtocal(29528, this.handle29528);//改造台事件 this.RegisterProtocal(29531, this.handle29531);//神秘商人事件 this.RegisterProtocal(29534, this.handle29534);//獎勵列表更新 this.RegisterProtocal(29535, this.handle29535);//領取獎勵 this.RegisterProtocal(29541, this.handle29541);//陷阱或者祝福推送 // this.RegisterProtocal(29542, this.handle29542);//人物状态buff this.RegisterProtocal(29543, this.handle29543);//日志 }, reqBaseFromServer: function( _cb ){ let cfgs = [ "adventure_endless_data", "adventure_weekly_data", ] this.loadConfigs( cfgs, ( _ret, _data ) =>{ return nx.dt.fnInvoke( _cb, true ); } ) }, isMonster:function(event_type){ return event_type == AdventureEvent.EventType.boss || event_type == AdventureEvent.EventType.mon || event_type == AdventureEvent.EventType.mon1 || event_type == AdventureEvent.EventType.mon2 || event_type == AdventureEvent.EventType.mon3; }, openWindowByConfig:function(data){ var room_data = this.getRoomDataByXY(data.room_id[0].x,data.room_id[0].y); let config = null; if(this.model_type == 1){ config = game.configs.adventure_endless_data.data_adventure_event[room_data.evt_id]; }else{ config = game.configs.adventure_weekly_data.data_adventure_event[room_data.evt_id]; } if(!config)return; if(config.evt_type == 4 || config.evt_type == 5 || config.evt_type == 6){//NPC事件 nx.bridge.createPanel("WndAdventurePeople",{room_id:room_data.room_id[0], config:config}); }else if(config.evt_type == 7){//商店 nx.bridge.createPanel("WndAdventureShop",{room_id:room_data.room_id[0], config:config}); }else if(config.evt_type == 10){ nx.bridge.createPanel("WndAdventureTransform",{room_id:room_data.room_id[0], config:config}); }else if(config.evt_type == 1 || config.evt_type == 2 || config.evt_type == 3){ nx.bridge.createPanel("WndAdventureFight",{room_id:room_data.room_id[0], config:config}); } }, resetActionConfig(room_id){ let room_data = this.getRoomDataByXY(room_id.x,room_id.y); let config = null; if(this.model_type == 1){ config = game.configs.adventure_endless_data.data_adventure_event[room_data.evt_id]; }else{ config = game.configs.adventure_weekly_data.data_adventure_event[room_data.evt_id]; } this.setCurEvtType(null); if(!config){ return; } if(config.evt_type == 4 || config.evt_type == 5 || config.evt_type == 6){//NPC事件 this.setNPCData(null); }else if(config.evt_type == 8){//陷阱 this.setTrapPos(room_id); }else if(config.evt_type == 7){ this.setShopData(null); }else if(config.evt_type == 10){ this.setTransData(null); }else if(config.evt_type == 1 || config.evt_type == 2 || config.evt_type == 3){ this.setMonsterData(null); nx.bridge.closePanel("WndAdventureFight"); } }, send29500:function(type){ var protocal = {}; protocal.type = type; this.SendProtocal(29500, protocal); }, send29501:function(type){ var protocal = {}; protocal.type = type; this.SendProtocal(29501, protocal); }, send29502:function(type){ var protocal = {}; protocal.type = type; this.SendProtocal(29502, protocal); }, //请求当前所有英雄数据 send29504:function(type){ var protocal = {}; protocal.type = type; this.SendProtocal(29504, protocal); }, send29505:function(type,plist){ var protocal = {}; protocal.plist = plist; protocal.type = type; this.SendProtocal(29505, protocal); }, send29506:function(type){ var protocal = {}; protocal.type = type; this.SendProtocal(29506, protocal); }, send29507(id,type,_cb){ var protocal = {}; protocal.item_id = id; protocal.type = type || this.model_type; this.SendProtocal(29507, protocal,_cb); }, //随机伙伴信息 send29509:function(type){ var protocal = {}; protocal.type = type; this.SendProtocal(29509, protocal); }, send29510:function(id){ var protocal = {}; protocal.id = id; protocal.type = this.model_type; this.SendProtocal(29510, protocal); }, //游戲結束 send29512:function(){ this.SendProtocal(29512, {}); }, //購買體力 send29513:function(){ this.SendProtocal(29513, {}); }, //探索路径 send29508:function(path,type){ var protocal = {}; protocal.room_ids = path; protocal.type = type; this.SendProtocal(29508, protocal); }, //探索事件 send29520:function(room_id,action,ext_list,type){ var protocal = {}; protocal.room_id = room_id; protocal.action = action; protocal.ext_list = ext_list; protocal.type = type; this.SendProtocal(29520, protocal); }, send29534:function(type){ var protocal = {}; protocal.type = type; this.SendProtocal(29534, protocal); }, send29535:function(id){ var protocal = {}; protocal.id = id; protocal.type = this.model_type; this.SendProtocal(29535, protocal); }, send29543:function(type){//日志 var protocal = {}; protocal.type = type; this.SendProtocal(29543, protocal); }, handle29500:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } this.setBaseData(data); //在模式界面初始化用 gcore.GlobalEvent.fire(AdventureEvent.Init_Model_Win,data); }, handle29501:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } gcore.GlobalEvent.fire(AdventureEvent.Udpate_Buff_List,data); gcore.GlobalEvent.fire(AdventureEvent.Update_More_Item,data.buff_list); }, handle29502:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } this.setRoomData(data.room_list); }, handle29503:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } this.updateRoomData(data); }, handle29504:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } //设置上阵英雄列表 this.setFormHeros(data.type,data.partners); }, handle29505:function(data){ this.is_init = false; // 失败判定 // if( !this.isGoodData( data ) ) { // return; // } //选择完上阵英雄后,无尽模式此时在主界面,则直接请求数据 if(this.model_type == ADVCONST.PLAY_MODEL.ENDLESS){ this.send29500(1); this.send29502(1); this.is_init = true; }else if(this.model_type == ADVCONST.PLAY_MODEL.WEEKLY){ nx.bridge.createPanel("WndAdventureMain",{type:data.type}); } }, handle29506:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } //刷新背包 gcore.GlobalEvent.fire(AdventureEvent.Update_Goods,data); gcore.GlobalEvent.fire(AdventureEvent.Update_More_Item,data.items_list); this.setBagItems(data.items_list); }, handle29507:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } }, handle29508:function(data){ if(data.code == 1){ //矫正以后的正确路径 gcore.GlobalEvent.fire(AdventureEvent.Update_Room_Path,data); if(data.is_poison == 1){ gcore.GlobalEvent.fire(AdventureEvent.Update_Role_Good_Status,"E66002"); } }else{ //room不存在,重置路径 nx.tbox(data.msg); gcore.GlobalEvent.fire(AdventureEvent.Reset_Room_Path); } }, handle29509:function(data){ gcore.GlobalEvent.fire(AdventureEvent.UpModel_Up_Cfg,data); // 失败判定 if( !this.isGoodData( data ) ) { if(data.type == ADVCONST.PLAY_MODEL.ENDLESS){ this.send29500(1); this.send29502(1); } return; } if(data.type == ADVCONST.PLAY_MODEL.ENDLESS){ if(!this.is_open_endlesshero){ this.openEndlessHeroPanel(true,data.plist,data.camp_list,data.partner_up_list,data.times); } }else if(data.type == ADVCONST.PLAY_MODEL.WEEKLY){ //不能直接打開窗口,需要保存數據 this.setWeeklyPartnerData(data); } }, setIsOpenEndlessHero(status){ this.is_open_endlesshero = status; }, handle29510:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } }, handle29512:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } if(data.code == 1 && data.msg != ""){ nx.tbox(data.msg); } this.setCurLeader(null); this.partners[this.model_type] = {}; this.id_dead = true; nx.bridge.closePanel("WndAdventureMain"); // nx.bridge.createPanel("WndAdventureModel",{}); }, handle29513:function(data){ if(data.code == 0){ nx.tbox(data.msg); }else{ gcore.GlobalEvent.fire(AdventureEvent.Buy_Energy,data.energy); } }, handle29520:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } //事件請求數據,打開界面 if(data.action == 0){ this.openWindowByConfig(data); }else if(data.action == 1){//事件操作完畢,可能需要重置數據或者狀態 this.resetActionConfig(data.room_id[0]); if((data.msg).length > 0){ nx.tbox(data.msg); } } }, handle29524:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } this.setMonsterData(data); }, handle29527:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { this.setNPCData(null); return; } this.setNPCData(data); }, handle29528:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } this.setTransData(data); }, handle29534:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } gcore.GlobalEvent.fire(AdventureEvent.Update_Awards,data.list); }, handle29535:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } nx.tbox(data.msg); }, handle29531:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } this.setShopData(data); gcore.GlobalEvent.fire(AdventureEvent.Update_Shop_Data,data); }, handle29541:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } //陷阱推送則需要彈窗提示 if(data.cate == 0){//陷阱 nx.bridge.createPanel("WndAdventureTrap",{evt_id: data.evt_id,is_battle:data.is_battle}); }else{//增益 nx.bridge.createPanel("WndAdventureMsg",{type:1,data:data}); } }, // handle29542:function(data){ // // 失败判定 // if( !this.isGoodData( data ) ) { // return; // } // }, handle29543:function(data){ // 失败判定 if( !this.isGoodData( data ) ) { return; } gcore.GlobalEvent.fire(AdventureEvent.Update_Fight_Log,data); }, openEndlessHeroPanel(status,plist,camp_list,partner_up_list,times){ if(status){ nx.bridge.createPanel("WndAdventureEndlessHero",{partners:plist,camps:camp_list,uplist:partner_up_list,times:times}); }else{ nx.bridge.closePanel("WndAdventureEndlessHero"); } }, openMoreItemsWindow(type,list){ nx.bridge.createPanel("WndAdventureMore",{type:type,list:list}); }, /////////////////////////////////////////////////// //新的model isInitProtol(){ return this.is_init; }, //设置游玩模式 1 无尽模式 2 周回模式 setPlayModel(type){ this.model_type = type; }, getPlayModel(){ return this.model_type; }, //操作事件時設置事件類型,操作完畢后置空,然後根據類型重置數據 setCurEvtType(type){ this.cur_evt_type = type; }, getCurEvtType(){ return this.cur_evt_type; }, setBaseData(data){ this.base_data = data; //设置起始位置 this.setCurStartPos(data.room_id[0]); //设置基础地图配置 this.setMapsInfo(data.maps_info[0]); //boss击杀 this.isKillBoss(data.is_kill_boss); //所有活动是否已结束 this.setActStatus(data.is_all_finish); //設置當前英雄 this.setCurLeader(data.partner_bid); gcore.GlobalEvent.fire(AdventureEvent.Update_Player_Info,data); }, getBaseData(){ return this.base_data; }, setCurStartPos(pos){//x,y this.startPos = pos; }, getCurStartPos(){ return this.startPos; }, isKillBoss(status){ this.isKilled = status == 1?true:false; }, getKillBossStatus(){ return this.isKilled; }, setActStatus(status){ this.isFinish = status == 1?true:false; }, getActStatus(){ return this.isFinish; }, setMapsInfo(info){ this.mapSize = info; }, getMapsInfo(){ return this.mapSize; }, setRoomData(room_list){ this.room_list = room_list; //刷新房间地图信息 gcore.GlobalEvent.fire(AdventureEvent.Update_Room_Base_Info); }, getRoomDataByIndex(index){ if(nx.dt.arrEmpty(this.room_list))return; let data = this.room_list[index]; if(!nx.dt.objEmpty(data)){ return data; } return null; }, getRoomDataByXY(x,y){ if(nx.dt.arrEmpty(this.room_list))return; for(let i = 0;i < this.room_list.length;i++){ let data = this.room_list[i]; if(data.room_id[0].x == x && data.room_id[0].y == y){ return data; } } return null; }, updateRoomData(data){ let xy = data.room_id[0]; let index = null; if(this.room_list){ for(let i = 0;i < this.room_list.length;i++){ let data2 = this.room_list[i]; if(xy.x == data2.room_id[0].x && xy.y == data2.room_id[0].y){ this.room_list[i].status = data.status; this.room_list[i].lock = data.lock; this.room_list[i].evt_id = data.evt_id; this.room_list[i].res_id = data.res_id; index = i; } } } //可能需要刷新这个地图块 gcore.GlobalEvent.fire(AdventureEvent.Update_Room_Info,index); }, //设置上阵英雄列表 setFormHeros(type,partners){ this.partners[type] = {}; if(type == ADVCONST.PLAY_MODEL.ENDLESS){ for(let i in partners){ let bid = partners[i].bid; this.partners[ADVCONST.PLAY_MODEL.ENDLESS][bid] = partners[i]; } }else if(type == ADVCONST.PLAY_MODEL.WEEKLY){ for(let i in partners){ let bid = partners[i].bid; this.partners[ADVCONST.PLAY_MODEL.WEEKLY][bid] = partners[i]; } } if(!BattleController.getInstance().isInFight()){ this.useReliveProp(); } //刷新界面英雄 gcore.GlobalEvent.fire(AdventureEvent.Update_Hero_Info,this.partners[type]); }, useReliveProp(){ let partners = this.partners[this.model_type]; let is_all_dead = false; for(let i in partners){ let hero = partners[i]; if(hero.bid == this.leader){ if(hero.now_hp <= 0){ is_all_dead = true; break; } } } //人物全部死亡 if(is_all_dead){ nx.bridge.createPanel("WndAdventureRelive",{}); } }, getAllFormPartners(){ let partners = this.partners[this.model_type]; if(partners){ return partners; } return null; }, //获取要使用的上阵英雄 getFormPartnerByBid(bid){ if(!this.partners[this.model_type])return null; let partner_list = this.partners[this.model_type]; let data = partner_list[bid]; if(nx.dt.objEmpty(data)){ return null; } return data; }, setBagItems(items){ this.bag_items = items; }, //判斷某個道具是否有數量 getItemBybid(bid){ if(!this.bag_items)return null; for(let i in this.bag_items){ let data = this.bag_items[i]; if(bid == data.bid){ return data; } } return null; }, setCurLeader(bid){ this.leader = bid; this.checkIsDead(bid); }, checkIsDead(bid){ if(!bid || !this.partners[this.model_type])return; let cur_hero = this.partners[this.model_type][bid]; if(cur_hero){ if(cur_hero.now_hp <= 0){//死亡 this.id_dead = true; }else{ this.id_dead = false; } } }, getDeadStatus(){ return this.id_dead; }, getCurLeader(){ return this.leader; }, setNPCData(data){ this.npc_event_data = data; }, getNPCData(){ return this.npc_event_data; }, setShopData(data){ this.shop_event_data = data; }, getShopData(){ return this.shop_event_data; }, setTransData(data){ this.trans_event_data = data; }, getTransData(){ return this.trans_event_data; }, setMonsterData(data){ this.monster_event_data = data; }, getMonsterData(){ return this.monster_event_data }, //選擇模式會請求29509消息,此時無法打開周回選人界面,先保存數據 setWeeklyPartnerData(data){ this.weekly_heros = data; }, getWeeklyPartnerData(){ return this.weekly_heros; }, setTrapPos(room_id){ this.trapPos = room_id; }, getTrapPos(){ return this.trapPos; }, }); module.exports = AdventureController;