TotalReachLogic.lua 6.4 KB

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