Browse Source

通用节日活动-登录豪礼

gitxsm 4 months ago
parent
commit
af888ce9ff

+ 2 - 0
script/common/LogDefine.lua

@@ -272,6 +272,8 @@ DEFINE = {
 	UnlimitDrawCard			= 275,			 -- 无限高抽
 	OpenServerGiftPackage   = 276,			 -- 开服礼包
 	item_hecheng  			= 277,			 -- 物品合成
+	CommonActLoginGift		= 278,			 -- 通用节日活动 - 登录豪礼
+	CommonActMoneyTree		= 279,			 -- 通用节日活动 - 摇钱树
 
 	abs_totalReach          = 500,           -- 周期性活动累计
     abs_singleReach         = 501,           -- 周期性活动单次

+ 5 - 1
script/common/ProtoID.lua

@@ -1767,4 +1767,8 @@ _ENV[1806]="GC_BREATHROUGHTHEME_ADVANCEDREWARD_QUERY"
 _ENV[1807]="CG_BREATHROUGHTHEME_GET_REWARD"
 _ENV[1808]="GC_BREATHROUGHTHEME_REDDOT"
 _ENV[1809]="CG_BREATHROUGHTHEME_SHOW_TIPS"
-_ENV[1810]="GC_BREATHROUGHTHEME_SHOW_TIPS"
+_ENV[1810]="GC_BREATHROUGHTHEME_SHOW_TIPS"
+
+_ENV[1811]="CG_ABS_COMONACT_LOGINGIFT_QUERY"
+_ENV[1812]="GC_ABS_COMONACT_LOGINGIFT_QUERY"
+_ENV[1813]="CG_ABS_COMONACT_LOGINGIFT_GET_REWARD"

+ 7 - 1
script/module/absAct/AbsActLogic.lua

@@ -85,7 +85,7 @@ function onLogin(human)
     end
     -- 是否有新增活动
     for k,v in pairs(absActConfig) do 
-        local ok,realEndTime = isStarted(human,k)
+        local ok,realEndTime, realStartTime = isStarted(human,k)
         if ok and  human.db.absAct[k] then
             --- 同步结束时间
             local nowTime = os.time()
@@ -93,6 +93,10 @@ function onLogin(human)
             if  finishTime >= nowTime and  finishTime ~= realEndTime then
                 human.db.absAct[k].finish = realEndTime
             end
+
+            if not human.db.absAct[k].realStartTime or human.db.absAct[k].realStartTime ~= realStartTime then
+                human.db.absAct[k].realStartTime = realStartTime
+            end
         end
         if ok and not human.db.absAct[k] then 
             human.db.absAct[k] = {}
@@ -101,6 +105,8 @@ function onLogin(human)
                 human.db.absAct[k] = f.genAbsActData(v)
             end
             human.db.absAct[k].finish = realEndTime -- 记录活动结束时间
+
+            human.db.absAct[k].realStartTime = realStartTime
         end
     end
     -- 登录奖励重置

+ 274 - 0
script/module/absAct/CommonActLoginGift.lua

@@ -0,0 +1,274 @@
+-- 通用节日活动 - 登录豪礼
+-- db
+--[=[
+    human.db.absAct[actId] = {
+        getRecordData = {
+            [gitftType] = {
+                [day1] = true,
+                [day3] = true,
+            },
+        },
+
+        buyGiftType = nil, -- 已经购买的礼包类型
+    }   
+]=]--
+
+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 LoginGiftConfig = require("excel.commonact").loginreward
+local CommonDefine = require("common.CommonDefine")
+local Util = require("common.Util")
+local YunYingLogic = require("yunying.YunYingLogic")
+local AbsActExcel = require("excel.absAct")
+local BuyLogic = require("topup.BuyLogic")
+
+local LOGTYPE = "CommonActLoginGift"
+local COMMONACT_LOGINGIFT_ID = 7505
+
+
+local function getActData(human)
+    return human.db.absAct[COMMONACT_LOGINGIFT_ID]
+end
+
+local function updateGetRecordData(human, giftType, dayIdx)
+    human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData = human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData or {}
+    human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData[giftType] = human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData[giftType] or {}
+    human.db.absAct[COMMONACT_LOGINGIFT_ID].getRecordData[giftType][dayIdx] = true
+end
+
+local function updateBuyGiftType(human, giftType)
+    human.db.absAct[COMMONACT_LOGINGIFT_ID].buyGiftType = giftType
+end
+
+
+
+local function isOpen(human, funcID)
+    return AbsActLogic.isStarted(human, funcID)
+end
+
+local function transformCfg()
+    local tb = {}
+    for _, giftCfg in ipairs(LoginGiftConfig) do
+        if not tb[giftCfg.giftType] then
+            tb[giftCfg.giftType] = {}
+        end
+        local t = tb[giftCfg.giftType]
+        t[#t+1] = giftCfg
+    end
+
+    return tb
+end
+
+local function getAwardState(human, giftType, dayIdx)
+    local actData = getActData(human)
+    local diffDays = Util.diffDay(actData.realStartTime) + 1
+    local getRecordData = actData and actData.getRecordData or {}
+    local nowGiftTypeGetRecord = getRecordData[giftType] or {}
+    local buyGiftType = actData and actData.buyGiftType
+
+    local isBuy = true
+    local state = CommonDefine.COMMON_PRIZE_STATE_CANGET
+
+    if giftType ~= 1 and (not buyGiftType or buyGiftType ~= giftType) then -- 需要充值的礼包类型
+        state = CommonDefine.COMMON_PRIZE_STATE_NOGET
+        isBuy = false
+    end
+
+    if isBuy and diffDays >= dayIdx and nowGiftTypeGetRecord[dayIdx] then
+        state = CommonDefine.COMMON_PRIZE_STATE_GET
+    end
+
+    return state
+end
+
+-- 检查是否有可领取的奖励
+local function isCanGet(human)
+    local type_2_cfg = transformCfg()
+
+    for giftType, giftCfgArr in pairs(type_2_cfg) do
+        for _, giftCfg in ipairs(giftCfgArr) do
+            local state = getAwardState(human, giftType, giftCfg.dayIdx)
+            if state == CommonDefine.COMMON_PRIZE_STATE_CANGET then
+                return true
+            end
+        end
+    end
+
+    return false
+end
+-- 填充协议结构
+local function populateGiftMsg(human, net, giftCfg, nowGiftType)
+    net.reward[0] = #giftCfg.reward
+    for i, itemInfo in ipairs(giftCfg.reward) do
+        Grid.makeItem(net.reward[i], itemInfo[1], itemInfo[2])
+    end
+
+    net.reallyDays = giftCfg.dayIdx
+    net.rewardState = getAwardState(human, nowGiftType, giftCfg.dayIdx)
+    BuyLogic.fontBuyItem(human, net.buyMsg, giftCfg.buyId)
+    net.giftType = nowGiftType
+end
+-- 主动刷新一次红点
+local function updateRedDot(human)
+    YunYingLogic.sendBanner(human)
+    local config = AbsActExcel.absActivity[COMMONACT_LOGINGIFT_ID]
+    YunYingLogic.sendGroupUpdate(YYInfo[COMMONACT_LOGINGIFT_ID], human, config.panelID)
+end
+
+
+
+
+function isRed(human, funcConfig)
+    local state = isOpen(human, funcConfig and funcConfig.funcID)
+    if not state then
+        return false
+    end
+
+    return isCanGet(human)
+end
+
+function isOpen(human, YYInfo, funcConfig)
+    return isOpen(human, funcConfig and funcConfig.funcID)
+end
+
+function isActive(human, YYInfo, funcConfig)
+    return not isOpen(human, YYInfo, funcConfig)
+end
+
+function onCharge(human, price, funcID, buyID, buyNum)
+    local actData = getActData(human)
+    local buyGiftType = actData and actData.buyGiftType
+    if buyGiftType then
+        return
+    end
+
+    local type_2_cfg = transformCfg()
+
+    for giftType, giftCfgArr in pairs(type_2_cfg) do
+        local singleCfg = giftCfgArr[1]
+        if singleCfg.buyId == buyID then
+            updateBuyGiftType(human, giftType)
+            updateRedDot(human)
+            CommonActLoginGift_Query(human)
+            break
+        end
+    end
+end
+
+function updateDaily(human, funcID)
+    if isOpen(human, nil, COMMONACT_LOGINGIFT_ID) then
+        return
+    end
+
+    updateRedDot(human)
+end
+
+
+
+
+-- 查询
+function CommonActLoginGift_Query(human)
+    local msgRet = Msg.gc.GC_ABS_COMONACT_LOGINGIFT_QUERY
+    msgRet.giftDatafree[0] = 0
+    msgRet.giftData68[0] = 0
+    msgRet.giftData128[0] = 0
+    msgRet.giftData328[0] = 0
+    msgRet.giftData648[0] = 0
+    msgRet.isEnd = 0
+    msgRet.isStart = 1
+
+    local len, msgOnceLen = 0, 5
+    local type_2_cfg = transformCfg()
+    local configNum = type_2_cfg[1] and #type_2_cfg[1] or 0
+
+    for i=1, configNum do
+        len = len + 1
+
+        if type_2_cfg[1] then
+            msgRet.giftDatafree[0] = len
+            populateGiftMsg(human, msgRet.giftDatafree[len], type_2_cfg[1][i], 1)
+        end
+
+        if type_2_cfg[2] then
+            msgRet.giftData68[0] = len
+            populateGiftMsg(human, msgRet.giftData68[len], type_2_cfg[2][i], 2)
+        end
+
+        if type_2_cfg[3] then
+            msgRet.giftData128[0] = len
+            populateGiftMsg(human, msgRet.giftData128[len], type_2_cfg[3][i], 3)
+        end
+
+        if type_2_cfg[4] then
+            msgRet.giftData328[0] = len
+            populateGiftMsg(human, msgRet.giftData328[len], type_2_cfg[4][i], 4)
+        end
+
+        if type_2_cfg[5] then
+            msgRet.giftData648[0] = len
+            populateGiftMsg(human, msgRet.giftData648[len], type_2_cfg[5][i], 5)
+        end
+
+        if len >= msgOnceLen then
+            configNum = configNum - len
+            if configNum <= 0 then
+                msgRet.isEnd = 1
+                return Msg.send(msgRet, human.fd)
+            end
+
+            Msg.send(msgRet, human.fd)
+            len = 0
+            msgRet.isStart = 0
+        end
+    end
+
+    if len > 0 then
+        msgRet.isEnd = 1
+        Msg.send(msgRet, human.fd)
+    end
+end
+
+-- 领取奖励
+function CommonActLoginGift_GetReward(human, targetGiftType)
+    local type_2_cfg = transformCfg()
+    local giftArr = type_2_cfg[targetGiftType]
+    if not giftArr then
+        return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
+    end
+
+    local actData = getActData(human)
+    local buyGiftType = actData and actData.buyGiftType
+    if targetGiftType ~= 1 and (not buyGiftType or buyGiftType ~= targetGiftType) then
+        return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
+    end
+
+    local itemArr = {}
+    for _, giftCfg in ipairs(giftArr) do
+        local state = getAwardState(human, targetGiftType, giftCfg.dayIdx)
+        if state == CommonDefine.COMMON_PRIZE_STATE_CANGET then
+            for _, itemInfo in ipairs(giftCfg.reward) do
+                itemArr[#itemArr+1] = { itemInfo[1], itemInfo[2] }
+            end
+
+            -- 记录领取
+            updateGetRecordData(human, targetGiftType, giftCfg.dayIdx)
+        end
+    end
+
+    if #itemArr == 0 then
+        return Broadcast.sendErr(human, Lang.HO_NO_CAN_GET)
+    end
+
+    -- 发放道具
+    BagLogic.addItemList(human, itemArr, LOGTYPE)
+
+    -- 更红点
+    updateRedDot(human)
+
+    -- 推送最新数给客户端
+    CommonActLoginGift_Query(human)
+end

+ 17 - 0
script/module/absAct/CommonActMoneyTree.lua

@@ -0,0 +1,17 @@
+-- 通用节日活动 - 摇钱树
+
+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 LoginGiftConfig = require("excel.commonact").loginreward
+local CommonDefine = require("common.CommonDefine")
+local Util = require("common.Util")
+local YunYingLogic = require("yunying.YunYingLogic")
+local AbsActExcel = require("excel.absAct")
+local BuyLogic = require("topup.BuyLogic")
+
+
+local LOGTYPE = "CommonActMoneyTree"

+ 13 - 0
script/module/absAct/Handler.lua

@@ -50,6 +50,8 @@ local CommonActBoss = require("absAct.CommonActBoss")
 local CommonActShop = require("absAct.CommonActShop")
 local CommonActCharge = require("absAct.CommonActCharge")
 local CommonActFindTreasure = require("absAct.CommonActFindTreasure")
+local CommonActLoginGift = require("absAct.CommonActLoginGift")
+local CommonActMoneyTree = require("absAct.CommonActMoneyTree")
 
 function CG_ABS_ACT_DETAIL_QUERY(human, msg)
     -- local Log = require("common.Log")
@@ -505,4 +507,15 @@ end
 
 function CG_ABS_FESTIVAL_SEVENDAY_CARD_DO(human, msg)
     CommonActFindTreasure.CommonActFindTreasure_Do(human, msg.nType)
+end
+
+
+----------------------------------------------------通用节日活动 — 登录豪礼 --------------------------------------------------
+
+function CG_ABS_COMONACT_LOGINGIFT_QUERY(human, msg)
+    CommonActLoginGift.CommonActLoginGift_Query(human)
+end
+
+function CG_ABS_COMONACT_LOGINGIFT_GET_REWARD(human, msg)
+    CommonActLoginGift.CommonActLoginGift_GetReward(human, msg.giftType)
 end

+ 28 - 0
script/module/absAct/Proto.lua

@@ -1636,4 +1636,32 @@ GC_ABS_FESTIVAL_SEVENDAY_CARD_QUERY = {
 -- 抽取
 CG_ABS_FESTIVAL_SEVENDAY_CARD_DO = {
     {"nType",       1,      "byte"},        -- 抽取类型 1-单抽 2-十连
+}
+
+
+---------------------节日活动 - 登录豪礼 -------------------
+
+COMONACT_LOGINGIFT_INFO = {
+    {"reward",          2,      ItemData},      -- 奖励信息
+    {"reallyDays",      1,      "short"},       -- 第几天
+    {"rewardState",     1,      "byte"},        -- 奖励状态, 0-不可领, 1-可领, 2-已领
+    {"buyMsg",	        1,      BuyItem},       -- buyID
+    {"giftType",        1,      "byte"},        -- 礼包类型, 1-登录豪礼, 2-68礼包, 3-128礼包, 4-328礼包, 5-648礼包
+}
+
+-- 查询
+CG_ABS_COMONACT_LOGINGIFT_QUERY = {}
+GC_ABS_COMONACT_LOGINGIFT_QUERY = {
+    {"giftDatafree",    5,     COMONACT_LOGINGIFT_INFO},      -- 奖励信息
+    {"giftData68",      5,     COMONACT_LOGINGIFT_INFO},      -- 奖励信息
+    {"giftData128",     5,     COMONACT_LOGINGIFT_INFO},      -- 奖励信息
+    {"giftData328",     5,     COMONACT_LOGINGIFT_INFO},      -- 奖励信息
+    {"giftData648",     5,     COMONACT_LOGINGIFT_INFO},      -- 奖励信息
+    {"isEnd",           1,      "byte"},                      -- 是否发完数据, 0-否, 1-是
+    {"isStart",         1,      "byte"},                      -- 是否是第一段数据, 0-否, 1-是
+}
+
+-- 领奖
+CG_ABS_COMONACT_LOGINGIFT_GET_REWARD= {
+    {"giftType",        1,      "byte"},        -- 礼包类型, 1-登录豪礼, 2-68礼包, 3-128礼包, 4-328礼包, 5-648礼包
 }