NewHeroLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. BuyLogic.fontBuyItem(human, msgRet.giftlist[index].buyMsg[1], buyID)
  172. end
  173. msgRet.giftlist[0] = index
  174. if index == 0 then
  175. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  176. end
  177. Msg.send(msgRet, human.fd)
  178. end
  179. function getgiftbybuyid(buyid, actId)
  180. for giftId, v in pairs(AbsActExcel.absEva) do
  181. if v.buyID == buyid and v.actId == actId then
  182. return giftId
  183. end
  184. end
  185. end
  186. function newheroGift(human, id, buyConf, isFirst, cnt, buyNum)
  187. local state = AbsActLogic.isStarted(human, id)
  188. local absConfig = AbsActExcel.absActivity[id]
  189. if absConfig == nil then
  190. Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
  191. "[NewHeroLogic.newheroGift] absActivity config not found, actId=%s, buyID=%s, newUniqueTag=%s",
  192. tostring(id), tostring(buyConf and buyConf.id), tostring(human.db.newUniqueTag)))
  193. return
  194. end
  195. if not state then
  196. Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
  197. "[NewHeroLogic.newheroGift] act not started, actId=%s, buyID=%s, newUniqueTag=%s, now=%s",
  198. tostring(id), tostring(buyConf.id), tostring(human.db.newUniqueTag), os.time()))
  199. return
  200. end
  201. -- 存在多个特惠礼包 同时 开放
  202. local giftid = getgiftbybuyid(buyConf.id, id)
  203. if not giftid then
  204. Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
  205. "[NewHeroLogic.newheroGift] absEva gift not found, actId=%s, buyID=%s, newUniqueTag=%s",
  206. tostring(id), tostring(buyConf.id), tostring(human.db.newUniqueTag)))
  207. return
  208. end
  209. local config = getGiftConfig(giftid, id)
  210. if not config then
  211. Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
  212. "[NewHeroLogic.newheroGift] absEva gift config invalid, actId=%s, giftId=%s, buyID=%s, newUniqueTag=%s",
  213. tostring(id), tostring(giftid), tostring(buyConf.id), tostring(human.db.newUniqueTag)))
  214. return
  215. end
  216. AbsActLogic.checkAbsActClean(human, id)
  217. human.db.absAct[id].newheroCnt = human.db.absAct[id].newheroCnt or { }
  218. local nowBuyCnt = human.db.absAct[id].newheroCnt[giftid] or 0
  219. -- 判断是否达到购买上限
  220. if nowBuyCnt >= config.limit then
  221. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  222. return
  223. end
  224. -- if nowBuyCnt + buyNum >= config.limit then
  225. -- Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  226. -- return
  227. -- end
  228. -- 当金币购买之后超过最大金币时,不允许购买
  229. for j = 1, #config.reward do
  230. local itemID = config.reward[j][1]
  231. local itemCnt = config.reward[j][2]
  232. if itemID == ItemDefine.ITEM_JINBI_ID then
  233. if not ObjHuman.canAddJinbi(human, itemCnt) then
  234. return
  235. end
  236. end
  237. end
  238. -- 增加已购买次数
  239. -- human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + buyNum
  240. -- -- 发放物品
  241. -- local items = { }
  242. -- for _, v in ipairs(config.reward) do
  243. -- table.insert(items, {v[1], v[2] * buyNum})
  244. -- end
  245. -- BagLogic.addItemList(human, config.reward, "newhero_reward")
  246. human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + 1
  247. -- 发放物品
  248. local items = copyRewardList(config.reward)
  249. BagLogic.addItemList(human, items, getActLogType(id))
  250. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  251. AbsActLogic.actDetailQuery(human, id)
  252. end
  253. function giftBuy(human, giftid)
  254. local actId = getActiveActId(human)
  255. if not actId then
  256. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  257. end
  258. local state = AbsActLogic.isStarted(human, actId)
  259. if state ~= true then
  260. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  261. end
  262. local absConfig = AbsActExcel.absActivity[actId]
  263. if not absConfig then
  264. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  265. end
  266. AbsActLogic.checkAbsActClean(human, actId)
  267. -- 存在多个特惠礼包 同时 开放
  268. local config = getGiftConfig(giftid, actId)
  269. if not config then
  270. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  271. end
  272. if config.buyID ~= 0 then
  273. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  274. end
  275. -- 初始化已购买次数
  276. human.db.absAct[actId].newheroCnt = human.db.absAct[actId].newheroCnt or { }
  277. local nowBuyCnt = human.db.absAct[actId].newheroCnt[giftid] or 0
  278. -- 判断是否达到购买上限
  279. if nowBuyCnt >= config.limit then
  280. Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
  281. return
  282. end
  283. local itemID = ItemDefine.ITEM_ZUANSHI_ID
  284. local itemCnt = config.price
  285. if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
  286. Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  287. return
  288. end
  289. -- 当金币购买之后超过最大金币时,不允许购买
  290. for j = 1, #config.reward do
  291. local itemID = config.reward[j][1]
  292. local itemCnt = config.reward[j][2]
  293. if itemID == ItemDefine.ITEM_JINBI_ID then
  294. if not ObjHuman.canAddJinbi(human, itemCnt) then
  295. return
  296. end
  297. end
  298. end
  299. BagLogic.delItem(human, itemID, itemCnt, getActLogType(actId))
  300. -- 增加已购买次数
  301. human.db.absAct[actId].newheroCnt[giftid] = nowBuyCnt + 1
  302. -- 发放物品
  303. local items = copyRewardList(config.reward)
  304. BagLogic.addItemList(human, items, getActLogType(actId))
  305. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  306. AbsActLogic.actDetailQuery(human, actId)
  307. end
  308. function updateDaily(human, id)
  309. if not id then return end
  310. if human.db.absAct[id] then
  311. human.db.absAct[id] = {}
  312. end
  313. local state = AbsActLogic.isStarted(human, id)
  314. if state ~= true then
  315. if getActiveActId(human) == nil then
  316. human.db.drawCard.list[8] = {}
  317. end
  318. end
  319. AbsActLogic.actDetailQuery(human, id)
  320. end
  321. -- function GetRemainNum(human, nBuyID)
  322. -- local config = AbsActExcel.absEva[nBuyID]
  323. -- if not config then
  324. -- return 0
  325. -- end
  326. -- local giftid = getgiftbybuyid(nBuyID)
  327. -- if not giftid then return 0 end
  328. -- if not human.db.absAct[ABS_ACT_ID].newheroCnt then
  329. -- return config.limit
  330. -- end
  331. -- if not human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] then
  332. -- return config.limit
  333. -- else
  334. -- return config.limit - human.db.absAct[ABS_ACT_ID].newheroCnt[giftid]
  335. -- end
  336. -- end