| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- local AbsActExcel = require("excel.absAct")
- local Lang = require("common.Lang")
- local ObjHuman = require("core.ObjHuman")
- local Msg = require("core.Msg")
- local Broadcast = require("broadcast.Broadcast")
- local Grid = require("bag.Grid")
- local BagLogic = require("bag.BagLogic")
- local ItemDefine = require("bag.ItemDefine")
- local BuyLogic = require("topup.BuyLogic")
- local AbsActDefine = require("absAct.AbsActDefine")
- local AbsActLogic = require("absAct.AbsActLogic")
- local Log = require("common.Log")
- local YunYingLogic = require("yunying.YunYingLogic")
- ABS_ACT_ID = 9001
- NEW_HERO_MODULE_FN = "absAct.NewHeroLogic"
- NEW_HERO_ACT_TYPES = {}
- --
- function initAfterHot()
- NEW_HERO_ACT_TYPES = {}
- for _, config in pairs(AbsActExcel.absActivity) do
- if config.moduleFn == NEW_HERO_MODULE_FN then
- NEW_HERO_ACT_TYPES[#NEW_HERO_ACT_TYPES + 1] = config.type
- end
- end
- end
- function getActiveActId(human)
- for _, actType in ipairs(NEW_HERO_ACT_TYPES) do
- local state, actId = AbsActLogic.isStartedByType(human, actType)
- if state and actId then
- return actId
- end
- end
- end
- local function getGiftConfig(giftId, actId)
- local config = AbsActExcel.absEva[giftId]
- if not config or config.actId ~= actId then
- return
- end
- return config
- end
- local function copyRewardList(reward)
- local items = {}
- for _, v in ipairs(reward) do
- items[#items + 1] = {v[1], v[2], v[3]}
- end
- return items
- end
- --
- function isActive(human, YYInfo, funcConfig)
- return not isOpen(human, YYInfo, funcConfig)
- end
- --
- function isOpen(human, YYInfo, funcConfig)
- return AbsActLogic.isStarted(human, funcConfig.funcID)
- end
- --
- function isRed(human, YYInfo, funcConfig)
- return false
- end
- --
- function getLeftTime(human, YInfo, funcConfig)
- local actId = funcConfig and funcConfig.funcID or getActiveActId(human)
- if not actId then
- return 0
- end
- local ret, endTime, startTime = AbsActLogic.isStarted(human, actId)
- if ret == true then
- return endTime - os.time()
- else
- return 0
- end
- end
- function getNewHeroID(human)
- local actId = getActiveActId(human)
- if not actId then return 0 end
- local absActConfig = AbsActExcel.absActivity[actId]
- if not absActConfig then return 0 end
- return absActConfig.icon
- end
- -- 精英召唤drawCard配置: 主池, 100抽UP, 十连保底, 40抽SSR
- local NEW_HERO_DRAW_CONFIG = {
- [9001] = {8, 9, 10, 11},
- [9002] = {13, 14, 15, 16},
- [9003] = {17, 18, 19, 20},
- }
- local DEFAULT_NEW_HERO_DRAW_CONFIG = {8, 9, 10, 11}
- function getNewHeroDrawConfigIds(actId)
- local ids = (actId and NEW_HERO_DRAW_CONFIG[actId]) or DEFAULT_NEW_HERO_DRAW_CONFIG
- return ids[1], ids[2], ids[3], ids[4]
- end
- local function getActClientIndex(actId)
- if actId == 9001 then
- return 1
- elseif actId == 9002 then
- return 2
- elseif actId == 9003 then
- return 3
- end
- return 0
- end
- local function getActLogType(actId)
- if actId == 9002 then
- return "newhero_reward_9002"
- elseif actId == 9003 then
- return "newhero_reward_9003"
- end
- return "newhero_reward"
- end
- function getAndSendMsg(human, id, actId)
- local now = os.time()
- local startedFlag, endTime, startTime = AbsActLogic.isStarted(human, id)
- if not startedFlag then
- return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
- end
- local absActConfig = AbsActExcel.absActivity[id]
- if not absActConfig then
- return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
- end
- local absAct = human.db.absAct[id]
- if not absAct then
- return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
- end
- local msgRet = Msg.gc.GC_ABS_NEWHERO
- msgRet.id = absActConfig.icon
- msgRet.startTime = startTime
- msgRet.endTime = endTime
- msgRet.actIndex = getActClientIndex(id)
- local index = 0
- local giftIds = {}
- for giftId, v in pairs(AbsActExcel.absEva) do
- if v.actId == id then
- giftIds[#giftIds + 1] = giftId
- end
- end
- table.sort(giftIds)
- for _, giftId in ipairs(giftIds) do
- local v = AbsActExcel.absEva[giftId]
- index = index + 1
- for j = 1, #v.reward do
- Grid.makeItem(msgRet.giftlist[index].item[j], v.reward[j][1], v.reward[j][2])
- end
- msgRet.giftlist[index].item[0] = #v.reward
- msgRet.giftlist[index].cnt = absAct.newheroCnt and absAct.newheroCnt[giftId] or 0
- msgRet.giftlist[index].id = giftId
- msgRet.giftlist[index].maxCnt = v.limit
- local buyID = v.buyID
- msgRet.giftlist[index].buyMsg[0] = 1
- if v.buyID == 0 then
- msgRet.giftlist[index].buyMsg[1] = {
- buyID = buyID,
- region = "zuanshi",
- cost = v.price,
- icon = 0,
- name = "",
- isFirst = 0,
- desc = "",
- doubleCnt = 0,
- actDoubleCnt = 0,
- useDoubleCnt = 0,
- buyCnt = 0,
- vipExp = 0,
- yuanjia = 0,
- zhekou = 0,
- voucher = 0,
- productId = "",
- nCanBuyNum = 0,
- }
- else
- BuyLogic.fontBuyItem(human, msgRet.giftlist[index].buyMsg[1], buyID)
- end
- end
- msgRet.giftlist[0] = index
- if index == 0 then
- return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
- end
- Msg.send(msgRet, human.fd)
- end
- function getgiftbybuyid(buyid, actId)
- for giftId, v in pairs(AbsActExcel.absEva) do
- if v.buyID == buyid and v.actId == actId then
- return giftId
- end
- end
- end
- function newheroGift(human, id, buyConf, isFirst, cnt, buyNum)
- local state = AbsActLogic.isStarted(human, id)
- local absConfig = AbsActExcel.absActivity[id]
- if absConfig == nil then
- Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
- "[NewHeroLogic.newheroGift] absActivity config not found, actId=%s, buyID=%s, newUniqueTag=%s",
- tostring(id), tostring(buyConf and buyConf.id), tostring(human.db.newUniqueTag)))
- return
- end
- if not state then
- Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
- "[NewHeroLogic.newheroGift] act not started, actId=%s, buyID=%s, newUniqueTag=%s, now=%s",
- tostring(id), tostring(buyConf.id), tostring(human.db.newUniqueTag), os.time()))
- return
- end
- -- 存在多个特惠礼包 同时 开放
- local giftid = getgiftbybuyid(buyConf.id, id)
- if not giftid then
- Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
- "[NewHeroLogic.newheroGift] absEva gift not found, actId=%s, buyID=%s, newUniqueTag=%s",
- tostring(id), tostring(buyConf.id), tostring(human.db.newUniqueTag)))
- return
- end
- local config = getGiftConfig(giftid, id)
- if not config then
- Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
- "[NewHeroLogic.newheroGift] absEva gift config invalid, actId=%s, giftId=%s, buyID=%s, newUniqueTag=%s",
- tostring(id), tostring(giftid), tostring(buyConf.id), tostring(human.db.newUniqueTag)))
- return
- end
- AbsActLogic.checkAbsActClean(human, id)
- human.db.absAct[id].newheroCnt = human.db.absAct[id].newheroCnt or { }
- local nowBuyCnt = human.db.absAct[id].newheroCnt[giftid] or 0
- -- 判断是否达到购买上限
- if nowBuyCnt >= config.limit then
- Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
- return
- end
- -- if nowBuyCnt + buyNum >= config.limit then
- -- Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
- -- return
- -- end
- -- 当金币购买之后超过最大金币时,不允许购买
- for j = 1, #config.reward do
- local itemID = config.reward[j][1]
- local itemCnt = config.reward[j][2]
- if itemID == ItemDefine.ITEM_JINBI_ID then
- if not ObjHuman.canAddJinbi(human, itemCnt) then
- return
- end
- end
- end
- -- 增加已购买次数
- -- human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + buyNum
- -- -- 发放物品
- -- local items = { }
- -- for _, v in ipairs(config.reward) do
- -- table.insert(items, {v[1], v[2] * buyNum})
- -- end
-
- -- BagLogic.addItemList(human, config.reward, "newhero_reward")
- human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + 1
- -- 发放物品
- local items = copyRewardList(config.reward)
- BagLogic.addItemList(human, items, getActLogType(id))
- Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
- AbsActLogic.actDetailQuery(human, id)
- end
- function giftBuy(human, giftid)
- local actId = getActiveActId(human)
- if not actId then
- return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
- end
- local state = AbsActLogic.isStarted(human, actId)
- if state ~= true then
- return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
- end
- local absConfig = AbsActExcel.absActivity[actId]
- if not absConfig then
- return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
- end
- AbsActLogic.checkAbsActClean(human, actId)
- -- 存在多个特惠礼包 同时 开放
- local config = getGiftConfig(giftid, actId)
- if not config then
- return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
- end
- if config.buyID ~= 0 then
- return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
- end
- -- 初始化已购买次数
- human.db.absAct[actId].newheroCnt = human.db.absAct[actId].newheroCnt or { }
- local nowBuyCnt = human.db.absAct[actId].newheroCnt[giftid] or 0
- -- 判断是否达到购买上限
- if nowBuyCnt >= config.limit then
- Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
- return
- end
- local itemID = ItemDefine.ITEM_ZUANSHI_ID
- local itemCnt = config.price
- if not BagLogic.checkItemCnt(human, itemID, itemCnt) then
- Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
- return
- end
- -- 当金币购买之后超过最大金币时,不允许购买
- for j = 1, #config.reward do
- local itemID = config.reward[j][1]
- local itemCnt = config.reward[j][2]
- if itemID == ItemDefine.ITEM_JINBI_ID then
- if not ObjHuman.canAddJinbi(human, itemCnt) then
- return
- end
- end
- end
- BagLogic.delItem(human, itemID, itemCnt, getActLogType(actId))
- -- 增加已购买次数
- human.db.absAct[actId].newheroCnt[giftid] = nowBuyCnt + 1
- -- 发放物品
- local items = copyRewardList(config.reward)
- BagLogic.addItemList(human, items, getActLogType(actId))
- Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
- AbsActLogic.actDetailQuery(human, actId)
- end
- function updateDaily(human, id)
- if not id then return end
- if human.db.absAct[id] then
- human.db.absAct[id] = {}
- end
- local state = AbsActLogic.isStarted(human, id)
- if state ~= true then
- if getActiveActId(human) == nil then
- human.db.drawCard.list[8] = {}
- end
- end
- AbsActLogic.actDetailQuery(human, id)
- end
- -- function GetRemainNum(human, nBuyID)
- -- local config = AbsActExcel.absEva[nBuyID]
- -- if not config then
- -- return 0
- -- end
- -- local giftid = getgiftbybuyid(nBuyID)
- -- if not giftid then return 0 end
- -- if not human.db.absAct[ABS_ACT_ID].newheroCnt then
- -- return config.limit
- -- end
- -- if not human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] then
- -- return config.limit
- -- else
- -- return config.limit - human.db.absAct[ABS_ACT_ID].newheroCnt[giftid]
- -- end
- -- end
|