源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

501 行
16 KiB

  1. CSGWarModel = CSGWarModel or BaseClass(BaseVo)
  2. local table_insert = table.insert
  3. function CSGWarModel:__init()
  4. CSGWarModel.Instance = self
  5. self:InitCSGWarCityCFG()
  6. -- self:InitCSGWarKVCFG()
  7. self:Reset()
  8. end
  9. function CSGWarModel:Reset()
  10. self.CSGWar_base_info = {}--活动基础信息
  11. self.CSGWar_occupy_info = {}--占领信息 结算之后才会有的
  12. self.CSGWar_sign_info = {}--帮战参赛信息-报名阶段和活动进行中
  13. self.CSGWar_guild_sign_list = {}--社团报名榜
  14. self.CSGWar_support_sign_list = {}--外援报名榜
  15. self.CSGWar_city_info = {}--场景城池信息
  16. self.CSGWar_result_info = {}--结算信息
  17. self.CSGWar_group_info = {}--社团分组信息
  18. self.CSGWar_fight_guild_info = {} --本阵营参战公会id表
  19. self.CSGWar_support_info = {} --应援信息表
  20. self.CSGWar_record_info = {}--日志信息
  21. self.CSGWar_overlord_info = {}--霸主限购信息
  22. self.my_support_num = 0--我的应援次数
  23. self.free_support_num = 0--我的免费应援次数
  24. self.is_CSGWar_sign = false--是否已经报名了
  25. self.support_view_toggle = false
  26. self.has_open_csgwar_view = false--是否已经开过界面了
  27. self.start_wait_info = true
  28. self.wait_list = {}
  29. self.CSGWar_red_data = {}--缓存红点数据
  30. self.CSGWar_activity_tip_open_data = {}--缓存邀请函打开记录,报名,声援,开战在活动期间只弹一次
  31. end
  32. function CSGWarModel:GetInstance()
  33. if CSGWarModel.Instance == nil then
  34. CSGWarModel.Instance = CSGWarModel.New()
  35. end
  36. return CSGWarModel.Instance
  37. end
  38. function CSGWarModel:getInstance()
  39. if CSGWarModel.Instance == nil then
  40. CSGWarModel.Instance = CSGWarModel.New()
  41. end
  42. return CSGWarModel.Instance
  43. end
  44. --场景城区配置
  45. function CSGWarModel:InitCSGWarCityCFG( )
  46. local cfg = Config.Crossguildwarscene
  47. for i,v in ipairs(cfg) do
  48. v.city_pos = stringtotable(v.flag)
  49. v.monster_pos = stringtotable(v.mon_list)
  50. end
  51. end
  52. --常量配置
  53. function CSGWarModel:InitCSGWarKVCFG( )
  54. self.CSGWar_kv_cfg = {}
  55. local cfg = Config.Crossguildwarconfig
  56. for i,v in pairs(cfg) do
  57. self.CSGWar_kv_cfg[Trim(v.key)] = v
  58. end
  59. end
  60. function CSGWarModel:GetCSGWarKVCFG( key )
  61. if not self.CSGWar_kv_cfg then
  62. self:InitCSGWarKVCFG()
  63. end
  64. return self.CSGWar_kv_cfg[key]
  65. end
  66. function CSGWarModel:SetCSGWarBaseInfo( vo )
  67. self.CSGWar_base_info = vo
  68. self:ChangeVar("CSGWar_base_info", self.CSGWar_base_info, false, true)
  69. end
  70. function CSGWarModel:GetCSGWarBaseInfo( )
  71. return self.CSGWar_base_info
  72. end
  73. function CSGWarModel:SetCSGWarOccupyInfo( vo )
  74. local data = {}
  75. for ii,vv in ipairs(vo.city_list) do
  76. data[vv.city_id] = vv
  77. end
  78. self.CSGWar_occupy_info = data
  79. self:ChangeVar("CSGWar_occupy_info", self.CSGWar_occupy_info, false, true)
  80. end
  81. function CSGWarModel:GetCSGWarOccupyInfo()
  82. return self.CSGWar_occupy_info
  83. end
  84. function CSGWarModel:SetCSGWarSignInfo( vo )
  85. local country = KfWorldModel:GetInstance():GetMyCountryId()
  86. self.CSGWar_fight_guild_info = {}
  87. self.is_CSGWar_sign = vo.is_sign_up == 1
  88. self.last_sign_time = vo.last_sign
  89. local data = {}
  90. for ii,vv in ipairs(vo.guild_list) do
  91. data[vv.fact_id] = vv
  92. if vv.fact_id == country then
  93. self.CSGWar_fight_guild_info[vv.guild_id] = true
  94. end
  95. end
  96. self.CSGWar_sign_info = data
  97. self:ChangeVar("CSGWar_sign_info", self.CSGWar_sign_info, false, true)
  98. end
  99. function CSGWarModel:GetCSGWarSignInfo( index )
  100. return self.CSGWar_sign_info
  101. end
  102. function CSGWarModel:IsCSGWarSign( )
  103. return self.is_CSGWar_sign
  104. end
  105. function CSGWarModel:GetLastSignTime( )
  106. return self.last_sign_time or 0
  107. end
  108. --社团报名榜
  109. function CSGWarModel:SetCSGWarGuildSignList( vo )
  110. self.CSGWar_guild_sign_list = vo.rank_list
  111. self:Fire(CSGWarConst.UPDATE_CSGWAR_SIGN_LIST)
  112. end
  113. function CSGWarModel:GetCSGWarGuildSignList( )
  114. return self.CSGWar_guild_sign_list
  115. end
  116. --外援报名榜
  117. function CSGWarModel:SetCSGWarSupportSignList( vo )
  118. self.CSGWar_support_sign_list = vo.rank_list
  119. self:Fire(CSGWarConst.UPDATE_CSGWAR_SIGN_LIST)
  120. end
  121. function CSGWarModel:GetCSGWarSupportSignList( )
  122. return self.CSGWar_support_sign_list
  123. end
  124. function CSGWarModel:SetCSGWarCityInfo( vo )
  125. local data = {}
  126. for i,v in ipairs(vo) do
  127. data[v.city_id] = v
  128. end
  129. self.CSGWar_city_info = data
  130. self:Fire(CSGWarConst.UPDATE_CSGWAR_CITY_INFO)
  131. end
  132. function CSGWarModel:GetCSGWarCityInfo( )
  133. return self.CSGWar_city_info
  134. end
  135. function CSGWarModel:SetCSGWarResultInfo( vo )
  136. self.CSGWar_result_info = vo
  137. self:ChangeVar("CSGWar_result_info", self.CSGWar_result_info, false, true)
  138. end
  139. function CSGWarModel:GetCSGWarResultInfo( )
  140. return self.CSGWar_result_info
  141. end
  142. --是否在活动中
  143. function CSGWarModel:IsCSGWarOpen( )
  144. local bool = false
  145. if self.CSGWar_base_info then
  146. bool = self.CSGWar_base_info.switch == 1 and self.CSGWar_base_info.state == CSGWarConst.CSGWAR_STATE.START
  147. or self.CSGWar_base_info.state == CSGWarConst.CSGWAR_STATE.SIGN
  148. or self.CSGWar_base_info.state == CSGWarConst.CSGWAR_STATE.SUPPORT
  149. end
  150. return bool
  151. end
  152. --阵营分组信息
  153. function CSGWarModel:SetCSGWarCountryInfo( vo )
  154. for i,v in ipairs(vo) do
  155. if not self.CSGWar_group_info[v.group] then
  156. self.CSGWar_group_info[v.group] = {}
  157. end
  158. self.CSGWar_group_info[v.group][v.guild_id] = v
  159. end
  160. end
  161. --通过帮派id获取阵营
  162. function CSGWarModel:GetCountryIdByGuildId( guild_id )
  163. for i,v in pairs(self.CSGWar_group_info) do
  164. if v[guild_id] then
  165. return i
  166. end
  167. end
  168. return 0
  169. end
  170. --根据帮派id获取是否是参战的公会
  171. function CSGWarModel:IsCSGWarFightGuild( guild_id )
  172. return self.CSGWar_fight_guild_info[guild_id] or false
  173. end
  174. --设置应援列表
  175. function CSGWarModel:SetCSGWarSupportInfo( vo )
  176. self.my_support_num = vo.cur_help_num
  177. self.free_support_num = vo.free_help_num
  178. local all_support_num = 0
  179. if not self.CSGWar_support_info then
  180. self.CSGWar_support_info = {}
  181. end
  182. local data = {}
  183. for i,v in ipairs(vo.help_list) do
  184. data[v.fact_id] = v
  185. all_support_num = all_support_num + v.help_num
  186. end
  187. self.CSGWar_support_info = data
  188. self.all_support_num = all_support_num
  189. self.CSGWar_support_info.all_support_num = all_support_num
  190. self:ChangeVar("CSGWar_support_info", self.CSGWar_support_info, false, true)
  191. end
  192. function CSGWarModel:GetCSGWarSupportInfo( )
  193. return self.CSGWar_support_info or {}
  194. end
  195. function CSGWarModel:GetMySupportNum( )
  196. return self.my_support_num
  197. end
  198. function CSGWarModel:GetMyFreeSupportNum( )
  199. return self.free_support_num
  200. end
  201. function CSGWarModel:SetCSGWarRecordInfo( vo )
  202. local data = {}
  203. local temp_data = {}
  204. local temp_city = {}
  205. for i,v in ipairs(vo.logs) do
  206. temp_data = {
  207. time = v.time,
  208. }
  209. temp_city = {}
  210. for iii,vvv in ipairs(v.city_list) do
  211. temp_city[vvv.city_id] = vvv
  212. end
  213. temp_data.city_list = DeepCopy(temp_city)
  214. data[#data+1] = DeepCopy(temp_data)
  215. end
  216. self.CSGWar_record_info = data
  217. self:ChangeVar("CSGWar_record_info", self.CSGWar_record_info, false, true)
  218. end
  219. function CSGWarModel:GetCSGWarRecordInfo( )
  220. return self.CSGWar_record_info
  221. end
  222. function CSGWarModel:IsCSGWarNeedRed( )
  223. local bool = false
  224. local base_data = self:GetCSGWarBaseInfo()
  225. --没有打开过界面报名期间就有红点
  226. self.CSGWar_red_data.one_red = false
  227. if base_data and TableSize(base_data) > 0 and base_data.state == CSGWarConst.CSGWAR_STATE.SIGN and base_data.switch == 1 then
  228. if not self.has_open_csgwar_view then
  229. if not self:IsCSGWarSignPlayer() then
  230. bool = true
  231. self.CSGWar_red_data.one_red = true
  232. end
  233. end
  234. end
  235. --有免费应援次数也有红点
  236. self.CSGWar_red_data.support_red = false
  237. if base_data and TableSize(base_data) > 0 and base_data.state == CSGWarConst.CSGWAR_STATE.SUPPORT and base_data.switch == 1 then
  238. bool = bool or self:GetMyFreeSupportNum() > 0
  239. self.CSGWar_red_data.support_red = self:GetMyFreeSupportNum() > 0
  240. end
  241. --战场开启,可以进的玩家有红点
  242. self.CSGWar_red_data.fight_red = false
  243. if base_data and TableSize(base_data) > 0 and base_data.state == CSGWarConst.CSGWAR_STATE.START and base_data.switch == 1 then
  244. bool = bool or self:IsCSGWarSignPlayer()
  245. self.CSGWar_red_data.fight_red = self:IsCSGWarSignPlayer()
  246. end
  247. --日常占领奖励可领取红点
  248. --可领取的时机为不是报名和不是开打阶段
  249. local occupy_red_data = {}
  250. self.CSGWar_red_data.occupy_red = false
  251. 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
  252. local data = self:GetCSGWarOccupyInfo()
  253. local server_id = RoleManager.Instance.mainRoleInfo.server_id
  254. for i,v in pairs(data) do
  255. if server_id == v.server_id and v.is_received_reward == 0 then
  256. bool = true
  257. occupy_red_data[v.city_id] = true
  258. self.CSGWar_red_data.occupy_red = true
  259. end
  260. end
  261. end
  262. self.CSGWar_red_data.occupy_red_data = occupy_red_data
  263. self:Fire(CSGWarConst.ANS_CSGWAR_RED)
  264. return bool
  265. end
  266. function CSGWarModel:GetCSGWarRedData( )
  267. return self.CSGWar_red_data
  268. end
  269. --是否是参战玩家
  270. function CSGWarModel:IsCSGWarSignPlayer( )
  271. return self.is_CSGWar_sign
  272. end
  273. --判断是否可以弹邀请函
  274. function CSGWarModel:CheckCanOpenCSGWarTip( )
  275. local base_data = self:GetCSGWarBaseInfo()
  276. if self:IsCSGWarSignPlayer() and TableSize(base_data) > 0 and base_data.state == CSGWarConst.CSGWAR_STATE.START and base_data.switch == 1 then
  277. if not self.CSGWar_activity_tip_open_data[CSGWarConst.CSGWAR_STATE.START] then
  278. GlobalEventSystem:Fire(EventName.OPEN_ACITVITY_TIP,601,nil,true)
  279. self.CSGWar_activity_tip_open_data[CSGWarConst.CSGWAR_STATE.START] = true
  280. end
  281. end
  282. end
  283. --等待协议数据
  284. function CSGWarModel:SetCSGWarWaitInfo( scmd_num )
  285. self.wait_list[scmd_num] = true
  286. if self.start_wait_info and self.wait_list[60100] and self.wait_list[60102] then
  287. self.start_wait_info = false
  288. self:CheckCanOpenCSGWarTip()
  289. end
  290. end
  291. function CSGWarModel:SetCSGWarOverlordInfo( vo )
  292. self.CSGWar_overlord_info = vo
  293. end
  294. function CSGWarModel:GetCSGWarOverlordInfo( )
  295. return self.CSGWar_overlord_info
  296. end
  297. ----------公示相关-start---------
  298. -- 通过活动日历判断是否需要展示公示界面
  299. function CSGWarModel:NeedShowCSGWarResult()
  300. -- 要满足跨服
  301. local cur_stage = KfWorldModel:GetInstance():GetCurStage( )
  302. if cur_stage < 2 then
  303. return false
  304. end
  305. -- 要有占领数据
  306. if TableSize(self:GetCSGWarOccupyInfo()) <= 0 then
  307. return false
  308. end
  309. -- 要满足开服/跨服天数
  310. local act_cfg = Config.Ac["601@0@1"]
  311. local act_cfg_merge = Config.Ac["601@0@2"]
  312. local open_day = ServerTimeModel:getInstance():GetOpenServerDay()
  313. local merge_day = ServerTimeModel:getInstance():GetMergeServerDay()
  314. local openDay_limit = tonumber(stringtotable(act_cfg.open_day)[1][1])
  315. local mergeDay_limt = tonumber(stringtotable(act_cfg_merge.merge_day)[1][1])
  316. -- 有合服 且合服天数小于等于限制条件则不显示
  317. if mergeDay_limt and merge_day > 0 and merge_day < mergeDay_limt then
  318. return false
  319. -- 有开服限制 且开服天数小于等于限制条件则不显示
  320. elseif openDay_limit and open_day > 0 and open_day < openDay_limit then
  321. return false
  322. end
  323. local act_end_week = stringtotable(act_cfg.week)[1] -- 活动结束是周几
  324. local act_end_time = stringtotable(act_cfg.time_region)[1][2] -- 活动结束时间(时分)
  325. local act_open_hour = tonumber(act_end_time[1])
  326. local act_open_min = tonumber(act_end_time[2])
  327. local show_time = 24 * 3600 * self:GetCSGWarKVCFG( "public_time" ).value -- 公示持续时间 3天
  328. local show_end_time = false -- 展示结束时间
  329. local key_time -- 刚满足开服时间的那一天的时间戳
  330. if mergeDay_limt and merge_day > 0 then
  331. key_time = ServerTimeModel:getInstance():GetMergeServerTime() + (mergeDay_limt - 1) * 3600 * 24
  332. else
  333. key_time = ServerTimeModel:getInstance():GetOpenServerTime() + (openDay_limit - 1) * 3600 * 24
  334. end
  335. local act_first_open_time = self:GetNextWeekDayTime( act_end_week, key_time, act_open_hour, act_open_min, 0)
  336. local cur_time = TimeUtil:getServerTime()
  337. -- 当前时间在开服后第一次开活动的时间内 (特殊判断第一个满足的周N )
  338. show_end_time = act_first_open_time + show_time
  339. --print('=======Msh:CSGWarModel.lua[359] =======', TimeUtil:timeConversion(key_time, 'mm-dd hh:MM:ss'))
  340. --print('=======Msh:CSGWarModel.lua[359] =======', TimeUtil:timeConversion(act_first_open_time, 'mm-dd hh:MM:ss'))
  341. --print('=======Msh:CSGWarModel.lua[359] =======', TimeUtil:timeConversion(show_end_time, 'mm-dd hh:MM:ss'))
  342. if cur_time <= show_end_time then
  343. if cur_time >= act_first_open_time then
  344. return true, show_end_time
  345. else
  346. --print('=======Msh:CSGWarModel.lua[363] =======', data)
  347. return false
  348. end
  349. end
  350. -- 正常的自然周判断
  351. local last_open_time = self:GetLastWeekDayTime( act_end_week, cur_time, act_open_hour, act_open_min, 0)
  352. show_end_time = last_open_time + show_time
  353. if cur_time <= show_end_time and cur_time > last_open_time then
  354. return true, show_end_time
  355. else
  356. --print('=======Msh:CSGWarModel.lua[373] =======', data)
  357. return false
  358. end
  359. end
  360. -- 传入时间time得到 该时间的【上一个周几week】 的 【hour点min分sec秒】 的时间戳
  361. function CSGWarModel:GetLastWeekDayTime( week, t_time, hour, min, sec )
  362. local t_time = t_time or TimeUtil:getServerTime()
  363. local date = os.date("*t", t_time)
  364. local date_n = {
  365. year = date.year,
  366. month = date.month,
  367. day = date.day,
  368. hour = hour or 0,
  369. min = min or 0,
  370. sec = sec or 0,
  371. }
  372. local cur_time = os.time(date_n)
  373. local cur_week_day = tonumber(os.date("%w", cur_time)) -- 今天周几
  374. cur_week_day = cur_week_day == 0 and 7 or cur_week_day
  375. local offset_day = self:GetLastOrNextWeekOffset( cur_week_day, week, true)
  376. local one_day_sec = 24 * 60 * 60
  377. local target_time = cur_time - offset_day * one_day_sec
  378. if t_time - target_time >= 7 * one_day_sec and cur_week_day == tonumber(week) then -- 两个时间的间隔超过七天(不合理)
  379. -- 特殊判断临界值的情况
  380. return cur_time
  381. end
  382. return target_time
  383. end
  384. -- 传入时间time得到 该时间的【下一个周几week】 的 【hour点min分sec秒】 的时间戳
  385. function CSGWarModel:GetNextWeekDayTime( week, t_time, hour, min, sec)
  386. local t_time = t_time or TimeUtil:getServerTime()
  387. local date = os.date("*t", t_time)
  388. local date_n = {
  389. year = date.year,
  390. month = date.month,
  391. day = date.day,
  392. hour = hour or 0,
  393. min = min or 0,
  394. sec = sec or 0,
  395. }
  396. local cur_time = os.time(date_n)
  397. local cur_week_day = tonumber(os.date("%w", cur_time)) -- 今天周几
  398. cur_week_day = cur_week_day == 0 and 7 or cur_week_day
  399. if cur_week_day == tonumber(week) then
  400. return cur_time
  401. end
  402. local offset_day = self:GetLastOrNextWeekOffset( cur_week_day, week)
  403. local target_time = cur_time + offset_day * 24 * 60 * 60
  404. return target_time
  405. end
  406. -- 当前周cur_week_day 与 获取的下一个 或 上一个 周week 的相差的天数
  407. function CSGWarModel:GetLastOrNextWeekOffset( cur_week_day, week, is_last)
  408. if is_last then -- 上一个周几
  409. if week < cur_week_day then
  410. return cur_week_day - week
  411. else
  412. return cur_week_day + 7 - week
  413. end
  414. else -- 下一个周几
  415. if cur_week_day < week then
  416. return week - cur_week_day
  417. else
  418. return week + 7 - cur_week_day
  419. end
  420. end
  421. end
  422. -- 获取公示的红点
  423. function CSGWarModel:GetShowIconRed( )
  424. -- 占领奖励红点
  425. local bool1 = false
  426. local red_data = self:GetCSGWarRedData()
  427. if red_data.occupy_red then
  428. bool1 = true
  429. end
  430. -- 每天首次登陆红点
  431. local bool2 = self:GetLoginRed( )
  432. return bool1 or bool2
  433. end
  434. -- 每天首次登陆红点cookie
  435. function CSGWarModel:SetLoginCookie( bool )
  436. CookieWrapper.Instance:SaveCookie(CookieLevelType.Account,
  437. CookieTimeType.TYPE_DAY2, CookieKey.CSGWAR_SHOW_ICON_LOGIN_RED, bool)
  438. CookieWrapper.Instance:WriteAll()
  439. end
  440. function CSGWarModel:GetLoginRed( )
  441. local today_has_show = CookieWrapper.Instance:GetCookie(CookieLevelType.Account,
  442. CookieKey.CSGWAR_SHOW_ICON_LOGIN_RED)
  443. return not today_has_show
  444. end
  445. function CSGWarModel:SetLoginRed( bool )
  446. if bool == false then
  447. self:SetLoginCookie( true )
  448. self:UpdateShowIconRed( )
  449. end
  450. end
  451. -- 刷新公示图标红点
  452. function CSGWarModel:UpdateShowIconRed( )
  453. local bool = self:GetShowIconRed( )
  454. GlobalEventSystem:Fire(ActivityIconManager.UPDATE_ICON_TIPS, 60101, bool)
  455. end
  456. ----------公示相关-end-----------