VoyageDataMgr.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. local VoyageDataMgr = class("VoyageDataMgr", require("DataBase"))
  2. local VoyageAirShipData = require('Voyage/VoyageAirShipData')
  3. local CommonLogData = require('CommomLogData')
  4. local CreateActorSystem = require('CreateActorSystem')
  5. local REQ_GUILD_CD = 1000
  6. local AirShipSort = function (a, b)
  7. if a.endTime == b.endTime then
  8. if a.quality == b.quality then
  9. return a.uid < b.uid
  10. else
  11. return a.quality < b.quality
  12. end
  13. end
  14. return a.endTime < b.endTime
  15. end
  16. function VoyageDataMgr:ctor()
  17. self.lastSendMsgTimeMap = nil -- 发送消息的冷却时间,避免操作过快
  18. self.rpStatus = nil
  19. self.challengeNum = 0
  20. self.voyageNum = 0
  21. self.curAirShipId = 1
  22. self.notifyAirShipUpTip = false
  23. self.refreshAirShipResult = nil
  24. self:ClearLastAttackData()
  25. self.keepVoyageing = nil
  26. self:ClearViewListData()
  27. self.selfAirShipData = nil
  28. -- if self.selfAirShipCompleteTimer then
  29. -- self.selfAirShipCompleteTimer:Stop()
  30. -- self.selfAirShipCompleteTimer = nil
  31. -- end
  32. self:ClearLogData()
  33. end
  34. function VoyageDataMgr:Clear()
  35. self.lastSendMsgTimeMap = nil
  36. self.rpStatus = nil
  37. self.challengeNum = 0
  38. self.voyageNum = 0
  39. self.curAirShipId = 1
  40. self.notifyAirShipUpTip = false
  41. self.refreshAirShipResult = nil
  42. self:ClearLastAttackData()
  43. self.keepVoyageing = nil
  44. self:ClearViewListData()
  45. self.selfAirShipData = nil
  46. -- if self.selfAirShipCompleteTimer then
  47. -- self.selfAirShipCompleteTimer:Stop()
  48. -- self.selfAirShipCompleteTimer = nil
  49. -- end
  50. self:ClearLogData()
  51. end
  52. function VoyageDataMgr:Destroy()
  53. self.lastSendMsgTimeMap = nil
  54. self.rpStatus = nil
  55. self.challengeNum = nil
  56. self.voyageNum = nil
  57. self.curAirShipId = nil
  58. self.notifyAirShipUpTip = nil
  59. self.refreshAirShipResult = nil
  60. self:ClearLastAttackData()
  61. self.keepVoyageing = nil
  62. self:DisposeViewListData()
  63. self.selfAirShipData = nil
  64. -- if self.selfAirShipCompleteTimer then
  65. -- self.selfAirShipCompleteTimer:Stop()
  66. -- self.selfAirShipCompleteTimer = nil
  67. -- end
  68. self:ClearLogData()
  69. self:UnRegisterNetEvents()
  70. end
  71. function VoyageDataMgr:RegisterNetEvents()
  72. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_DATA_NTF, self.OnVoyageSelfDataNtf, self)
  73. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_VIEW_LIST_ACK, self.OnVoyageKeepAck, self)
  74. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_VIEW_LIST_NTF, self.OnVoyageKeepNtf, self)
  75. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_REFRESH_TRIAL_TYPE_ACK, self.OnVoyageRefreshAirShipAck, self)
  76. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_ACK, self.OnVoyageTakeOffAirShipAck, self)
  77. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_REWARD_ACK, self.OnVoyageGetRewardAck, self)
  78. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_INFO_ACK, self.OnVoyageCheckInfoAck, self)
  79. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_CHALLENGE_ACK, self.OnVoyageChallengeAck, self)
  80. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_CHALLENGE_RESULT_ACK, self.OnVoyageChallengeResultAck, self)
  81. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_RANK_LIST_ACK, self.OnVoyageRankDatasAck, self)
  82. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_LOG_ACK, self.OnVoyageLogAck, self)
  83. end
  84. function VoyageDataMgr:UnRegisterNetEvents()
  85. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_DATA_NTF)
  86. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_VIEW_LIST_ACK)
  87. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_VIEW_LIST_NTF)
  88. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_REFRESH_TRIAL_TYPE_ACK)
  89. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_ACK)
  90. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_REWARD_ACK)
  91. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_INFO_ACK)
  92. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_CHALLENGE_ACK)
  93. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_CHALLENGE_RESULT_ACK)
  94. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_RANK_LIST_ACK)
  95. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_CROSS_YUAN_HANG_TRIAL_LOG_ACK)
  96. end
  97. function VoyageDataMgr:IsCanSend(key, cdTime)
  98. local curTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  99. if not self.lastSendMsgTimeMap then
  100. self.lastSendMsgTimeMap = {}
  101. self.lastSendMsgTimeMap[key] = curTime
  102. return true
  103. end
  104. local lastTime = self.lastSendMsgTimeMap[key]
  105. if lastTime then
  106. local cd = cdTime or REQ_GUILD_CD
  107. if (curTime - lastTime) < cd then
  108. return false
  109. end
  110. end
  111. self.lastSendMsgTimeMap[key] = curTime
  112. return true
  113. end
  114. function VoyageDataMgr:OnVoyageSelfDataNtf(data)
  115. -- LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_DATA_NTF " .. Inspect(data))
  116. if ManagerContainer.NetManager:IsErrorData(data) then
  117. return
  118. end
  119. data = data.yuanhangtrial_data
  120. self:RefreshSelfVoyageData(data)
  121. end
  122. function VoyageDataMgr:RefreshSelfVoyageData(data)
  123. if not data then
  124. return
  125. end
  126. local challengeNum = data.challenge_num or 0
  127. local voyageNum = data.trial_num or 0
  128. local curAirShipId = data.refresh_trial_type or 1
  129. local changed1 = (self.challengeNum ~= challengeNum)
  130. local changed2 = (self.voyageNum ~= voyageNum)
  131. local changed3 = (self.curAirShipId ~= curAirShipId)
  132. self.challengeNum = challengeNum
  133. self.voyageNum = voyageNum
  134. self.curAirShipId = curAirShipId
  135. self:RefreshSelfAirShip(data.trial_data)
  136. if changed1 then
  137. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.VOYAGE_CHALLENGE_NUM_CHANGED)
  138. end
  139. if changed2 then
  140. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.VOYAGE_NUM_CHANGED)
  141. end
  142. if changed3 then
  143. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.VOYAGE_AIRSHIP_CHANGED)
  144. end
  145. if self.rpStatus == nil or self.rpStatus then
  146. local rpStatus = (self.voyageNum < GlobalConfig.Instance:GetConfigIntValue(323))
  147. self:SetRpStatus(rpStatus)
  148. end
  149. end
  150. function VoyageDataMgr:RefreshSelfAirShip(data)
  151. local changed = true
  152. if data and data.uid and data.uid ~= 0 then
  153. if self.selfAirShipData then
  154. self.selfAirShipData:SetData(data)
  155. if not self.selfAirShipData:IsChange() then
  156. changed = false
  157. end
  158. else
  159. self.selfAirShipData = VoyageAirShipData:new(data)
  160. end
  161. else
  162. if self.selfAirShipData then
  163. self.selfAirShipData = nil
  164. else
  165. changed = false
  166. end
  167. end
  168. if changed then
  169. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.VOYAGE_SELF_AIRSHIP_DATA_CHANGED)
  170. end
  171. if self.selfAirShipData and not self.selfAirShipData.awardReceived then
  172. if self.selfAirShipData:IsChangeEndTime() then
  173. -- local curTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  174. -- local remindTime = (self.selfAirShipData.endTime - curTime) / 1000
  175. -- remindTime = type(remindTime) == "number" and remindTime or (#remindTime + 1)
  176. -- if not self.selfAirShipCompleteTimer then
  177. -- self.selfAirShipCompleteTimer = Timer.New(slot(self.CompleteSelfAirShip, self), remindTime, 1)
  178. -- else
  179. -- self.selfAirShipCompleteTimer.time = remindTime
  180. -- self.selfAirShipCompleteTimer.duration = remindTime
  181. -- self.selfAirShipCompleteTimer.loop = 1
  182. -- end
  183. end
  184. -- if self.selfAirShipCompleteTimer then
  185. -- if not self.selfAirShipCompleteTimer.running then
  186. -- self.selfAirShipCompleteTimer:Start()
  187. -- end
  188. -- end
  189. else
  190. -- if self.selfAirShipCompleteTimer then
  191. -- self.selfAirShipCompleteTimer:Stop()
  192. -- self.selfAirShipCompleteTimer = nil
  193. -- end
  194. -- self:CompleteSelfAirShip(true)
  195. end
  196. end
  197. -- function VoyageDataMgr:CompleteSelfAirShip(noRewards)
  198. -- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.VoyageCompleteReward, not noRewards)
  199. -- end
  200. function VoyageDataMgr:OnVoyageKeepAck(data)
  201. -- LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_VIEW_LIST_ACK " .. Inspect(data))
  202. if ManagerContainer.NetManager:IsErrorData(data) then
  203. return
  204. end
  205. self:RefreshAirShipDatas(data.trial_view_list)
  206. end
  207. function VoyageDataMgr:OnVoyageKeepNtf(data)
  208. -- LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_VIEW_LIST_NTF " .. Inspect(data))
  209. if ManagerContainer.NetManager:IsErrorData(data) then
  210. return
  211. end
  212. self:RefreshAirShipDatas(data.trial_view_list)
  213. end
  214. function VoyageDataMgr:RefreshAirShipDatas(list)
  215. local airShipDatas = self.airShipDatas
  216. local airShipDataMap = self.airShipDataMap
  217. local len = #airShipDatas
  218. local uid = nil
  219. local endTime = nil
  220. local airShipDataIdx = nil
  221. local airShipData = nil
  222. local needReset = false
  223. local curTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  224. local selfuid = ManagerContainer.DataMgr.UserData:GetUserId()
  225. for _, value in pairs(list) do
  226. uid = value.uid
  227. endTime = value.end_time_stamp
  228. -- 超出一分钟的数据就不管了
  229. if (endTime - curTime) > 60000 and selfuid ~= uid then
  230. if airShipDataMap[uid] then
  231. airShipData = airShipDataMap[uid]
  232. airShipData:SetData(value)
  233. if airShipData:IsChangeEndTime() then
  234. needReset = true
  235. end
  236. else
  237. airShipData = VoyageAirShipData:new(value)
  238. len = len + 1
  239. airShipDatas[len] = airShipData
  240. airShipDataMap[uid] = airShipData
  241. needReset = true
  242. end
  243. end
  244. end
  245. if needReset then
  246. table.sort(airShipDatas, AirShipSort)
  247. end
  248. for i = len, 1, -1 do
  249. airShipData = airShipDatas[i]
  250. endTime = (airShipData.endTime - curTime)
  251. -- 超出一分钟的数据就不管了
  252. if endTime <= -60000 then
  253. table.remove(airShipDatas, i)
  254. airShipDataMap[airShipData.uid] = nil
  255. len = len - 1
  256. elseif endTime < 0 then
  257. -- 缓存数据过多,清理一下
  258. if len > 300 then
  259. table.remove(airShipDatas, i)
  260. airShipDataMap[airShipData.uid] = nil
  261. len = len - 1
  262. end
  263. else
  264. break
  265. end
  266. end
  267. end
  268. function VoyageDataMgr:OnVoyageRefreshAirShipAck(data)
  269. -- LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_REFRESH_TRIAL_TYPE_ACK " .. Inspect(data))
  270. if not data then
  271. return
  272. end
  273. if not data.error or data.error == 0 then
  274. self.refreshAirShipResult = true
  275. elseif data.error == Enum.NetErrorCode.ERROR_CROSS_YUANHANGTRIAL_REFRESH_FAILED then
  276. self.refreshAirShipResult = false
  277. else
  278. self.refreshAirShipResult = false
  279. end
  280. end
  281. function VoyageDataMgr:OnVoyageTakeOffAirShipAck(data)
  282. -- LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_ACK " .. Inspect(data))
  283. if ManagerContainer.NetManager:IsErrorData(data) then
  284. return
  285. end
  286. -- self:RefreshSelfAirShip(data.trial_data)
  287. end
  288. function VoyageDataMgr:OnVoyageGetRewardAck(data)
  289. -- LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_REWARD_ACK " .. Inspect(data))
  290. if ManagerContainer.NetManager:IsErrorData(data) then
  291. return
  292. end
  293. CommonUtil.ACKShowRewardList(data.reward_list)
  294. end
  295. function VoyageDataMgr:OnVoyageCheckInfoAck(data)
  296. -- LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_INFO_ACK " .. Inspect(data))
  297. if ManagerContainer.NetManager:IsErrorData(data) then
  298. return
  299. end
  300. if not data.trial_data then
  301. return
  302. end
  303. self:RefreshAirShipDatas({data.trial_data})
  304. local uid = data.trial_data.uid
  305. local airShipData = self:GetAirShipDataByUid(uid)
  306. if airShipData then
  307. airShipData:SetName(CommonUtil.GetVaildNickName(data.nick_name))
  308. end
  309. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.VOYAGE_CHECK_AIRSHIP_CHANGED, uid)
  310. end
  311. function VoyageDataMgr:OnVoyageChallengeAck(data)
  312. LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_CHALLENGE_ACK " .. Inspect(data))
  313. if ManagerContainer.NetManager:IsErrorData(data) then
  314. return
  315. end
  316. local actorSystem = CreateActorSystem:new()
  317. actorSystem:ParseFightRoleInfo(data.fight_info)
  318. self:EnterBattle(data.challenge_uid, data.challenge_uid_end_time, actorSystem)
  319. end
  320. function VoyageDataMgr:OnVoyageChallengeResultAck(data)
  321. LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_CHALLENGE_RESULT_ACK " .. Inspect(data))
  322. if ManagerContainer.NetManager:IsErrorData(data) then
  323. self.lastBattleRewards = nil
  324. return
  325. end
  326. local rewards = {}
  327. local rewardLs = data.reward_list
  328. if rewardLs then
  329. for i = 1, #rewardLs do
  330. local rewardData = rewardLs[i]
  331. rewards[#rewards + 1] = {rewardData.key, rewardData.value}
  332. end
  333. end
  334. self.lastBattleRewards = rewards
  335. self.lastBattleScores = {data.old_score, data.new_score}
  336. if self.waitChallengeResultTimer then
  337. self.waitChallengeResultTimer:Stop()
  338. self.waitChallengeResultTimer = nil
  339. end
  340. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.DOJO_CHALLENGE_RESULT_CHANGED)
  341. end
  342. function VoyageDataMgr:OnVoyageRankDatasAck(data)
  343. LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_RANK_LIST_ACK " .. Inspect(data))
  344. if ManagerContainer.NetManager:IsErrorData(data) then
  345. LogError("=== SC_CROSS_YUAN_HANG_TRIAL_RANK_LIST_ACK Error " .. Inspect(data))
  346. return
  347. end
  348. self.selfRank = data.self_rank
  349. self.selfScore = data.self_score
  350. local rankDatas = self.rankDatas
  351. if not rankDatas then
  352. rankDatas = {}
  353. self.rankDatas = rankDatas
  354. end
  355. local rankLs = data.rank_list
  356. local rank = nil
  357. for i = 1, #rankLs do
  358. rank = rankLs[i]
  359. rankDatas[rank.rank] = {
  360. rank = rank.rank,
  361. playerBrief = ProtocalDataNormal.ParsePlayerBriefInfo(rank.brief_info),
  362. score = rank.score
  363. }
  364. end
  365. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.VOYAGE_RANK_CHANGED)
  366. end
  367. function VoyageDataMgr:OnVoyageLogAck(data)
  368. -- LogError("[wboy] SC_CROSS_YUAN_HANG_TRIAL_LOG_ACK " .. Inspect(data))
  369. if ManagerContainer.NetManager:IsErrorData(data) then
  370. return
  371. end
  372. if not self.logsData then
  373. self.logsData = CommonLogData:new()
  374. end
  375. local changed, startChanged, endChanged = self.logsData:SetLogs(data.log_list, data.is_end)
  376. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.VOYAGE_LOG_CHANGED, changed, startChanged, endChanged)
  377. end
  378. function VoyageDataMgr:SendKeepVoyageReq(isNew)
  379. -- if not self:IsCanSend(1) then
  380. -- return false
  381. -- end
  382. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_VIEW_LIST_REQ, { notify = (not isNew) })
  383. -- return true
  384. end
  385. function VoyageDataMgr:SendExitVoyageReq()
  386. -- if not self:IsCanSend(2) then
  387. -- return false
  388. -- end
  389. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_VIEW_LIST_OUT_REQ)
  390. -- return true
  391. end
  392. function VoyageDataMgr:SendRefreshAirShipReq(upHighest)
  393. if not self:IsCanSend(3) then
  394. return false
  395. end
  396. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_REFRESH_TRIAL_TYPE_REQ, {force = upHighest})
  397. return true
  398. end
  399. function VoyageDataMgr:SendTakeOffAirShipReq()
  400. if not self:IsCanSend(4) then
  401. return false
  402. end
  403. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_REQ)
  404. return true
  405. end
  406. function VoyageDataMgr:SendGetRewardReq()
  407. if not self:IsCanSend(5) then
  408. return false
  409. end
  410. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_REWARD_REQ)
  411. return true
  412. end
  413. function VoyageDataMgr:SendCheckInfoReq(uid, endTime)
  414. if not self:IsCanSend(6) then
  415. return false
  416. end
  417. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_INFO_REQ, { trial_uid = uid, trial_end_time = endTime })
  418. return true
  419. end
  420. function VoyageDataMgr:SendChallengeReq(uid, endTime)
  421. if not self:IsCanSend(7) then
  422. return false
  423. end
  424. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_CHALLENGE_REQ, {challenge_uid = uid, challenge_uid_end_time = endTime})
  425. return true
  426. end
  427. function VoyageDataMgr:SendChallengeResultReq(uid, endTime, fightTime, isWin)
  428. if not self:IsCanSend(8) then
  429. return false
  430. end
  431. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_CHALLENGE_RESULT_REQ, {challenge_uid = uid, challenge_uid_end_time = endTime, fight_time = fightTime, win = isWin})
  432. return true
  433. end
  434. function VoyageDataMgr:SendGetVoyageRankDatasReq(startIdx)
  435. if not self:IsCanSend(9) then
  436. return false
  437. end
  438. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_RANK_LIST_REQ, { start_idx = startIdx })
  439. return true
  440. end
  441. function VoyageDataMgr:SendLogReq(logTime)
  442. if not self:IsCanSend(10) then
  443. return false
  444. end
  445. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CROSS_YUAN_HANG_TRIAL_LOG_REQ, { log_time = logTime })
  446. return true
  447. end
  448. function VoyageDataMgr:GetChallengeNum()
  449. return self.challengeNum
  450. end
  451. function VoyageDataMgr:GetVoyageNum()
  452. return self.voyageNum
  453. end
  454. function VoyageDataMgr:GetRpStatus()
  455. return self.rpStatus
  456. end
  457. function VoyageDataMgr:SetRpStatus(status)
  458. if self.rpStatus == status then
  459. return
  460. end
  461. self.rpStatus = status
  462. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.VoyageCanChallage, status)
  463. end
  464. function VoyageDataMgr:GetCurAirShipId()
  465. return self.curAirShipId
  466. end
  467. function VoyageDataMgr:GetNotifyAirShipUpTip()
  468. return self.notifyAirShipUpTip
  469. end
  470. function VoyageDataMgr:SetNotifyAirShipUpTip(status)
  471. if self.notifyAirShipUpTip == status then
  472. return false
  473. end
  474. self.notifyAirShipUpTip = status
  475. return true
  476. end
  477. function VoyageDataMgr:GetRefreshAirShipResult()
  478. return self.refreshAirShipResult
  479. end
  480. function VoyageDataMgr:GetSelfAirShipData()
  481. return self.selfAirShipData
  482. end
  483. function VoyageDataMgr:SetKeepVoyageState(status)
  484. if self.keepVoyageing == status then
  485. return
  486. end
  487. self.keepVoyageing = status
  488. if status then
  489. if self.exitVoyageTimer then
  490. self.exitVoyageTimer:Stop()
  491. self.exitVoyageTimer = nil
  492. else
  493. self:SendKeepVoyageReq(true)
  494. self:ClearViewListData()
  495. end
  496. if not self.keepVoyageTimer then
  497. self.keepVoyageTimer = Timer.New(slot(self.SendKeepVoyageReq, self), 300, -1)
  498. else
  499. self.keepVoyageTimer.time = 300
  500. end
  501. if not self.keepVoyageTimer.running then
  502. self.keepVoyageTimer:Start()
  503. end
  504. else
  505. if self.keepVoyageTimer then
  506. self.keepVoyageTimer:Stop()
  507. self.keepVoyageTimer = nil
  508. end
  509. if not self.exitVoyageTimer then
  510. self.exitVoyageTimer = Timer.New(slot(self.ExitVoyage, self), 5, -1)
  511. else
  512. self.exitVoyageTimer.time = 5
  513. end
  514. if not self.exitVoyageTimer.running then
  515. self.exitVoyageTimer:Start()
  516. end
  517. end
  518. end
  519. function VoyageDataMgr:ExitVoyage()
  520. self:SendExitVoyageReq()
  521. self:ClearViewListData()
  522. self:ClearLogData()
  523. end
  524. function VoyageDataMgr:GetAirShipDatas()
  525. return self.airShipDatas
  526. end
  527. function VoyageDataMgr:GetAirShipDataByUid(uid)
  528. return self.airShipDataMap[uid]
  529. end
  530. function VoyageDataMgr:ClearViewListData()
  531. if self.keepVoyageTimer then
  532. self.keepVoyageTimer:Stop()
  533. end
  534. self.keepVoyageTimer = nil
  535. if self.exitVoyageTimer then
  536. self.exitVoyageTimer:Stop()
  537. end
  538. self.exitVoyageTimer = nil
  539. self.airShipDatas = {}
  540. self.airShipDataMap = {}
  541. end
  542. function VoyageDataMgr:DisposeViewListData()
  543. if self.keepVoyageTimer then
  544. self.keepVoyageTimer:Stop()
  545. end
  546. self.keepVoyageTimer = nil
  547. if self.exitVoyageTimer then
  548. self.exitVoyageTimer:Stop()
  549. end
  550. self.exitVoyageTimer = nil
  551. self.airShipDatas = nil
  552. self.airShipDataMap = nil
  553. end
  554. function VoyageDataMgr:GetSelfRank()
  555. return self.selfRank
  556. end
  557. function VoyageDataMgr:GetSelfScore()
  558. return self.selfScore
  559. end
  560. function VoyageDataMgr:GetRankDatas()
  561. return self.rankDatas
  562. end
  563. function VoyageDataMgr:ClearRankData()
  564. self.selfRank = nil
  565. self.selfScore = nil
  566. self.rankDatas = nil
  567. end
  568. function VoyageDataMgr:GetLogsData()
  569. return self.logsData
  570. end
  571. function VoyageDataMgr:ClearLogData()
  572. self.logsData = nil
  573. end
  574. ----------------------------------------- 战斗 -----------------------------------------
  575. function VoyageDataMgr:EnterBattle(attackUid, endTime, actorSystem)
  576. self:ClearLastAttackData()
  577. self.lastAttackUid = attackUid
  578. self.lastEndTime = endTime
  579. self.actorSystem = actorSystem
  580. ManagerContainer.LuaGameMgr:RefreshTeamData()
  581. self.matchFighterName = actorSystem:GetUserNickname()
  582. self.enemyActors = {}
  583. if actorSystem:GetPlayerActorParam() ~= nil then
  584. self.enemyActors[#self.enemyActors+1] = actorSystem:GetPlayerActorParam()
  585. end
  586. local fellowActors = actorSystem:GetFellowActorParam()
  587. if fellowActors ~= nil then
  588. for k,actor in pairs(fellowActors) do
  589. self.enemyActors[#self.enemyActors +1] = actor
  590. end
  591. end
  592. self.ourMembers = {}
  593. local actorData = ManagerContainer.LuaActorDataMgr:GetActorData(true, ManagerContainer.DataMgr.UserData:GetId())
  594. if actorData then
  595. self.ourMembers[#self.ourMembers + 1] = actorData
  596. end
  597. local list = ManagerContainer.DataMgr.PartnerData:GetPartnerDatas()
  598. if list ~= nil then
  599. for _,v in pairs(list) do
  600. if v.owned and v.isBattle then
  601. actorData = ManagerContainer.LuaActorDataMgr:GetActorData(false, v.configId)
  602. if actorData then
  603. self.ourMembers[#self.ourMembers + 1] = actorData
  604. end
  605. end
  606. end
  607. end
  608. local selfMaskDatas = nil
  609. local enemyPvPVal = actorSystem:GetSkillPvPVal()
  610. local OurPvPVal = ManagerContainer.DataMgr.UserData:GetCurrRoleSkillPress()
  611. local IsPresspoint,BuffId = ManagerContainer.CfgMgr:GetPresspointPvPCfg(OurPvPVal,enemyPvPVal)
  612. if BuffId > -1 then
  613. selfMaskDatas = {}
  614. selfMaskDatas[1] = GvGMark.New(BuffId, 1)
  615. end
  616. local limitedTime = self:GetLimitedTime()
  617. local battleEndCondList = System.Array.CreateInstance(Enum.TypeInfo.BattleEndCondition, 2)
  618. battleEndCondList[0] = BattleEndCondition.New(Constants.EndBattle_By_UndeadCount, Constants.ResultType_Normal)
  619. battleEndCondList[1] = BattleEndCondition.New(Constants.EndBattle_By_BattleTime, limitedTime, Constants.ResultType_Normal, false)
  620. ManagerContainer.LuaGameMgr:EnterVoyageBattle('scenes_test_pvp', self.ourMembers, self.enemyActors, limitedTime,selfMaskDatas,IsPresspoint,OurPvPVal+enemyPvPVal, battleEndCondList)
  621. end
  622. function VoyageDataMgr:BattleEnd(result)
  623. local battleTime = LuaBattleBridge.GetFightingTime()
  624. if battleTime < 0 then
  625. battleTime = 0
  626. else
  627. battleTime = Mathf.Ceil(battleTime)
  628. end
  629. self.lastBattleWin = result
  630. local isWin = (result == 1)
  631. if isWin then
  632. self:SendChallengeResultReq(self.lastAttackUid, self.lastEndTime, battleTime, isWin)
  633. if self.waitChallengeResultTimer then
  634. self.waitChallengeResultTimer.time = 5
  635. self.waitChallengeResultTimer.loop = 1
  636. else
  637. self.waitChallengeResultTimer = Timer.New(slot(self.ForceExitBattle, self), 5, 1)
  638. end
  639. if not self.waitChallengeResultTimer.running then
  640. self.waitChallengeResultTimer:Start()
  641. end
  642. end
  643. self.actorSystem = nil
  644. self.matchFighterName = nil
  645. self.enemyActors = nil
  646. self.ourMembers = nil
  647. end
  648. function VoyageDataMgr:ForceExitBattle()
  649. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.DOJO_CHALLENGE_RESULT_CHANGED)
  650. end
  651. function VoyageDataMgr:GetMatchFighterName()
  652. return self.matchFighterName
  653. end
  654. function VoyageDataMgr:GetOurMembers()
  655. return self.ourMembers
  656. end
  657. function VoyageDataMgr:GetEnemyMembers()
  658. return self.enemyActors
  659. end
  660. function VoyageDataMgr:GetLimitedTime()
  661. return GlobalConfig.Instance:GetConfigIntValue(251)
  662. end
  663. function VoyageDataMgr:GetLastAttackUid()
  664. return self.lastAttackUid
  665. end
  666. function VoyageDataMgr:GetLastBattleRewards()
  667. return self.lastBattleRewards
  668. end
  669. function VoyageDataMgr:GetLastBattleScores()
  670. return self.lastBattleScores
  671. end
  672. function VoyageDataMgr:GetLastBattleWin()
  673. return self.lastBattleWin
  674. end
  675. function VoyageDataMgr:ClearLastAttackData()
  676. self.lastAttackUid = nil
  677. self.lastEndTime = nil
  678. self.lastBattleRewards = nil
  679. self.lastBattleScores = nil
  680. self.lastBattleWin = nil
  681. if self.waitChallengeResultTimer then
  682. self.waitChallengeResultTimer:Stop()
  683. self.waitChallengeResultTimer = nil
  684. end
  685. end
  686. return VoyageDataMgr