TotalReachLogic.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. TOTAL_REACH_TYPE_1 = 1 -- �߳�
  22. TOTAL_REACH_TYPE_2 = 2 -- ��ֵ
  23. TOTAL_REACH_TYPE_3 = 3 -- �����ٻ�
  24. TOTAL_REACH_TYPE_4 = 4 -- ��ʯ����
  25. function isOpen(human, YYInfo, funcConfig)
  26. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  27. if not state then return end
  28. local absAct = human.db.absAct[funcConfig.funcID]
  29. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  30. return false
  31. end
  32. return true, endTime, startTime
  33. end
  34. function getLeftTime(human,YYInfo,funcConfig)
  35. local ok,start,finish = isOpen(human,YYInfo,funcConfig)
  36. if not ok then
  37. return 0
  38. end
  39. return finish - os.time()
  40. end
  41. function isActive(human, YYInfo, funcConfig)
  42. return not isOpen(human, YYInfo, funcConfig)
  43. end
  44. local function fontDabiaoNet(db,net,config,id)
  45. net.id = id
  46. net.needCnt = config.needCnt
  47. net.desc = Util.format(config.desc, config.needCnt)
  48. net.state = db.reward and (db.reward[id] or 0) or 0
  49. local len = #config.item
  50. for i = 1,len do
  51. Grid.makeItem(net.item[i],config.item[i][1],config.item[i][2])
  52. end
  53. net.item[0] = len
  54. end
  55. function getAndSendMsg(human,id)
  56. -- �жϻ�Ƿ���
  57. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  58. if not state then return end
  59. local absConfig = AbsActExcel.absActivity[id]
  60. if not absConfig then return end
  61. local absAct = human.db.absAct[id]
  62. if not absAct then
  63. return
  64. end
  65. local config = AbsActExcel.totalReach
  66. local msgRet = Msg.gc.GC_ABS_XS_REACH_QUERY
  67. msgRet.nowCnt = absAct.count or 0
  68. local len = #config
  69. local count = 0
  70. for i = 1,len do
  71. local v = config[i]
  72. if v.actId == absConfig.actId and v.mainId == id then
  73. count = count + 1
  74. local net = msgRet.dabiaoList[count]
  75. fontDabiaoNet(absAct,net,v,i)
  76. end
  77. end
  78. msgRet.dabiaoList[0] = count
  79. Msg.send(msgRet,human.fd)
  80. end
  81. -- �߳�
  82. function onDrawCard(human,funcID, parameter)
  83. changeReach(human,funcID,TOTAL_REACH_TYPE_1,parameter)
  84. end
  85. -- ����
  86. function onTMDrawCard(human,funcID, parameter)
  87. changeReach(human,funcID,TOTAL_REACH_TYPE_3,parameter)
  88. end
  89. -- ��ֵ
  90. function onCharge(human, parameter,funcID)
  91. changeReach(human,funcID,TOTAL_REACH_TYPE_2,parameter)
  92. end
  93. -- ������ʯ
  94. function onDecZuanshi(human,funcID,parameter)
  95. changeReach(human,funcID,TOTAL_REACH_TYPE_4,parameter)
  96. end
  97. function changeReach(human,id,type,param)
  98. local absConfig = AbsActExcel.absActivity[id]
  99. if not absConfig then return end
  100. if type ~= absConfig.param[1] then
  101. return
  102. end
  103. AbsActLogic.checkAbsActClean(human, id)
  104. local absAct = human.db.absAct[id]
  105. if not absAct then
  106. return
  107. end
  108. --��������
  109. absAct.count = absAct.count or 0
  110. absAct.count = absAct.count + param
  111. absAct.reward = absAct.reward or {}
  112. local config = AbsActExcel.totalReach
  113. local len = #config
  114. for i = 1,len do
  115. if config[i].actId == absConfig.actId and config[i].mainId == id then
  116. -- �ж������Ƿ�����
  117. if not absAct.reward[i] and absAct.count >= config[i].needCnt then
  118. absAct.reward[i] = 1
  119. end
  120. end
  121. end
  122. YunYingLogic.updateIcon(YYInfo[id], human)
  123. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  124. end
  125. function getTotalReachReward(human,id,giftId)
  126. -- �жϻ�Ƿ���
  127. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  128. if not state then return end
  129. local absConfig = AbsActExcel.absActivity[id]
  130. if not absConfig then return end
  131. AbsActLogic.checkAbsActClean(human, id)
  132. local absAct = human.db.absAct[id]
  133. if not absAct then
  134. return
  135. end
  136. -- ״̬��Ϊ���죬����
  137. absAct.reward = absAct.reward or {}
  138. if absAct.reward[giftId] ~= 1 then
  139. return
  140. end
  141. local config = AbsActExcel.totalReach[giftId]
  142. if config.mainId ~= id or config.actId ~= absConfig.actId then
  143. return
  144. end
  145. -- ����״̬Ϊ����ȡ
  146. absAct.reward[giftId] = 2
  147. -- ������
  148. BagLogic.addItemList(human, config.item, "abs_totalReach")
  149. getAndSendMsg(human,id)
  150. YunYingLogic.updateIcon(YYInfo[id], human)
  151. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  152. end
  153. function isRed(human, YYInfo, funcConfig)
  154. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  155. if not state then return end
  156. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  157. local absAct = human.db.absAct[funcConfig.funcID]
  158. if not absAct then return end
  159. absAct.reward = absAct.reward or {}
  160. for k,v in pairs(absAct.reward) do
  161. if v == 1 then
  162. return true
  163. end
  164. end
  165. return false
  166. end