NewHeroLogic.lua 6.6 KB

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