"use strict"; cc._RF.push(module, '0ab24G2T2JArJP7gMPVFyU/', 'element_controller'); // Scripts/mod/pve/element/element_controller.js "use strict"; // -------------------------------------------------------------------- // @author: xxx@syg.com(必填, 创建模块的人员) // @description: // 这里填写详细说明,主要填写该模块的功能简要 //
Create: 2019-09-16 19:26:31 // -------------------------------------------------------------------- var BridgeController = require("bridge.controller"); var ElementEvent = require("element_event"); var BattleConst = require("battle_const"); var HeroController = require("hero_controller"); var RoleController = require("role_controller"); var BattleController = require("battle_controller"); var ElementController = cc.Class({ "extends": BridgeController, ctor: function ctor() {}, // 初始化配置数据 initConfig: function initConfig() { var ElementModel = require("element_model"); this.model = new ElementModel(); this.model.initConfig(); }, // 返回当前的model getModel: function getModel() { return this.model; }, // 注册监听事件 registerEvents: function registerEvents() {}, // 注册协议接受事件 registerProtocals: function registerProtocals() { // this.RegisterProtocal(1110, this.on1110); this.RegisterProtocal(25000, this.handle25000); // 元素神殿基础数据 this.RegisterProtocal(25001, this.handle25001); // 元素神殿挑战 this.RegisterProtocal(25002, this.handle25002); // 元素神殿扫荡 this.RegisterProtocal(25003, this.handle25003); // 购买挑战次数 this.RegisterProtocal(25004, this.handle25004); // 挑战次数刷新 this.RegisterProtocal(25005, this.handle25005); // 最大关卡数更新 }, // 从服务器初始化数据 reqBaseFromServer: function reqBaseFromServer(_cb) { var _this = this; // 配置加载 var cfgs = ["element_temple_data" // 元素神殿(阵营战) ]; this.loadConfigs(cfgs, function (_ret, _data) { _this.reqElementData(_cb); }); }, reqElementData: function reqElementData(_cb) { // 功能解锁检查 var ret = this.checkIsOpen(); // 锁定中不请求数据 if (nx.dt.objNEmpty(ret.val)) { nx.dt.fnInvoke(_cb, true); return; } this.SendProtocal(25000, {}, _cb); }, checkIsOpen: function checkIsOpen() { var open_config = game.configs.element_temple_data.data_const.join_lev; if (open_config == null) return null; var ret = nx.bridge.checkConditions(["lev", open_config.val]); return ret; }, sender25000: function sender25000() { var protocal = {}; this.SendProtocal(25000, protocal); }, handle25000: function handle25000(data) { if (data) { this.model.setElementData(data); gcore.GlobalEvent.fire(ElementEvent.Update_Element_Data_Event); // if (!this.first_enter) { // this.first_enter = true // BattleController.getInstance().requestOpenBattleRelevanceWindow(BattleConst.Fight_Type.ElementWar) // } } }, sender25001: function sender25001(type, boss_id, formation_type, pos_info, hallows_id) { var protocal = {}; protocal.type = type; protocal.boss_id = boss_id; protocal.formation_type = formation_type; protocal.pos_info = pos_info; protocal.hallows_id = hallows_id; this.SendProtocal(25001, protocal); }, handle25001: function handle25001(data) { if (data) { nx.tbox(data.msg); } }, //扫荡元素神殿 sender25002: function sender25002(type, boss_id) { var protocal = {}; protocal.type = type; protocal.boss_id = boss_id; this.SendProtocal(25002, protocal); }, handle25002: function handle25002(data) { // if(data){ // nx.tbox(data.msg); // } }, sender25003: function sender25003(_cb) { var protocal = {}; this.SendProtocal(25003, protocal, _cb); }, handle25003: function handle25003(data) { nx.tbox(data.msg); if (data) { if (data.code == 1 && this._temp_ele_type && this._temp_customs_id && this._temp_formation_type && this._temp_pos_info && this._temp_hallows_id) { this.sender25001(this._temp_ele_type, this._temp_customs_id, this._temp_formation_type, this._temp_pos_info, this._temp_hallows_id); this._temp_ele_type = null; this._temp_customs_id = null; this._temp_formation_type = null; this._temp_pos_info = null; this._temp_hallows_id = null; } else if (data.code == 1 && this._temp_type && this._temp_boss_id) { this.sender25002(this._temp_type, this._temp_boss_id); this._temp_type = null; this._temp_boss_id = null; } } }, // sender25004(data){ // }, //挑战次数刷新 handle25004: function handle25004(data) { if (data) { this.model.updateElementCountData(data); gcore.GlobalEvent.fire(ElementEvent.Update_Element_Count_Event); gcore.GlobalEvent.fire(ElementEvent.Update_Element_Customs_Event); } }, //最大关卡数更新 handle25005: function handle25005(data) { if (data) { this.model.updateElementCustomsData(data); gcore.GlobalEvent.fire(ElementEvent.Update_Element_Customs_Event); } }, checkJoinHeavenBattle: function checkJoinHeavenBattle(ele_type, customs_id, formation_type, pos_info, hallows_id) { if (this.model.getLeftChallengeCount() > 0) { this.sender25001(ele_type, customs_id, formation_type, pos_info, hallows_id); HeroController.getInstance().openFormGoFightPanel(false); } else if (this.model.getTodayLeftBuyCount() > 0) { var normal_buy_count = this.model.getNormalBuyCount(); var buy_cfg = game.configs.element_temple_data.data_buy_count[normal_buy_count + 1]; var privilege_status = RoleController.getInstance().getModel().checkPrivilegeStatus(4); //-- 特權激活狀態 if (buy_cfg) { var str = cc.js.formatStr(nx.text.getKey("lab_ladder_controller_tip2"), PathTool.getItemRes(3), buy_cfg.cost); } else if (privilege_status) { var buy_count = this.model.getPrivilegeBuyCount(); var pri_cost = game.configs.element_temple_data.data_privilege[buy_count + 1]; if (pri_cost) { var _str = cc.js.formatStr(nx.text.getKey("lab_ladder_controller_tip2"), PathTool.getItemRes(3), pri_cost); } } } else { nx.tbox("lab_ladder_controller_tip3"); HeroController.getInstance().openFormGoFightPanel(false); } }, //检测挑战次数并进行扫荡 checkSweepHeaven: function checkSweepHeaven(type, boss_id) { var _this2 = this; if (this.model.getLeftChallengeCount() > 0) { this.sender25002(type, boss_id); } else if (this.model.getTodayLeftBuyCount() > 0) { var normal_buy_count = this.model.getNormalBuyCount(); var buy_cfg = game.configs.element_temple_data.data_buy_count[normal_buy_count + 1]; var privilege_status = RoleController.getInstance().getModel().checkPrivilegeStatus(4); // 特權激活狀態 if (buy_cfg) { var str = cc.js.formatStr(nx.text.getKey("lab_element_controller_tip1"), 3, buy_cfg.cost); nx.mbox(str, ["cancel", "confirm"], function (_key, _box) { _box.close(); if (_key == "confirm") { _this2.sender25003(); } }); } else if (privilege_status) { var buy_count = this.model.getPrivilegeBuyCount(); var pri_cost = game.configs.element_temple_data.data_privilege[buy_count + 1]; if (pri_cost) { var str2 = cc.js.formatStr(nx.text.getKey("lab_element_controller_tip1"), 3, pri_cost); nx.mbox(str2, ["cancel", "confirm"], function (_key, _box) { _box.close(); if (_key == "confirm") { _this2.sender25003(); } }); } } } else { nx.tbox("lab_ladder_controller_tip3"); } }, //打开元素神殿主界面 openElementMainWindow: function openElementMainWindow(status, setting) { if (status) { nx.bridge.createPanel("WndElement", {}); } else { nx.bridge.closePanel("WndElement"); } }, //打开元素神殿副本挑战界面 openElementEctypeWindow: function openElementEctypeWindow(status, data) { if (status) { if (this.element_ectype_wnd == null) { var ElementEctypeWindow = require("element_ectype_window"); this.element_ectype_wnd = new ElementEctypeWindow(); } this.element_ectype_wnd.open(data); } else { if (this.element_ectype_wnd) { this.element_ectype_wnd.close(); this.element_ectype_wnd = null; } } } }); module.exports = ElementController; cc._RF.pop();