AbsZhanbuLunpanLogic.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. local Msg = require("core.Msg")
  2. local Util = require("common.Util")
  3. local Lang = require("common.Lang")
  4. local Broadcast = require("broadcast.Broadcast")
  5. local Grid = require("bag.Grid")
  6. local BagLogic = require("bag.BagLogic")
  7. local AbsActLogic = require("absAct.AbsActLogic")
  8. local AbsActDefine = require("absAct.AbsActDefine")
  9. local MailManager = require("mail.MailManager")
  10. local MailExcel = require("excel.mail")
  11. local AbsActExcel = require("excel.absAct")
  12. local ItemExcel = require("excel.item").item
  13. local ItemDefine = require("bag.ItemDefine")
  14. local YunYingLogic = require("yunying.YunYingLogic")
  15. local PanelDefine = require("broadcast.PanelDefine")
  16. --[[
  17. 占卜轮盘
  18. 1.actID(活动ID)或开始时间不一样则把DB数据重置
  19. 2.抽奖规则,每次抽奖获得是策划按顺序配置的固定奖励
  20. 3.轮盘奖励全部抽完,不刷新.
  21. 4.活动开启时间,占卜功能中的每次合成和刷新都会获得配置相对应的道具奖励
  22. 5.活动结束后,剩余的抽奖道具全部转化为其它配置的道具,并通过邮件发送
  23. DB:
  24. human.db.absAct[id] = {
  25. startTime = xxx, --占卜轮盘开始时间
  26. times = xxx, --占卜轮盘抽奖次数
  27. }
  28. local:
  29. getActID() --获取活动id
  30. recoveryItem() --活动结束后回收道具
  31. getInitDB() --初始DB数据
  32. recovery() --0点后自动执行回收逻辑
  33. getDrawCnt() --获得下次抽奖需要的道具数量
  34. public:
  35. getAndSendMsg() --发送活动数据
  36. get() --活动抽奖
  37. isRed() --红点提醒
  38. isActive() --激活状态
  39. isOpen() --活动开启
  40. updateDaily() --0点时回调
  41. onZhanbuRefresh() --占卜功能刷新时回调
  42. onZhanbuCompose() --占卜合成时回调
  43. getZhanbuComposeCnt()--占卜合成时可得到道具数量
  44. --]]
  45. local function getActID(human)
  46. local state, id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_9)
  47. if not state then return end
  48. return id
  49. end
  50. local function recoveryItem(human, id)
  51. local absActConfig = AbsActExcel.absActivity[id]
  52. if not absActConfig then return end
  53. local zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.actId]
  54. if not zblpConfig then
  55. zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.turns[1]]
  56. if not zblpConfig then return end
  57. end
  58. local cnt = BagLogic.getItemCnt(human, zblpConfig.itemID)
  59. if cnt > 0 then
  60. BagLogic.delItem(human, zblpConfig.itemID, cnt, "zhanbulunpan_recovery")
  61. local mailConfig = MailExcel.mail[zblpConfig.mailID]
  62. local title = mailConfig.title
  63. local senderName = mailConfig.senderName
  64. local content = mailConfig.content
  65. local itemName = ItemExcel[zblpConfig.recoveryItemId].name
  66. local itemCnt = math.ceil(cnt / zblpConfig.recoveryProb[1]) * zblpConfig.recoveryProb[2]
  67. local items = { {zblpConfig.recoveryItemId, itemCnt} }
  68. MailManager.add(MailManager.SYSTEM, human.db._id, title, Util.format(content, itemName), items, senderName)
  69. end
  70. end
  71. local function getInitDB(human, id, isRecovery)
  72. if not id then
  73. id = getActID(human)
  74. if not id then return end
  75. end
  76. local ret, endTime, startTime = AbsActLogic.isStarted(human, id)
  77. if not ret then
  78. --活动已结束,回收道具
  79. if isRecovery then
  80. recoveryItem(human, id)
  81. end
  82. return
  83. else
  84. --活动重新开过,回收道具
  85. local actDB = human.db.absAct[id]
  86. if actDB then
  87. actDB.times = actDB.times or 0
  88. end
  89. --[[ 不判断开始时间是否相等了 有玩家出现过活动在也回收了,
  90. 注释掉后,但后面如果配成每期之间没有间隔或在下一期开始后再上线,会出现回收不掉的问题。
  91. 解决方案思路是存actID,例actDB.actId = absActConfig.actId,后面有配置这种情这样解决。
  92. if actDB and actDB.startTime ~= startTime then
  93. actDB.startTime = startTime
  94. actDB.times = 0
  95. if isRecovery then
  96. recoveryItem(human, id)
  97. end
  98. end --]]
  99. return actDB
  100. end
  101. end
  102. local function recovery(human, activityID)
  103. getInitDB(human, activityID, true)
  104. end
  105. local function getDrawCnt(human, times, id)
  106. local absActConfig = AbsActExcel.absActivity[id]
  107. if not absActConfig then return end
  108. local zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.actId]
  109. return zblpConfig.itemCnts[times + 1] or zblpConfig.itemCnts[#zblpConfig.itemCnts]
  110. end
  111. local init
  112. function getAndSendMsg(human, id)
  113. local actDB = getInitDB(human, id)
  114. if not actDB then return end
  115. local absActConfig = AbsActExcel.absActivity[id]
  116. if not absActConfig then return end
  117. local msgRet = Msg.gc.GC_ABS_ZHAN_BU_LUA_PAN_QUERY
  118. if not init then
  119. local zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.actId]
  120. Grid.makeItem(msgRet.needItem, zblpConfig.itemID, 1)
  121. local len = 0
  122. for _, rewardCf in ipairs(zblpConfig.itemRewards) do
  123. len = len + 1
  124. Grid.makeItem(msgRet.list[len], rewardCf[1], rewardCf[2])
  125. end
  126. msgRet.list[0] = len
  127. len = 0
  128. for _, order in ipairs(zblpConfig.itemRewardOrders) do
  129. len = len + 1
  130. msgRet.orderList[len] = order
  131. end
  132. msgRet.orderList[0] = len
  133. len = 0
  134. for _, cnt in ipairs(zblpConfig.composeItemRewardCnts) do
  135. len = len + 1
  136. Grid.makeItem(msgRet.composeItems[len], zblpConfig.itemID, cnt)
  137. end
  138. msgRet.composeItems[0] = len
  139. Grid.makeItem(msgRet.resershItem, zblpConfig.itemID, zblpConfig.refreshItemRewardCnt)
  140. Grid.makeItem(msgRet.recoveryItem, zblpConfig.recoveryItemId, 1)
  141. msgRet.recoveryProb = tostring(zblpConfig.recoveryProb[1]) .. ":" .. tostring(zblpConfig.recoveryProb[2])
  142. init = true
  143. end
  144. msgRet.times = actDB.times
  145. msgRet.itemCnt = getDrawCnt(human, actDB.times, id)
  146. Msg.send(msgRet, human.fd)
  147. end
  148. function get(human, id)
  149. local actDB = getInitDB(human, id)
  150. if not actDB then return end
  151. local absActConfig = AbsActExcel.absActivity[id]
  152. if not absActConfig then return end
  153. local zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.actId]
  154. local nextTimes = actDB.times + 1
  155. local nextOrder = zblpConfig.itemRewardOrders[nextTimes]
  156. if not nextOrder then
  157. return Broadcast.sendErr(human, Lang.ABS_ZHANBU_LUNPAN_ERR)
  158. end
  159. local drawItemCf = zblpConfig.itemRewards[nextOrder]
  160. if not drawItemCf then
  161. return Broadcast.sendErr(human, Lang.ABS_ZHANBU_LUNPAN_ERR)
  162. end
  163. local needItemCnt = getDrawCnt(human, actDB.times, id)
  164. if not BagLogic.checkItemCnt(human, zblpConfig.itemID, needItemCnt) then
  165. return
  166. end
  167. BagLogic.delItem(human, zblpConfig.itemID, needItemCnt, "zhanbulunpan_get")
  168. actDB.times = nextTimes
  169. BagLogic.addItem(human, drawItemCf[1], drawItemCf[2], "zhanbulunpan_get")
  170. local msgRet = Msg.gc.GC_ABS_ZHAN_BU_LUA_PAN_GET
  171. msgRet.times = nextTimes
  172. msgRet.itemCnt = getDrawCnt(human, actDB.times, id)
  173. Msg.send(msgRet, human.fd)
  174. YunYingLogic.updateIcon(YYInfo[id], human)
  175. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3308)
  176. end
  177. function isRed(human, YYInfo, absActConfig)
  178. local actDB = getInitDB(human, absActConfig.funcID)
  179. if not actDB then return end
  180. local zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.actId]
  181. local nextTimes = actDB.times + 1
  182. local nextOrder = zblpConfig.itemRewardOrders[nextTimes]
  183. if not nextOrder then
  184. return
  185. end
  186. local drawItemCf = zblpConfig.itemRewards[nextOrder]
  187. if not drawItemCf then
  188. return
  189. end
  190. local needItemCnt = getDrawCnt(human, actDB.times, absActConfig.funcID)
  191. local zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.actId]
  192. if zblpConfig.itemID == ItemDefine.ITEM_ZUANSHI_ID then
  193. local sum = human.db.zuanshi
  194. if sum < needItemCnt then
  195. return
  196. end
  197. end
  198. if BagLogic.getItemCnt(human, zblpConfig.itemID) < needItemCnt then
  199. return
  200. end
  201. return true
  202. end
  203. function isActive(human, YYInfo, funcConfig)
  204. return not isOpen(human, YYInfo, funcConfig)
  205. end
  206. function isOpen(human, YYInfo, funcConfig)
  207. return AbsActLogic.isStarted(human, funcConfig.funcID)
  208. end
  209. function updateDaily(human, activityID)
  210. recovery(human, activityID)
  211. end
  212. function onZhanbuRefresh(human)
  213. local id = getActID(human)
  214. if not id then return end
  215. local absActConfig = AbsActExcel.absActivity[id]
  216. if not absActConfig then return end
  217. local zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.actId]
  218. if not zblpConfig then return end
  219. local ret = AbsActLogic.isStarted(human, id)
  220. if ret then
  221. if zblpConfig.refreshItemRewardCnt <= 0 then return end
  222. BagLogic.addItem(human, zblpConfig.itemID, zblpConfig.refreshItemRewardCnt, "zhanbulunpan_get")
  223. end
  224. end
  225. function onZhanbuCompose(human, grade)
  226. local itemID,cnt = getZhanbuComposeCnt(human, grade)
  227. if cnt <= 0 then return end
  228. BagLogic.addItem(human, itemID, cnt, "zhanbulunpan_get")
  229. end
  230. function getZhanbuComposeCnt(human, grade)
  231. local id = getActID(human)
  232. if not id then return 0,0 end
  233. local absActConfig = AbsActExcel.absActivity[id]
  234. if not absActConfig then return 0,0 end
  235. local zblpConfig = AbsActExcel.zhanbuLunpan[absActConfig.actId]
  236. if not zblpConfig then return 0,0 end
  237. local ret = AbsActLogic.isStarted(human, id)
  238. return ret and zblpConfig.itemID,zblpConfig.composeItemRewardCnts[grade] or 0,0
  239. end