Selaa lähdekoodia

通用节日活动-摇钱树

gitxsm 3 kuukautta sitten
vanhempi
sitoutus
5d6344f131

+ 2 - 0
script/common/Lang.lua

@@ -586,6 +586,8 @@ YUNYING_BUY_ERR_CNT = [[剩余购买次数不足]]
 YUNYING_BUY_ERR_VIP = [[VIP等级不足]]
 YUNYING_BUY_ERR_HAD = [[已购买]]
 
+MONEYTREE_IS_MAX = [[篮子已撑破, 不能再获得奖励了]]
+
 QQAPI_ERR_TIMEOUT = [[登录状态超时,请刷新游戏后再次尝试]]
 
 PRESENT_TUISONGLIBAO_NOTBUY = [[不可购买]]

+ 8 - 10
script/common/ProtoID.lua

@@ -1751,19 +1751,11 @@ _ENV[1792]="GC_SERVEERCOMMERCE_ACT_BATTLEGROUND_RANKAWARD_QUERY"
 _ENV[1793]="CG_SERVEERCOMMERCE_ACT_BATTLEGROUND_UPDATE_MATCHLIST"
 _ENV[1794]="CG_SERVEERCOMMERCE_ACT_BATTLEGROUND_ONECLICK_SWEEP"
 _ENV[1795]="GC_AB_TIPS"
-
-
-_ENV[1896]="CG_ZHUANPAN_SUBSCRIBE_REWARD_QUERY"
-_ENV[1897]="GC_ZHUANPAN_SUBSCRIBE_REWARD_QUERY"
-_ENV[1898]="CG_ZHUANPAN_SUBSCRIBE_REWARD_GET"
-
 _ENV[1796]="CG_SERVEERCOMMERCE_ACT_BATTLEGROUND_ALREAFY_KNOW"
-
 _ENV[1797]="CG_HEROTY_QUERY"
 _ENV[1798]="GC_HEROTY_QUERY"
 _ENV[1799]="CG_HEROTY_POINT_UPGRADE"
 _ENV[1800]="CG_HEROTY_STAGE_UPGRADE"
-
 _ENV[1801]="CG_BREATHROUGHTHEME_LINEUP_QUERY"
 _ENV[1802]="GC_BREATHROUGHTHEME_LINEUP_QUERY"
 _ENV[1803]="CG_BREATHROUGHTHEME_BREAKTHROUGHREWARD_QUERY"
@@ -1774,11 +1766,17 @@ _ENV[1807]="CG_BREATHROUGHTHEME_GET_REWARD"
 _ENV[1808]="GC_BREATHROUGHTHEME_REDDOT"
 _ENV[1809]="CG_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"
-
 _ENV[1814]="GC_COMBAT_JiBan_DESC"
+_ENV[1815]="CG_ABS_COMONACT_MONEYTREE_QUERY"
+_ENV[1816]="GC_ABS_COMONACT_MONEYTREE_QUERY"
+_ENV[1817]="CG_ABS_COMONACT_MONEYTREE_LOTTERY"
+_ENV[1818]="GC_ABS_COMONACT_MONEYTREE_LOTTERY"
+_ENV[1819]="CG_ABS_COMONACT_MONEYTREE_GET_REWARD"
 
+_ENV[1896]="CG_ZHUANPAN_SUBSCRIBE_REWARD_QUERY"
+_ENV[1897]="GC_ZHUANPAN_SUBSCRIBE_REWARD_QUERY"
+_ENV[1898]="CG_ZHUANPAN_SUBSCRIBE_REWARD_GET"
 

+ 3 - 2
script/module/absAct/CommonActLoginGift.lua

@@ -184,6 +184,7 @@ function CommonActLoginGift_Query(human)
     local len, msgOnceLen = 0, 5
     local type_2_cfg = transformCfg()
     local configNum = type_2_cfg[1] and #type_2_cfg[1] or 0
+    local num = configNum
 
     for i=1, configNum do
         len = len + 1
@@ -214,8 +215,8 @@ function CommonActLoginGift_Query(human)
         end
 
         if len >= msgOnceLen then
-            configNum = configNum - len
-            if configNum <= 0 then
+            num = num - len
+            if num <= 0 then
                 msgRet.isEnd = 1
                 return Msg.send(msgRet, human.fd)
             end

+ 267 - 5
script/module/absAct/CommonActMoneyTree.lua

