TotalReachLogic.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. local MailExcel = require("excel.mail")
  22. local MailManager = require("mail.MailManager")
  23. TOTAL_REACH_TYPE_1 = 1 -- 高抽
  24. TOTAL_REACH_TYPE_2 = 2 -- 充值
  25. TOTAL_REACH_TYPE_3 = 3 -- 天命召唤
  26. TOTAL_REACH_TYPE_4 = 4 -- 钻石消耗
  27. local ActivityCleanMailId = 8001
  28. function isOpen(human, YYInfo, funcConfig)
  29. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  30. if not state then return end
  31. local absAct = human.db.absAct[funcConfig.funcID]
  32. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  33. return false
  34. end
  35. return true, endTime, startTime
  36. end
  37. function isActive(human, YYInfo, funcConfig)
  38. return not isOpen(human, YYInfo, funcConfig)
  39. end
  40. local function fontDabiaoNet(db,net,config,id)
  41. net.id = id
  42. net.needCnt = config.needCnt
  43. net.desc = Util.format(config.desc, config.needCnt)
  44. net.state = db.reward and (db.reward[id] or 0) or 0
  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.totalReach
  62. local msgRet = Msg.gc.GC_ABS_XS_REACH_QUERY
  63. msgRet.nowCnt = absAct.count or 0
  64. local len = #config
  65. local count = 0
  66. for i = 1,len do
  67. local v = config[i]
  68. if v.mainId == id then
  69. count = count + 1
  70. local net = msgRet.dabiaoList[count]
  71. fontDabiaoNet(absAct,net,v,i)
  72. end
  73. end
  74. msgRet.dabiaoList[0] = count
  75. Msg.send(msgRet,human.fd)
  76. end
  77. -- �߳�
  78. function onDrawCard(human,funcID, parameter)
  79. changeReach(human,funcID,TOTAL_REACH_TYPE_1,parameter)
  80. end
  81. -- ����
  82. function onTMDrawCard(human,funcID, parameter)
  83. changeReach(human,funcID,TOTAL_REACH_TYPE_3,parameter)
  84. end
  85. -- ��ֵ
  86. function onCharge(human, parameter,funcID)
  87. changeReach(human,funcID,TOTAL_REACH_TYPE_2,parameter)
  88. end
  89. -- ������ʯ
  90. function onDecZuanshi(human,funcID,parameter)
  91. changeReach(human,funcID,TOTAL_REACH_TYPE_4,parameter)
  92. end
  93. function changeReach(human,id,type,param)
  94. local absConfig = AbsActExcel.absActivity[id]
  95. if not absConfig then return end
  96. if type ~= absConfig.param[1] then
  97. return
  98. end
  99. AbsActLogic.checkAbsActClean(human, id)
  100. local absAct = human.db.absAct[id]
  101. if not absAct then
  102. return
  103. end
  104. --��������
  105. absAct.count = absAct.count or 0
  106. absAct.count = absAct.count + param
  107. absAct.reward = absAct.reward or {}
  108. local config = AbsActExcel.totalReach
  109. local len = #config
  110. for i = 1,len do
  111. if config[i].mainId == id then
  112. -- �ж������Ƿ�����
  113. if not absAct.reward[i] and absAct.count >= config[i].needCnt then
  114. absAct.reward[i] = 1
  115. end
  116. end
  117. end
  118. YunYingLogic.updateIcon(YYInfo[id], human)
  119. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  120. end
  121. function getTotalReachReward(human,id,giftId)
  122. -- �жϻ�Ƿ���
  123. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  124. if not state then return end
  125. local absConfig = AbsActExcel.absActivity[id]
  126. if not absConfig then return end
  127. AbsActLogic.checkAbsActClean(human, id)
  128. local absAct = human.db.absAct[id]
  129. if not absAct then
  130. return
  131. end
  132. local config = AbsActExcel.totalReach[giftId]
  133. if config.mainId ~= id then
  134. return
  135. end
  136. -- ״̬��Ϊ���죬����
  137. absAct.reward = absAct.reward or {}
  138. if absAct.reward[giftId] ~= 1 then
  139. return
  140. end
  141. -- ����״̬Ϊ����ȡ
  142. absAct.reward[giftId] = 2
  143. -- ������
  144. BagLogic.addItemList(human, config.item, "abs_totalReach")
  145. getAndSendMsg(human,id)
  146. YunYingLogic.updateIcon(YYInfo[id], human)
  147. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  148. end
  149. function isRed(human, YYInfo, funcConfig)
  150. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  151. if not state then return end
  152. local absConfig = AbsActExcel.absActivity[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 == 1 then
  158. return true
  159. end
  160. end
  161. return false
  162. end
  163. -- 活动过期相关处理
  164. function clean(human,id)
  165. local config = AbsActExcel.absActivity[id]
  166. local mailCfg = MailExcel.mail[ActivityCleanMailId]
  167. local items = {}
  168. local absAct = human.db.absAct[id]
  169. local reachCfg = AbsActExcel.totalReach
  170. for idx,state in pairs(absAct.reward) do
  171. if state == 1 then
  172. for _,item in pairs(reachCfg[idx].item) do
  173. items[#items + 1] = item
  174. end
  175. end
  176. end
  177. -- 处理充值相关
  178. if config.param[1] == TOTAL_REACH_TYPE_2 then
  179. MailManager.add(1, human.db._id, mailCfg.title, mailCfg.content, items, mailCfg.senderName)
  180. end
  181. end