LoginSignLogic.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. --每日签到
  2. local Util = require("common.Util")
  3. local Msg = require("core.Msg")
  4. local ObjHuman = require("core.ObjHuman")
  5. local LoginSignExcel = require("excel.loginSign")
  6. local ItemExcel = require("excel.item")
  7. local BagLogic = require("bag.BagLogic")
  8. local Grid = require("bag.Grid")
  9. local YunYingLogic = require("yunying.YunYingLogic")
  10. local PanelDefine = require("broadcast.PanelDefine")
  11. local GuideLogic = require("guide.GuideLogic")
  12. SIGN_DAY = 31
  13. STATUS_TYPE1 = 1 -- 已签到可领取
  14. STATUS_TYPE2 = 2 -- 可以充值签到
  15. STATUS_TYPE3 = 3 -- 充值后可领取
  16. STATUS_TYPE4 = 4 -- 不能领取
  17. function updateGM(human, day)
  18. local now = os.time()
  19. human.db.signIn = {startTime = now,upTime = now,status = {},cnt = 1}
  20. human.db.signIn.startTime = human.db.signIn.startTime - 24 * 60 * 60 * day
  21. human.db.signIn.cnt = day
  22. end
  23. local function checkDB(human)
  24. local now = os.time()
  25. human.db.signIn = human.db.signIn or {startTime = now,upTime = now,status = {},cnt = 1}
  26. local signInDB = human.db.signIn
  27. if not Util.isSameDay(signInDB.upTime) then
  28. signInDB.cnt = signInDB.cnt + 1
  29. signInDB.upTime = now
  30. print(" signInDB.cnt ", signInDB.cnt )
  31. if signInDB.cnt > SIGN_DAY then
  32. human.db.signIn = {startTime = now,upTime = now,status = {},cnt = 1}
  33. else
  34. print(" not signInDB.cnt ", signInDB.cnt )
  35. end
  36. end
  37. end
  38. local function checkBuy(human)
  39. if (human.db.topupAcountDaily or 0) > 0 then
  40. return 1
  41. else
  42. return 0
  43. end
  44. end
  45. local function getState(day,signInDB,buyToday)
  46. if signInDB.cnt < day then
  47. return 0
  48. end
  49. if not signInDB.status[day] then
  50. return STATUS_TYPE1
  51. end
  52. if signInDB.status[day] == 1 and buyToday ~= 1 and signInDB.cnt == day then
  53. return STATUS_TYPE2
  54. end
  55. if signInDB.status[day] == 1 and buyToday == 1 and signInDB.cnt == day then
  56. return STATUS_TYPE3
  57. end
  58. return STATUS_TYPE4
  59. end
  60. local function getConfig(human)
  61. return LoginSignExcel.firstMonth
  62. end
  63. function query(human)
  64. -- 初始化数据库数据
  65. checkDB(human)
  66. local signInDB = human.db.signIn
  67. local msgRet = Msg.gc.GC_LOGIN_SIGN_QUERY
  68. local now = os.time()
  69. local time = Util.getDayStartTime()
  70. msgRet.nextTime = time + 24 * 60 * 60 - now
  71. msgRet.curCnt = signInDB.cnt
  72. msgRet.maxCnt = SIGN_DAY
  73. msgRet.actID = 1
  74. local len = 0
  75. local buyToday = checkBuy(human)
  76. local config = getConfig(human)
  77. for k,v in ipairs(config) do
  78. len = len + 1
  79. local net = msgRet.list[len]
  80. net.state = getState(k,signInDB,buyToday)
  81. Grid.makeItem(net.item,v.rewardID,v.cnt)
  82. end
  83. msgRet.list[0] = len
  84. Msg.send(msgRet,human.fd)
  85. end
  86. -- 发放物品
  87. function getReward(human,day)
  88. checkDB(human)
  89. local signInDB = human.db.signIn
  90. local buyToday = checkBuy(human)
  91. local state = getState(day,signInDB,buyToday)
  92. if state == 0 or state == STATUS_TYPE4 or state == STATUS_TYPE2 then
  93. return
  94. end
  95. local config = getConfig(human)
  96. local itemID = nil
  97. local itemCnt = nil
  98. itemID = config[day].rewardID
  99. itemCnt = config[day].cnt
  100. -- 改db
  101. signInDB.status[day] = signInDB.status[day] or 0
  102. signInDB.status[day] = signInDB.status[day] + 1
  103. BagLogic.cleanMomentItemList()
  104. BagLogic.updateMomentItem(1, itemID, itemCnt)
  105. BagLogic.addMomentItemList(human, "signInReward")
  106. query(human)
  107. for k, v in pairs(funcID) do
  108. YunYingLogic.updateIcon(YYInfo[k], human)
  109. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3502)
  110. break
  111. end
  112. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_LOGINSIGN)
  113. end
  114. function isRed(human)
  115. checkDB(human)
  116. local signInDB = human.db.signIn
  117. local buyToday = checkBuy(human)
  118. local config = getConfig(human)
  119. for k,v in ipairs(config) do
  120. local state = getState(k,signInDB,buyToday)
  121. if state == STATUS_TYPE1 or state == STATUS_TYPE3 then
  122. return true
  123. end
  124. end
  125. end
  126. function chargeAfter(human)
  127. for k, v in pairs(funcID) do
  128. YunYingLogic.updateIcon(YYInfo[k], human)
  129. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3502)
  130. break
  131. end
  132. end