VoyageDataMgr.lua 28 KB

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