Files
fc/dev/project/assets/Scripts/mod/pve/element/element_controller.js
T
2026-05-23 22:10:14 +08:00

255 lines
9.0 KiB
JavaScript

// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
// 这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2019-09-16 19:26:31
// --------------------------------------------------------------------
const BridgeController = require( "bridge.controller" );
var ElementEvent = require("element_event")
var BattleConst = require("battle_const")
var HeroController = require("hero_controller")
var RoleController = require("role_controller")
const BattleController = require("battle_controller");
var ElementController = cc.Class({
extends: BridgeController,
ctor: function () {
},
// 初始化配置数据
initConfig: function () {
var ElementModel = require("element_model");
this.model = new ElementModel();
this.model.initConfig();
},
// 返回当前的model
getModel: function () {
return this.model;
},
// 注册监听事件
registerEvents: function () {
},
// 注册协议接受事件
registerProtocals: function () {
// 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( _cb ) {
// 配置加载
let cfgs = [
"element_temple_data", // 元素神殿(阵营战)
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
this.reqElementData( _cb );
} );
},
reqElementData( _cb ){
// 功能解锁检查
let ret = this.checkIsOpen();
// 锁定中不请求数据
if( nx.dt.objNEmpty( ret.val ) ) {
nx.dt.fnInvoke( _cb, true );
return;
}
this.SendProtocal( 25000, {}, _cb );
},
checkIsOpen:function(){
var open_config = game.configs.element_temple_data.data_const.join_lev;
if(open_config == null)return null;
let ret = nx.bridge.checkConditions( ["lev",open_config.val] );
return ret;
},
sender25000(){
let protocal = {}
this.SendProtocal(25000, protocal)
},
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( type, boss_id, formation_type, pos_info, hallows_id ){
let 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(data){
if(data){
nx.tbox(data.msg);
}
},
//扫荡元素神殿
sender25002(type, boss_id){
let protocal = {}
protocal.type = type
protocal.boss_id = boss_id
this.SendProtocal(25002, protocal)
},
handle25002(data){
// if(data){
// nx.tbox(data.msg);
// }
},
sender25003(_cb){
let protocal = {}
this.SendProtocal(25003, protocal,_cb)
},
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(data){
if (data) {
this.model.updateElementCountData(data)
gcore.GlobalEvent.fire(ElementEvent.Update_Element_Count_Event)
gcore.GlobalEvent.fire(ElementEvent.Update_Element_Customs_Event)
}
},
//最大关卡数更新
handle25005(data){
if (data) {
this.model.updateElementCustomsData(data)
gcore.GlobalEvent.fire(ElementEvent.Update_Element_Customs_Event)
}
},
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 ){
let normal_buy_count = this.model.getNormalBuyCount();
let buy_cfg = game.configs.element_temple_data.data_buy_count[normal_buy_count + 1]
let privilege_status = RoleController.getInstance().getModel().checkPrivilegeStatus(4) //-- 特權激活狀態
if (buy_cfg) {
let str = cc.js.formatStr(nx.text.getKey("lab_ladder_controller_tip2"), PathTool.getItemRes(3), buy_cfg.cost)
} else if( privilege_status) {
let buy_count = this.model.getPrivilegeBuyCount()
let pri_cost = game.configs.element_temple_data.data_privilege[buy_count+1]
if (pri_cost) {
let 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(type, boss_id){
if (this.model.getLeftChallengeCount() > 0) {
this.sender25002(type, boss_id)
}else if( this.model.getTodayLeftBuyCount() > 0) {
let normal_buy_count = this.model.getNormalBuyCount()
let buy_cfg = game.configs.element_temple_data.data_buy_count[normal_buy_count + 1]
let privilege_status = RoleController.getInstance().getModel().checkPrivilegeStatus(4) // 特權激活狀態
if (buy_cfg) {
let str = cc.js.formatStr(nx.text.getKey("lab_element_controller_tip1"), 3, buy_cfg.cost)
nx.mbox(str,["cancel","confirm"],(_key,_box)=>{
_box.close();
if(_key == "confirm"){
this.sender25003();
}
});
}else if (privilege_status) {
let buy_count = this.model.getPrivilegeBuyCount()
let pri_cost = game.configs.element_temple_data.data_privilege[buy_count+1]
if (pri_cost) {
let str2 = cc.js.formatStr(nx.text.getKey("lab_element_controller_tip1"), 3, pri_cost)
nx.mbox(str2,["cancel","confirm"],(_key,_box)=>{
_box.close();
if(_key == "confirm"){
this.sender25003();
}
});
}
}
}else{
nx.tbox("lab_ladder_controller_tip3")
}
},
//打开元素神殿主界面
openElementMainWindow( status, setting ){
if(status){
nx.bridge.createPanel("WndElement",{});
}else{
nx.bridge.closePanel("WndElement");
}
},
//打开元素神殿副本挑战界面
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;