SingleReachLogic.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. --[[
  2. absAct[id] = {
  3. reward[id] = {
  4. state = 1
  5. cnt = 0
  6. getCnt = 0
  7. }
  8. }
  9. ]]
  10. local AbsActLogic = require("absAct.AbsActLogic")
  11. local AbsActExcel = require("excel.absAct")
  12. local BuyExcel = require("excel.buy")
  13. local Util = require("common.Util")
  14. local Msg = require("core.Msg")
  15. local Grid = require("bag.Grid")
  16. local BagLogic = require("bag.BagLogic")
  17. local BuyLogic = require("topup.BuyLogic")
  18. local ObjHuman = require("core.ObjHuman")
  19. local Lang = require("common.Lang")
  20. local Broadcast = require("broadcast.Broadcast")
  21. local YunYingLogic = require("yunying.YunYingLogic")
  22. function isOpen(human, YYInfo, funcConfig)
  23. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  24. if not state then return end
  25. local absAct = human.db.absAct[funcConfig.funcID]
  26. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  27. return false
  28. end
  29. return true, endTime, startTime
  30. end
  31. function isActive(human, YYInfo, funcConfig)
  32. return not isOpen(human, YYInfo, funcConfig)
  33. end
  34. local function fontDabiaoNet(db,net,config,id)
  35. net.id = id
  36. net.limitCnt = config.maxCnt
  37. net.state = 0
  38. net.nowCnt = 0
  39. if db.reward and db.reward[id] then
  40. net.state = db.reward[id].state or 0
  41. net.nowCnt = db.reward[id].cnt or 0
  42. end
  43. net.desc = config.desc
  44. net.buyID = config.buyID
  45. local len = #config.item
  46. for i = 1,len do
  47. Grid.makeItem(net.item[i],config.item[i][1],config.item[i][2])
  48. end
  49. net.item[0] = len
  50. end
  51. function getAndSendMsg(human,id)
  52. -- 判断活动是否开起
  53. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  54. if not state then return end
  55. local absConfig = AbsActExcel.absActivity[id]
  56. if not absConfig then return end
  57. local absAct = human.db.absAct[id]
  58. if not absAct then
  59. return
  60. end
  61. local config = AbsActExcel.singleReach
  62. local msgRet = Msg.gc.GC_ABS_XS_SINGLE_REACH_QUERY
  63. local len = #config
  64. local count = 0
  65. for i = 1,len do
  66. local v = config[i]
  67. if v.mainId == id and v.actId == absConfig.actId then
  68. count = count + 1
  69. local net = msgRet.dabiaoList[count]
  70. fontDabiaoNet(absAct,net,v,i)
  71. end
  72. end
  73. msgRet.dabiaoList[0] = count
  74. Msg.send(msgRet,human.fd)
  75. end
  76. function touchSingleReach(human,id,param)
  77. local absConfig = AbsActExcel.absActivity[id]
  78. if not absConfig then return end
  79. AbsActLogic.checkAbsActClean(human, id)
  80. local absAct = human.db.absAct[id]
  81. if not absAct then
  82. return
  83. end
  84. --增加钻石使用数量
  85. absAct.reward = absAct.reward or {}
  86. local config = AbsActExcel.singleReach
  87. local len = #config
  88. for i = 1,len do
  89. if config[i].actId == absConfig.actId and config[i].mainId == id then
  90. -- 判断钻石使用数量是否达标了
  91. absAct.reward[i] = absAct.reward[i] or {}
  92. absAct.reward[i].state = absAct.reward[i].state or 0
  93. absAct.reward[i].cnt = absAct.reward[i].cnt or 0
  94. absAct.reward[i].getCnt = absAct.reward[i].getCnt or 0
  95. if absAct.reward[i].state ~= 2 and param == config[i].buyID and (absAct.reward[i].cnt + absAct.reward[i].getCnt < config[i].maxCnt) then
  96. absAct.reward[i].state = 1
  97. absAct.reward[i].getCnt = absAct.reward[i].getCnt + 1
  98. end
  99. end
  100. end
  101. YunYingLogic.updateIcon(YYInfo[id], human)
  102. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  103. end
  104. function getSingleReachReward(human,id,giftId)
  105. -- 判断活动是否开启
  106. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  107. if not state then return end
  108. local absConfig = AbsActExcel.absActivity[id]
  109. if not absConfig then return end
  110. local absAct = human.db.absAct[id]
  111. if not absAct then
  112. return
  113. end
  114. -- 状态不为可领,返回
  115. absAct.reward = absAct.reward or {}
  116. if not absAct.reward[giftId] or absAct.reward[giftId].state ~= 1 or absAct.reward[giftId].getCnt <= 0 then
  117. return
  118. end
  119. local config = AbsActExcel.singleReach[giftId]
  120. if config.mainId ~= id or config.actId ~= absConfig.actId then
  121. return
  122. end
  123. -- 设置状态为已领取
  124. absAct.reward[giftId].state = 2
  125. absAct.reward[giftId].cnt = absAct.reward[giftId].cnt + 1
  126. absAct.reward[giftId].getCnt = absAct.reward[giftId].getCnt - 1
  127. if absAct.reward[giftId].getCnt > 0 and absAct.reward[giftId].cnt < config.maxCnt then
  128. absAct.reward[giftId].state = 1
  129. elseif absAct.reward[giftId].cnt < config.maxCnt then
  130. absAct.reward[giftId].state = 0
  131. end
  132. -- 发奖励
  133. BagLogic.addItemList(human, config.item, "abs_singleReach")
  134. getAndSendMsg(human,id)
  135. YunYingLogic.updateIcon(YYInfo[id], human)
  136. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  137. end
  138. function isRed(human, YYInfo, funcConfig)
  139. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  140. if not state then return end
  141. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  142. local absAct = human.db.absAct[funcConfig.funcID]
  143. if not absAct then return end
  144. absAct.reward = absAct.reward or {}
  145. for k,v in pairs(absAct.reward) do
  146. if v.state == 1 then
  147. return true
  148. end
  149. end
  150. return false
  151. end
  152. function updateDaily(human,id)
  153. -- 判断活动是否开启
  154. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  155. if not state then return end
  156. local absConfig = AbsActExcel.absActivity[id]
  157. if not absConfig then return end
  158. local absAct = human.db.absAct[id]
  159. if not absAct then
  160. return
  161. end
  162. absAct.reward = nil
  163. end