WishGiftLogic.lua 8.0 KB

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