Count_1.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Count = class()
  2. local this = Count
  3. function this:ctor(t)
  4. if t == nil then
  5. self.type = 0
  6. self.key = 0
  7. self.count = 0
  8. self.updateTime = 0
  9. self.total = 0
  10. self.totalUpdateTime = 0
  11. else
  12. self.type = t.type
  13. self.key = t.key
  14. self.count = t.count
  15. self.updateTime = t.updateTime
  16. self.total = t.total
  17. self.totalUpdateTime = t.totalUpdateTime
  18. end
  19. end
  20. function this:canAdd(add)
  21. if self.type == 0 then
  22. return true
  23. end
  24. local count = self.count + add
  25. if count > self.total then
  26. return false
  27. end
  28. return true
  29. end
  30. function this:countNum(actor, add)
  31. local now = getbaseinfo("nowsec")
  32. local oldCount = self.count
  33. local oldTime = self.updateTime
  34. self.count = self.count + add
  35. self.updateTime = now
  36. LogManager.log(actor, LogOpType.COUNT, "key:" ..self.key.. " countNum oldCount:" .. oldCount .. " add:" .. add .. " oldTime:" .. oldTime)
  37. -- info("玩家", actor, "计数计数数据", "oldCount", oldCount, "add", add, "oldTime", oldTime, "当前数据", self)
  38. return self.count
  39. end
  40. function this:canRefreshTotal(now)
  41. return false
  42. end
  43. function this:refreshTotal(now)
  44. return false
  45. end
  46. function this:canResetCount(now)
  47. if self.type == 1 or self.type == 7 then
  48. return false
  49. elseif self.type == 2 and (not TimeUtil.isSameMonth(self.updateTime, now)) then
  50. return true
  51. elseif self.type == 3 and (not TimeUtil.isSameWeek(self.updateTime, now)) then
  52. return true
  53. elseif self.type == 4 and (not TimeUtil.isSameDay(self.updateTime, now)) then
  54. return true
  55. elseif self.type == 5 and (TimeUtil.diffDays(self.updateTime, now) >= 7) then
  56. return true
  57. elseif self.type == 6 and (TimeUtil.diffDays(self.updateTime, now) >= 30) then
  58. return true
  59. elseif self.type == 8 and (TimeUtil.diffDays(self.updateTime, now) >= 30) then
  60. return true
  61. end
  62. return false
  63. end
  64. function this:reset(actor, now)
  65. local oldCount = self.count
  66. local oldTime = self.updateTime
  67. self.count = 0
  68. self.updateTime = now
  69. LogManager.log(actor, LogOpType.COUNT, "key:" ..self.key.. " resetCount oldCount:" .. oldCount .. " oldTime:" .. oldTime)
  70. -- info("玩家", actor, "重置计数数据", "oldCount", oldCount, "oldTime", oldTime, "当前数据", self)
  71. end
  72. function this:toBuilder()
  73. return {
  74. ["key"] = self.key,
  75. ["count"] = self.count,
  76. ["total"] = self.total
  77. }
  78. end