GuildWarBattleLogData.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. local GuildWarBattleLogData = class('GuildWarBattleLogData')
  2. local LogSort = function(a, b)
  3. return b.time < a.time
  4. end
  5. function GuildWarBattleLogData:ctor()
  6. self.logWhole = false
  7. self.logs = {}
  8. end
  9. function GuildWarBattleLogData:Clear()
  10. self.logWhole = false
  11. self.logs = {}
  12. end
  13. function GuildWarBattleLogData:Dispose()
  14. self.logWhole = nil
  15. self.logs = nil
  16. end
  17. ---@return boolean,boolean|nil,boolean|nil
  18. function GuildWarBattleLogData:SetLogs(logs, isEnd)
  19. local len = logs and #logs or 0
  20. if len <= 0 then
  21. isEnd = true
  22. end
  23. local addStart = false
  24. local add = false
  25. local addEnd = false
  26. if isEnd then
  27. if self.logWhole ~= isEnd then
  28. self.logWhole = isEnd
  29. addEnd = true
  30. end
  31. end
  32. if len <= 0 then return add, addStart, addEnd end
  33. if not self.logs then
  34. self.logs = {}
  35. end
  36. local exitLen = #self.logs
  37. local startTime = nil
  38. local endTime = nil
  39. if self.logs[1] then
  40. startTime = self.logs[1].time
  41. end
  42. if self.logs[exitLen] then
  43. endTime = self.logs[exitLen].time
  44. end
  45. for i = 1, len do
  46. local log = logs[i]
  47. local needAdd = true
  48. if startTime and int64.__lt(startTime, log.record_time) then
  49. addStart = true
  50. elseif endTime and int64.__lt(log.record_time, endTime) then
  51. addEnd = true
  52. else
  53. -- 这时候就需要查看是否列表中已存在
  54. for j = 1, exitLen do
  55. if int64.equals(self.logs[j].time, log.record_time) then
  56. needAdd = false
  57. break
  58. end
  59. end
  60. end
  61. if needAdd then
  62. add = true
  63. self.logs[#self.logs + 1] = {
  64. type = log.type,
  65. state = log.state,
  66. playerName = CommonUtil.GetVaildNickName(log.target_player_name),
  67. uid = log.target_player_uid,
  68. guildId = log.target_guild_id,
  69. areaId = log.pos_idx,
  70. time = log.record_time,
  71. challengePlayerName = CommonUtil.GetVaildNickName(log.challenge_player_name),
  72. challengeUid = log.challenge_player_uid,
  73. challengeGuildId = log.challenge_guild_id,
  74. winSteak = log.win_steak,
  75. }
  76. end
  77. end
  78. if add then
  79. table.sort(self.logs, LogSort)
  80. if #self.logs > 50 then
  81. for i = 51, #self.logs do
  82. self.logs[i] = nil
  83. end
  84. end
  85. end
  86. return add, addStart, addEnd
  87. end
  88. function GuildWarBattleLogData:GetReloadLogStartTime()
  89. return 0
  90. end
  91. function GuildWarBattleLogData:GetNextLoadLogStartTime()
  92. if self.logWhole then return nil end
  93. if self.logs then
  94. local log = self.logs[#self.logs]
  95. if log and log.time then
  96. return log.time
  97. end
  98. end
  99. return self:GetReloadLogStartTime()
  100. end
  101. function GuildWarBattleLogData:GetLogById(idx)
  102. if not self.logs then return nil end
  103. return self.logs[idx]
  104. end
  105. function GuildWarBattleLogData:GetLogs()
  106. return self.logs
  107. end
  108. function GuildWarBattleLogData:GetLogNum()
  109. if not self.logs then return 0 end
  110. return #self.logs
  111. end
  112. function GuildWarBattleLogData:GetLogWhole()
  113. return self.logWhole
  114. end
  115. return GuildWarBattleLogData