Quellcode durchsuchen

提交新商业活动-登录豪礼, 新商业活动-特价商店 逻辑文件

gitxsm vor 1 Jahr
Ursprung
Commit
91486402b9

+ 111 - 0
script/module/absAct/AbsDiscountStoreLogic.lua

@@ -0,0 +1,111 @@
+--新商业化活动——特价商店
+--db
+--[=[
+    human.db.absAct[id] = {
+        buyRecord = {
+            [1] = 2, --key是道具在配置中的id, value是已经购买次数
+            [2] = 1,
+        }
+    }
+]=]--
+
+local Msg = require("core.Msg")
+local Grid = require("bag.Grid")
+local BagLogic = require("bag.BagLogic")
+local AbsActLogic = require("absAct.AbsActLogic")
+local Broadcast = require("broadcast.Broadcast")
+local Lang = require("common.Lang")
+local Config = require("excel.absAct").AbsDiscountStore
+
+local LOGTAG = "AbsDiscountStore" --日志标识
+
+
+function isOpen(human, YYInfo, funcConfig)
+    local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
+    return state, endTime, startTime
+end
+
+
+function isActive(human, YYInfo, funcConfig)
+    local state = isOpen(human, YYInfo, funcConfig)
+    return not state
+end
+
+
+--查询
+function Query(human, id)
+    local state = AbsActLogic.isStarted(human, id)
+    if not state then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local actData = human.db.absAct[id]
+    if not actData then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local buyRecord = actData.buyRecord
+    local msgRet = Msg.gc.GC_DISCOUNTSTORE_QUERY
+
+    local itemVec = msgRet.itemVec
+    itemVec[0] = #Config
+
+    for k,v in ipairs(Config) do
+        local singleItem = itemVec[k]
+        singleItem.idx = k
+        singleItem.maxBuyCnt = v.maxBuyCnt
+        singleItem.nowBuyCnt = buyRecord and buyRecord[k] or 0
+        Grid.makeItem(singleItem.item, v.item[1], v.item[2])
+        -- singleItem.currencyId = v.currencyInfo[1]
+        -- singleItem.currencyCnt = v.currencyInfo[2]
+        Grid.makeItem(singleItem.currency, v.currencyInfo[1], v.currencyInfo[2])
+    end
+
+    Msg.send(msgRet, human.fd)
+end
+
+--购买商品
+function BuyItem(human, id, itemIdx, buyCnt)
+    local state = AbsActLogic.isStarted(human, id)
+    if not state then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local actData = human.db.absAct[id]
+    if not actData then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local itemCfg = Config[itemIdx]
+    if not itemCfg then
+        return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
+    end
+
+    local buyRecord = actData.buyRecord
+    if buyRecord and buyRecord[itemIdx] then
+        if buyRecord[itemIdx] + buyCnt > itemCfg.maxBuyCnt then
+            return Broadcast.sendErr(human, Lang.COMMON_BUY_NUM_NOT_ENOUGH)
+        end
+    end
+
+    local currencyInfo = itemCfg.currencyInfo
+    if BagLogic.getItemCnt(human, currencyInfo[1]) < currencyInfo[2] then
+        return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH)
+    end
+    BagLogic.delItem(human, currencyInfo[1], currencyInfo[2], LOGTAG)
+
+    --更新数据
+    buyRecord = buyRecord or {}
+    buyRecord[itemIdx] = (buyRecord[itemIdx] or 0) + buyCnt
+    actData.buyRecord = buyRecord
+
+    --发放奖励
+    local itemInfo = itemCfg.item
+    BagLogic.addItemList(human, {{itemInfo[1], itemInfo[2] * buyCnt}}, LOGTAG)
+
+    --下发数据
+    local msgRet = Msg.gc.GC_DISCOUNTSTORE_BUY
+    msgRet.idx = itemIdx
+    msgRet.nowBuyCnt = itemCfg.buyRecord[itemIdx]
+    Msg.send(msgRet, human.fd)
+end

+ 203 - 0
script/module/absAct/AbsLoginRewardLogic.lua

