"use strict";
cc._RF.push(module, '2a75aWyuEhNnp+ieh6x44kp', 'adventure_controller');
// Scripts/mod/adventure/adventure_controller.js
"use strict";
var _cc$Class;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
// 冒险主控制器
//
Create: 2019-05-09 14:14:52
// --------------------------------------------------------------------
var AdventureEvent = require("adventure_event");
var BattleConst = require("battle_const");
var MainuiController = require("mainui_controller");
var MainuiConst = require("mainui_const");
var BattleController = require("battle_controller");
var AdventureController = cc.Class((_cc$Class = {
"extends": BaseController,
ctor: function ctor() {},
// 初始化配置数据
initConfig: function initConfig() {
var AdventureModel = require("adventure_model");
this.model = new AdventureModel();
this.model.initConfig();
},
// 返回当前的model
getModel: function getModel() {
return this.model;
},
// 注册监听事件
registerEvents: function registerEvents() {},
// 注册协议接受事件
registerProtocals: function registerProtocals() {
this.RegisterProtocal(20600, this.handle20600); //基本信息
this.RegisterProtocal(20601, this.handle20601); //BUFF信息
this.RegisterProtocal(20602, this.handle20602); //房间信息
this.RegisterProtocal(20603, this.handle20603); //服务端通知更新指定房间信息
this.RegisterProtocal(20604, this.handle20604); //获取当前伙伴信息数据
this.RegisterProtocal(20605, this.handle20605); //设置上阵伙伴信息
this.RegisterProtocal(20606, this.handle20606); //每一层结算
this.RegisterProtocal(20607, this.handle20607); //使用3个主要技能的
this.RegisterProtocal(20608, this.handle20608); //进去指定房间
this.RegisterProtocal(20609, this.handle20609); //技能信息
this.RegisterProtocal(20610, this.handle20610); //选中伙伴
this.RegisterProtocal(20611, this.handle20611); //一击必杀请求
this.RegisterProtocal(20612, this.handle20612); //冒险重置
this.RegisterProtocal(20620, this.handle20620); //事件反馈
this.RegisterProtocal(20621, this.handle20621); //猜拳结果反馈
this.RegisterProtocal(20622, this.handle20622); //buff信息查看
this.RegisterProtocal(20623, this.handle20623); //答题信息
this.RegisterProtocal(20624, this.handle20624); //怪物信息
this.RegisterProtocal(20625, this.handle20625); //获得技能,主要是用于表现效果处理
this.RegisterProtocal(20627, this.handle20627); //NPC对话序号
this.RegisterProtocal(20628, this.handle20628); //NPC对话结果
this.RegisterProtocal(20630, this.handle20630); //宝箱打开结果
this.RegisterProtocal(20631, this.handle20631); //神秘商店事件
this.RegisterProtocal(20632, this.handle20632); //神秘商店总览
this.RegisterProtocal(20633, this.handle20633); //神秘商店购买
this.RegisterProtocal(20634, this.handle20634);
this.RegisterProtocal(20635, this.handle20635);
},
isMonster: function isMonster(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;
},
openAnswerView: function openAnswerView(value, data) {
if (value == false) {
if (this.adventure_answer_view != null) {
this.adventure_answer_view.close();
this.adventure_answer_view = null;
}
} else {
if (this.adventure_answer_view == null) {
this.adventure_answer_view = Utils.createClass("adventure_evt_answer_window", this);
}
if (this.adventure_answer_view && this.adventure_answer_view.isOpen() == false) {
this.adventure_answer_view.open(data);
}
}
},
//==============================--
//desc:进入冒险的主入口
//@return
//==============================--
requestEnterAdventure: function requestEnterAdventure() {
var form_list = this.model.getFormList();
if (form_list == null || Utils.next(form_list) == null) {
this.openAdventureFormWindow(true);
} else {
MainuiController.getInstance().requestOpenBattleRelevanceWindow(BattleConst.Fight_Type.Adventrue);
}
},
// ==============================--
// desc:打开冒险站前布阵界面
// @status:
// @return
// ==============================--
openAdventureFormWindow: function openAdventureFormWindow(status) {
if (!status) {
if (this.form_window) {
this.form_window.close();
this.form_window = null;
}
} else {
if (this.form_window == null) {
this.form_window = Utils.createClass("adventure_form_window", this);
}
if (this.form_window && this.form_window.isOpen() == false) {
this.form_window.open();
}
}
},
// -- 引导需要
// function AdventureController:getAdventureRoot()
// if this.adventure_window then
// return this.adventure_window.root_wnd
// end
// end
// -- 引导需要下一层的指引
// function AdventureController:getNextAlertRoot()
// if this.adventure_window then
// var alert = this.adventure_window:getAlert()
// if alert then
// return alert.root_wnd
// end
// end
// end
openAdventureMainWindow: function openAdventureMainWindow(status) {
if (!status) {
if (this.adventure_window) {
this.adventure_window.close();
this.adventure_window = null;
}
} else {
// 没有布阵是不给进去的
var form_list = this.model.getFormList();
if (form_list == null || Utils.next(form_list) == null) {
// print("跳转进入神界冒险有误,当前还没有布阵 ============>")
return;
} // 没有基础数据也不做响应
var base_data = this.model.getAdventureBaseData();
if (base_data == null) return;
if (this.adventure_window == null) {
this.adventure_window = Utils.createClass("adventure_main_window", this);
}
if (this.adventure_window && this.adventure_window.isOpen() == false) {
this.adventure_window.open();
}
}
},
openWindowByConfig: function openWindowByConfig(data) {
if (data == null || data.config == null) return;
var config = data.config;
if (this.isMonster(config.evt_type)) {
//boss或者怪物
if (this.model.allHeroIsDie() == true) {
message(Utils.TI18N("英雄全部阵亡,本轮冒险已结束!"));
return;
}
this.openEvtViewByType(true, "adventure_evt_challenge_window", data);
} else if (config.evt_type == AdventureEvent.EventType.box) {
//B宝箱
this.openEvtViewByType(true, "adventure_evt_box_window", data);
} else if (config.evt_type == AdventureEvent.EventType.finger_guessing) {
//猜拳
this.openEvtViewByType(true, "adventure_evt_fighterguess_window", data);
} else if (config.evt_type == AdventureEvent.EventType.answer) {
//答题
this.openEvtViewByType(true, "adventure_evt_answer_start_window", data);
} else if (config.evt_type == AdventureEvent.EventType.npc) {
//npc事件
this.openEvtViewByType(true, "adventure_evt_npc_window", data);
} else if (config.evt_type == AdventureEvent.EventType.freebox) {
//免费宝箱
this.openEvtViewByType(true, "adventure_evt_free_box_window", data);
} else if (config.evt_type == AdventureEvent.EventType.npc_talk) {
//npc对话
this.openEvtViewByType(true, "adventure_evt_other_npc_window", data);
} else if (config.evt_type == AdventureEvent.EventType.shop) {
//神秘商店
this.openEvtViewByType(true, "adventure_evt_shop_window", data);
} else if (config.evt_type == AdventureEvent.EventType.effect) {
//特效事件
this.send20620(data.id, AdventureEvent.AdventureEvenHandleType.handle, {});
}
},
// 打开各种事件面板
openEvtViewByType: function openEvtViewByType(status, ref_class, data, extendparam, is_other) {
if (status == false) {
if (this.adventure_evt_view != null) {
this.adventure_evt_view.close();
this.adventure_evt_view = null;
}
} else {
if (data == null) return;
var ref_class = ref_class || "adventure_evt_challenge_window";
if (this.adventure_evt_view == null) {
this.adventure_evt_view = Utils.createClass(ref_class, this);
}
if (this.adventure_evt_view && this.adventure_evt_view.isOpen() == false) {
this.adventure_evt_view.open(data);
}
}
},
// ==============================--
// desc:冒险商店
// @status:
// @return
// ==============================--
openAdventrueShopWindow: function openAdventrueShopWindow(status) {
if (!status) {
if (this.shop_window) {
this.shop_window.close();
this.shop_window = null;
}
} else {
if (this.shop_window == null) {
this.shop_window = Utils.createClass("adventure_shop_window", this);
}
if (this.shop_window && this.shop_window.isOpen() == false) {
this.shop_window.open();
}
}
},
// ==============================--
// desc:一击必杀界面
// @status:
// @return
// ==============================--
openAdventureShotKillWindow: function openAdventureShotKillWindow(status, config) {
if (!status) {
if (this.shot_kill_window) {
this.shot_kill_window.close();
this.shot_kill_window = null;
}
} else {
if (config == null) return;
if (this.shot_kill_window == null) {
this.shot_kill_window = Utils.createClass("adventure_shot_kill_window", this);
}
if (this.shot_kill_window && this.shot_kill_window.isOpen() == false) {
this.shot_kill_window.open(config);
}
}
},
// ==============================--
// desc:使用药品
// @status:
// @return
// ==============================--
openAdventureUseHPWindow: function openAdventureUseHPWindow(status, config) {
if (!status) {
if (this.use_hp_window) {
this.use_hp_window.close();
this.use_hp_window = null;
}
} else {
if (config == null) return;
if (this.use_hp_window == null) {
this.use_hp_window = Utils.createClass("adventure_use_hp_window", this);
}
if (this.use_hp_window && this.use_hp_window.isOpen() == false) {
this.use_hp_window.open(config);
}
}
},
// 事件操作
send20620: function send20620(room_id, action, ext_list) {
var protocal = {};
protocal.room_id = room_id;
protocal.action = action;
protocal.ext_list = ext_list || {};
this.SendProtocal(20620, protocal);
},
handle20620: function handle20620(data) {
message(data.msg);
if (data.code == 2) {
this.openEvtViewByType(false);
}
},
// 请求房间信息
send20602: function send20602() {
var protocal = {};
this.SendProtocal(20602, protocal);
},
// 房间信息返回
handle20602: function handle20602(data) {
this.model.setRoomList(data);
},
// 服务端通知更新指定房间信息
handle20603: function handle20603(data) {
this.model.updateRoomList(data);
},
send20604: function send20604() {
this.SendProtocal(20604, {});
},
// 获取当前伙伴信息数据
handle20604: function handle20604(data) {
this.model.updateFormPartner(data.partners, data.id); // if(NEEDCHANGEENTERSTATUS == 2 && !this.first_enter){//如果是1就跳转到出具
// this.first_enter = true;
// MainuiController.getInstance().changeMainUIStatus(MainuiConst.btn_index.drama_scene);
// }
},
// 请求布阵
requestSetForm: function requestSetForm(plist) {
var protocal = {};
protocal.plist = plist || {};
this.SendProtocal(20605, protocal);
},
handle20605: function handle20605(data) {
if (data.code == 1) {
this.openAdventureFormWindow(false); // 请求进入
MainuiController.getInstance().requestOpenBattleRelevanceWindow(BattleConst.Fight_Type.Adventrue);
}
},
send20608: function send20608(room_id) {
var protocal = {};
protocal.room_id = room_id;
this.SendProtocal(20608, protocal);
},
handle20608: function handle20608(data) {
message(data.msg);
if (data.code == 1) {
gcore.GlobalEvent.fire(AdventureEvent.HandleRoomOverEvent, data.room_id);
}
},
// 基本信息
send20600: function send20600() {
var protocal = {};
this.SendProtocal(20600, protocal);
},
// 基本信息返回
handle20600: function handle20600(data) {
if (data) {
this.model.setAdventureBaseData(data);
}
},
// buff信息
send20601: function send20601() {
this.SendProtocal(20601, {});
},
// buff信息返回
handle20601: function handle20601(data) {
if (data) {
this.model.setBuffData(data);
}
},
handle20622: function handle20622(data) {
if (data) {
gcore.GlobalEvent.fire(AdventureEvent.Update_Evt_Buff_Info, data);
}
},
handle20621: function handle20621(data) {
if (data) {
gcore.GlobalEvent.fire(AdventureEvent.Update_Evt_Guess_Result, data);
}
},
handle20623: function handle20623(data) {
if (data) {
gcore.GlobalEvent.fire(AdventureEvent.Update_Evt_Answer_Info, data);
}
},
handle20628: function handle20628(data) {
if (data) {
message(data.msg);
gcore.Timer.set(function () {
this.openEvtViewByType(false);
this.showGetItemTips(data.items);
}.bind(this), 1000, 1);
}
},
handle20630: function handle20630(data) {
if (data) {
gcore.GlobalEvent.fire(AdventureEvent.Update_Evt_Box_Result_Info, data);
}
},
handle20627: function handle20627(data) {
if (data) {
gcore.GlobalEvent.fire(AdventureEvent.Update_Evt_Npc_Info, data);
}
},
handle20631: function handle20631(data) {
if (data.type == 1) {
//点击房间事件时候请求20协议之后返回处理
gcore.GlobalEvent.fire(AdventureEvent.Update_Evt_Shop_Info, data);
} else if (data.type == 2) {
//点击技能商店直接弹出
this.openAdventureEvtShopView(true, data.list);
}
},
// ==============================--
// desc:主动打开神秘商店
// @status:
// @data:
// @return
// ==============================--
openAdventureEvtShopView: function openAdventureEvtShopView(status, data) {
if (!status) {
if (this.shop_evt_window) {
this.shop_evt_window.close();
this.shop_evt_window = null;
}
} else {
if (this.shop_evt_window == null) {
this.shop_evt_window = Utils.createClass("adventure_evt_shop_window", this);
}
if (this.shop_evt_window && this.shop_evt_window.isOpen() == false) {
if (data) {
data.is_auto = true;
}
this.shop_evt_window.open(data);
}
}
},
// ==============================--
// desc:冒险中飘字处理
// @items:
// @is_guess:是否是猜拳结果
// @ret:猜拳的结果
// @return
// ==============================--
showGetItemTips: function showGetItemTips(items, is_guess, ret) {
if (items) {
var str = "";
for (var i in items) {
var v = items[i];
if (str != "") {
str = str + ",";
}
var item_config = Utils.getItemConfig(v.bid);
if (gdata("item_data", "data_assets_id2label", v.bid)) {
str = cc.js.formatStr("%s
x%s", str, item_config.icon, v.num);
} else {
var BackPackConst = require("backpack_const");
str = cc.js.formatStr("%s%sx%s", str, BackPackConst.quality_color(item_config.quality), item_config.name, v.num);
}
}
if (is_guess == true) {
ret = ret || 0;
if (ret == 0) {
//平
str = cc.js.formatStr(Utils.TI18N("平局!太可惜了,%s还你"), str);
} else if (ret == 1) {
//赢
str = cc.js.formatStr(Utils.TI18N("好吧,这%s归你了"), str);
} else {
str = cc.js.formatStr(Utils.TI18N("看你这么可怜,还你%s吧"), str);
}
} else {
str = cc.js.formatStr(Utils.TI18N("获取%s"), str);
}
Utils.playButtonSound("c_get");
message(str);
}
},
// 冒险每一层结算数据
openAdventureFloorResultWindow: function openAdventureFloorResultWindow(status, data) {
if (!status) {
if (this.floor_result_window) {
this.floor_result_window.close();
this.floor_result_window = null;
}
} else {
if (data == null || data.items_list == null) return;
if (this.floor_result_window == null) {
this.floor_result_window = Utils.createClass("adventure_floor_result_window", this);
}
if (this.floor_result_window && this.floor_result_window.isOpen() == false) {
this.floor_result_window.open(data);
}
}
},
// 服务端主动推送的结算界面
handle20606: function handle20606(data) {
this.openAdventureFloorResultWindow(true, data);
},
// ==============================--
// desc:请求技能信息
// @return
// ==============================--
send20609: function send20609() {
this.SendProtocal(20609, {});
},
// ==============================--
// desc:使用3个技能
// @skill_id:
// @val:
// @return
// ==============================--
send20607: function send20607(skill_id, val) {
var protocal = {};
protocal.skill_id = skill_id;
protocal.val = val;
this.SendProtocal(20607, protocal);
},
// ==============================--
// desc:使用技能
// time:2019-01-24 04:57:32
// @data:
// @return
// ==============================--
handle20607: function handle20607(data) {
message(data.msg);
if (data.code == 1) {
this.openAdventureShotKillWindow(false);
this.openAdventureUseHPWindow(false);
}
}
}, _defineProperty(_cc$Class, "send20609", function send20609(data) {
this.SendProtocal(20609, {});
}), _defineProperty(_cc$Class, "handle20609", function handle20609(data) {
if (data) {
gcore.GlobalEvent.fire(AdventureEvent.UpdateSkillInfo, data.skill_list);
}
}), _defineProperty(_cc$Class, "requestSelectPartner", function requestSelectPartner(id) {
var protocal = {};
protocal.id = id;
this.SendProtocal(20610, protocal);
}), _defineProperty(_cc$Class, "handle20610", function handle20610(data) {
// -- message(data.msg)
if (data.code == 1) {
this.model.updateSelectPartnerID(data.id);
}
}), _defineProperty(_cc$Class, "handle20624", function handle20624(data) {
gcore.GlobalEvent.fire(AdventureEvent.UpdateMonsterHP, data.hp_per);
}), _defineProperty(_cc$Class, "send20611", function send20611() {
this.SendProtocal(20611, {});
}), _defineProperty(_cc$Class, "handle20611", function handle20611(data) {
gcore.GlobalEvent.fire(AdventureEvent.UpdateShotKillInfo, data.room_list);
}), _defineProperty(_cc$Class, "requestShopTotal", function requestShopTotal() {
this.SendProtocal(20632, {});
}), _defineProperty(_cc$Class, "handle20632", function handle20632(data) {
gcore.GlobalEvent.fire(AdventureEvent.UpdateShopTotalEvent, data.list);
}), _defineProperty(_cc$Class, "requestBuyShopItem", function requestBuyShopItem(id) {
var protocal = {};
protocal.id = id;
this.SendProtocal(20633, protocal);
}), _defineProperty(_cc$Class, "handle20633", function handle20633(data) {
message(data.msg);
if (data.code == 1) {
gcore.GlobalEvent.fire(AdventureEvent.UpdateShopItemEvent, data.id);
}
}), _defineProperty(_cc$Class, "send20634", function send20634() {
this.SendProtocal(20634, {});
}), _defineProperty(_cc$Class, "handle20634", function handle20634(data) {
this.model.setAdventureBoxStatus(data);
gcore.GlobalEvent.fire(AdventureEvent.UpdateBoxTeskEvent, data);
}), _defineProperty(_cc$Class, "send20635", function send20635(id) {
var proto = {};
proto.id = id;
this.SendProtocal(20635, proto);
}), _defineProperty(_cc$Class, "handle20635", function handle20635(data) {
message(data.msg);
}), _defineProperty(_cc$Class, "openAdventureBoxRewardView", function openAdventureBoxRewardView(status, kill_master) {
if (status == true) {
if (this.box_reward_window == null) {
this.box_reward_window = Utils.createClass("adventure_box_reward_window", this);
}
if (this.box_reward_window && this.box_reward_window.isOpen() == false) {
this.box_reward_window.open(kill_master);
}
} else {
if (this.box_reward_window) {
this.box_reward_window.close();
this.box_reward_window = null;
}
}
}), _defineProperty(_cc$Class, "handle20625", function handle20625(data) {
gcore.GlobalEvent.fire(AdventureEvent.GetSkillForEffectAction, data.id, data.skill_id);
}), _defineProperty(_cc$Class, "handle20612", function handle20612(data) {
var ui_fight_type = MainuiController.getInstance().getUIFightType();
if (ui_fight_type == MainuiConst.ui_fight_type.sky_scene) {
var is_in_fight = BattleController.getInstance().isInFight();
if (is_in_fight) {
//如果是在战斗中,则等战斗结束之后,弹出提示
if (this.battle_exit_event == null) {
this.battle_exit_event = gcore.GlobalEvent.bind(EventId.EXIT_FIGHT, function (combat_type) {
if (combat_type == BattleConst.Fight_Type.Adventrue) {
this.showAdventureReset();
}
}.bind(this));
}
} else {
this.showAdventureReset();
}
}
}), _defineProperty(_cc$Class, "showAdventureReset", function showAdventureReset() {
if (this.battle_exit_event) {
gcore.GlobalEvent.unbind(this.battle_exit_event);
this.battle_exit_event = null;
}
MainuiController.getInstance().changeMainUIStatus(MainuiConst.btn_index.main_scene);
gcore.Timer.set(function () {
var msg = Utils.TI18N("神界冒险已重置,是否重新进入?");
var CommonAlert = require("commonalert");
CommonAlert.show(msg, Utils.TI18N("确定"), function () {
this.requestEnterAdventure();
}.bind(this), Utils.TI18N("取消"));
}.bind(this), 200, 1);
}), _cc$Class));
module.exports = AdventureController;
cc._RF.pop();