361 lines
12 KiB
JavaScript
361 lines
12 KiB
JavaScript
// --------------------------------------------------------------------
|
|
// @author: xxx@syg.com(必填, 创建模块的人员)
|
|
// @description:
|
|
// 这里填写详细说明,主要填写该模块的功能简要
|
|
// <br/>Create: 2019-01-14 10:57:08
|
|
// --------------------------------------------------------------------
|
|
const BridgeClass = require( "bridge.class" );
|
|
const GuildListVo = require( "guild_list_vo" );
|
|
const GuildConst = require( "guild_const" );
|
|
const GuildEvent = require( "guild_event" );
|
|
const GuildMyInfoVo = require( "guild_my_info_vo" );
|
|
const RoleController = require( "role_controller" );
|
|
const GuildMemberVo = require( "guild_member_vo" );
|
|
const GuildController = require( "guild_controller" );
|
|
|
|
const GuildModel = cc.Class( {
|
|
|
|
extends: BridgeClass,
|
|
|
|
ctor: function() {
|
|
|
|
this.ctrl = GuildController.getInstance();
|
|
|
|
this.guild_cache_list = {}; // 缓存的当前服务器列表
|
|
this.apply_join_list = {}; // 公会申请列表
|
|
this.donate_sum = 0; // 今天已经捐献的次数
|
|
this.guild_member_list = {}; // 成员列表
|
|
this.guild_list = []; // 当前所有的公会列表
|
|
this.guild_search_list = []; // 当前待查找的公会列表
|
|
this.my_guild_assistant = {}; // 当前副会长的数据
|
|
this.donate_rewards = []; // 捐献活跃宝箱清空
|
|
},
|
|
|
|
properties: {
|
|
},
|
|
|
|
initConfig: function() {
|
|
this.donate_exp = 0;
|
|
},
|
|
|
|
updateGuildList: function( name, data_list ) {
|
|
if( name == "" ) {
|
|
this.guild_list = [];
|
|
for( var i in data_list ) {
|
|
var v = data_list[ i ];
|
|
var guild_vo = this.guild_cache_list[ Utils.getNorKey( v.gid, v.gsrv_id ) ];
|
|
if( guild_vo == null ) {
|
|
guild_vo = new GuildListVo();
|
|
this.guild_cache_list[ Utils.getNorKey( v.gid, v.gsrv_id ) ] = guild_vo;
|
|
}
|
|
guild_vo.updateData( v );
|
|
this.guild_list.push( guild_vo );
|
|
}
|
|
} else {
|
|
this.guild_search_list = [];
|
|
for( var i in data_list ) {
|
|
var v = data_list[ i ];
|
|
var guild_vo = this.guild_cache_list[ Utils.getNorKey( v.gid, v.gsrv_id ) ];
|
|
if( guild_vo == null ) {
|
|
guild_vo = new GuildListVo();
|
|
this.guild_cache_list[ Utils.getNorKey( v.gid, v.gsrv_id ) ] = guild_vo;
|
|
}
|
|
guild_vo.updateData( v );
|
|
this.guild_search_list.push( guild_vo );
|
|
}
|
|
}
|
|
var type = GuildConst.ListType.Total;
|
|
var guild_list = this.guild_list;
|
|
if( name != "" ) {
|
|
type = GuildConst.ListType.Search;
|
|
guild_list = this.guild_search_list;
|
|
}
|
|
gcore.GlobalEvent.fire( GuildEvent.UpdateGuildList, type, guild_list );
|
|
},
|
|
|
|
//申请某个公会的返回
|
|
updateGuildApplyStatus: function( gid, gsrv_id, is_apply ) {
|
|
var guild_list_vo = this.guild_cache_list[ Utils.getNorKey( gid, gsrv_id ) ];
|
|
if( guild_list_vo != null )
|
|
guild_list_vo.setGuildAttribute( "is_apply", is_apply );
|
|
},
|
|
|
|
//更新自己公会的基础信息
|
|
updateMyGuildInfo: function( data ) {
|
|
if( this.my_guild_info == null )
|
|
this.my_guild_info = new GuildMyInfoVo();
|
|
this.my_guild_info.updateData( data );
|
|
},
|
|
|
|
// 清楚联盟相关缓存数据
|
|
clearMyGuildInfo: function() {
|
|
|
|
this.my_guild_info = null
|
|
this.my_guild_assistant = {};
|
|
this.guild_member_list = {};
|
|
this.donate_rewards = [];
|
|
|
|
// 提示关闭(暂时分开设置)
|
|
nx.mTip.openTip( "guild.donate.tip", false );
|
|
nx.mTip.openTip( "guild.donate.reward", false );
|
|
nx.mTip.openTip( "guild.reqJoin", false );
|
|
nx.mTip.openTip( "guild.active.lvup", false );
|
|
nx.mTip.openTip( "guild.dailyReward", false );
|
|
},
|
|
|
|
//获取自己公会信息
|
|
getMyGuildInfo: function() {
|
|
return this.my_guild_info;
|
|
},
|
|
|
|
//更新成员列表,增删
|
|
//type:"0:更新 1:添加 2:删除"
|
|
updateMyGuildMemberList: function( data_list, type ) {
|
|
var role_vo = RoleController.getInstance().getRoleVo();
|
|
if( role_vo == null )
|
|
return
|
|
if( type == 2 ) {
|
|
for( var i in data_list ) {
|
|
var v = data_list[ i ];
|
|
this.guild_member_list[ Utils.getNorKey( v.rid, v.srv_id ) ] = null;
|
|
if( this.my_guild_assistant[ Utils.getNorKey( v.rid, v.srv_id ) ] != null ) {
|
|
this.my_guild_assistant[ Utils.getNorKey( v.rid, v.srv_id ) ] = null;
|
|
//这里抛出时间更新副会长的数量吧
|
|
if( role_vo.position != GuildConst.PositionType.Member )
|
|
gcore.GlobalEvent.fire( GuildEvent.UpdateAssistantNumEvent );
|
|
}
|
|
}
|
|
} else {
|
|
var member_vo = null;
|
|
for( var i in data_list ) {
|
|
var v = data_list[ i ];
|
|
member_vo = this.guild_member_list[ Utils.getNorKey( v.rid, v.srv_id ) ];
|
|
//如果之前存在副会长,但是现在没有了的话,就移除掉
|
|
if( this.my_guild_assistant[ Utils.getNorKey( v.rid, v.srv_id ) ] != null ) {
|
|
if( v.post != GuildConst.PositionType.Assistant ) {
|
|
this.my_guild_assistant[ Utils.getNorKey( v.rid, v.srv_id ) ] = null;
|
|
if( role_vo.position != GuildConst.PositionType.Member )
|
|
gcore.GlobalEvent.fire( GuildEvent.UpdateAssistantNumEvent );
|
|
}
|
|
} else {
|
|
if( v.post == GuildConst.PositionType.Assistant ) {
|
|
this.my_guild_assistant[ Utils.getNorKey( v.rid, v.srv_id ) ] = v;
|
|
if( role_vo.position != GuildConst.PositionType.Member )
|
|
gcore.GlobalEvent.fire( GuildEvent.UpdateAssistantNumEvent );
|
|
}
|
|
}
|
|
|
|
if( member_vo == null ) {
|
|
member_vo = new GuildMemberVo();
|
|
this.guild_member_list[ Utils.getNorKey( v.rid, v.srv_id ) ] = member_vo;
|
|
}
|
|
if( v.is_self == null ) {
|
|
v.is_self = RoleController.getInstance().checkIsSelf( v.srv_id, v.rid ); //当前是不是自己
|
|
}
|
|
v.role_post = role_vo.position;
|
|
member_vo.updateData( v );
|
|
}
|
|
}
|
|
gcore.GlobalEvent.fire( GuildEvent.UpdateMyMemberListEvent, type );
|
|
},
|
|
|
|
//自己职位变化的时候更改一下成员列表里面的自己职位数据
|
|
updateMemberByPosition: function( value ) {
|
|
if( this.guild_member_list != null ) {
|
|
for( var k in this.guild_member_list ) {
|
|
this.guild_member_list[ k ].setGuildAttribute( "role_post", value );
|
|
}
|
|
}
|
|
},
|
|
|
|
//获取当前副会长的总数
|
|
getAssistantSum: function() {
|
|
if( this.my_guild_assistant == null )
|
|
return
|
|
var sum = 0;
|
|
for( var k in this.my_guild_assistant ) {
|
|
if( this.my_guild_assistant[ k ] != null )
|
|
sum = sum + 1;
|
|
}
|
|
return sum
|
|
},
|
|
|
|
//获取成员列表
|
|
getGuildMemberList: function() {
|
|
var member_list = [];
|
|
for( var k in this.guild_member_list ) {
|
|
if( this.guild_member_list[ k ] != null )
|
|
member_list.push( this.guild_member_list[ k ] );
|
|
}
|
|
|
|
if( member_list.length > 0 ) {
|
|
member_list.sort( Utils.tableUpperSorter( [ "online", "post_sort", "donate" ] ) );
|
|
}
|
|
return member_list
|
|
},
|
|
|
|
//获取当前申请列表,按照在线,战力以及vip等级从打到小排序
|
|
getGuildApplyList: function() {
|
|
var apply_list = [];
|
|
for( var k in this.apply_join_list ) {
|
|
if( this.apply_join_list[ k ] != null )
|
|
apply_list.push( this.apply_join_list[ k ] );
|
|
}
|
|
if( apply_list.length > 0 )
|
|
apply_list.sort( Utils.tableUpperSorter( [ "is_online", "power", "vip_lev" ] ) );
|
|
return apply_list
|
|
},
|
|
|
|
|
|
// ===========================================================================
|
|
// 工会捐献
|
|
// ===========================================================================
|
|
|
|
// 更新玩家捐献情况
|
|
updateDonateInfo: function( data_list ) {
|
|
|
|
this.donate_sum = 0;
|
|
this.donate_list = [];
|
|
for( let i in data_list ) {
|
|
let v = data_list[ i ];
|
|
this.donate_list[ v.type ] = v.num;
|
|
this.donate_sum = this.donate_sum + v.num;
|
|
}
|
|
gcore.GlobalEvent.fire( GuildEvent.UpdateDonateInfo );
|
|
|
|
this.freshDonateTips( true );
|
|
},
|
|
|
|
// 这里表示捐献成功了
|
|
setGuildDonateStatus: function() {
|
|
this.donate_sum = this.donate_sum + 1;
|
|
this.freshDonateTips();
|
|
},
|
|
|
|
// 判断某一个捐献状态
|
|
checkDonateStatus: function( type ) {
|
|
let num = this.donate_list[ type ];
|
|
return [ ( this.donate_sum > 0 ), ( num && num > 0 ) ]
|
|
},
|
|
|
|
// 捐献活跃宝箱情况
|
|
updateDonateBoxInfo: function( boxes, donate_exp ) {
|
|
|
|
// 当前公会捐献活跃度
|
|
this.donate_exp = donate_exp;
|
|
this.donate_rewards = {};
|
|
for( let i in boxes ) {
|
|
this.donate_rewards[ boxes[ i ].box_id ] = true;
|
|
}
|
|
|
|
this.freshDonateTips();
|
|
},
|
|
|
|
// 设置某个捐献宝箱的状态
|
|
setDonateBoxStatus: function( box_id ) {
|
|
|
|
if( this.donate_rewards == null ) {
|
|
this.donate_rewards = {};
|
|
}
|
|
|
|
this.donate_rewards[ box_id ] = true;
|
|
gcore.GlobalEvent.fire( GuildEvent.UpdateDonateBoxStatus, box_id );
|
|
this.freshDonateTips();
|
|
},
|
|
|
|
// 别人捐献的时候更新当前捐献进度,可能同步会有红点提示
|
|
updateDonateActivity: function( value ) {
|
|
this.donate_exp = value;
|
|
gcore.GlobalEvent.fire( GuildEvent.UpdateDonateBoxStatus );
|
|
this.freshDonateTips();
|
|
},
|
|
|
|
// 捐献提示更新
|
|
freshDonateTips: function( _can ) {
|
|
|
|
if( !game.configs.guild_data ){
|
|
return;
|
|
}
|
|
// 可捐献
|
|
if( _can ) {
|
|
let tipCan = ( this.donate_sum == 0 );
|
|
nx.mTip.openTip( "guild.donate.tip", tipCan );
|
|
}
|
|
|
|
// 有奖励
|
|
let tipReward = false;
|
|
let exp = this.donate_exp || 0;
|
|
let boxes = game.configs.guild_data.data_donate_box;
|
|
for( let id in boxes ) {
|
|
let box = boxes[ id ];
|
|
if( exp >= box.box_val &&
|
|
!this.donate_rewards[ id ] ) {
|
|
tipReward = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
nx.mTip.openTip( "guild.donate.reward", tipReward );
|
|
},
|
|
|
|
// ===========================================================================
|
|
// 工会管理
|
|
// ===========================================================================
|
|
|
|
// 更新申请列表,
|
|
updateApplyJoinList: function( data_list ) {
|
|
|
|
this.apply_join_list = {};
|
|
for( var i in data_list ) {
|
|
var v = data_list[ i ];
|
|
let key = Utils.getNorKey( v.rid, v.srv_id );
|
|
this.apply_join_list[ key ] = v;
|
|
}
|
|
this.freshApplyJoinTips();
|
|
},
|
|
|
|
// 处理完成某个玩家申请请求之后,在总的申请列表中删除这个数据
|
|
deleteApplyInfo: function( rid, srv_id ) {
|
|
|
|
let key = Utils.getNorKey( rid, srv_id );
|
|
delete this.apply_join_list[ key ];
|
|
this.freshApplyJoinTips();
|
|
},
|
|
|
|
// 更新提示
|
|
freshApplyJoinTips: function() {
|
|
|
|
let tip = false;
|
|
if( nx.dt.objNEmpty( this.apply_join_list ) ) {
|
|
tip = true;
|
|
}
|
|
|
|
nx.mTip.openTip( "guild.reqJoin", tip );
|
|
},
|
|
|
|
// ===========================================================================
|
|
// 工会活跃
|
|
// ===========================================================================
|
|
|
|
// 更新提示
|
|
freshActiveTips: function( _data ) {
|
|
|
|
if( !game.configs.guild_quest_data ){
|
|
return;
|
|
}
|
|
let tip = false;
|
|
if( _data ) {
|
|
let DATA = game.configs.guild_quest_data.data_lev_data;
|
|
let from = DATA[ _data.lev ];
|
|
let next = DATA[ _data.lev + 1 ];
|
|
if( from && next && _data.exp >= from.exp ) {
|
|
tip = true;
|
|
}
|
|
}
|
|
|
|
nx.mTip.openTip( "guild.active.lvup", tip );
|
|
|
|
},
|
|
|
|
} );
|