NewHeroLogic.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. }
  88. else
  89. BuyLogic.fontBuyItem(human, msgRet.giftlist[index].buyMsg[1], buyID)
  90. end
  91. end
  92. msgRet.giftlist[0] = index
  93. Msg.send(msgRet, human.fd)
  94. end
  95. function getgiftbybuyid(buyid)
  96. for giftId, v in ipairs(AbsActExcel.absEva) do
  97. if v.buyID == buyid then
  98. return giftId
  99. end
  100. end
  101. end
  102. function newheroGift(human, id, buyConf, isFirst, cnt)
  103. local state = AbsActLogic.isStarted(human, id)
  104. local absConfig = AbsActExcel.absActivity[id]
  105. if absConfig == nil or not state then return end
  106. -- 存在多个特惠礼包 同时 开放
  107. local giftid = getgiftbybuyid(buyConf.id)
  108. if not giftid then return end
  109. local config = AbsActExcel.absEva[giftid]
  110. if not config then return end
  111. AbsActLogic.checkAbsActClean(human, id)
  112. human.db.absAct[id].newheroCnt = human.db.absAct[id].newheroCnt or { }
  113. local nowBuyCnt = human.db.absAct[id].newheroCnt[giftid] or 0
  114. -- 判断是否达到购买上限
  115. if nowBuyCnt >= config.limit then
  116. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  117. return
  118. end
  119. -- 当金币购买之后超过最大金币时,不允许购买
  120. for j = 1, #config.reward do
  121. local itemID = config.reward[j][1]
  122. local itemCnt = config.reward[j][2]
  123. if itemID == ItemDefine.ITEM_JINBI_ID then
  124. if not ObjHuman.canAddJinbi(human, itemCnt) then
  125. return
  126. end
  127. end
  128. end
  129. -- 增加已购买次数
  130. human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + 1
  131. -- 发放物品
  132. -- local items = { }
  133. BagLogic.addItemList(human, config.reward, "newhero_reward")
  134. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  135. AbsActLogic.actDetailQuery(human, id)
  136. end
  137. function giftBuy(human, giftid)
  138. local state = AbsActLogic.isStarted(human, ABS_ACT_ID)
  139. if state ~= true then return end
  140. local absConfig = AbsActExcel.absActivity[ABS_ACT_ID]
  141. if not absConfig then return end
  142. AbsActLogic.checkAbsActClean(human, ABS_ACT_ID)
  143. -- 存在多个特惠礼包 同时 开放
  144. local config = AbsActExcel.absEva[giftid]
  145. if config.buyID ~= 0 then return end
  146. -- 初始化已购买次数
  147. human.db.absAct[ABS_ACT_ID].newheroCnt = human.db.absAct[ABS_ACT_ID].newheroCnt or { }
  148. local nowBuyCnt = human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] or 0
  149. -- 判断是否达到购买上限
  150. if nowBuyCnt >= config.limit then
  151. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  152. return
  153. end
  154. local itemID = ItemDefine.ITEM_ZUANSHI_ID
  155. local itemCnt = config.price
  156. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  157. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  158. return
  159. end
  160. -- 当金币购买之后超过最大金币时,不允许购买
  161. for j = 1, #config.reward do
  162. local itemID = config.reward[j][1]
  163. local itemCnt = config.reward[j][2]
  164. if itemID == ItemDefine.ITEM_JINBI_ID then
  165. if not ObjHuman.canAddJinbi(human, itemCnt) then
  166. return
  167. end
  168. end
  169. end
  170. BagLogic.delItem(human, itemID, itemCnt, "newhero_reward")
  171. -- 增加已购买次数
  172. human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] = nowBuyCnt + 1
  173. -- 发放物品
  174. -- local items = { }
  175. BagLogic.addItemList(human, AbsActExcel.absEva[giftid].reward, "newhero_reward")
  176. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  177. AbsActLogic.actDetailQuery(human, ABS_ACT_ID)
  178. end
  179. function updateDaily(human, id)
  180. if human.db.absAct[ABS_ACT_ID] then
  181. human.db.absAct[ABS_ACT_ID] = {}
  182. end
  183. local state = AbsActLogic.isStarted(human, ABS_ACT_ID)
  184. if state ~= true then
  185. human.db.drawCard.list[8] = {}
  186. end
  187. AbsActLogic.actDetailQuery(human, ABS_ACT_ID)
  188. end