WishGiftLogic.lua 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. local AbsActExcel = require("excel.absAct")
  2. local Lang = require("common.Lang")
  3. local ObjHuman = require("core.ObjHuman")
  4. local Msg = require("core.Msg")
  5. local Broadcast = require("broadcast.Broadcast")
  6. local Grid = require("bag.Grid")
  7. local BagLogic = require("bag.BagLogic")
  8. local ItemDefine = require("bag.ItemDefine")
  9. local BuyLogic = require("topup.BuyLogic")
  10. local AbsActDefine = require("absAct.AbsActDefine")
  11. local AbsActLogic = require("absAct.AbsActLogic")
  12. local Log = require("common.Log")
  13. local CycleActivityLogic = require("yunying.CycleActivity")
  14. --[[
  15. absAct.xlxs-wishGift
  16. 新英雄来袭-夙愿礼盒
  17. 1.默认初始化礼盒数据
  18. 2.礼盒分直购和钻石购买
  19. DB:
  20. human.db.absAct[id] = {
  21. premiumCnt = {
  22. xxx = xxx, -- 配置的礼包id = 购买数量
  23. }
  24. }
  25. public:
  26. initAfterHot() -- 初始礼盒数据
  27. getAndSendMsg() -- 发送活动数据
  28. isRed() -- 红点提醒
  29. isActive() -- 激活状态
  30. isOpen() -- 活动开启 、
  31. getLeftTime() -- 得到活动剩余时间(YunYingLogic统一调用)
  32. wishGift() -- 直购礼盒(统一从YunYingLogic.onBuy中调用)
  33. giftBuy() -- 钻石购买礼盒
  34. --]]
  35. ABS_PREMIUM_GIFT_LIST_ACTID = { } -- 所有礼盒数据配置id
  36. ABS_PREMIUM_GIFT_LIST_BUYID = { } -- 所有需要直购的礼盒数据 buyID => 配置id
  37. function initAfterHot()
  38. ABS_PREMIUM_GIFT_LIST_ACTID = {}
  39. for k, v in pairs(AbsActExcel.wishGift) do
  40. ABS_PREMIUM_GIFT_LIST_ACTID[v.actId] = ABS_PREMIUM_GIFT_LIST_ACTID[v.actId] or { }
  41. ABS_PREMIUM_GIFT_LIST_ACTID[v.actId][#ABS_PREMIUM_GIFT_LIST_ACTID[v.actId] + 1] = k
  42. if v.buyID ~= 0 then
  43. ABS_PREMIUM_GIFT_LIST_BUYID[v.buyID] = k
  44. end
  45. end
  46. end
  47. function getAndSendMsg(human, id, actId)
  48. -- local startedFlag, endTime, startTime = AbsActLogic.isStarted(human, id)
  49. local startedFlag, endTime, startTime = CycleActivityLogic.isStarted(human, id)
  50. if not startedFlag then return end
  51. local absActConfig = AbsActExcel.absActivity[id]
  52. if not absActConfig then return end
  53. local absAct = human.db.absAct[id]
  54. if not absAct then return end
  55. local msgRet = Msg.gc.GC_ABS_ACT_WISH_GIFT_QUERY
  56. msgRet.templateId = absActConfig.panelID
  57. msgRet.ad = absActConfig.adIcon
  58. msgRet.absActId = id
  59. msgRet.status = absAct.status or 0
  60. local index = 0
  61. for k, giftId in pairs(ABS_PREMIUM_GIFT_LIST_ACTID[absActConfig.actId]) do
  62. local v = AbsActExcel.wishGift[giftId]
  63. if v then
  64. index = index + 1
  65. for j = 1, #v.reward do
  66. Grid.makeItem(msgRet.premiumGiftMsg[index].item[j], v.reward[j][1], v.reward[j][2])
  67. end
  68. msgRet.premiumGiftMsg[index].item[0] = #v.reward
  69. msgRet.premiumGiftMsg[index].cnt = absAct.premiumCnt and absAct.premiumCnt[giftId] or 0
  70. msgRet.premiumGiftMsg[index].id = giftId
  71. msgRet.premiumGiftMsg[index].maxCnt = v.cnt
  72. msgRet.premiumGiftMsg[index].icon = v.icon or 0
  73. msgRet.premiumGiftMsg[index].name = v.name or ""
  74. local buyID = v.buyID
  75. msgRet.premiumGiftMsg[index].buyMsg[0] = 0
  76. msgRet.premiumGiftMsg[index].needItem[0] = 0
  77. if v.buyID == 0 then
  78. local len = 0
  79. for _, item in ipairs(v.needItem) do
  80. len = len + 1
  81. Grid.makeItem(msgRet.premiumGiftMsg[index].needItem[len], item[1], item[2])
  82. end
  83. msgRet.premiumGiftMsg[index].needItem[0] = len
  84. else
  85. BuyLogic.fontBuyItem(human, msgRet.premiumGiftMsg[index].buyMsg[1], buyID)
  86. msgRet.premiumGiftMsg[index].buyMsg[0] = 1
  87. end
  88. end
  89. end
  90. msgRet.premiumGiftMsg[0] = index
  91. msgRet.startTime = startTime
  92. msgRet.endTime = endTime
  93. Msg.send(msgRet, human.fd)
  94. end
  95. function isRed(human, YYInfo, funcConfig)
  96. return false
  97. end
  98. function isActive(human, YYInfo, funcConfig)
  99. return not isOpen(human, YYInfo, funcConfig)
  100. end
  101. function isOpen(human, YYInfo, funcConfig)
  102. -- return AbsActLogic.isStarted(human, funcConfig.funcID)
  103. return CycleActivityLogic.isStarted(human, funcConfig.funcID)
  104. end
  105. function getLeftTime(human, YInfo, funcConfig)
  106. -- local ret, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  107. local ret, endTime, startTime = CycleActivityLogic.isStarted(human, funcConfig.funcID)
  108. if ret == true then
  109. return endTime - os.time()
  110. else
  111. return 0
  112. end
  113. end
  114. function wishGift(human, id, buyConf, isFirst, cnt)
  115. -- local state = AbsActLogic.isStarted(human, id)
  116. local state = CycleActivityLogic.isStarted(human, id)
  117. local absConfig = AbsActExcel.absActivity[id]
  118. if absConfig == nil or not state then return end
  119. -- 存在多个特惠礼包 同时 开放
  120. local premiumID = ABS_PREMIUM_GIFT_LIST_BUYID[buyConf.id]
  121. if not premiumID then return end
  122. local config = AbsActExcel.wishGift[premiumID]
  123. if not config then return end
  124. if config.actId ~= absConfig.actId then return end
  125. -- AbsActLogic.checkAbsActClean(human, id)
  126. human.db.absAct[id].premiumCnt = human.db.absAct[id].premiumCnt or { }
  127. local nowBuyCnt = human.db.absAct[id].premiumCnt[premiumID] or 0
  128. -- 判断是否达到购买上限
  129. if nowBuyCnt >= config.cnt then
  130. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  131. return
  132. end
  133. -- 当金币购买之后超过最大金币时,不允许购买
  134. for j = 1, #config.reward do
  135. local itemID = config.reward[j][1]
  136. local itemCnt = config.reward[j][2]
  137. if itemID == ItemDefine.ITEM_JINBI_ID then
  138. if not ObjHuman.canAddJinbi(human, itemCnt) then
  139. return
  140. end
  141. end
  142. end
  143. -- 增加已购买次数
  144. human.db.absAct[id].premiumCnt[premiumID] = nowBuyCnt + 1
  145. -- 发放物品
  146. -- local items = { }
  147. BagLogic.addItemList(human, AbsActExcel.wishGift[premiumID].reward, "abs_wish_gift_buy")
  148. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  149. AbsActLogic.actDetailQuery(human, id)
  150. end
  151. function giftBuy(human, id, premiumID)
  152. -- local state = AbsActLogic.isStarted(human, id)
  153. local state = CycleActivityLogic.isStarted(human, id)
  154. if state ~= true then return Broadcast.sendErr(human, Lang.ACT_WAS_OVER) end
  155. local absConfig = AbsActExcel.absActivity[id]
  156. if not absConfig then return end
  157. -- AbsActLogic.checkAbsActClean(human, id)
  158. -- 存在多个特惠礼包 同时 开放
  159. local config = AbsActExcel.wishGift[premiumID]
  160. if config.buyID ~= 0 then return end
  161. -- 初始化已购买次数
  162. human.db.absAct[id].premiumCnt = human.db.absAct[id].premiumCnt or { }
  163. local nowBuyCnt = human.db.absAct[id].premiumCnt[premiumID] or 0
  164. -- 判断是否达到购买上限
  165. if nowBuyCnt >= config.cnt then
  166. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  167. return
  168. end
  169. for _, item in ipairs(config.needItem) do
  170. local itemID = item[1]
  171. local itemCnt = item[2]
  172. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  173. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  174. return
  175. end
  176. end
  177. -- 当金币购买之后超过最大金币时,不允许购买
  178. for j = 1, #config.reward do
  179. local itemID = config.reward[j][1]
  180. local itemCnt = config.reward[j][2]
  181. if itemID == ItemDefine.ITEM_JINBI_ID then
  182. if not ObjHuman.canAddJinbi(human, itemCnt) then
  183. return
  184. end
  185. end
  186. end
  187. for _, item in ipairs(config.needItem) do
  188. local itemID = item[1]
  189. local itemCnt = item[2]
  190. BagLogic.delItem(human, itemID, itemCnt, "abs_wish_gift_reward")
  191. end
  192. -- 增加已购买次数
  193. human.db.absAct[id].premiumCnt[premiumID] = nowBuyCnt + 1
  194. -- 发放物品
  195. -- local items = { }
  196. BagLogic.addItemList(human, AbsActExcel.wishGift[premiumID].reward, "abs_wish_gift_reward")
  197. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  198. AbsActLogic.actDetailQuery(human, id)
  199. end