gitxsm 3 месяцев назад
Родитель
Сommit
b2c1fa2107

+ 1 - 0
script/common/LogDefine.lua

@@ -319,6 +319,7 @@ DEFINE = {
 	ServerCommerceActBattleGround 	= 779,  -- 巅峰战场
 	HeroTianYuan 			= 780,  		-- 英雄天元系统
 	BreakThroughTheme 		= 781,  		-- 闯关主题
+	VoucherInvest 			= 782,  		-- 代金券投资
 
 	errHandle				= 99999,		-- 异常处理
 }

+ 5 - 0
script/common/ProtoID.lua

@@ -1776,6 +1776,11 @@ _ENV[1817]="CG_ABS_COMONACT_MONEYTREE_LOTTERY"
 _ENV[1818]="GC_ABS_COMONACT_MONEYTREE_LOTTERY"
 _ENV[1819]="CG_ABS_COMONACT_MONEYTREE_GET_REWARD"
 
+_ENV[1820]="CG_VOUCHER_INVEST_QUERY"
+_ENV[1821]="GC_VOUCHER_INVEST_QUERY"
+_ENV[1822]="CG_VOUCHER_INVEST_GET"
+
+
 _ENV[1896]="CG_ZHUANPAN_SUBSCRIBE_REWARD_QUERY"
 _ENV[1897]="GC_ZHUANPAN_SUBSCRIBE_REWARD_QUERY"
 _ENV[1898]="CG_ZHUANPAN_SUBSCRIBE_REWARD_GET"

+ 4 - 0
script/core/ObjHuman.lua

@@ -112,6 +112,7 @@ local Json = require("common.Json")
 local UnionLogic
 local GodsAreaNS
 local DataCache
+local VoucherInvest
 
 
 fds				= fds or {}				-- fd->obj_id,包括创角中+游戏中
@@ -398,6 +399,9 @@ function sendAttr(human,key)
 
 	if key == RoleDefine.ZHANDOULI then
 		TriggerLogic.PublishEvent(TriggerDefine.ZHANDOULI, human.db._id, human.attr[key])
+
+		VoucherInvest = VoucherInvest or require("voucher.VoucherInvest")
+		VoucherInvest.PowerUpdate(human)
 	end
 end
 

+ 1 - 1
script/module/absAct/Handler.lua

@@ -524,7 +524,7 @@ end
 ----------------------------------------------------通用节日活动 — 摇钱树 --------------------------------------------------
 
 function CG_ABS_COMONACT_MONEYTREE_QUERY(human, msg)
-    CommonActMoneyTree.CommonActLoginGift_Query(human)
+    CommonActMoneyTree.CommonActMoneyTree_Query(human)
 end
 
 function CG_ABS_COMONACT_MONEYTREE_LOTTERY(human, msg)

+ 14 - 0
script/module/voucher/Handler.lua

@@ -7,6 +7,8 @@
 
 local voucherShopLogic = require("voucher.VoucherShopLogic")
 
+local VoucherInvest = require("voucher.VoucherInvest")
+
 -- 请求代金券商店信息
 function CG_VOUCHER_QUERY_SHOP(human, msg)
     voucherShopLogic.VoucherShop_QueryShop(human)
@@ -20,4 +22,16 @@ end
 -- 请求代金券购买商品
 function CG_VOUCHER_BUY_ITEM(human, msg)
     voucherShopLogic.VoucherShop_BuyItem(human, msg.nBuyID, msg.nBuyNum)
+end
+
+
+
+
+
+function CG_VOUCHER_INVEST_QUERY(human, msg)
+    VoucherInvest.VoucherInvest_Query(human)
+end
+
+function CG_VOUCHER_INVEST_GET(human, msg)
+    VoucherInvest.VoucherInvest_Get(human)
 end

+ 20 - 1
script/module/voucher/Proto.lua

@@ -47,4 +47,23 @@ CG_VOUCHER_BUY_ITEM =
     {"nBuyNum",                 1,          "byte"},    -- 购买次数
 }
 
--- 无回包
+-- 无回包
+
+---------------------------------------代金券投资---------------------------
+
+VOUCHER_INVEST_AWARD_INFO = {
+    {"item",                 1,          ItemData},     -- 代金券
+    {"state",                1,           "byte"},      -- 0-不可领,1-可领, 2-已领
+}
+
+-- 查询
+CG_VOUCHER_INVEST_QUERY = {}
+GC_VOUCHER_INVEST_QUERY = {
+    {"buyItem",           1,          BuyItem},   -- 购买物品信息
+    {"isBuy",             1,           "byte"},   -- 是否购买(0:未购买,1:已购买)
+    {"awardArr",          15,          VOUCHER_INVEST_AWARD_INFO},   -- 物品信息
+    {"isEnd",             1,           "byte"},   -- 是否发完(0:没有,1:发完)
+}
+
+-- 领取奖励
+CG_VOUCHER_INVEST_GET = {}