@@ -1,4 +1,12 @@
 -- 通用节日活动 - 摇钱树
+-- db
+--[=[
+    human.db.absAct[actId] = {
+        basketItemArr = nil, --篮子里的道具idx列表
+
+        lotteryTimes = nil, -- 抽奖次数
+    }   
+]=]--
 
 local Msg = require("core.Msg")
 local Grid = require("bag.Grid")
@@ -6,12 +14,266 @@ 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 MoneyTreeConfig = require("excel.commonact").treereward
 local YunYingLogic = require("yunying.YunYingLogic")
 local AbsActExcel = require("excel.absAct")
-local BuyLogic = require("topup.BuyLogic")
 
 
-local LOGTYPE = "CommonActMoneyTree"
+local LOGTYPE = "CommonActMoneyTree" -- 日志标识
+local COMMONACT_MONEYTREE_ID = 7506  -- 活动Id
+local BASKET_WEIGHT = 100           -- 篮子可承受的总重量
+
+
+local function getData(human)
+    return human.db.absAct[COMMONACT_MONEYTREE_ID]
+end
+
+local function updateLotteryTimes(human, val)
+    local actData = getData(human)
+    actData.lotteryTimes = (actData.lotteryTimes or 0) + val
+end
+
+local function insertBasketItemArr(human, itemIdx)
+    local actData = getData(human)
+    actData.basketItemArr = actData.basketItemArr or {}
+    table.insert(actData.basketItemArr, itemIdx)
+end
+
+local function updateBasketItemArr(human, newBasketItemArr)
+    local actData = getData(human)
+    actData.basketItemArr = newBasketItemArr
+end
+
+local function resetBasketArr(human)
+    local actData = getData(human)
+    actData.basketItemArr = nil
+end
+
+
+
+local function isOpenAct(human, funcID)
+    return AbsActLogic.isStarted(human, funcID)
+end
+
+-- 计算篮子中所有道具的总重量
+local function calcBasketWeight(basketItemArr)
+    local weightSum = 0
+
+    for _, cfgIdx in ipairs(basketItemArr or {}) do
+        local itemCfg = MoneyTreeConfig[cfgIdx]
+        weightSum = weightSum + itemCfg.value
+    end
+
+    return weightSum
+end
+
+-- 抽奖
+local function lottery()
+    local totalWeight = 0
+    for _, itemCfg in ipairs(MoneyTreeConfig) do
+        totalWeight = totalWeight + itemCfg.nWeight
+    end
+
+    local finalIdx = 0
+    local weight = 0
+    local randWeight = math.random(0, totalWeight)
+    for i, itemCfg in ipairs(MoneyTreeConfig) do
+        weight = weight + itemCfg.nWeight
+        if randWeight <= weight then
+            finalIdx = i
+            break
+        end
+    end
+
+    return finalIdx
+end
+
+-- 将篮子中每个道具都随机一次, 获得最新的篮子道具
+local function randBasketItem(basketItemArr)
+    local val = 50
+    local newBasketItemArr = {}
+    for _,itemCfgIdx in ipairs(basketItemArr) do
+        local randVal = math.random(1, 100)
+        if randVal >= val then
+            newBasketItemArr[#newBasketItemArr+1] = itemCfgIdx
+        end
+    end
+
+    return newBasketItemArr
+end
+
+-- 主动刷新一次红点
+local function updateRedDot(human)
+    YunYingLogic.sendBanner(human)
+    local config = AbsActExcel.absActivity[COMMONACT_MONEYTREE_ID]
+    YunYingLogic.sendGroupUpdate(YYInfo[COMMONACT_MONEYTREE_ID], human, config.panelID)
+end
+
+
+
+function isRed(human, funcConfig)
+    local state = isOpenAct(human, funcConfig and funcConfig.funcID)
+    if not state then
+        return false
+    end
+
+    local actData = getData(human)
+    if (actData.lotteryTimes or 0) > 0 then
+        return true
+    end
+
+    return false
+end
+
+function isOpen(human, YYInfo, funcConfig)
+    return isOpenAct(human, funcConfig and funcConfig.funcID)
+end
+
+function isActive(human, YYInfo, funcConfig)
+    return not isOpen(human, YYInfo, funcConfig)
+end
+
+-- 日常任务活跃值达标
+function CompleteHuoYueTask(human)
+    if not isOpenAct(human, COMMONACT_MONEYTREE_ID) then
+        return
+    end
+
+    updateLotteryTimes(human, 1)
+
+    updateRedDot(human)
+end
+
+function updateDaily(human, funcID)
+    if not isOpenAct(human, funcID) then
+        return
+    end
+
+    updateLotteryTimes(human, 1)
+
+    updateRedDot(human)
+end
+
+
+
+-- 查询
+function CommonActMoneyTree_Query(human)
+    local msgRet = Msg.gc.GC_ABS_COMONACT_MONEYTREE_QUERY
+    msgRet.rewardBasket[0] = 0
+    msgRet.weighMax = BASKET_WEIGHT
+    msgRet.weighNow = 0
+    msgRet.lotteryTimes = 0
+    msgRet.isStart = 1
+    msgRet.isEnd = 0
+
+    local actData = getData(human)
+
+    if actData.lotteryTimes then
+        msgRet.lotteryTimes = actData.lotteryTimes
+    end
+
+    if actData.basketItemArr then
+        msgRet.weighNow = calcBasketWeight(actData.basketItemArr)
+    end
+
+    local itemNum = actData.basketItemArr and #actData.basketItemArr or 0
+    if itemNum == 0 then
+        return Msg.send(msgRet, human.fd)
+    end
+
+    local len, msgOneceMaxLen = 0, 20
+
+    for _, itemCfgIdx in ipairs(actData.basketItemArr) do
+        len = len + 1
+        msgRet.rewardBasket[0] = len
+
+        local itemCfg = MoneyTreeConfig[itemCfgIdx].reward
+        Grid.makeItem(msgRet.rewardBasket[len], itemCfg[1], itemCfg[2])
+
+        if len >= msgOneceMaxLen then
+            itemNum = itemNum - len
+            if itemNum <= 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 CommonActMoneyTree_Lottery(human)
+    if not isOpenAct(human, COMMONACT_MONEYTREE_ID) then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local actData = getData(human)
+    if (actData.lotteryTimes or 0) <= 0 then
+        return Broadcast.sendErr(human, Lang.JINBI_EXCHANGE_ERR_CNT)
+    end
+
+    if actData.basketItemArr then
+        local weightNow = calcBasketWeight(actData.basketItemArr)
+        if weightNow > BASKET_WEIGHT then
+            return Broadcast.sendErr(human, Lang.MONEYTREE_IS_MAX)
+        end
+    end
+
+    -- 扣除次数
+    updateLotteryTimes(human, -1)
+
+    local finalIdx = lottery()
+    if finalIdx == 0 then
+        return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
+    end
+
+    -- 检查当前篮子中道具重量是否超过限定重量, 如果超过则当前篮子中每个道具都有50%几率失去
+    insertBasketItemArr(human, finalIdx)
+    local weightNow = calcBasketWeight(actData.basketItemArr)
+    if weightNow > BASKET_WEIGHT then
+        local newBasketItemArr = randBasketItem(actData.basketItemArr)
+        updateBasketItemArr(human, newBasketItemArr)
+        CommonActMoneyTree_Query(human)
+    end
+
+    local msgRet = Msg.gc.GC_ABS_COMONACT_MONEYTREE_LOTTERY
+    local itemCfg = MoneyTreeConfig[finalIdx]
+    Grid.makeItem(msgRet.reward, itemCfg.reward[1], itemCfg.reward[2])
+    Msg.send(msgRet, human.fd)
+end
+
+-- 领取奖励
+function CommonActMoneyTree_GetReward(human)
+    if not isOpenAct(human, COMMONACT_MONEYTREE_ID) then
+        return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local actData = getData(human)
+
+    if not actData.basketItemArr or not next(actData.basketItemArr) then
+        return Broadcast.sendErr(human, Lang.SHARE_GROUP_GET_ERR_CNT)
+    end
+
+    local itemList = {}
+    for _, itemCfgIdx in ipairs(actData.basketItemArr) do
+        local itemCfg = MoneyTreeConfig[itemCfgIdx].reward
+        local itemId, itemNum = itemCfg[1], itemCfg[2]
+        itemList[itemId] = (itemList[itemId] or 0) + itemNum
+    end
+
+    -- 重置篮子中道具数据
+    resetBasketArr(human)
+
+    -- 发放道具
+    BagLogic.addItemList(human, itemList, LOGTYPE)
+
+    CommonActMoneyTree_Query(human)
+end

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

@@ -518,4 +518,19 @@ end
 
 function CG_ABS_COMONACT_LOGINGIFT_GET_REWARD(human, msg)
     CommonActLoginGift.CommonActLoginGift_GetReward(human, msg.giftType)
+end
+
+
+----------------------------------------------------通用节日活动 — 摇钱树 --------------------------------------------------
+
+function CG_ABS_COMONACT_MONEYTREE_QUERY(human, msg)
+    CommonActMoneyTree.CommonActLoginGift_Query(human)
+end
+
+function CG_ABS_COMONACT_MONEYTREE_LOTTERY(human, msg)
+    CommonActMoneyTree.CommonActMoneyTree_Lottery(human)
+end
+
+function CG_ABS_COMONACT_MONEYTREE_GET_REWARD(human, msg)
+    CommonActMoneyTree.CommonActMoneyTree_GetReward(human)
 end

+ 24 - 1
script/module/absAct/Proto.lua

@@ -1664,4 +1664,27 @@ GC_ABS_COMONACT_LOGINGIFT_QUERY = {
 -- 领奖
 CG_ABS_COMONACT_LOGINGIFT_GET_REWARD= {
     {"giftType",        1,      "byte"},        -- 礼包类型, 1-登录豪礼, 2-68礼包, 3-128礼包, 4-328礼包, 5-648礼包
-}
+}
+
+
+---------------------节日活动 - 摇钱树 -------------------
+
+-- 查询
+CG_ABS_COMONACT_MONEYTREE_QUERY = {}
+GC_ABS_COMONACT_MONEYTREE_QUERY = {
+    {"rewardBasket",        20,      ItemData},      -- 篮子中道具
+    {"weighMax",            1,      "short"},        -- 篮子可承受总重量
+    {"weighNow",            1,      "short"},        -- 当前篮子中重量
+    {"lotteryTimes",        1,      "short"},        -- 可抽取次数
+    {"isStart",             1,      "byte"},         -- 是否是第一段数据, 0-否, 1-是
+    {"isEnd",               1,      "byte"},         -- 是否发完数据, 0-否, 1-是
+}
+
+-- 抽奖
+CG_ABS_COMONACT_MONEYTREE_LOTTERY = {}
+GC_ABS_COMONACT_MONEYTREE_LOTTERY = {
+    {"reward",          1,      ItemData},      -- 获得的道具
+}
+
+-- 领奖
+CG_ABS_COMONACT_MONEYTREE_GET_REWARD = {}

+ 8 - 0
script/module/anotherWorldBattle/AnotherWorldBattleNS.lua

@@ -670,6 +670,10 @@ end
 
 -- 玩家战力更新
 function PlayerPowerChange(human)
+    if not human.db.anotherWorlBattle then
+        return
+    end
+
     if not baseCondCheck(human) then
         return false
     end
@@ -723,6 +727,10 @@ end
 
 -- 玩家改名
 function PlayerChangeName(human)
+    if not human.db.anotherWorlBattle then
+        return
+    end
+
     if not baseCondCheck(human) then
         return false
     end

+ 10 - 1
script/module/dailyTask/DailyTaskLogic.lua

@@ -15,6 +15,8 @@ local YunYingLogic = require("yunying.YunYingLogic")
 local WeekTaskLogic = require("dailyTask.WeekTaskLogic")
 local HonorTaskLogic = require("dailyTask.HonorJourney")
 
+local CommonActMoneyTree
+
 DAILY_TASK_ID_1  = 1  --日常登陆1次 o
 DAILY_TASK_ID_2  = 2  --赠送友情点5次 o
 DAILY_TASK_ID_3  = 3  --进行3次招将 o
@@ -372,7 +374,14 @@ function onDailyTaskHuoYue(human,sum)
 
 	human.db.dailyTask.nowHuoYue = (human.db.dailyTask.nowHuoYue or 0) + sum
 
-    YunYingLogic.onCallBack(human, "onDailyTask",sum)   
+    YunYingLogic.onCallBack(human, "onDailyTask",sum)
+
+	local finallyIdx = #DailyTaskExcel.huoYueBox
+	local finallyCfg = DailyTaskExcel.huoYueBox[finallyIdx]
+	if human.db.dailyTask.nowHuoYue >= finallyCfg.needHuoYue then
+		CommonActMoneyTree = CommonActMoneyTree or require("absAct.CommonActMoneyTree")
+		CommonActMoneyTree.CompleteHuoYueTask(human)
+	end
 end
 
 function onLogin(human)