476 lines
16 KiB
JavaScript
476 lines
16 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'd687cdm/r1FBouA7+dwDJZA', 'guildbat.mod');
|
|
// Scripts/mod/guild/guildbat/guildbat.mod.js
|
|
|
|
"use strict";
|
|
|
|
// --------------------------------------------------------------------
|
|
// @author: xxx@syg.com(必填, 创建模块的人员)
|
|
// @description:
|
|
// 工會戰(聯盟榮耀戰)
|
|
// <br/>Create: 2019-02-27 11:03:16
|
|
// --------------------------------------------------------------------
|
|
|
|
var BridgeController = require("bridge.controller");
|
|
var RoleController = require("role_controller");
|
|
var GuildwarEvent = require("guildwar_event");
|
|
var GuildwarConst = require("guildbat.define");
|
|
var GuildbatMod = cc.Class({
|
|
"extends": BridgeController,
|
|
ctor: function ctor() {},
|
|
// 初始化配置数据
|
|
initConfig: function initConfig() {
|
|
this.challengeCount = 0; // 已挑战次数
|
|
this.guildWarResult = GuildwarConst.result.fighting; // 战斗结果
|
|
this.myGuildWarBaseInfo = {}; // 我方联盟战基础数据(星数、buff等)
|
|
this.enemyGuildWarBaseInfo = {}; // 敌方联盟战基础数据(星数、名称)
|
|
this.guildWarStatus = GuildwarConst.status.close; // 联盟战状态
|
|
this.guildWarStartTime = 0; // 联盟战开始时间
|
|
this.guildWarEndTime = 0; // 联盟战结束时间
|
|
this.guildWarEnemyFlag = 0; // 是否匹配到对手
|
|
this.guildWarTopThreeRank = {}; // 前三排名
|
|
this.award_box_data = {};
|
|
},
|
|
// 注册协议接受事件
|
|
registerProtocals: function registerProtocals() {
|
|
this.RegisterProtocal(24200, this.handle24200); // 联盟战详细信息
|
|
this.RegisterProtocal(24201, this.handle24201); // 敌方单个据点信息
|
|
this.RegisterProtocal(24202, this.handle24202); // 发起战斗
|
|
this.RegisterProtocal(24203, this.handle24203); // 战斗结果
|
|
this.RegisterProtocal(24204, this.handle24204); // 联盟战的状态
|
|
this.RegisterProtocal(24205, this.handle24205); // 对战列表
|
|
this.RegisterProtocal(24206, this.handle24206); // 据点数据更新(只更新有变化的)
|
|
this.RegisterProtocal(24207, this.handle24207); // 联盟战基础数据更新(星数、buff等)
|
|
this.RegisterProtocal(24208, this.handle24208); // 本方联盟战据点数据
|
|
this.RegisterProtocal(24209, this.handle24209); // 防守记录
|
|
this.RegisterProtocal(24210, this.handle24210); // 有新的日志产生
|
|
this.RegisterProtocal(24212, this.handle24212); // 战场日志
|
|
this.RegisterProtocal(24213, this.handle24213); // 联盟战详细排名
|
|
this.RegisterProtocal(24214, this.handle24214); // 联盟战结果
|
|
this.RegisterProtocal(24220, this.handle24220); //寶箱數據
|
|
this.RegisterProtocal(24221, this.handle24221); //領取寶箱
|
|
this.RegisterProtocal(24223, this.handle24223); //寶箱被領取推送
|
|
},
|
|
|
|
// 从服务器初始化数据
|
|
reqBaseFromServer: function reqBaseFromServer(_cb) {
|
|
var _this = this;
|
|
// 配置加载
|
|
var cfgs = ["guild_war_data"];
|
|
this.loadConfigs(cfgs, function (_ret, _data) {
|
|
_this.requestGuildWarData(_cb);
|
|
});
|
|
},
|
|
//请求联盟战详细数据
|
|
requestGuildWarData: function requestGuildWarData(_cb) {
|
|
this.SendProtocal(24200, {}, _cb);
|
|
},
|
|
// 请求基礎信息返回
|
|
handle24200: function handle24200(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
if (_data.count) {
|
|
//已挑战次数
|
|
this.setGuildWarChallengeCount(_data.count);
|
|
}
|
|
if (_data.result) {
|
|
this.setGuildWarResult(_data.result);
|
|
}
|
|
if (_data.ranks) {
|
|
this.setGuildWarTopThreeRank(_data.ranks);
|
|
}
|
|
//我方联盟基础信息
|
|
var myBaseInfo = {};
|
|
myBaseInfo.gname = _data.gname1;
|
|
myBaseInfo.hp = _data.hp1;
|
|
myBaseInfo.buff_lev = _data.buff_lev1;
|
|
this.setMyGuildWarBaseInfo(myBaseInfo);
|
|
//敌方联盟数据
|
|
this.setEnemyGuildWarData(_data);
|
|
gcore.GlobalEvent.fire(GuildwarEvent.GuildWarEnemyPositionDataInitEvent);
|
|
},
|
|
//请求敌方单个据点数据
|
|
requestEnemyPositionData: function requestEnemyPositionData(pos, _cb) {
|
|
if (!pos) return;
|
|
var protocal = {};
|
|
protocal.pos = pos;
|
|
this.SendProtocal(24201, protocal, _cb);
|
|
},
|
|
handle24201: function handle24201(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
nx.bridge.createPanel("WndGuildBatForm", {
|
|
data: _data
|
|
});
|
|
},
|
|
//发起战斗
|
|
requestGuildWarFighting: function requestGuildWarFighting(pos, hp, flag, _cb) {
|
|
if (!pos) return;
|
|
var protocal = {};
|
|
protocal.pos = pos;
|
|
protocal.hp = hp;
|
|
protocal.flag = flag;
|
|
this.SendProtocal(24202, protocal, _cb);
|
|
},
|
|
//发起战斗
|
|
handle24202: function handle24202(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
if (_data.code == 1) {
|
|
this.setGuildWarChallengeCount(_data.count);
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildwarChallengeCountEvent);
|
|
// this.openAttkPositionWindow(false);
|
|
// this.openAttkLookWindow(false);
|
|
}
|
|
},
|
|
|
|
handle24203: function handle24203(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
nx.bridge.vset("ResultInfo", _data);
|
|
},
|
|
//请求联盟战状态
|
|
reqestGuildWarStatus: function reqestGuildWarStatus(_cb) {
|
|
this.SendProtocal(24204, {}, _cb);
|
|
},
|
|
handle24204: function handle24204(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
this.setGuildWarStatus(_data);
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarStatusEvent, _data.status, _data.flag);
|
|
},
|
|
//请求对战列表数据
|
|
requestGuildWarBattleList: function requestGuildWarBattleList(_cb) {
|
|
this.SendProtocal(24205, {}, _cb);
|
|
},
|
|
//联盟战对阵列表
|
|
handle24205: function handle24205(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
// if (data && this.battle_list_window) {
|
|
// this.battle_list_window.setData(data);
|
|
// }
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateMateViewsEvent, _data);
|
|
},
|
|
//据点数据更新(本方与对方都走这里,变量更)
|
|
handle24206: function handle24206(data) {
|
|
if (!this.isGoodData(data)) {
|
|
return;
|
|
}
|
|
if (data) {
|
|
if (data.flag && data.flag == 1) {
|
|
this.updateMyGuildWarPositionData(data.defense);
|
|
} else {
|
|
this.updateEnemyGuildWarPositionData(data.defense);
|
|
}
|
|
}
|
|
},
|
|
//联盟战基础数据更新(星数、buff等)
|
|
handle24207: function handle24207(data) {
|
|
if (!this.isGoodData(data)) {
|
|
return;
|
|
}
|
|
if (data) {
|
|
if (data.result) {
|
|
this.setGuildWarResult(data.result);
|
|
}
|
|
var myBaseInfo = {};
|
|
myBaseInfo.hp = data.hp;
|
|
myBaseInfo.buff_lev = data.buff_lev;
|
|
this.updateMyGuildWarBaseInfo(myBaseInfo);
|
|
if (data.hp2) {
|
|
this.updateEnemyGuildWarBaseInfo(data.hp2);
|
|
}
|
|
if (data.ranks) {
|
|
this.setGuildWarTopThreeRank(data.ranks);
|
|
}
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarBaseInfoEvent);
|
|
}
|
|
},
|
|
//请求本方联盟战据点数据
|
|
requestMyGuildPositionData: function requestMyGuildPositionData(_cb) {
|
|
this.SendProtocal(24208, {}, _cb);
|
|
},
|
|
//本方据点数据
|
|
handle24208: function handle24208(data) {
|
|
if (!this.isGoodData(data)) {
|
|
return;
|
|
}
|
|
this.setMyGuildWarPositionData(data.defense);
|
|
this.setAvgPower(data.avg_power);
|
|
gcore.GlobalEvent.fire(GuildwarEvent.GetGuildWarMyPositionDataEvent);
|
|
},
|
|
//请求据点防守记录
|
|
requestPositionDefendData: function requestPositionDefendData(g_id1, g_sid1, pos, _cb) {
|
|
var protocal = {};
|
|
protocal.pos = pos;
|
|
protocal.g_id1 = g_id1;
|
|
protocal.g_sid1 = g_sid1;
|
|
this.SendProtocal(24209, protocal, _cb);
|
|
},
|
|
//防守记录
|
|
handle24209: function handle24209(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
},
|
|
//有新的日志产生
|
|
handle24210: function handle24210() {
|
|
// var GuildConst = require("guild_const");
|
|
// this.model.updateGuildWarRedStatus(GuildConst.red_index.guildwar_log, true, true)
|
|
},
|
|
//请求战场日志
|
|
requestBattleLogData: function requestBattleLogData(_cb) {
|
|
this.SendProtocal(24212, {}, _cb);
|
|
},
|
|
//战场日志
|
|
handle24212: function handle24212(_data) {
|
|
if (!this.isGoodData(_data)) {
|
|
return;
|
|
}
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateBatLogEvent, _data);
|
|
},
|
|
//请求联盟战详细排名数据
|
|
requestGuildWarRankData: function requestGuildWarRankData(_cb) {
|
|
this.SendProtocal(24213, {}, _cb);
|
|
},
|
|
//联盟战详细排名
|
|
handle24213: function handle24213(data) {
|
|
if (!this.isGoodData(data)) {
|
|
return;
|
|
}
|
|
// gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarRankDataEvent, data.ranks);
|
|
nx.bridge.createPanel("WndGuildBatRank", {
|
|
ranks: data.ranks
|
|
});
|
|
},
|
|
//联盟战结果
|
|
handle24214: function handle24214(data) {
|
|
if (!this.isGoodData(data)) {
|
|
return;
|
|
}
|
|
this.setGuildWarResult(data.result);
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarBaseInfoEvent);
|
|
},
|
|
//请求宝箱数据
|
|
requestAwardBoxData: function requestAwardBoxData(_cb) {
|
|
this.SendProtocal(24220, {}, _cb);
|
|
},
|
|
//联盟战宝箱数据
|
|
handle24220: function handle24220(data) {
|
|
if (!this.isGoodData(data)) {
|
|
return;
|
|
}
|
|
this.setGuildWarBoxData(data);
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarBoxDataEvent, data);
|
|
},
|
|
//请求领取宝箱数据
|
|
requestGetBoxAward: function requestGetBoxAward(order, _cb) {
|
|
var protocal = {};
|
|
protocal.order = order;
|
|
this.SendProtocal(24221, protocal, _cb);
|
|
},
|
|
//领取宝箱
|
|
handle24221: function handle24221(data) {
|
|
if (!this.isGoodData(data)) {
|
|
return;
|
|
}
|
|
},
|
|
//更新单个宝箱数据
|
|
handle24223: function handle24223(data) {
|
|
if (!this.isGoodData(data)) {
|
|
return;
|
|
}
|
|
this.updateGuildWarBoxData(data);
|
|
this.role_vo = RoleController.getInstance().getRoleVo();
|
|
//判断一下是否为玩家自己领取了宝箱,更新界面领取状态
|
|
if (this.role_vo && data.rid == this.role_vo.rid && data.sid == this.role_vo.srv_id) {
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateMyAwardBoxEvent);
|
|
}
|
|
},
|
|
setGuildWarBoxData: function setGuildWarBoxData(data) {
|
|
this.award_box_data = data;
|
|
},
|
|
updateGuildWarBoxData: function updateGuildWarBoxData(data) {
|
|
var total_list = this.award_box_data.guild_war_box;
|
|
for (var i in total_list) {
|
|
if (data.order == total_list[i].order) {
|
|
total_list[i] = data;
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
//根据序号获取宝箱数据
|
|
getGuildWarDataByOrder: function getGuildWarDataByOrder(order) {
|
|
for (var k in this.award_box_data.guild_war_box) {
|
|
var box_vo = this.award_box_data.guild_war_box[k];
|
|
if (box_vo.order == order) {
|
|
return box_vo;
|
|
}
|
|
}
|
|
},
|
|
//获取全部宝箱数据
|
|
getGuildWarBoxData: function getGuildWarBoxData() {
|
|
return this.award_box_data;
|
|
},
|
|
//设置已挑战次数
|
|
setGuildWarChallengeCount: function setGuildWarChallengeCount(count) {
|
|
this.challengeCount = count || 0;
|
|
},
|
|
getGuildWarChallengeCount: function getGuildWarChallengeCount() {
|
|
return this.challengeCount;
|
|
},
|
|
//设置联盟战结果
|
|
setGuildWarResult: function setGuildWarResult(result) {
|
|
this.guildWarResult = result;
|
|
},
|
|
getGuildWarResult: function getGuildWarResult() {
|
|
return this.guildWarResult;
|
|
},
|
|
//设置联盟战前三名数据
|
|
setGuildWarTopThreeRank: function setGuildWarTopThreeRank(data) {
|
|
this.guildWarTopThreeRank = data;
|
|
},
|
|
getGuildWarTopThreeRank: function getGuildWarTopThreeRank() {
|
|
return this.guildWarTopThreeRank;
|
|
},
|
|
//设置我方联盟战基础数据(星数、buff等)
|
|
setMyGuildWarBaseInfo: function setMyGuildWarBaseInfo(data) {
|
|
this.myGuildWarBaseInfo = data || {};
|
|
},
|
|
getMyGuildWarBaseInfo: function getMyGuildWarBaseInfo() {
|
|
return this.myGuildWarBaseInfo;
|
|
},
|
|
//更新我方联盟战基础数据
|
|
updateMyGuildWarBaseInfo: function updateMyGuildWarBaseInfo(data) {
|
|
for (var k in data) {
|
|
this.myGuildWarBaseInfo[k] = data[k];
|
|
}
|
|
},
|
|
//更新敌方联盟战基础数据(目前只是星数)
|
|
updateEnemyGuildWarBaseInfo: function updateEnemyGuildWarBaseInfo(hp) {
|
|
this.enemyGuildWarBaseInfo.hp = hp;
|
|
},
|
|
getEnemyGuildWarBaseInfo: function getEnemyGuildWarBaseInfo() {
|
|
return this.enemyGuildWarBaseInfo;
|
|
},
|
|
//设置敌方联盟战数据
|
|
setEnemyGuildWarData: function setEnemyGuildWarData(data) {
|
|
//基础数据
|
|
this.enemyGuildWarBaseInfo.gname = data.gname2 || "";
|
|
this.enemyGuildWarBaseInfo.hp = data.hp2 || 0;
|
|
this.enemyGuildWarBaseInfo.g_id = data.g_id || 0;
|
|
this.enemyGuildWarBaseInfo.g_sid = data.g_sid || "";
|
|
|
|
//据点数据
|
|
this.enemyGuildWarPositionList = {};
|
|
for (var k in data.defense) {
|
|
var pdata = data.defense[k];
|
|
this.enemyGuildWarPositionList[pdata.pos] = pdata;
|
|
}
|
|
},
|
|
getEnemyGuildWarPositionList: function getEnemyGuildWarPositionList() {
|
|
var list = [];
|
|
for (var i in this.enemyGuildWarPositionList) {
|
|
var vo = this.enemyGuildWarPositionList[i];
|
|
if (vo) {
|
|
list.push(vo);
|
|
}
|
|
}
|
|
return list;
|
|
},
|
|
//获取敌方某一据点的当前血量
|
|
getEnemyPositionHpByPos: function getEnemyPositionHpByPos(pos) {
|
|
var position_vo = this.enemyGuildWarPositionList[pos];
|
|
if (position_vo) {
|
|
return position_vo.hp;
|
|
}
|
|
return 0;
|
|
},
|
|
//敌方是否还有存活的据点
|
|
checkEnemyIsHaveLivePosition: function checkEnemyIsHaveLivePosition() {
|
|
var is_have = false;
|
|
for (var k in this.enemyGuildWarPositionList) {
|
|
var vo = this.enemyGuildWarPositionList[k];
|
|
if (vo.hp > 0) {
|
|
is_have = true;
|
|
break;
|
|
}
|
|
}
|
|
return is_have;
|
|
},
|
|
//设置我方联盟战据点数据
|
|
setMyGuildWarPositionData: function setMyGuildWarPositionData(dataList) {
|
|
this.myGuildWarPositionList = {};
|
|
for (var k in dataList) {
|
|
var data = dataList[k];
|
|
this.myGuildWarPositionList[data.pos] = data;
|
|
}
|
|
},
|
|
getMyGuildWarPositionList: function getMyGuildWarPositionList() {
|
|
var list = [];
|
|
for (var i in this.myGuildWarPositionList) {
|
|
var vo = this.myGuildWarPositionList[i];
|
|
if (vo) {
|
|
list.push(vo);
|
|
}
|
|
}
|
|
return list;
|
|
},
|
|
//更新我方据点数据(变量更)
|
|
updateMyGuildWarPositionData: function updateMyGuildWarPositionData(dataList) {
|
|
for (var k in dataList) {
|
|
var data = dataList[k];
|
|
this.myGuildWarPositionList[data.pos] = data;
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarPositionDataEvent, data.pos, data);
|
|
}
|
|
},
|
|
//更新敌方据点数据(变量更)
|
|
updateEnemyGuildWarPositionData: function updateEnemyGuildWarPositionData(dataList) {
|
|
for (var k in dataList) {
|
|
var data = dataList[k];
|
|
this.enemyGuildWarPositionList[data.pos] = data;
|
|
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarPositionDataEvent, data.pos, data);
|
|
}
|
|
},
|
|
//设置联盟战状态数据
|
|
setGuildWarStatus: function setGuildWarStatus(data) {
|
|
this.guildWarStatus = data.status || GuildwarConst.status.close;
|
|
this.guildWarStartTime = data.start_time || 0;
|
|
this.guildWarEndTime = data.end_time || 0;
|
|
this.guildWarEnemyFlag = data.flag || 0;
|
|
|
|
//当状态变为未开启时,清掉缓存数据
|
|
if (this.guildWarStatus == GuildwarConst.status.close) {
|
|
this.initConfig();
|
|
}
|
|
},
|
|
getENdTime: function getENdTime() {
|
|
return this.guildWarEndTime;
|
|
},
|
|
getGuildWarStatus: function getGuildWarStatus() {
|
|
return this.guildWarStatus;
|
|
},
|
|
getGuildWarSurplusTime: function getGuildWarSurplusTime() {
|
|
return this.guildWarEndTime - client.socket.getTime();
|
|
},
|
|
getGuildWarEnemyFlag: function getGuildWarEnemyFlag() {
|
|
return this.guildWarEnemyFlag;
|
|
},
|
|
// --聯盟總戰力
|
|
setAvgPower: function setAvgPower(avg_power) {
|
|
this.avg_power = avg_power || 0;
|
|
},
|
|
getAvgPower: function getAvgPower() {
|
|
return this.avg_power || 0;
|
|
}
|
|
});
|
|
module.exports = GuildbatMod;
|
|
|
|
cc._RF.pop(); |