+ 310 - 0
script/module/voucher/VoucherInvest.lua

@@ -0,0 +1,310 @@
+-- 代金券投资
+-- db
+--[=[
+    human.db.voucherInvestData = {
+        getRecord = { -- 领取记录数组, 初始为nil
+            idx1,
+            idx2,
+        }
+        isBuy = nil, 是否已经充值, 充值成功后为true
+        nowRound = nil, 当前轮数, 默认为1
+    }
+]=]--
+
+local Util = require("common.Util")
+local Lang = require("common.Lang")
+local Broadcast = require("broadcast.Broadcast")
+local Msg = require("core.Msg")
+local Grid = require("bag.Grid")
+local BagLogic = require("bag.BagLogic")
+local BuyLogic = require("topup.BuyLogic")
+local YunYingLogic = require("yunying.YunYingLogic")
+local voucherInvestConfig = require("excel.VoucherInvest").Sheet1
+local CommonDefine = require("common.CommonDefine")
+local YunYingExcel = require("excel.yunying")
+
+
+local LOGTYPE = "VoucherInvest" -- 日志标识
+local ACT_ID = 8203 -- 活动Id
+
+
+local function initData(human)
+    human.db.voucherInvestData = {
+        nowRound = 1,
+        isBuy = false,
+    }
+end
+
+local function getData(human)
+    if not human.db.voucherInvestData then
+        initData(human)
+    end
+    return human.db.voucherInvestData
+end
+
+local function updateBuyState(human, buyState)
+    local voucherInvestData = getData(human)
+    voucherInvestData.isBuy = buyState
+end
+
+local function updateGetRecord(human, idx)
+    local voucherInvestData = getData(human)
+    voucherInvestData.getRecord = voucherInvestData.getRecord or {}
+    table.insert(voucherInvestData.getRecord, idx)
+end
+
+local function resetData(human, newRound)
+    local voucherInvestData = getData(human)
+    voucherInvestData.nowRound = newRound
+    voucherInvestData.isBuy = false
+    Util.initTable(voucherInvestData.getRecord)
+end
+
+
+
+-- 是否已经充值
+local function isBuy(human)
+    local voucherInvestData = getData(human)
+    return voucherInvestData.isBuy
+end
+
+-- 通过轮数获取购买项Id
+local function getBuyIdByRound(round)
+    for _, v in ipairs(voucherInvestConfig) do
+        if v.round and v.round == round then
+            return v.buyid
+        end
+    end
+end
+
+-- 通过轮数获取配置Id
+local function getRounCfgIdArr(round)
+    local idArr = {}
+    for id, v in ipairs(voucherInvestConfig) do
+        if v.round and v.round == round then
+            idArr[#idArr+1] = id
+        end
+    end
+
+    return idArr
+end
+
+-- 获取最大轮数
+local function getMaxRound()
+    return voucherInvestConfig[#voucherInvestConfig].round
+end
+
+-- 奖励状态
+local function getAwardState(human, id)
+    local voucherInvestData = getData(human)
+    local getRecordData = voucherInvestData.getRecord or {}
+
+    if table.find(getRecordData, id) then
+        return CommonDefine.COMMON_PRIZE_STATE_GET
+    else
+        if not isBuy(human) then
+            return CommonDefine.COMMON_PRIZE_STATE_NOGET
+        end
+
+        local cfg = voucherInvestConfig[id]
+        if human.db.zhandouli >= cfg.power then
+            return CommonDefine.COMMON_PRIZE_STATE_CANGET
+        end
+    end
+
+    return CommonDefine.COMMON_PRIZE_STATE_NOGET
+end
+
+-- 填充协议结构
+local function populateAwardMsg(human, net, id, cfg)
+    net.state = getAwardState(human, id)
+    Grid.makeItem(net.item, cfg.reward[1], cfg.reward[2])
+end
+
+-- 主动刷新一次红点
+local function updateRedDot(human)
+    YunYingLogic.sendBanner(human)
+    local config = YunYingExcel.func[ACT_ID]
+    YunYingLogic.sendGroupUpdate(YYInfo[ACT_ID], human, config.panelID)
+end
+
+
+
+function isOpen(human, YYInfo, funcConfig)
+    return true
+end
+
+function isRed(human)
+    if not isOpen(human) then
+        return false
+    end
+
+    if not isBuy(human) then
+        return false
+    end
+
+    local voucherInvestData = getData(human)
+    local nowRound = voucherInvestData.nowRound
+    local maxRound = getMaxRound()
+    -- 已经领完最后一轮
+    if nowRound > maxRound then
+        return false
+    end
+
+    local ids = getRounCfgIdArr(nowRound)
+    for _, id in ipairs(ids) do
+        local awardState = getAwardState(human, id)
+        if awardState == CommonDefine.COMMON_PRIZE_STATE_CANGET then
+            return true
+        end
+    end
+
+    return false
+end
+
+function onCharge(human, price, funcID, buyID)
+    if not isOpen(human) then
+        return
+    end
+
+    if isBuy(human) then
+        return
+    end
+
+    local voucherInvestData = getData(human)
+    local nowRound = voucherInvestData.nowRound
+    local buyId = getBuyIdByRound(nowRound)
+    if buyId ~= buyID then
+        return
+    end
+
+    updateBuyState(human, true)
+
+    updateRedDot(human)
+end
+
+-- 战力更新
+function onZhandouli(human)
+    if not isOpen(human) then
+        return
+    end
+
+    if not isBuy(human) then
+        return
+    end
+
+    updateRedDot(human)
+end
+
+-- 战力更新
+function PowerUpdate(human)
+    if not isOpen(human) then
+        return
+    end
+
+    if not isBuy(human) then
+        return
+    end
+
+    updateRedDot(human)
+end
+
+
+
+
+-- 查询
+function VoucherInvest_Query(human)
+    if not isOpen(human) then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local voucherInvestData = getData(human)
+    local nowRound = voucherInvestData.nowRound
+    local maxRound = getMaxRound()
+    nowRound = math.min(nowRound, maxRound)
+    local buyId = getBuyIdByRound(nowRound)
+
+    local msgRet = Msg.gc.GC_VOUCHER_INVEST_QUERY
+    BuyLogic.fontBuyItem(human, msgRet.buyItem, buyId)
+
+    msgRet.isBuy = voucherInvestData.isBuy and 1 or 0
+    msgRet.awardArr[0] = 0
+    msgRet.isEnd = 0
+
+    local ids = getRounCfgIdArr(round)
+    local cfgNum = #ids
+    local len, msgOnceLen = 0, 15
+
+    for _, id in ipairs(ids) do
+        len = len + 1
+        msgRet.awardArr[0] = len
+        local cfg = voucherInvestConfig[id]
+        populateAwardMsg(human, msgRet.awardArr[len], id, cfg)
+
+        if len >= msgOnceLen then
+            cfgNum = cfgNum - len
+            if cfgNum <= 0 then
+                msgRet.isEnd = 1
+                return Msg.send(msgRet, human.fd)
+            end
+
+            Msg.send(msgRet, human.fd)
+            len = 0
+        end
+    end
+
+    if len > 0 then
+        msgRet.isEnd = 1
+        Msg.send(msgRet, human.fd)
+    end
+end
+
+-- 领奖
+function VoucherInvest_Get(human)
+    if not isOpen(human) then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    if not isBuy(human) then
+        return Broadcast.sendErr(human, Lang.SHARE_GROUP_GET_ERR_CNT)
+    end
+
+    local voucherInvestData = getData(human)
+    local nowRound = voucherInvestData.nowRound
+    local maxRound = getMaxRound()
+
+    if nowRound > maxRound then
+        return Broadcast.sendErr(human, Lang.SHARE_GROUP_GET_ERR_CNT)
+    end
+
+    local ids = getRounCfgIdArr(voucherInvestData.nowRound)
+    local itemList = {}
+
+    for _, id in ipairs(ids) do
+        local cfg = voucherInvestConfig[id]
+        local awardState = getAwardState(human, id)
+
+        if awardState == CommonDefine.COMMON_PRIZE_STATE_CANGET then
+            -- 更新领取记录
+            updateGetRecord(human, id)
+
+            local itemId, itemNum = cfg.reward[1], cfg.reward[2]
+            itemList[itemId] = (itemList[itemId] or 0) + itemNum
+        end
+    end
+
+    if not next(itemList) then
+        Broadcast.sendErr(human, Lang.SHARE_GROUP_GET_ERR_CNT)
+    end
+
+    BagLogic.addItemList(human, itemList, LOGTYPE)
+
+    -- 领完则进入下一轮
+    if #voucherInvestData.getRecord == #ids then
+        resetData(human, voucherInvestData.nowRound + 1)
+
+        updateRedDot(human)
+    end
+
+    VoucherInvest_Query(human)
+end