UseDiamondLogic.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. --[[
  2. absAct[id] = {
  3. use = 1000
  4. count = 0
  5. reward[id] = {
  6. state = 1
  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 fontUseDiamondNet(net,absAct,id,v)
  35. net.id = id
  36. net.state = 1
  37. if absAct.reward[id] then
  38. net.state = absAct.reward[id]
  39. end
  40. net.needUse = v.needUse
  41. net.desc = v.desc
  42. net.nowUse = 0
  43. if absAct.use then
  44. net.nowUse = absAct.use
  45. end
  46. if v.special == 1 then
  47. net.nowUse = absAct.count or 0
  48. end
  49. local rewardLen = #v.item
  50. for j = 1,rewardLen do
  51. local itemID = v.item[j][1]
  52. local itemCnt = v.item[j][2]
  53. Grid.makeItem(net.item[j],itemID,itemCnt)
  54. end
  55. net.item[0] = rewardLen
  56. end
  57. function getAndSendMsg(human,id)
  58. -- 判断活动是否开启
  59. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  60. if not state then return end
  61. local absConfig = AbsActExcel.absActivity[id]
  62. if not absConfig then return end
  63. local absAct = human.db.absAct[id]
  64. if not absAct then
  65. return
  66. end
  67. absAct.reward = absAct.reward or {}
  68. local config = AbsActExcel.useDiamond
  69. local msgRet = Msg.gc.GC_ABS_HF_USE_DIAMOND_QUERY
  70. local len = #config
  71. local count = 0
  72. local cnt = 0
  73. for i = 1,len do
  74. if config[i].special == 1 then
  75. cnt = cnt + 1
  76. fontUseDiamondNet(msgRet.backReward[cnt],absAct,i,config[i])
  77. else
  78. count = count + 1
  79. fontUseDiamondNet(msgRet.useRewardList[count],absAct,i,config[i])
  80. end
  81. end
  82. msgRet.backReward[0] = cnt
  83. msgRet.useRewardList[0] = count
  84. Msg.send(msgRet,human.fd)
  85. end
  86. function onDecZuanshi(human,id,value)
  87. useDiamondBack(human,value,id)
  88. end
  89. function useDiamondBack(human,value,id)
  90. local absConfig = AbsActExcel.absActivity[id]
  91. if not absConfig then return end
  92. AbsActLogic.checkAbsActClean(human, id)
  93. local absAct = human.db.absAct[id]
  94. if not absAct then
  95. return
  96. end
  97. --增加钻石使用数量
  98. absAct.count = absAct.count or 0
  99. absAct.use = absAct.use or 0
  100. absAct.reward = absAct.reward or {}
  101. absAct.use = absAct.use + value
  102. local config = AbsActExcel.useDiamond
  103. local len = #config
  104. for i = 1,len do
  105. if config[i].special ~= 1 then
  106. -- 判断钻石使用数量是否达标了
  107. if not absAct.reward[i] and absAct.use >= config[i].needUse then
  108. absAct.reward[i] = 0
  109. -- 达标,则增加任务完成数量
  110. absAct.count = absAct.count + 10
  111. end
  112. else
  113. -- 判断任务完成数量是否达标
  114. if not absAct.reward[i] and absAct.count >= config[i].needUse then
  115. absAct.reward[i] = 0
  116. end
  117. end
  118. end
  119. YunYingLogic.sendBanner(human)
  120. YunYingLogic.updateIcon(YYInfo[id], human)
  121. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  122. end
  123. function getUseDiamondReward(human,id,giftId)
  124. -- 判断活动是否开启
  125. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  126. if not state then return end
  127. local absConfig = AbsActExcel.absActivity[id]
  128. if not absConfig then return end
  129. local absAct = human.db.absAct[id]
  130. if not absAct then
  131. return
  132. end
  133. -- 状态不为可领,返回
  134. absAct.reward = absAct.reward or {}
  135. if absAct.reward[giftId] ~= 0 then
  136. return
  137. end
  138. -- 设置状态为已领取
  139. absAct.reward[giftId] = 2
  140. -- 发奖励
  141. local config = AbsActExcel.useDiamond[giftId]
  142. BagLogic.addItemList(human, config.item, "abs_useDiamond")
  143. getAndSendMsg(human,id)
  144. YunYingLogic.sendBanner(human)
  145. YunYingLogic.updateIcon(YYInfo[id], human)
  146. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  147. end
  148. function isRed(human, YYInfo, funcConfig)
  149. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  150. if not state then return end
  151. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  152. AbsActLogic.checkAbsActClean(human, funcConfig.funcID)
  153. local absAct = human.db.absAct[funcConfig.funcID]
  154. if not absAct then return end
  155. absAct.reward = absAct.reward or {}
  156. for k,v in pairs(absAct.reward) do
  157. if v == 0 then
  158. return true
  159. end
  160. end
  161. return false
  162. end