| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- -- 新商业化活动2——6元闯关
- -- 玩法: 充值指定购买项后, 获得一次参与机会,通过权重随机出前进步数,获得1~最终位置的所有奖励
- -- db
- --[=[
- human.db.absAct[id] = {
- times = nil, --参与次数
- dailyBuyCnt = nil, --每日购买次数
- }
- ]=]--
- local Msg = require("core.Msg")
- local Grid = require("bag.Grid")
- local Lang = require("common.Lang")
- local BagLogic = require("bag.BagLogic")
- local BuyLogic = require("topup.BuyLogic")
- local AbsActExcel = require("excel.absAct")
- local Broadcast = require("broadcast.Broadcast")
- local YunYingLogic = require("yunying.YunYingLogic")
- local CycleActivityLogic = require("yunying.CycleActivity")
- local actVariableCfg = require("excel.commercializationActivity").variable[2]
- local breakThroughCfg = require("excel.commercializationActivity").breakThrough
- -- 本活动日志标识
- local LOGTAG = "cycleAct_breakThrough"
- local DAILY_MAX_BUY_CNT = 50
- local function getActData(human, actId)
- return human.db.absAct[actId]
- end
- local function updateActTimes(human, actId, value)
- local actData = getActData(human, actId)
- actData.times = (actData.times or 0) + value
- end
- local function updateActDailyBuyCnt(human, actId, value)
- local actData = getActData(human, actId)
- actData.dailyBuyCnt = (actData.dailyBuyCnt or 0) + value
- actData.dailyBuyCnt = math.max(actData.dailyBuyCnt, 0)
- end
- local function calcWeightSum()
- local weight = 0
- for _, v in ipairs(breakThroughCfg) do
- weight = weight + v.weight
- end
- return weight
- end
- -- 更新红点
- local function updateRedDot(human, actId)
- YunYingLogic.sendBanner(human)
- local otherConfig = AbsActExcel.absActivity[actId]
- YunYingLogic.sendGroupUpdate(YYInfo[actId], human, otherConfig.panelID)
- end
- function isOpen(human, YYInfo, funcConfig)
- local state, endTime, startTime = CycleActivityLogic.isStarted(human, funcConfig.funcID)
- if not state then return end
- return true, endTime, startTime
- end
- function isActive(human, YYInfo, funcConfig)
- return not isOpen(human, YYInfo, funcConfig)
- end
- function isRed(human, YYInfo, funcConfig)
- local actData = getActData(human, funcConfig.funcID)
- if not actData then
- return false
- end
- if not actData.times or actData.times <= 0 then
- return false
- end
- return true
- end
- function onCharge(human, price, funcID, buyID)
- local actData = getActData(human, funcID)
- if not actData then
- return
- end
- if buyID == actVariableCfg.va1[1] and (not actData.dailyBuyCnt or actData.dailyBuyCnt < DAILY_MAX_BUY_CNT) then
- local oldTimes = actData.times or 0
- updateActTimes(human, funcID, 1)
- updateActDailyBuyCnt(human, funcID, 1)
- Query(human, funcID)
- if oldTimes <= 0 then
- updateRedDot(human, funcID)
- end
- end
- end
- function updateDaily(human, funcID)
- local actData = getActData(human, funcID)
- if not actData then
- return
- end
- updateActDailyBuyCnt(human, funcID, -DAILY_MAX_BUY_CNT)
- end
- function Query(human, actId)
- local actData = getActData(human, actId)
- if not actData then
- return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
- end
- local msgRet = Msg.gc.GC_CYCLEBREAKTHROUGH_QUERY
- msgRet.state = 0
- if actData.times and actData.times > 0 then
- msgRet.state = 1
- end
- msgRet.maxDailyBuyCnt = DAILY_MAX_BUY_CNT
- msgRet.nowDailyBuyCnt = actData.dailyBuyCnt or 0
- BuyLogic.fontBuyItem(human, msgRet.buyMsg, actVariableCfg.va1[1])
- local gridList = msgRet.gridList
- for idx, gridCfg in ipairs(breakThroughCfg) do
- gridList[0] = idx
- local rewardList = gridList[idx].rewardList
- for k, itemCfg in ipairs(gridCfg.reward) do
- rewardList[0] = k
- Grid.makeItem(rewardList[k], itemCfg[1], itemCfg[2])
- end
- end
- Msg.send(msgRet, human.fd)
- end
- function RandPos(human, actId)
- local actData = getActData(human, actId)
- if not actData then
- return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
- end
- if not actData.times or actData.times <= 0 then
- return Broadcast.sendErr(human, Lang.JINBI_EXCHANGE_ERR_CNT)
- end
- local weightSum = calcWeightSum()
- local randWeight = math.random(1, weightSum)
- local itemVec = {}
- local len, randIdx, weight = 0, 0, 0
- for idx, gridCfg in ipairs(breakThroughCfg) do
- for _, itemCfg in ipairs(gridCfg.reward) do
- len = len + 1
- itemVec[len] = {itemCfg[1], itemCfg[2]}
- end
- weight = weight + gridCfg.weight
- if weight >= randWeight then
- randIdx = idx
- break
- end
- end
- -- 扣除次数
- updateActTimes(human, actId, -1)
- local msgRet = Msg.gc.GC_CYCLEBREAKTHROUGH_RAND
- msgRet.randVal = randIdx
- msgRet.state = 1
- local itemArray = msgRet.itemArray
- for idx, itemInfo in ipairs(itemVec) do
- itemArray[0] = idx
- Grid.makeItem(itemArray[idx], itemInfo[1], itemInfo[2])
- BagLogic.addItem(human, itemInfo[1], itemInfo[2], LOGTAG)
- end
- if actData.times <= 0 then
- msgRet.state = 0
- updateRedDot(human, actId)
- end
- Msg.send(msgRet, human.fd)
- -- BagLogic.addItemList(human, itemVec, LOGTAG)
- end
|