NewHeroLogic.lua 7.9 KB

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