EveryDayPrayLogic.lua 5.1 KB

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