@@ -0,0 +1,203 @@
+--新商业化活动——登录豪礼
+--db
+--[=[
+    human.db.absAct[id] = {
+        loginDay = nil, --活动期间登录的天数
+        getRewardRecord = nil, {1,3,2,6} --已领取的奖励记录, 记录的是第几天
+    }
+]=]--
+
+local Msg = require("core.Msg")
+local Grid = require("bag.Grid")
+local BagLogic = require("bag.BagLogic")
+local AbsActLogic = require("absAct.AbsActLogic")
+local Broadcast = require("broadcast.Broadcast")
+local Lang = require("common.Lang")
+local Config = require("excel.absAct").AbsLoginReward
+local AbsActExcel = require("excel.absAct")
+local YunYingLogic = require("yunying.YunYingLogic")
+
+local LOGTAG = "AbsLoginReward" --日志标识
+
+
+local function check(tbl, day)
+    if not tbl or not day then
+        return false
+    end
+
+    for _, v in ipairs(tbl) do
+        if v == day then
+            return true
+        end
+    end
+
+    return false
+end
+
+function isOpen(human, YYInfo, funcConfig)
+    local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
+    return state, endTime, startTime
+end
+
+
+function isActive(human, YYInfo, funcConfig)
+    local state = isOpen(human, YYInfo, funcConfig)
+    return not state
+end
+
+
+--红点判断
+function isRed(human, YYInfo, funcConfig)
+    local actData = human.db.absAct[funcConfig.funcID]
+    if not actData then
+        return false
+    end
+
+    local loginDay = actData.loginDay
+    if not loginDay then
+        return false
+    end
+
+    local getRewardRecord = actData.getRewardRecord
+    if getRewardRecord and #getRewardRecord >= loginDay then
+        return false
+    end
+
+    return true
+end
+
+function onLogin(human, id)
+    local state = AbsActLogic.isStarted(human, id)
+    if not state then
+        return
+    end
+
+    local actData = human.db.absAct[id]
+    if not actData then
+        return
+    end
+
+    --处理活动更到线上前,玩家当天已经登录,没有记录当天登录的情况
+    if not actData.loginDay then
+        actData.loginDay = 1
+        --红点刷新
+        YunYingLogic.sendBanner(human)
+        local config = AbsActExcel.absActivity[id]
+        YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
+    end
+end
+
+
+
+--跨天函数
+function updateDaily(human, id)
+    local state = AbsActLogic.isStarted(human, id)
+    if not state then
+        return
+    end
+
+    local actData = human.db.absAct[id]
+    if not actData then
+        return
+    end
+
+    actData.loginDay =( actData.loginDay or 0) + 1
+
+    --红点刷新
+    YunYingLogic.sendBanner(human)
+    local config = AbsActExcel.absActivity[id]
+    YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
+end
+
+
+--查询
+function Query(human, id)
+    local state = AbsActLogic.isStarted(human, id)
+    if not state then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local actData = human.db.absAct[id]
+    if not actData then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local msgRet = Msg.gc.GC_LOGINREWARD_QUERY
+    local dayRewardData = msgRet.dayRewardData
+
+
+    dayRewardData[0] = #Config
+    local loginDay = actData.loginDay
+    local getRewardRecord = actData.getRewardRecord
+
+    for day, cfg in ipairs(Config) do
+        dayRewardData[day].day = day
+        dayRewardData[day].state = 0
+        local isGet = check(getRewardRecord, day)
+
+        if loginDay and loginDay >= day and isGet then
+            dayRewardData[day].state = 2
+        elseif loginDay and loginDay >= day and not isGet then
+            dayRewardData[day].state = 1
+        end
+
+        local rewardInfo = dayRewardData[day].rewardInfo
+        rewardInfo[0] = #cfg.item
+        for idx, itemInfo in ipairs(cfg.item) do
+            Grid.makeItem(rewardInfo[idx], itemInfo[1], itemInfo[2])
+        end
+    end
+
+    Msg.send(msgRet, human.fd)
+end
+
+
+--领奖
+function GetReward(human, id, dayIndex)
+    local state = AbsActLogic.isStarted(human, id)
+    if not state then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local actData = human.db.absAct[id]
+    if not actData then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local loginDay = actData.loginDay
+    if not loginDay or dayIndex > loginDay then
+        return Broadcast.sendErr(human, Lang.COMMON_TIME_NOT_ENOUGH)
+    end
+
+
+    local getRewardRecord = actData.getRewardRecord
+    if getRewardRecord then
+        if check(getRewardRecord, dayIndex) then
+            return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
+        end
+    end
+
+    if dayIndex > #Config then
+        return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
+    end
+
+    --更新db
+    getRewardRecord = getRewardRecord or {}
+    table.insert(getRewardRecord, dayIndex)
+    actData.getRewardRecord = getRewardRecord
+
+    --发放奖励
+    local targetDayReward = Config[dayIndex].item
+    BagLogic.addItemList(human, targetDayReward, LOGTAG)
+
+    --发下客户端更新数据
+    Query(human, id) --暂定使用查询协议更新数据
+
+
+    --更新红点
+    if #getRewardRecord >= loginDay then
+        YunYingLogic.sendBanner(human)
+        local config = AbsActExcel.absActivity[id]
+        YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
+    end
+end