|
CSGWarModel = CSGWarModel or BaseClass(BaseVo)
|
|
local table_insert = table.insert
|
|
|
|
function CSGWarModel:__init()
|
|
CSGWarModel.Instance = self
|
|
self:InitCSGWarCityCFG()
|
|
-- self:InitCSGWarKVCFG()
|
|
self:Reset()
|
|
end
|
|
function CSGWarModel:Reset()
|
|
self.CSGWar_base_info = {}--活动基础信息
|
|
self.CSGWar_occupy_info = {}--占领信息 结算之后才会有的
|
|
self.CSGWar_sign_info = {}--帮战参赛信息-报名阶段和活动进行中
|
|
self.CSGWar_guild_sign_list = {}--社团报名榜
|
|
self.CSGWar_support_sign_list = {}--外援报名榜
|
|
self.CSGWar_city_info = {}--场景城池信息
|
|
self.CSGWar_result_info = {}--结算信息
|
|
self.CSGWar_group_info = {}--社团分组信息
|
|
self.CSGWar_fight_guild_info = {} --本阵营参战公会id表
|
|
self.CSGWar_support_info = {} --应援信息表
|
|
self.CSGWar_record_info = {}--日志信息
|
|
self.CSGWar_overlord_info = {}--霸主限购信息
|
|
self.my_support_num = 0--我的应援次数
|
|
self.free_support_num = 0--我的免费应援次数
|
|
self.is_CSGWar_sign = false--是否已经报名了
|
|
self.support_view_toggle = false
|
|
self.has_open_csgwar_view = false--是否已经开过界面了
|
|
self.start_wait_info = true
|
|
self.wait_list = {}
|
|
self.CSGWar_red_data = {}--缓存红点数据
|
|
|
|
self.CSGWar_activity_tip_open_data = {}--缓存邀请函打开记录,报名,声援,开战在活动期间只弹一次
|
|
end
|
|
|
|
function CSGWarModel:GetInstance()
|
|
if CSGWarModel.Instance == nil then
|
|
CSGWarModel.Instance = CSGWarModel.New()
|
|
end
|
|
return CSGWarModel.Instance
|
|
end
|
|
|
|
function CSGWarModel:getInstance()
|
|
if CSGWarModel.Instance == nil then
|
|
CSGWarModel.Instance = CSGWarModel.New()
|
|
end
|
|
return CSGWarModel.Instance
|
|
end
|
|
--场景城区配置
|
|
function CSGWarModel:InitCSGWarCityCFG( )
|
|
local cfg = Config.Crossguildwarscene
|
|
for i,v in ipairs(cfg) do
|
|
v.city_pos = stringtotable(v.flag)
|
|
v.monster_pos = stringtotable(v.mon_list)
|
|
end
|
|
end
|
|
--常量配置
|
|
function CSGWarModel:InitCSGWarKVCFG( )
|
|
self.CSGWar_kv_cfg = {}
|
|
local cfg = Config.Crossguildwarconfig
|
|
for i,v in pairs(cfg) do
|
|
self.CSGWar_kv_cfg[Trim(v.key)] = v
|
|
end
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarKVCFG( key )
|
|
if not self.CSGWar_kv_cfg then
|
|
self:InitCSGWarKVCFG()
|
|
end
|
|
return self.CSGWar_kv_cfg[key]
|
|
end
|
|
|
|
function CSGWarModel:SetCSGWarBaseInfo( vo )
|
|
self.CSGWar_base_info = vo
|
|
self:ChangeVar("CSGWar_base_info", self.CSGWar_base_info, false, true)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarBaseInfo( )
|
|
return self.CSGWar_base_info
|
|
end
|
|
|
|
function CSGWarModel:SetCSGWarOccupyInfo( vo )
|
|
local data = {}
|
|
for ii,vv in ipairs(vo.city_list) do
|
|
data[vv.city_id] = vv
|
|
end
|
|
self.CSGWar_occupy_info = data
|
|
self:ChangeVar("CSGWar_occupy_info", self.CSGWar_occupy_info, false, true)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarOccupyInfo()
|
|
return self.CSGWar_occupy_info
|
|
end
|
|
|
|
function CSGWarModel:SetCSGWarSignInfo( vo )
|
|
local country = KfWorldModel:GetInstance():GetMyCountryId()
|
|
self.CSGWar_fight_guild_info = {}
|
|
self.is_CSGWar_sign = vo.is_sign_up == 1
|
|
self.last_sign_time = vo.last_sign
|
|
local data = {}
|
|
for ii,vv in ipairs(vo.guild_list) do
|
|
data[vv.fact_id] = vv
|
|
if vv.fact_id == country then
|
|
self.CSGWar_fight_guild_info[vv.guild_id] = true
|
|
end
|
|
end
|
|
self.CSGWar_sign_info = data
|
|
self:ChangeVar("CSGWar_sign_info", self.CSGWar_sign_info, false, true)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarSignInfo( index )
|
|
return self.CSGWar_sign_info
|
|
end
|
|
|
|
function CSGWarModel:IsCSGWarSign( )
|
|
return self.is_CSGWar_sign
|
|
end
|
|
|
|
function CSGWarModel:GetLastSignTime( )
|
|
return self.last_sign_time or 0
|
|
end
|
|
--社团报名榜
|
|
function CSGWarModel:SetCSGWarGuildSignList( vo )
|
|
self.CSGWar_guild_sign_list = vo.rank_list
|
|
self:Fire(CSGWarConst.UPDATE_CSGWAR_SIGN_LIST)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarGuildSignList( )
|
|
return self.CSGWar_guild_sign_list
|
|
end
|
|
--外援报名榜
|
|
function CSGWarModel:SetCSGWarSupportSignList( vo )
|
|
self.CSGWar_support_sign_list = vo.rank_list
|
|
self:Fire(CSGWarConst.UPDATE_CSGWAR_SIGN_LIST)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarSupportSignList( )
|
|
return self.CSGWar_support_sign_list
|
|
end
|
|
|
|
function CSGWarModel:SetCSGWarCityInfo( vo )
|
|
local data = {}
|
|
for i,v in ipairs(vo) do
|
|
data[v.city_id] = v
|
|
end
|
|
self.CSGWar_city_info = data
|
|
self:Fire(CSGWarConst.UPDATE_CSGWAR_CITY_INFO)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarCityInfo( )
|
|
return self.CSGWar_city_info
|
|
end
|
|
|
|
function CSGWarModel:SetCSGWarResultInfo( vo )
|
|
self.CSGWar_result_info = vo
|
|
self:ChangeVar("CSGWar_result_info", self.CSGWar_result_info, false, true)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarResultInfo( )
|
|
return self.CSGWar_result_info
|
|
end
|
|
--是否在活动中
|
|
function CSGWarModel:IsCSGWarOpen( )
|
|
local bool = false
|
|
if self.CSGWar_base_info then
|
|
bool = self.CSGWar_base_info.switch == 1 and self.CSGWar_base_info.state == CSGWarConst.CSGWAR_STATE.START
|
|
or self.CSGWar_base_info.state == CSGWarConst.CSGWAR_STATE.SIGN
|
|
or self.CSGWar_base_info.state == CSGWarConst.CSGWAR_STATE.SUPPORT
|
|
end
|
|
return bool
|
|
end
|
|
--阵营分组信息
|
|
function CSGWarModel:SetCSGWarCountryInfo( vo )
|
|
for i,v in ipairs(vo) do
|
|
if not self.CSGWar_group_info[v.group] then
|
|
self.CSGWar_group_info[v.group] = {}
|
|
end
|
|
self.CSGWar_group_info[v.group][v.guild_id] = v
|
|
end
|
|
end
|
|
--通过帮派id获取阵营
|
|
function CSGWarModel:GetCountryIdByGuildId( guild_id )
|
|
for i,v in pairs(self.CSGWar_group_info) do
|
|
if v[guild_id] then
|
|
return i
|
|
end
|
|
end
|
|
return 0
|
|
end
|
|
--根据帮派id获取是否是参战的公会
|
|
function CSGWarModel:IsCSGWarFightGuild( guild_id )
|
|
return self.CSGWar_fight_guild_info[guild_id] or false
|
|
end
|
|
--设置应援列表
|
|
function CSGWarModel:SetCSGWarSupportInfo( vo )
|
|
self.my_support_num = vo.cur_help_num
|
|
self.free_support_num = vo.free_help_num
|
|
local all_support_num = 0
|
|
if not self.CSGWar_support_info then
|
|
self.CSGWar_support_info = {}
|
|
end
|
|
local data = {}
|
|
for i,v in ipairs(vo.help_list) do
|
|
data[v.fact_id] = v
|
|
all_support_num = all_support_num + v.help_num
|
|
end
|
|
self.CSGWar_support_info = data
|
|
self.all_support_num = all_support_num
|
|
self.CSGWar_support_info.all_support_num = all_support_num
|
|
self:ChangeVar("CSGWar_support_info", self.CSGWar_support_info, false, true)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarSupportInfo( )
|
|
return self.CSGWar_support_info or {}
|
|
end
|
|
|
|
function CSGWarModel:GetMySupportNum( )
|
|
return self.my_support_num
|
|
end
|
|
|
|
function CSGWarModel:GetMyFreeSupportNum( )
|
|
return self.free_support_num
|
|
end
|
|
|
|
function CSGWarModel:SetCSGWarRecordInfo( vo )
|
|
local data = {}
|
|
local temp_data = {}
|
|
local temp_city = {}
|
|
for i,v in ipairs(vo.logs) do
|
|
temp_data = {
|
|
time = v.time,
|
|
}
|
|
temp_city = {}
|
|
for iii,vvv in ipairs(v.city_list) do
|
|
temp_city[vvv.city_id] = vvv
|
|
end
|
|
temp_data.city_list = DeepCopy(temp_city)
|
|
data[#data+1] = DeepCopy(temp_data)
|
|
end
|
|
self.CSGWar_record_info = data
|
|
self:ChangeVar("CSGWar_record_info", self.CSGWar_record_info, false, true)
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarRecordInfo( )
|
|
return self.CSGWar_record_info
|
|
end
|
|
|
|
function CSGWarModel:IsCSGWarNeedRed( )
|
|
local bool = false
|
|
local base_data = self:GetCSGWarBaseInfo()
|
|
--没有打开过界面报名期间就有红点
|
|
self.CSGWar_red_data.one_red = false
|
|
if base_data and TableSize(base_data) > 0 and base_data.state == CSGWarConst.CSGWAR_STATE.SIGN and base_data.switch == 1 then
|
|
if not self.has_open_csgwar_view then
|
|
if not self:IsCSGWarSignPlayer() then
|
|
bool = true
|
|
self.CSGWar_red_data.one_red = true
|
|
end
|
|
end
|
|
end
|
|
--有免费应援次数也有红点
|
|
self.CSGWar_red_data.support_red = false
|
|
if base_data and TableSize(base_data) > 0 and base_data.state == CSGWarConst.CSGWAR_STATE.SUPPORT and base_data.switch == 1 then
|
|
bool = bool or self:GetMyFreeSupportNum() > 0
|
|
self.CSGWar_red_data.support_red = self:GetMyFreeSupportNum() > 0
|
|
end
|
|
--战场开启,可以进的玩家有红点
|
|
self.CSGWar_red_data.fight_red = false
|
|
if base_data and TableSize(base_data) > 0 and base_data.state == CSGWarConst.CSGWAR_STATE.START and base_data.switch == 1 then
|
|
bool = bool or self:IsCSGWarSignPlayer()
|
|
self.CSGWar_red_data.fight_red = self:IsCSGWarSignPlayer()
|
|
end
|
|
--日常占领奖励可领取红点
|
|
--可领取的时机为不是报名和不是开打阶段
|
|
local occupy_red_data = {}
|
|
self.CSGWar_red_data.occupy_red = false
|
|
if base_data and TableSize(base_data) > 0 and (base_data.state == CSGWarConst.CSGWAR_STATE.IDLE or base_data.state == CSGWarConst.CSGWAR_STATE.END) and base_data.switch == 1 then
|
|
local data = self:GetCSGWarOccupyInfo()
|
|
local server_id = RoleManager.Instance.mainRoleInfo.server_id
|
|
for i,v in pairs(data) do
|
|
if server_id == v.server_id and v.is_received_reward == 0 then
|
|
bool = true
|
|
occupy_red_data[v.city_id] = true
|
|
self.CSGWar_red_data.occupy_red = true
|
|
end
|
|
end
|
|
end
|
|
self.CSGWar_red_data.occupy_red_data = occupy_red_data
|
|
self:Fire(CSGWarConst.ANS_CSGWAR_RED)
|
|
return bool
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarRedData( )
|
|
return self.CSGWar_red_data
|
|
end
|
|
--是否是参战玩家
|
|
function CSGWarModel:IsCSGWarSignPlayer( )
|
|
return self.is_CSGWar_sign
|
|
end
|
|
--判断是否可以弹邀请函
|
|
function CSGWarModel:CheckCanOpenCSGWarTip( )
|
|
local base_data = self:GetCSGWarBaseInfo()
|
|
if self:IsCSGWarSignPlayer() and TableSize(base_data) > 0 and base_data.state == CSGWarConst.CSGWAR_STATE.START and base_data.switch == 1 then
|
|
if not self.CSGWar_activity_tip_open_data[CSGWarConst.CSGWAR_STATE.START] then
|
|
GlobalEventSystem:Fire(EventName.OPEN_ACITVITY_TIP,601,nil,true)
|
|
self.CSGWar_activity_tip_open_data[CSGWarConst.CSGWAR_STATE.START] = true
|
|
end
|
|
end
|
|
end
|
|
--等待协议数据
|
|
function CSGWarModel:SetCSGWarWaitInfo( scmd_num )
|
|
self.wait_list[scmd_num] = true
|
|
if self.start_wait_info and self.wait_list[60100] and self.wait_list[60102] then
|
|
self.start_wait_info = false
|
|
self:CheckCanOpenCSGWarTip()
|
|
end
|
|
end
|
|
|
|
function CSGWarModel:SetCSGWarOverlordInfo( vo )
|
|
self.CSGWar_overlord_info = vo
|
|
end
|
|
|
|
function CSGWarModel:GetCSGWarOverlordInfo( )
|
|
return self.CSGWar_overlord_info
|
|
end
|
|
|
|
----------公示相关-start---------
|
|
-- 通过活动日历判断是否需要展示公示界面
|
|
function CSGWarModel:NeedShowCSGWarResult()
|
|
-- 要满足跨服
|
|
local cur_stage = KfWorldModel:GetInstance():GetCurStage( )
|
|
if cur_stage < 2 then
|
|
return false
|
|
end
|
|
|
|
-- 要有占领数据
|
|
if TableSize(self:GetCSGWarOccupyInfo()) <= 0 then
|
|
return false
|
|
end
|
|
|
|
-- 要满足开服/跨服天数
|
|
local act_cfg = Config.Ac["601@0@1"]
|
|
local act_cfg_merge = Config.Ac["601@0@2"]
|
|
local open_day = ServerTimeModel:getInstance():GetOpenServerDay()
|
|
local merge_day = ServerTimeModel:getInstance():GetMergeServerDay()
|
|
local openDay_limit = tonumber(stringtotable(act_cfg.open_day)[1][1])
|
|
local mergeDay_limt = tonumber(stringtotable(act_cfg_merge.merge_day)[1][1])
|
|
|
|
-- 有合服 且合服天数小于等于限制条件则不显示
|
|
if mergeDay_limt and merge_day > 0 and merge_day < mergeDay_limt then
|
|
return false
|
|
-- 有开服限制 且开服天数小于等于限制条件则不显示
|
|
elseif openDay_limit and open_day > 0 and open_day < openDay_limit then
|
|
return false
|
|
end
|
|
local act_end_week = stringtotable(act_cfg.week)[1] -- 活动结束是周几
|
|
local act_end_time = stringtotable(act_cfg.time_region)[1][2] -- 活动结束时间(时分)
|
|
local act_open_hour = tonumber(act_end_time[1])
|
|
local act_open_min = tonumber(act_end_time[2])
|
|
local show_time = 24 * 3600 * self:GetCSGWarKVCFG( "public_time" ).value -- 公示持续时间 3天
|
|
local show_end_time = false -- 展示结束时间
|
|
|
|
local key_time -- 刚满足开服时间的那一天的时间戳
|
|
if mergeDay_limt and merge_day > 0 then
|
|
key_time = ServerTimeModel:getInstance():GetMergeServerTime() + (mergeDay_limt - 1) * 3600 * 24
|
|
else
|
|
key_time = ServerTimeModel:getInstance():GetOpenServerTime() + (openDay_limit - 1) * 3600 * 24
|
|
end
|
|
|
|
local act_first_open_time = self:GetNextWeekDayTime( act_end_week, key_time, act_open_hour, act_open_min, 0)
|
|
local cur_time = TimeUtil:getServerTime()
|
|
|
|
-- 当前时间在开服后第一次开活动的时间内 (特殊判断第一个满足的周N )
|
|
show_end_time = act_first_open_time + show_time
|
|
--print('=======Msh:CSGWarModel.lua[359] =======', TimeUtil:timeConversion(key_time, 'mm-dd hh:MM:ss'))
|
|
--print('=======Msh:CSGWarModel.lua[359] =======', TimeUtil:timeConversion(act_first_open_time, 'mm-dd hh:MM:ss'))
|
|
--print('=======Msh:CSGWarModel.lua[359] =======', TimeUtil:timeConversion(show_end_time, 'mm-dd hh:MM:ss'))
|
|
if cur_time <= show_end_time then
|
|
if cur_time >= act_first_open_time then
|
|
return true, show_end_time
|
|
else
|
|
--print('=======Msh:CSGWarModel.lua[363] =======', data)
|
|
return false
|
|
end
|
|
end
|
|
|
|
-- 正常的自然周判断
|
|
local last_open_time = self:GetLastWeekDayTime( act_end_week, cur_time, act_open_hour, act_open_min, 0)
|
|
show_end_time = last_open_time + show_time
|
|
if cur_time <= show_end_time and cur_time > last_open_time then
|
|
return true, show_end_time
|
|
else
|
|
--print('=======Msh:CSGWarModel.lua[373] =======', data)
|
|
return false
|
|
end
|
|
end
|
|
|
|
-- 传入时间time得到 该时间的【上一个周几week】 的 【hour点min分sec秒】 的时间戳
|
|
function CSGWarModel:GetLastWeekDayTime( week, t_time, hour, min, sec )
|
|
local t_time = t_time or TimeUtil:getServerTime()
|
|
local date = os.date("*t", t_time)
|
|
local date_n = {
|
|
year = date.year,
|
|
month = date.month,
|
|
day = date.day,
|
|
hour = hour or 0,
|
|
min = min or 0,
|
|
sec = sec or 0,
|
|
}
|
|
local cur_time = os.time(date_n)
|
|
local cur_week_day = tonumber(os.date("%w", cur_time)) -- 今天周几
|
|
cur_week_day = cur_week_day == 0 and 7 or cur_week_day
|
|
local offset_day = self:GetLastOrNextWeekOffset( cur_week_day, week, true)
|
|
local one_day_sec = 24 * 60 * 60
|
|
local target_time = cur_time - offset_day * one_day_sec
|
|
if t_time - target_time >= 7 * one_day_sec and cur_week_day == tonumber(week) then -- 两个时间的间隔超过七天(不合理)
|
|
-- 特殊判断临界值的情况
|
|
return cur_time
|
|
end
|
|
|
|
return target_time
|
|
end
|
|
|
|
-- 传入时间time得到 该时间的【下一个周几week】 的 【hour点min分sec秒】 的时间戳
|
|
function CSGWarModel:GetNextWeekDayTime( week, t_time, hour, min, sec)
|
|
local t_time = t_time or TimeUtil:getServerTime()
|
|
local date = os.date("*t", t_time)
|
|
local date_n = {
|
|
year = date.year,
|
|
month = date.month,
|
|
day = date.day,
|
|
hour = hour or 0,
|
|
min = min or 0,
|
|
sec = sec or 0,
|
|
}
|
|
local cur_time = os.time(date_n)
|
|
local cur_week_day = tonumber(os.date("%w", cur_time)) -- 今天周几
|
|
cur_week_day = cur_week_day == 0 and 7 or cur_week_day
|
|
if cur_week_day == tonumber(week) then
|
|
return cur_time
|
|
end
|
|
local offset_day = self:GetLastOrNextWeekOffset( cur_week_day, week)
|
|
local target_time = cur_time + offset_day * 24 * 60 * 60
|
|
return target_time
|
|
end
|
|
|
|
-- 当前周cur_week_day 与 获取的下一个 或 上一个 周week 的相差的天数
|
|
function CSGWarModel:GetLastOrNextWeekOffset( cur_week_day, week, is_last)
|
|
if is_last then -- 上一个周几
|
|
if week < cur_week_day then
|
|
return cur_week_day - week
|
|
else
|
|
return cur_week_day + 7 - week
|
|
end
|
|
else -- 下一个周几
|
|
if cur_week_day < week then
|
|
return week - cur_week_day
|
|
else
|
|
return week + 7 - cur_week_day
|
|
end
|
|
end
|
|
end
|
|
|
|
-- 获取公示的红点
|
|
function CSGWarModel:GetShowIconRed( )
|
|
-- 占领奖励红点
|
|
local bool1 = false
|
|
local red_data = self:GetCSGWarRedData()
|
|
if red_data.occupy_red then
|
|
bool1 = true
|
|
end
|
|
|
|
-- 每天首次登陆红点
|
|
local bool2 = self:GetLoginRed( )
|
|
return bool1 or bool2
|
|
end
|
|
|
|
-- 每天首次登陆红点cookie
|
|
function CSGWarModel:SetLoginCookie( bool )
|
|
CookieWrapper.Instance:SaveCookie(CookieLevelType.Account,
|
|
CookieTimeType.TYPE_DAY2, CookieKey.CSGWAR_SHOW_ICON_LOGIN_RED, bool)
|
|
CookieWrapper.Instance:WriteAll()
|
|
end
|
|
|
|
function CSGWarModel:GetLoginRed( )
|
|
local today_has_show = CookieWrapper.Instance:GetCookie(CookieLevelType.Account,
|
|
CookieKey.CSGWAR_SHOW_ICON_LOGIN_RED)
|
|
return not today_has_show
|
|
end
|
|
|
|
function CSGWarModel:SetLoginRed( bool )
|
|
if bool == false then
|
|
self:SetLoginCookie( true )
|
|
self:UpdateShowIconRed( )
|
|
end
|
|
end
|
|
|
|
-- 刷新公示图标红点
|
|
function CSGWarModel:UpdateShowIconRed( )
|
|
local bool = self:GetShowIconRed( )
|
|
GlobalEventSystem:Fire(ActivityIconManager.UPDATE_ICON_TIPS, 60101, bool)
|
|
end
|
|
----------公示相关-end-----------
|