NewHeroLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. NEW_HERO_MODULE_FN = "absAct.NewHeroLogic"
  16. NEW_HERO_ACT_TYPES = {}
  17. --
  18. function initAfterHot()
  19. NEW_HERO_ACT_TYPES = {}
  20. for _, config in pairs(AbsActExcel.absActivity) do
  21. if config.moduleFn == NEW_HERO_MODULE_FN then
  22. NEW_HERO_ACT_TYPES[#NEW_HERO_ACT_TYPES + 1] = config.type
  23. end
  24. end
  25. end
  26. function getActiveActId(human)
  27. for _, actType in ipairs(NEW_HERO_ACT_TYPES) do
  28. local state, actId = AbsActLogic.isStartedByType(human, actType)
  29. if state and actId then
  30. return actId
  31. end
  32. end
  33. end
  34. local function getGiftConfig(giftId, actId)
  35. local config = AbsActExcel.absEva[giftId]
  36. if not config or config.actId ~= actId then
  37. return
  38. end
  39. return config
  40. end
  41. local function copyRewardList(reward)
  42. local items = {}
  43. for _, v in ipairs(reward) do
  44. items[#items + 1] = {v[1], v[2], v[3]}
  45. end
  46. return items
  47. end
  48. --
  49. function isActive(human, YYInfo, funcConfig)
  50. return not isOpen(human, YYInfo, funcConfig)
  51. end
  52. --
  53. function isOpen(human, YYInfo, funcConfig)
  54. return AbsActLogic.isStarted(human, funcConfig.funcID)
  55. end
  56. --
  57. function isRed(human, YYInfo, funcConfig)
  58. return false
  59. end
  60. --
  61. function getLeftTime(human, YInfo, funcConfig)
  62. local actId = funcConfig and funcConfig.funcID or getActiveActId(human)
  63. if not actId then
  64. return 0
  65. end
  66. local ret, endTime, startTime = AbsActLogic.isStarted(human, actId)
  67. if ret == true then
  68. return endTime - os.time()
  69. else
  70. return 0
  71. end
  72. end
  73. function getNewHeroID(human)
  74. local actId = getActiveActId(human)
  75. if not actId then return 0 end
  76. local absActConfig = AbsActExcel.absActivity[actId]
  77. if not absActConfig then return 0 end
  78. return absActConfig.icon
  79. end
  80. -- 精英召唤drawCard配置: 主池, 100抽UP, 十连保底, 40抽SSR
  81. local NEW_HERO_DRAW_CONFIG = {
  82. [9001] = {8, 9, 10, 11},
  83. [9002] = {13, 14, 15, 16},
  84. [9003] = {17, 18, 19, 20},
  85. }
  86. local DEFAULT_NEW_HERO_DRAW_CONFIG = {8, 9, 10, 11}
  87. function getNewHeroDrawConfigIds(actId)
  88. local ids = (actId and NEW_HERO_DRAW_CONFIG[actId]) or DEFAULT_NEW_HERO_DRAW_CONFIG
  89. return ids[1], ids[2], ids[3], ids[4]
  90. end
  91. local function getActClientIndex(actId)
  92. if actId == 9001 then
  93. return 1
  94. elseif actId == 9002 then
  95. return 2
  96. elseif actId == 9003 then
  97. return 3
  98. end
  99. return 0
  100. end
  101. local function getActLogType(actId)
  102. if actId == 9002 then
  103. return "newhero_reward_9002"
  104. elseif actId == 9003 then
  105. return "newhero_reward_9003"
  106. end
  107. return "newhero_reward"
  108. end
  109. function getAndSendMsg(human, id, actId)
  110. local now = os.time()
  111. local startedFlag, endTime, startTime = AbsActLogic.isStarted(human, id)
  112. if not startedFlag then
  113. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  114. end
  115. local absActConfig = AbsActExcel.absActivity[id]
  116. if not absActConfig then
  117. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  118. end
  119. local absAct = human.db.absAct[id]
  120. if not absAct then
  121. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  122. end
  123. local msgRet = Msg.gc.GC_ABS_NEWHERO
  124. msgRet.id = absActConfig.icon
  125. msgRet.startTime = startTime
  126. msgRet.endTime = endTime
  127. msgRet.actIndex = getActClientIndex(id)
  128. local index = 0
  129. local giftIds = {}
  130. for giftId, v in pairs(AbsActExcel.absEva) do
  131. if v.actId == id then
  132. giftIds[#giftIds + 1] = giftId
  133. end
  134. end
  135. table.sort(giftIds)
  136. for _, giftId in ipairs(giftIds) do
  137. local v = AbsActExcel.absEva[giftId]
  138. index = index + 1
  139. for j = 1, #v.reward do
  140. Grid.makeItem(msgRet.giftlist[index].item[j], v.reward[j][1], v.reward[j][2])
  141. end
  142. msgRet.giftlist[index].item[0] = #v.reward
  143. msgRet.giftlist[index].cnt = absAct.newheroCnt and absAct.newheroCnt[giftId] or 0
  144. msgRet.giftlist[index].id = giftId
  145. msgRet.giftlist[index].maxCnt = v.limit
  146. local buyID = v.buyID
  147. msgRet.giftlist[index].buyMsg[0] = 1
  148. if v.buyID == 0 then
  149. msgRet.giftlist[index].buyMsg[1] = {
  150. buyID = buyID,
  151. region = "zuanshi",
  152. cost = v.price,
  153. icon = 0,
  154. name = "",
  155. isFirst = 0,
  156. desc = "",
  157. doubleCnt = 0,
  158. actDoubleCnt = 0,
  159. useDoubleCnt = 0,
  160. buyCnt = 0,
  161. vipExp = 0,
  162. yuanjia = 0,
  163. zhekou = 0,
  164. voucher = 0,
  165. productId = "",
  166. nCanBuyNum = 0,
  167. }
  168. else
  169. BuyLogic.fontBuyItem(human, msgRet.giftlist[index].buyMsg[1], buyID)
  170. end
  171. end
  172. msgRet.giftlist[0] = index
  173. if index == 0 then
  174. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  175. end
  176. Msg.send(msgRet, human.fd)
  177. end
  178. function getgiftbybuyid(buyid, actId)
  179. for giftId, v in pairs(AbsActExcel.absEva) do
  180. if v.buyID == buyid and v.actId == actId then
  181. return giftId
  182. end
  183. end
  184. end
  185. function newheroGift(human, id, buyConf, isFirst, cnt, buyNum)
  186. local state = AbsActLogic.isStarted(human, id)
  187. local absConfig = AbsActExcel.absActivity[id]
  188. if absConfig == nil then
  189. Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
  190. "[NewHeroLogic.newheroGift] absActivity config not found, actId=%s, buyID=%s, newUniqueTag=%s",
  191. tostring(id), tostring(buyConf and buyConf.id), tostring(human.db.newUniqueTag)))
  192. return
  193. end
  194. if not state then
  195. Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
  196. "[NewHeroLogic.newheroGift] act not started, actId=%s, buyID=%s, newUniqueTag=%s, now=%s",
  197. tostring(id), tostring(buyConf.id), tostring(human.db.newUniqueTag), os.time()))
  198. return
  199. end
  200. -- 存在多个特惠礼包 同时 开放
  201. local giftid = getgiftbybuyid(buyConf.id, id)
  202. if not giftid then
  203. Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
  204. "[NewHeroLogic.newheroGift] absEva gift not found, actId=%s, buyID=%s, newUniqueTag=%s",
  205. tostring(id), tostring(buyConf.id), tostring(human.db.newUniqueTag)))
  206. return
  207. end
  208. local config = getGiftConfig(giftid, id)
  209. if not config then
  210. Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
  211. "[NewHeroLogic.newheroGift] absEva gift config invalid, actId=%s, giftId=%s, buyID=%s, newUniqueTag=%s",
  212. tostring(id), tostring(giftid), tostring(buyConf.id), tostring(human.db.newUniqueTag)))
  213. return
  214. end
  215. AbsActLogic.checkAbsActClean(human, id)
  216. human.db.absAct[id].newheroCnt = human.db.absAct[id].newheroCnt or { }
  217. local nowBuyCnt = human.db.absAct[id].newheroCnt[giftid] or 0
  218. -- 判断是否达到购买上限
  219. if nowBuyCnt >= config.limit then
  220. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  221. return
  222. end
  223. -- if nowBuyCnt + buyNum >= config.limit then
  224. -- Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  225. -- return
  226. -- end
  227. -- 当金币购买之后超过最大金币时,不允许购买
  228. for j = 1, #config.reward do
  229. local itemID = config.reward[j][1]
  230. local itemCnt = config.reward[j][2]
  231. if itemID == ItemDefine.ITEM_JINBI_ID then
  232. if not ObjHuman.canAddJinbi(human, itemCnt) then
  233. return
  234. end
  235. end
  236. end
  237. -- 增加已购买次数
  238. -- human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + buyNum
  239. -- -- 发放物品
  240. -- local items = { }
  241. -- for _, v in ipairs(config.reward) do
  242. -- table.insert(items, {v[1], v[2] * buyNum})
  243. -- end
  244. -- BagLogic.addItemList(human, config.reward, "newhero_reward")
  245. human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + 1
  246. -- 发放物品
  247. local items = copyRewardList(config.reward)
  248. BagLogic.addItemList(human, items, getActLogType(id))
  249. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  250. AbsActLogic.actDetailQuery(human, id)
  251. end
  252. function giftBuy(human, giftid)
  253. local actId = getActiveActId(human)
  254. if not actId then
  255. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  256. end
  257. local state = AbsActLogic.isStarted(human, actId)
  258. if state ~= true then
  259. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  260. end
  261. local absConfig = AbsActExcel.absActivity[actId]
  262. if not absConfig then
  263. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  264. end
  265. AbsActLogic.checkAbsActClean(human, actId)
  266. -- 存在多个特惠礼包 同时 开放
  267. local config = getGiftConfig(giftid, actId)
  268. if not config then
  269. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  270. end
  271. if config.buyID ~= 0 then
  272. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  273. end
  274. -- 初始化已购买次数
  275. human.db.absAct[actId].newheroCnt = human.db.absAct[actId].newheroCnt or { }
  276. local nowBuyCnt = human.db.absAct[actId].newheroCnt[giftid] or 0
  277. -- 判断是否达到购买上限
  278. if nowBuyCnt >= config.limit then
  279. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  280. return
  281. end
  282. local itemID = ItemDefine.ITEM_ZUANSHI_ID
  283. local itemCnt = config.price
  284. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  285. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  286. return
  287. end
  288. -- 当金币购买之后超过最大金币时,不允许购买
  289. for j = 1, #config.reward do
  290. local itemID = config.reward[j][1]
  291. local itemCnt = config.reward[j][2]
  292. if itemID == ItemDefine.ITEM_JINBI_ID then
  293. if not ObjHuman.canAddJinbi(human, itemCnt) then
  294. return
  295. end
  296. end
  297. end
  298. BagLogic.delItem(human, itemID, itemCnt, getActLogType(actId))
  299. -- 增加已购买次数
  300. human.db.absAct[actId].newheroCnt[giftid] = nowBuyCnt + 1
  301. -- 发放物品
  302. local items = copyRewardList(config.reward)
  303. BagLogic.addItemList(human, items, getActLogType(actId))
  304. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  305. AbsActLogic.actDetailQuery(human, actId)
  306. end
  307. function updateDaily(human, id)
  308. if not id then return end
  309. if human.db.absAct[id] then
  310. human.db.absAct[id] = {}
  311. end
  312. local state = AbsActLogic.isStarted(human, id)
  313. if state ~= true then
  314. if getActiveActId(human) == nil then
  315. human.db.drawCard.list[8] = {}
  316. end
  317. end
  318. AbsActLogic.actDetailQuery(human, id)
  319. end
  320. -- function GetRemainNum(human, nBuyID)
  321. -- local config = AbsActExcel.absEva[nBuyID]
  322. -- if not config then
  323. -- return 0
  324. -- end
  325. -- local giftid = getgiftbybuyid(nBuyID)
  326. -- if not giftid then return 0 end
  327. -- if not human.db.absAct[ABS_ACT_ID].newheroCnt then
  328. -- return config.limit
  329. -- end
  330. -- if not human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] then
  331. -- return config.limit
  332. -- else
  333. -- return config.limit - human.db.absAct[ABS_ACT_ID].newheroCnt[giftid]
  334. -- end
  335. -- end