Files
fc/dev/project/assets/Scripts/mod/guild/guildbat/guildbat.mod.js
T

532 lines
16 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
// 工會戰(聯盟榮耀戰)
// <br/>Create: 2019-02-27 11:03:16
// --------------------------------------------------------------------
const BridgeController = require( "bridge.controller" );
const RoleController = require("role_controller");
const GuildwarEvent = require("guildwar_event");
const GuildwarConst = require("guildbat.define");
const GuildbatMod = cc.Class( {
extends: BridgeController,
ctor: function() {
},
// 初始化配置数据
initConfig: function() {
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() {
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( _cb ) {
// 配置加载
let cfgs = [
"guild_war_data"
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
this.requestGuildWarData(_cb);
} );
},
//请求联盟战详细数据
requestGuildWarData: function (_cb) {
this.SendProtocal(24200, {}, _cb);
},
// 请求基礎信息返回
handle24200: function( _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 (pos,_cb) {
if (!pos) return
var protocal = {};
protocal.pos = pos;
this.SendProtocal(24201, protocal, _cb);
},
handle24201: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
nx.bridge.createPanel("WndGuildBatForm",{data:_data});
},
//发起战斗
requestGuildWarFighting: function (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 (_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( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
nx.bridge.vset("ResultInfo",_data);
},
//请求联盟战状态
reqestGuildWarStatus: function (_cb) {
this.SendProtocal(24204, {}, _cb);
},
handle24204: function( _data ) {
if( !this.isGoodData( _data ) ) {
return;
}
this.setGuildWarStatus(_data);
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarStatusEvent, _data.status, _data.flag)
},
//请求对战列表数据
requestGuildWarBattleList: function (_cb) {
this.SendProtocal(24205, {}, _cb);
},
//联盟战对阵列表
handle24205: function (_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 (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 (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 (_cb) {
this.SendProtocal(24208, {}, _cb);
},
//本方据点数据
handle24208: function (data) {
if( !this.isGoodData( data ) ) {
return;
}
this.setMyGuildWarPositionData(data.defense);
this.setAvgPower(data.avg_power)
gcore.GlobalEvent.fire(GuildwarEvent.GetGuildWarMyPositionDataEvent)
},
//请求据点防守记录
requestPositionDefendData: function (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 (_data) {
if( !this.isGoodData( _data ) ) {
return;
}
},
//有新的日志产生
handle24210: function () {
// var GuildConst = require("guild_const");
// this.model.updateGuildWarRedStatus(GuildConst.red_index.guildwar_log, true, true)
},
//请求战场日志
requestBattleLogData: function (_cb) {
this.SendProtocal(24212, {}, _cb);
},
//战场日志
handle24212: function (_data) {
if( !this.isGoodData( _data ) ) {
return;
}
gcore.GlobalEvent.fire(GuildwarEvent.UpdateBatLogEvent,_data);
},
//请求联盟战详细排名数据
requestGuildWarRankData: function (_cb) {
this.SendProtocal(24213, {}, _cb);
},
//联盟战详细排名
handle24213: function (data) {
if( !this.isGoodData( data ) ) {
return;
}
// gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarRankDataEvent, data.ranks);
nx.bridge.createPanel("WndGuildBatRank",{ranks:data.ranks});
},
//联盟战结果
handle24214: function (data) {
if( !this.isGoodData( data ) ) {
return;
}
this.setGuildWarResult(data.result);
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarBaseInfoEvent)
},
//请求宝箱数据
requestAwardBoxData: function (_cb) {
this.SendProtocal(24220, {}, _cb);
},
//联盟战宝箱数据
handle24220: function (data) {
if( !this.isGoodData( data ) ) {
return;
}
this.setGuildWarBoxData(data);
gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarBoxDataEvent, data);
},
//请求领取宝箱数据
requestGetBoxAward: function (order,_cb) {
var protocal = {};
protocal.order = order;
this.SendProtocal(24221, protocal, _cb);
},
//领取宝箱
handle24221: function (data) {
if( !this.isGoodData( data ) ) {
return;
}
},
//更新单个宝箱数据
handle24223: function (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(data){
this.award_box_data = data;
},
updateGuildWarBoxData(data){
let total_list = this.award_box_data.guild_war_box;
for(let i in total_list){
if(data.order == total_list[i].order){
total_list[i] = data;
break;
}
}
},
//根据序号获取宝箱数据
getGuildWarDataByOrder: function (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 () {
return this.award_box_data;
},
//设置已挑战次数
setGuildWarChallengeCount: function (count) {
this.challengeCount = count || 0;
},
getGuildWarChallengeCount: function () {
return this.challengeCount;
},
//设置联盟战结果
setGuildWarResult: function (result) {
this.guildWarResult = result;
},
getGuildWarResult: function () {
return this.guildWarResult
},
//设置联盟战前三名数据
setGuildWarTopThreeRank: function (data) {
this.guildWarTopThreeRank = data;
},
getGuildWarTopThreeRank: function () {
return this.guildWarTopThreeRank
},
//设置我方联盟战基础数据(星数、buff等)
setMyGuildWarBaseInfo: function (data) {
this.myGuildWarBaseInfo = data || {};
},
getMyGuildWarBaseInfo: function () {
return this.myGuildWarBaseInfo;
},
//更新我方联盟战基础数据
updateMyGuildWarBaseInfo:function(data){
for(var k in data){
this.myGuildWarBaseInfo[k] = data[k];
}
},
//更新敌方联盟战基础数据(目前只是星数)
updateEnemyGuildWarBaseInfo: function (hp) {
this.enemyGuildWarBaseInfo.hp = hp;
},
getEnemyGuildWarBaseInfo: function () {
return this.enemyGuildWarBaseInfo
},
//设置敌方联盟战数据
setEnemyGuildWarData: function (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 () {
var list = [];
for (var i in this.enemyGuildWarPositionList) {
var vo = this.enemyGuildWarPositionList[i];
if (vo) {
list.push(vo)
}
}
return list;
},
//获取敌方某一据点的当前血量
getEnemyPositionHpByPos: function (pos) {
var position_vo = this.enemyGuildWarPositionList[pos];
if (position_vo) {
return position_vo.hp;
}
return 0
},
//敌方是否还有存活的据点
checkEnemyIsHaveLivePosition: function () {
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 (dataList) {
this.myGuildWarPositionList = {};
for (var k in dataList) {
var data = dataList[k];
this.myGuildWarPositionList[data.pos] = data;
}
},
getMyGuildWarPositionList: function () {
var list = [];
for (var i in this.myGuildWarPositionList) {
var vo = this.myGuildWarPositionList[i];
if (vo) {
list.push(vo)
}
}
return list;
},
//更新我方据点数据(变量更)
updateMyGuildWarPositionData: function (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 (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 (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(){
return this.guildWarEndTime;
},
getGuildWarStatus: function () {
return this.guildWarStatus
},
getGuildWarSurplusTime: function () {
return this.guildWarEndTime - client.socket.getTime();
},
getGuildWarEnemyFlag: function () {
return this.guildWarEnemyFlag
},
// --聯盟總戰力
setAvgPower(avg_power){
this.avg_power = avg_power || 0
},
getAvgPower(){
return this.avg_power || 0
},
} );
module.exports = GuildbatMod;