Files
fc/dev/project/library/imports/2a/2a75a5b2-b848-4d9e-9fa2-7a1eb1e38929.js
T
2026-05-24 10:21:26 +08:00

717 lines
22 KiB
JavaScript

"use strict";
cc._RF.push(module, '2a75aWyuEhNnp+ieh6x44kp', 'adventure_controller');
// Scripts/mod/pve/adventure/adventure_controller.js
"use strict";
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
// 冒险主控制器
// <br/>Create: 2019-05-09 14:14:52
// --------------------------------------------------------------------
var BridgeController = require("bridge.controller");
var AdventureEvent = require("adventure_event");
var ADVCONST = require("adventure_const");
var BattleConst = require("battle_const");
var BattleController = require("battle_controller");
var AdventureController = cc.Class({
"extends": BridgeController,
ctor: function ctor() {},
// 初始化配置数据
initConfig: function initConfig() {
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 getModel() {
return this.model;
},
// 注册协议接受事件
registerProtocals: function registerProtocals() {
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 reqBaseFromServer(_cb) {
var cfgs = ["adventure_endless_data", "adventure_weekly_data"];
this.loadConfigs(cfgs, function (_ret, _data) {
return nx.dt.fnInvoke(_cb, true);
});
},
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;
},
openWindowByConfig: function openWindowByConfig(data) {
var room_data = this.getRoomDataByXY(data.room_id[0].x, data.room_id[0].y);
var 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: function resetActionConfig(room_id) {
var room_data = this.getRoomDataByXY(room_id.x, room_id.y);
var 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 send29500(type) {
var protocal = {};
protocal.type = type;
this.SendProtocal(29500, protocal);
},
send29501: function send29501(type) {
var protocal = {};
protocal.type = type;
this.SendProtocal(29501, protocal);
},
send29502: function send29502(type) {
var protocal = {};
protocal.type = type;
this.SendProtocal(29502, protocal);
},
//请求当前所有英雄数据
send29504: function send29504(type) {
var protocal = {};
protocal.type = type;
this.SendProtocal(29504, protocal);
},
send29505: function send29505(type, plist) {
var protocal = {};
protocal.plist = plist;
protocal.type = type;
this.SendProtocal(29505, protocal);
},
send29506: function send29506(type) {
var protocal = {};
protocal.type = type;
this.SendProtocal(29506, protocal);
},
send29507: function send29507(id, type, _cb) {
var protocal = {};
protocal.item_id = id;
protocal.type = type || this.model_type;
this.SendProtocal(29507, protocal, _cb);
},
//随机伙伴信息
send29509: function send29509(type) {
var protocal = {};
protocal.type = type;
this.SendProtocal(29509, protocal);
},
send29510: function send29510(id) {
var protocal = {};
protocal.id = id;
protocal.type = this.model_type;
this.SendProtocal(29510, protocal);
},
//游戲結束
send29512: function send29512() {
this.SendProtocal(29512, {});
},
//購買體力
send29513: function send29513() {
this.SendProtocal(29513, {});
},
//探索路径
send29508: function send29508(path, type) {
var protocal = {};
protocal.room_ids = path;
protocal.type = type;
this.SendProtocal(29508, protocal);
},
//探索事件
send29520: function send29520(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 send29534(type) {
var protocal = {};
protocal.type = type;
this.SendProtocal(29534, protocal);
},
send29535: function send29535(id) {
var protocal = {};
protocal.id = id;
protocal.type = this.model_type;
this.SendProtocal(29535, protocal);
},
send29543: function send29543(type) {
//日志
var protocal = {};
protocal.type = type;
this.SendProtocal(29543, protocal);
},
handle29500: function handle29500(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
this.setBaseData(data);
//在模式界面初始化用
gcore.GlobalEvent.fire(AdventureEvent.Init_Model_Win, data);
},
handle29501: function handle29501(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 handle29502(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
this.setRoomData(data.room_list);
},
handle29503: function handle29503(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
this.updateRoomData(data);
},
handle29504: function handle29504(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
//设置上阵英雄列表
this.setFormHeros(data.type, data.partners);
},
handle29505: function handle29505(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 handle29506(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 handle29507(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
},
handle29508: function handle29508(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 handle29509(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: function setIsOpenEndlessHero(status) {
this.is_open_endlesshero = status;
},
handle29510: function handle29510(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
},
handle29512: function handle29512(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 handle29513(data) {
if (data.code == 0) {
nx.tbox(data.msg);
} else {
gcore.GlobalEvent.fire(AdventureEvent.Buy_Energy, data.energy);
}
},
handle29520: function handle29520(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 handle29524(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
this.setMonsterData(data);
},
handle29527: function handle29527(data) {
// 失败判定
if (!this.isGoodData(data)) {
this.setNPCData(null);
return;
}
this.setNPCData(data);
},
handle29528: function handle29528(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
this.setTransData(data);
},
handle29534: function handle29534(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
gcore.GlobalEvent.fire(AdventureEvent.Update_Awards, data.list);
},
handle29535: function handle29535(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
nx.tbox(data.msg);
},
handle29531: function handle29531(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
this.setShopData(data);
gcore.GlobalEvent.fire(AdventureEvent.Update_Shop_Data, data);
},
handle29541: function handle29541(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 handle29543(data) {
// 失败判定
if (!this.isGoodData(data)) {
return;
}
gcore.GlobalEvent.fire(AdventureEvent.Update_Fight_Log, data);
},
openEndlessHeroPanel: function 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: function openMoreItemsWindow(type, list) {
nx.bridge.createPanel("WndAdventureMore", {
type: type,
list: list
});
},
///////////////////////////////////////////////////
//新的model
isInitProtol: function isInitProtol() {
return this.is_init;
},
//设置游玩模式 1 无尽模式 2 周回模式
setPlayModel: function setPlayModel(type) {
this.model_type = type;
},
getPlayModel: function getPlayModel() {
return this.model_type;
},
//操作事件時設置事件類型,操作完畢后置空,然後根據類型重置數據
setCurEvtType: function setCurEvtType(type) {
this.cur_evt_type = type;
},
getCurEvtType: function getCurEvtType() {
return this.cur_evt_type;
},
setBaseData: function 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: function getBaseData() {
return this.base_data;
},
setCurStartPos: function setCurStartPos(pos) {
//x,y
this.startPos = pos;
},
getCurStartPos: function getCurStartPos() {
return this.startPos;
},
isKillBoss: function isKillBoss(status) {
this.isKilled = status == 1 ? true : false;
},
getKillBossStatus: function getKillBossStatus() {
return this.isKilled;
},
setActStatus: function setActStatus(status) {
this.isFinish = status == 1 ? true : false;
},
getActStatus: function getActStatus() {
return this.isFinish;
},
setMapsInfo: function setMapsInfo(info) {
this.mapSize = info;
},
getMapsInfo: function getMapsInfo() {
return this.mapSize;
},
setRoomData: function setRoomData(room_list) {
this.room_list = room_list;
//刷新房间地图信息
gcore.GlobalEvent.fire(AdventureEvent.Update_Room_Base_Info);
},
getRoomDataByIndex: function getRoomDataByIndex(index) {
if (nx.dt.arrEmpty(this.room_list)) return;
var data = this.room_list[index];
if (!nx.dt.objEmpty(data)) {
return data;
}
return null;
},
getRoomDataByXY: function getRoomDataByXY(x, y) {
if (nx.dt.arrEmpty(this.room_list)) return;
for (var i = 0; i < this.room_list.length; i++) {
var data = this.room_list[i];
if (data.room_id[0].x == x && data.room_id[0].y == y) {
return data;
}
}
return null;
},
updateRoomData: function updateRoomData(data) {
var xy = data.room_id[0];
var index = null;
if (this.room_list) {
for (var i = 0; i < this.room_list.length; i++) {
var 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: function setFormHeros(type, partners) {
this.partners[type] = {};
if (type == ADVCONST.PLAY_MODEL.ENDLESS) {
for (var i in partners) {
var bid = partners[i].bid;
this.partners[ADVCONST.PLAY_MODEL.ENDLESS][bid] = partners[i];
}
} else if (type == ADVCONST.PLAY_MODEL.WEEKLY) {
for (var _i in partners) {
var _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: function useReliveProp() {
var partners = this.partners[this.model_type];
var is_all_dead = false;
for (var i in partners) {
var 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: function getAllFormPartners() {
var partners = this.partners[this.model_type];
if (partners) {
return partners;
}
return null;
},
//获取要使用的上阵英雄
getFormPartnerByBid: function getFormPartnerByBid(bid) {
if (!this.partners[this.model_type]) return null;
var partner_list = this.partners[this.model_type];
var data = partner_list[bid];
if (nx.dt.objEmpty(data)) {
return null;
}
return data;
},
setBagItems: function setBagItems(items) {
this.bag_items = items;
},
//判斷某個道具是否有數量
getItemBybid: function getItemBybid(bid) {
if (!this.bag_items) return null;
for (var i in this.bag_items) {
var data = this.bag_items[i];
if (bid == data.bid) {
return data;
}
}
return null;
},
setCurLeader: function setCurLeader(bid) {
this.leader = bid;
this.checkIsDead(bid);
},
checkIsDead: function checkIsDead(bid) {
if (!bid || !this.partners[this.model_type]) return;
var 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: function getDeadStatus() {
return this.id_dead;
},
getCurLeader: function getCurLeader() {
return this.leader;
},
setNPCData: function setNPCData(data) {
this.npc_event_data = data;
},
getNPCData: function getNPCData() {
return this.npc_event_data;
},
setShopData: function setShopData(data) {
this.shop_event_data = data;
},
getShopData: function getShopData() {
return this.shop_event_data;
},
setTransData: function setTransData(data) {
this.trans_event_data = data;
},
getTransData: function getTransData() {
return this.trans_event_data;
},
setMonsterData: function setMonsterData(data) {
this.monster_event_data = data;
},
getMonsterData: function getMonsterData() {
return this.monster_event_data;
},
//選擇模式會請求29509消息,此時無法打開周回選人界面,先保存數據
setWeeklyPartnerData: function setWeeklyPartnerData(data) {
this.weekly_heros = data;
},
getWeeklyPartnerData: function getWeeklyPartnerData() {
return this.weekly_heros;
},
setTrapPos: function setTrapPos(room_id) {
this.trapPos = room_id;
},
getTrapPos: function getTrapPos() {
return this.trapPos;
}
});
module.exports = AdventureController;
cc._RF.pop();