TotalReachLogic.lua 5.4 KB

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