NewHeroLogic.lua 12 KB

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