EveryDayPrayLogic.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. local AbsActExcel = require("excel.absAct")
  2. local Lang = require("common.Lang")
  3. local Util = require("common.Util")
  4. local Msg = require("core.Msg")
  5. local Broadcast = require("broadcast.Broadcast")
  6. local Grid = require("bag.Grid")
  7. local BagLogic = require("bag.BagLogic")
  8. local ItemDefine = require("bag.ItemDefine")
  9. local AbsActDefine = require("absAct.AbsActDefine")
  10. local AbsActLogic = require("absAct.AbsActLogic")
  11. local YunYingLogic = require("yunying.YunYingLogic")
  12. local HeroGrid = require("hero.HeroGrid")
  13. local PanelDefine = require("broadcast.PanelDefine")
  14. local HeroDefine = require("hero.HeroDefine")
  15. --[[
  16. absAct.xlxs-everyDayPray
  17. 新英雄来袭-每日祈福
  18. DB:
  19. human.db.absAct[id] = {
  20. itemGet = xxx, -- 最后的奖励是否已领取 1已领 0 未领
  21. xxx = 1, -- 指定天数奖励是否领取了
  22. ...
  23. }
  24. public:
  25. getAndSendMsg() -- 发送活动数据
  26. isRed() -- 红点提醒
  27. isActive() -- 激活状态
  28. isOpen() -- 活动开启
  29. get() -- 领取奖励
  30. --]]
  31. function getAndSendMsg(human, id)
  32. local absConfig = AbsActExcel.absActivity[id]
  33. local config = AbsActExcel.everyDayPray[absConfig.actId]
  34. if not config then return end
  35. AbsActLogic.checkAbsActClean(human, id)
  36. local absAct = human.db.absAct[id]
  37. local msgRet = Msg.gc.GC_ABS_ACT_EVERY_DAY_PRAY_QUERY
  38. msgRet.openDay = Util.diffDay(absConfig.realStartTime) + 1
  39. local heroCnt = 0
  40. for k, v in ipairs(config.items) do
  41. Grid.makeItem(msgRet.items[k], v[1], v[2])
  42. if HeroDefine.isHero(v[1]) then
  43. heroCnt = heroCnt + 1
  44. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple[heroCnt], v[1])
  45. end
  46. end
  47. msgRet.itemGet = absAct.itemGet and 1 or 0
  48. msgRet.get[0] = 0
  49. for k, v in ipairs(config.loginReward) do
  50. Grid.makeItem(msgRet.login[k], v[1], v[2])
  51. if absAct[k] then
  52. msgRet.get[0] = msgRet.get[0] + 1
  53. msgRet.get[msgRet.get[0]] = k
  54. end
  55. end
  56. msgRet.heroSimple[0] = heroCnt
  57. msgRet.items[0] = #config.items
  58. msgRet.login[0] = #config.loginReward
  59. Msg.send(msgRet,human.fd)
  60. end
  61. function isRed(human, YYInfo, funcConfig)
  62. local state = AbsActLogic.isStarted(human, funcConfig.funcID)
  63. if not state then return end
  64. AbsActLogic.checkAbsActClean(human, funcConfig.funcID)
  65. local absAct = human.db.absAct[funcConfig.funcID]
  66. if not absAct then return end
  67. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  68. local config = AbsActExcel.everyDayPray[absConfig.actId]
  69. local day = Util.diffDay(absConfig.realStartTime) + 1
  70. day = day > #config.loginReward and #config.loginReward or day
  71. for i = 1, day do
  72. if not absAct[i] then
  73. return true
  74. end
  75. end
  76. if day >= #config.loginReward then
  77. if not absAct.itemGet then
  78. return true
  79. end
  80. end
  81. end
  82. function isActive(human, YYInfo, funcConfig)
  83. return not isOpen(human, YYInfo, funcConfig)
  84. end
  85. function isOpen(human, YYInfo, funcConfig)
  86. return AbsActLogic.isStarted(human, funcConfig.funcID)
  87. end
  88. function get(human, type, id, param)
  89. local state= AbsActLogic.isStarted(human, id)
  90. if not state then return end
  91. AbsActLogic.checkAbsActClean(human, id)
  92. local absAct = human.db.absAct[id]
  93. local absConfig = AbsActExcel.absActivity[id]
  94. local config = AbsActExcel.everyDayPray[absConfig.actId]
  95. if not config then return end
  96. local day = Util.diffDay(absConfig.realStartTime) + 1
  97. if type == 0 then
  98. day = day > #config.loginReward and #config.loginReward or day
  99. BagLogic.cleanMomentItemList()
  100. local len = 0
  101. for i = 1, day do
  102. if not absAct[i] then
  103. absAct[i] = 1
  104. len = len + 1
  105. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, config.loginReward[i][1], config.loginReward[i][2])
  106. end
  107. end
  108. if len > 0 then
  109. BagLogic.addMomentItemList(human, "abs_every_day_pray_get")
  110. end
  111. else
  112. if day < #config.loginReward then
  113. return
  114. end
  115. if absAct.itemGet then return end
  116. absAct.itemGet = 1
  117. BagLogic.cleanMomentItemList()
  118. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, config.items[param][1], config.items[param][2])
  119. BagLogic.addMomentItemList(human, "abs_every_day_pray_get")
  120. end
  121. getAndSendMsg(human, id)
  122. YunYingLogic.sendBanner(human)
  123. YunYingLogic.updateIcon(YYInfo[id], human)
  124. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_5011)
  125. end