WishCupLogic.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. --[[
  2. absAct[id] = {
  3. cup[1] = 1
  4. chose = {1,2,3}
  5. state = 0
  6. huoyue = 0
  7. day = 1
  8. }
  9. ]]
  10. local AbsActLogic = require("absAct.AbsActLogic")
  11. local AbsActExcel = require("excel.absAct")
  12. local BuyExcel = require("excel.buy")
  13. local Util = require("common.Util")
  14. local Msg = require("core.Msg")
  15. local Grid = require("bag.Grid")
  16. local BagLogic = require("bag.BagLogic")
  17. local BuyLogic = require("topup.BuyLogic")
  18. local ObjHuman = require("core.ObjHuman")
  19. local Lang = require("common.Lang")
  20. local Broadcast = require("broadcast.Broadcast")
  21. local MailManager = require("mail.MailManager")
  22. local MailExcel = require("excel.mail")
  23. local YunYingLogic = require("yunying.YunYingLogic")
  24. function isOpen(human, YYInfo, funcConfig)
  25. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  26. if not state then return end
  27. local absAct = human.db.absAct[funcConfig.funcID]
  28. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  29. return false
  30. end
  31. return true, endTime, startTime
  32. end
  33. function isActive(human, YYInfo, funcConfig)
  34. return not isOpen(human, YYInfo, funcConfig)
  35. end
  36. function getAndSendMsg(human,id)
  37. -- 判断活动是否开启
  38. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  39. if not state then return end
  40. local absConfig = AbsActExcel.absActivity[id]
  41. if not absConfig then return end
  42. local absAct = human.db.absAct[id]
  43. if not absAct then
  44. return
  45. end
  46. local nowDay = Util.diffDay(starTime) + 1
  47. absAct.cup = absAct.cup or {1,1,1,1}
  48. absAct.chose = absAct.chose or {}
  49. absAct.state = absAct.state or 0
  50. local config = AbsActExcel.wishCup
  51. local msgRet = Msg.gc.GC_ABS_HF_WISH_CUP_QUERY
  52. local len = #config
  53. local count = 0
  54. for i = 1,len do
  55. v = config[i]
  56. if v.actId == absConfig.actId and nowDay == v.day then
  57. count = count + 1
  58. local cupId = i%6
  59. cupId = cupId == 0 and 6 or cupId
  60. msgRet.cupList[count].id = cupId
  61. msgRet.cupList[count].desc = v.desc
  62. if v.lock == 0 then
  63. msgRet.cupList[count].state = 0
  64. if absAct.chose[cupId] then
  65. msgRet.cupList[count].state = 1
  66. end
  67. else
  68. msgRet.cupList[count].state = 2
  69. if absAct.cup[cupId] then
  70. msgRet.cupList[count].state = 0
  71. end
  72. if absAct.chose[cupId] then
  73. msgRet.cupList[count].state = 1
  74. end
  75. end
  76. local rewardLen = #v.item
  77. for j = 1,rewardLen do
  78. local itemID = v.item[j][1]
  79. local itemCnt = v.item[j][2]
  80. Grid.makeItem(msgRet.cupList[count].item[j],itemID,itemCnt)
  81. end
  82. msgRet.cupList[count].item[0] = rewardLen
  83. end
  84. end
  85. msgRet.cupList[0] = count
  86. msgRet.state = absAct.state
  87. Msg.send(msgRet,human.fd)
  88. end
  89. -- 选择圣杯
  90. function selectCup(human,id,one,two,three)
  91. -- 判断活动是否开启
  92. local msgRet = Msg.gc.GC_ABS_HF_WISH_CUP_SELECT
  93. msgRet.ret = 0
  94. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  95. if not state then
  96. Msg.send(msgRet,human.fd)
  97. return
  98. end
  99. local absConfig = AbsActExcel.absActivity[id]
  100. if not absConfig then
  101. Msg.send(msgRet,human.fd)
  102. return
  103. end
  104. local absAct = human.db.absAct[id]
  105. if not absAct then
  106. Msg.send(msgRet,human.fd)
  107. return
  108. end
  109. local nowDay = Util.diffDay(starTime) + 1
  110. absAct.cup = absAct.cup or {1,1,1,1}
  111. absAct.chose = absAct.chose or {}
  112. absAct.state = absAct.state or 0
  113. absAct.day = nowDay
  114. absAct.actId = absConfig.actId
  115. -- 已许愿,不可更改
  116. if absAct.state ~= 0 then
  117. Msg.send(msgRet,human.fd)
  118. return
  119. end
  120. -- 杯子未解锁
  121. if not absAct.cup[one] or not absAct.cup[two] or not absAct.cup[three] then
  122. Msg.send(msgRet,human.fd)
  123. return
  124. end
  125. -- 保存选择
  126. absAct.chose[one] = 1
  127. absAct.chose[two] = 1
  128. absAct.chose[three] = 1
  129. -- 设置状态
  130. absAct.state = 1
  131. msgRet.ret = 1
  132. Msg.send(msgRet,human.fd)
  133. getAndSendMsg(human,id)
  134. YunYingLogic.sendBanner(human)
  135. YunYingLogic.updateIcon(YYInfo[id], human)
  136. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  137. end
  138. -- 每日任务活跃度
  139. function onDailyTask(human,funcID, parameter)
  140. AbsActLogic.checkAbsActClean(human, funcID)
  141. local absAct = human.db.absAct[funcID]
  142. if not absAct then
  143. return
  144. end
  145. absAct.huoyue = absAct.huoyue or 0
  146. absAct.huoyue = absAct.huoyue + parameter
  147. if absAct.huoyue >= 100 then
  148. activeCup(human,funcID,5)
  149. end
  150. end
  151. -- 充值
  152. function onCharge(human, parameter,funcID)
  153. AbsActLogic.checkAbsActClean(human, funcID)
  154. local absAct = human.db.absAct[funcID]
  155. if not absAct then
  156. return
  157. end
  158. activeCup(human,funcID,6)
  159. end
  160. -- 完成任务回调
  161. function activeCup(human,id,cupId)
  162. local absAct = human.db.absAct[id]
  163. if not absAct then
  164. return
  165. end
  166. absAct.cup = absAct.cup or {1,1,1,1}
  167. absAct.chose = absAct.chose or {}
  168. absAct.state = absAct.state or 0
  169. absAct.cup[cupId] = 1
  170. end
  171. -- 每日发放礼包
  172. function updateDaily(human,id)
  173. local absConfig = AbsActExcel.absActivity[id]
  174. if not absConfig then return end
  175. local absAct = human.db.absAct[id]
  176. if not absAct then
  177. return
  178. end
  179. absAct.huoyue = 0
  180. absAct.cup = absAct.cup or {1,1,1,1}
  181. absAct.chose = absAct.chose or {}
  182. absAct.state = absAct.state or 0
  183. local config = AbsActExcel.wishCup
  184. local len = #config
  185. local item = {}
  186. absAct.cup = {1,1,1,1}
  187. if absAct.state ~= 1 then
  188. absAct.chose = {}
  189. return
  190. end
  191. for i = 1,len do
  192. if config[i].actId == absAct.actId and absAct.day == config[i].day then
  193. local cupId = i%6
  194. cupId = cupId == 0 and 6 or cupId
  195. if absAct.chose[cupId] then
  196. for j = 1,#config[i].item do
  197. item[#item + 1] = {config[i].item[j][1],config[i].item[j][2]}
  198. end
  199. end
  200. end
  201. end
  202. absAct.chose = {}
  203. absAct.state = 0
  204. absAct.day = nil
  205. local mailConfig = MailExcel.mail[2007]
  206. local title = mailConfig.title
  207. local senderName = mailConfig.senderName
  208. local content = mailConfig.content
  209. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, item, senderName)
  210. YunYingLogic.sendBanner(human)
  211. YunYingLogic.updateIcon(YYInfo[id], human)
  212. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  213. end
  214. function isRed(human, YYInfo, funcConfig)
  215. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  216. if not state then return end
  217. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  218. local absAct = human.db.absAct[funcConfig.funcID]
  219. if not absAct then return end
  220. absAct.cup = absAct.cup or {1,1,1,1}
  221. absAct.chose = absAct.chose or {}
  222. absAct.state = absAct.state or 0
  223. if absAct.state ~= 1 then
  224. return true
  225. end
  226. return false
  227. end