VoyageDataMgr.lua 26 KB

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