TotalReachLogic.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. local AbsActDefine = require("absAct.AbsActDefine")
  24. TOTAL_REACH_TYPE_1 = 1 -- 高抽
  25. TOTAL_REACH_TYPE_2 = 2 -- 充值
  26. TOTAL_REACH_TYPE_3 = 3 -- 天命召唤
  27. TOTAL_REACH_TYPE_4 = 4 -- 钻石消耗
  28. local ActivityCleanMailId = 8001
  29. --[[
  30. datastruct = {
  31. [id] = { -- 活动id
  32. type = AbsActDefine.ABS_ACT_TYPE_71
  33. reward = map[idx]state -- idx对应状态
  34. count = number -- 进度
  35. }
  36. }
  37. ]]
  38. function genAbsActData()
  39. return {
  40. type = AbsActDefine.ABS_ACT_TYPE_71,
  41. reward = {},
  42. count = 0,
  43. }
  44. end
  45. function isOpen(human, YYInfo, funcConfig)
  46. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  47. if not state then return end
  48. local absAct = human.db.absAct[funcConfig.funcID]
  49. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  50. return false
  51. end
  52. return true, endTime, startTime
  53. end
  54. function isActive(human, YYInfo, funcConfig)
  55. return not isOpen(human, YYInfo, funcConfig)
  56. end
  57. local function fontDabiaoNet(db,net,config,id)
  58. net.id = id
  59. net.needCnt = config.needCnt
  60. net.desc = Util.format(config.desc, config.needCnt)
  61. net.state = db.reward and (db.reward[id] or 0) or 0
  62. local len = #config.item
  63. for i = 1,len do
  64. Grid.makeItem(net.item[i],config.item[i][1],config.item[i][2])
  65. end
  66. net.item[0] = len
  67. end
  68. function getAndSendMsg(human,id)
  69. -- �жϻ�Ƿ���
  70. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  71. if not state then return end
  72. local absConfig = AbsActExcel.absActivity[id]
  73. if not absConfig then return end
  74. local absAct = human.db.absAct[id]
  75. if not absAct then
  76. return
  77. end
  78. local config = AbsActExcel.totalReach
  79. local msgRet = Msg.gc.GC_ABS_XS_REACH_QUERY
  80. msgRet.nowCnt = absAct.count or 0
  81. local len = #config
  82. local count = 0
  83. for i = 1,len do
  84. local v = config[i]
  85. if v.mainId == id then
  86. count = count + 1
  87. local net = msgRet.dabiaoList[count]
  88. fontDabiaoNet(absAct,net,v,i)
  89. end
  90. end
  91. msgRet.dabiaoList[0] = count
  92. Msg.send(msgRet,human.fd)
  93. end
  94. -- �߳�
  95. function onDrawCard(human,funcID, parameter)
  96. changeReach(human,funcID,TOTAL_REACH_TYPE_1,parameter)
  97. end
  98. -- ����
  99. function onTMDrawCard(human,funcID, parameter)
  100. changeReach(human,funcID,TOTAL_REACH_TYPE_3,parameter)
  101. end
  102. -- ��ֵ
  103. function onCharge(human, parameter,funcID)
  104. changeReach(human,funcID,TOTAL_REACH_TYPE_2,parameter)
  105. end
  106. -- ������ʯ
  107. function onDecZuanshi(human,funcID,parameter)
  108. changeReach(human,funcID,TOTAL_REACH_TYPE_4,parameter)
  109. -- 检测活动那些是关注钻石相关的
  110. --[[local absAct = human.db.absAct
  111. local absActConfig = AbsActExcel.absActivity
  112. for id,data in pairs(absAct) do
  113. -- 确保是累计活动 并且类型是钻石
  114. if data.type == AbsActDefine.ABS_ACT_TYPE_71 and absActConfig[id].param[1] == TOTAL_REACH_TYPE_4 then
  115. changeReach(human,funcID,TOTAL_REACH_TYPE_4,parameter)
  116. end
  117. end]]
  118. end
  119. function changeReach(human,id,type,param)
  120. local absConfig = AbsActExcel.absActivity[id]
  121. if not absConfig then return end
  122. if type ~= absConfig.param[1] then
  123. return
  124. end
  125. AbsActLogic.checkAbsActClean(human, id)
  126. local absAct = human.db.absAct[id]
  127. if not absAct then
  128. return
  129. end
  130. --��������
  131. absAct.count = absAct.count or 0
  132. absAct.count = absAct.count + param
  133. absAct.reward = absAct.reward or {}
  134. local config = AbsActExcel.totalReach
  135. local len = #config
  136. for i = 1,len do
  137. if config[i].mainId == id then
  138. -- �ж������Ƿ�����
  139. if not absAct.reward[i] and absAct.count >= config[i].needCnt then
  140. absAct.reward[i] = 1
  141. end
  142. end
  143. end
  144. YunYingLogic.updateIcon(YYInfo[id], human)
  145. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  146. end
  147. function getTotalReachReward(human,id,giftId)
  148. -- �жϻ�Ƿ���
  149. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  150. if not state then return end
  151. local absConfig = AbsActExcel.absActivity[id]
  152. if not absConfig then return end
  153. AbsActLogic.checkAbsActClean(human, id)
  154. local absAct = human.db.absAct[id]
  155. if not absAct then
  156. return
  157. end
  158. local config = AbsActExcel.totalReach[giftId]
  159. if config.mainId ~= id then
  160. return
  161. end
  162. -- ״̬��Ϊ���죬����
  163. absAct.reward = absAct.reward or {}
  164. if absAct.reward[giftId] ~= 1 then
  165. return
  166. end
  167. -- ����״̬Ϊ����ȡ
  168. absAct.reward[giftId] = 2
  169. -- ������
  170. BagLogic.addItemList(human, config.item, "abs_totalReach")
  171. getAndSendMsg(human,id)
  172. YunYingLogic.updateIcon(YYInfo[id], human)
  173. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  174. end
  175. function isRed(human, YYInfo, funcConfig)
  176. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  177. if not state then return end
  178. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  179. local absAct = human.db.absAct[funcConfig.funcID]
  180. if not absAct then return end
  181. absAct.reward = absAct.reward or {}
  182. for k,v in pairs(absAct.reward) do
  183. if v == 1 then
  184. return true
  185. end
  186. end
  187. return false
  188. end
  189. -- 活动过期相关处理
  190. function clean(human,id)
  191. local config = AbsActExcel.absActivity[id]
  192. local mailCfg = MailExcel.mail[ActivityCleanMailId]
  193. local items = {}
  194. local absAct = human.db.absAct[id]
  195. local reachCfg = AbsActExcel.totalReach
  196. for idx,state in pairs(absAct.reward) do
  197. if state == 1 then
  198. for _,item in pairs(reachCfg[idx].item) do
  199. items[#items + 1] = item
  200. end
  201. end
  202. end
  203. -- 处理充值相关
  204. if config.param[1] == TOTAL_REACH_TYPE_2 then
  205. MailManager.add(1, human.db._id, mailCfg.title, mailCfg.content, items, mailCfg.senderName)
  206. end
  207. end