TotalReachLogic.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 getLeftTime(human, YInfo, funcConfig)
  120. local ret, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  121. if ret == true then
  122. return endTime - os.time()
  123. else
  124. return 0
  125. end
  126. end
  127. function changeReach(human,id,type,param)
  128. local absConfig = AbsActExcel.absActivity[id]
  129. if not absConfig then return end
  130. if type ~= absConfig.param[1] then
  131. return
  132. end
  133. AbsActLogic.checkAbsActClean(human, id)
  134. local absAct = human.db.absAct[id]
  135. if not absAct then
  136. return
  137. end
  138. --��������
  139. absAct.count = absAct.count or 0
  140. absAct.count = absAct.count + param
  141. absAct.reward = absAct.reward or {}
  142. local config = AbsActExcel.totalReach
  143. local len = #config
  144. for i = 1,len do
  145. if config[i].mainId == id then
  146. -- �ж������Ƿ�����
  147. if not absAct.reward[i] and absAct.count >= config[i].needCnt then
  148. absAct.reward[i] = 1
  149. end
  150. end
  151. end
  152. YunYingLogic.updateIcon(YYInfo[id], human)
  153. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  154. end
  155. function getTotalReachReward(human,id,giftId)
  156. -- �жϻ�Ƿ���
  157. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  158. if not state then return end
  159. local absConfig = AbsActExcel.absActivity[id]
  160. if not absConfig then return end
  161. AbsActLogic.checkAbsActClean(human, id)
  162. local absAct = human.db.absAct[id]
  163. if not absAct then
  164. return
  165. end
  166. local config = AbsActExcel.totalReach[giftId]
  167. if config.mainId ~= id then
  168. return
  169. end
  170. -- ״̬��Ϊ���죬����
  171. absAct.reward = absAct.reward or {}
  172. if absAct.reward[giftId] ~= 1 then
  173. return
  174. end
  175. -- ����״̬Ϊ����ȡ
  176. absAct.reward[giftId] = 2
  177. -- ������
  178. BagLogic.addItemList(human, config.item, "abs_totalReach")
  179. getAndSendMsg(human,id)
  180. YunYingLogic.updateIcon(YYInfo[id], human)
  181. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  182. end
  183. function isRed(human, YYInfo, funcConfig)
  184. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  185. if not state then return end
  186. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  187. local absAct = human.db.absAct[funcConfig.funcID]
  188. if not absAct then return end
  189. absAct.reward = absAct.reward or {}
  190. for k,v in pairs(absAct.reward) do
  191. if v == 1 then
  192. return true
  193. end
  194. end
  195. return false
  196. end
  197. -- 活动过期相关处理
  198. function clean(human,id)
  199. local config = AbsActExcel.absActivity[id]
  200. local mailCfg = MailExcel.mail[ActivityCleanMailId]
  201. local items = {}
  202. local absAct = human.db.absAct[id]
  203. local reachCfg = AbsActExcel.totalReach
  204. for idx,state in pairs(absAct.reward) do
  205. if state == 1 then
  206. for _,item in pairs(reachCfg[idx].item) do
  207. items[#items + 1] = item
  208. end
  209. end
  210. end
  211. -- 处理充值相关
  212. if config.param[1] == TOTAL_REACH_TYPE_2 then
  213. MailManager.add(1, human.db._id, mailCfg.title, mailCfg.content, items, mailCfg.senderName)
  214. end
  215. end