NewHeroLogic.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 YunYingLogic = require("yunying.YunYingLogic")
  14. ABS_ACT_ID = 9001
  15. --
  16. function initAfterHot()
  17. end
  18. --
  19. function isActive(human, YYInfo, funcConfig)
  20. return not isOpen(human, YYInfo, funcConfig)
  21. end
  22. --
  23. function isOpen(human, YYInfo, funcConfig)
  24. return AbsActLogic.isStarted(human, funcConfig.funcID)
  25. end
  26. --
  27. function isRed(human, YYInfo, funcConfig)
  28. return false
  29. end
  30. --
  31. function getLeftTime(human, YInfo, funcConfig)
  32. local ret, endTime, startTime = AbsActLogic.isStarted(human, ABS_ACT_ID)
  33. if ret == true then
  34. return endTime - os.time()
  35. else
  36. return 0
  37. end
  38. end
  39. function getNewHeroID(human)
  40. local startedFlag, endTime, startTime = AbsActLogic.isStarted(human, ABS_ACT_ID)
  41. if not startedFlag then return 0 end
  42. local absActConfig = AbsActExcel.absActivity[ABS_ACT_ID]
  43. if not absActConfig then return 0 end
  44. return absActConfig.icon
  45. end
  46. function getAndSendMsg(human, id, actId)
  47. local now = os.time()
  48. local startedFlag, endTime, startTime = AbsActLogic.isStarted(human, id)
  49. if not startedFlag then return end
  50. local absActConfig = AbsActExcel.absActivity[id]
  51. if not absActConfig then return end
  52. local absAct = human.db.absAct[id]
  53. if not absAct then return end
  54. local msgRet = Msg.gc.GC_ABS_NEWHERO
  55. msgRet.id = absActConfig.icon
  56. msgRet.startTime = startTime
  57. msgRet.endTime = endTime
  58. local index = 0
  59. for giftId, v in ipairs(AbsActExcel.absEva) do
  60. index = index + 1
  61. for j = 1, #v.reward do
  62. Grid.makeItem(msgRet.giftlist[index].item[j], v.reward[j][1], v.reward[j][2])
  63. end
  64. msgRet.giftlist[index].item[0] = #v.reward
  65. msgRet.giftlist[index].cnt = absAct.newheroCnt and absAct.newheroCnt[giftId] or 0
  66. msgRet.giftlist[index].id = giftId
  67. msgRet.giftlist[index].maxCnt = v.limit
  68. local buyID = v.buyID
  69. msgRet.giftlist[index].buyMsg[0] = 1
  70. if v.buyID == 0 then
  71. msgRet.giftlist[index].buyMsg[1] = {
  72. buyID = buyID,
  73. region = "zuanshi",
  74. cost = v.price,
  75. icon = 0,
  76. name = "",
  77. isFirst = 0,
  78. desc = "",
  79. doubleCnt = 0,
  80. actDoubleCnt = 0,
  81. useDoubleCnt = 0,
  82. buyCnt = 0,
  83. vipExp = 0,
  84. yuanjia = 0,
  85. zhekou = 0,
  86. voucher = 0,
  87. productId = "",
  88. }
  89. else
  90. BuyLogic.fontBuyItem(human, msgRet.giftlist[index].buyMsg[1], buyID)
  91. end
  92. end
  93. msgRet.giftlist[0] = index
  94. Msg.send(msgRet, human.fd)
  95. end
  96. function getgiftbybuyid(buyid)
  97. for giftId, v in ipairs(AbsActExcel.absEva) do
  98. if v.buyID == buyid then
  99. return giftId
  100. end
  101. end
  102. end
  103. function newheroGift(human, id, buyConf, isFirst, cnt)
  104. local state = AbsActLogic.isStarted(human, id)
  105. local absConfig = AbsActExcel.absActivity[id]
  106. if absConfig == nil or not state then return end
  107. -- 存在多个特惠礼包 同时 开放
  108. local giftid = getgiftbybuyid(buyConf.id)
  109. if not giftid then return end
  110. local config = AbsActExcel.absEva[giftid]
  111. if not config then return end
  112. AbsActLogic.checkAbsActClean(human, id)
  113. human.db.absAct[id].newheroCnt = human.db.absAct[id].newheroCnt or { }
  114. local nowBuyCnt = human.db.absAct[id].newheroCnt[giftid] or 0
  115. -- 判断是否达到购买上限
  116. if nowBuyCnt >= config.limit then
  117. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  118. return
  119. end
  120. -- 当金币购买之后超过最大金币时,不允许购买
  121. for j = 1, #config.reward do
  122. local itemID = config.reward[j][1]
  123. local itemCnt = config.reward[j][2]
  124. if itemID == ItemDefine.ITEM_JINBI_ID then
  125. if not ObjHuman.canAddJinbi(human, itemCnt) then
  126. return
  127. end
  128. end
  129. end
  130. -- 增加已购买次数
  131. human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + 1
  132. -- 发放物品
  133. -- local items = { }
  134. BagLogic.addItemList(human, config.reward, "newhero_reward")
  135. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  136. AbsActLogic.actDetailQuery(human, id)
  137. end
  138. function giftBuy(human, giftid)
  139. local state = AbsActLogic.isStarted(human, ABS_ACT_ID)
  140. if state ~= true then return end
  141. local absConfig = AbsActExcel.absActivity[ABS_ACT_ID]
  142. if not absConfig then return end
  143. AbsActLogic.checkAbsActClean(human, ABS_ACT_ID)
  144. -- 存在多个特惠礼包 同时 开放
  145. local config = AbsActExcel.absEva[giftid]
  146. if config.buyID ~= 0 then return end
  147. -- 初始化已购买次数
  148. human.db.absAct[ABS_ACT_ID].newheroCnt = human.db.absAct[ABS_ACT_ID].newheroCnt or { }
  149. local nowBuyCnt = human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] or 0
  150. -- 判断是否达到购买上限
  151. if nowBuyCnt >= config.limit then
  152. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  153. return
  154. end
  155. local itemID = ItemDefine.ITEM_ZUANSHI_ID
  156. local itemCnt = config.price
  157. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  158. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  159. return
  160. end
  161. -- 当金币购买之后超过最大金币时,不允许购买
  162. for j = 1, #config.reward do
  163. local itemID = config.reward[j][1]
  164. local itemCnt = config.reward[j][2]
  165. if itemID == ItemDefine.ITEM_JINBI_ID then
  166. if not ObjHuman.canAddJinbi(human, itemCnt) then
  167. return
  168. end
  169. end
  170. end
  171. BagLogic.delItem(human, itemID, itemCnt, "newhero_reward")
  172. -- 增加已购买次数
  173. human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] = nowBuyCnt + 1
  174. -- 发放物品
  175. -- local items = { }
  176. BagLogic.addItemList(human, AbsActExcel.absEva[giftid].reward, "newhero_reward")
  177. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  178. AbsActLogic.actDetailQuery(human, ABS_ACT_ID)
  179. end
  180. function updateDaily(human, id)
  181. if human.db.absAct[ABS_ACT_ID] then
  182. human.db.absAct[ABS_ACT_ID] = {}
  183. end
  184. local state = AbsActLogic.isStarted(human, ABS_ACT_ID)
  185. if state ~= true then
  186. human.db.drawCard.list[8] = {}
  187. end
  188. AbsActLogic.actDetailQuery(human, ABS_ACT_ID)
  189. end