From eae157a4416e524d99c982fcf07dabd0cb97192e Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Tue, 20 Jul 2021 15:08:23 +0800 Subject: [PATCH] feat: 月卡 + 特刊的道具兑换 --- src/GlobalVar.lua | 1 + src/ProtocolCode.lua | 1 + src/actions/RoleAction.lua | 32 ++++++++++++++++++++++++++++++++ src/models/RoleLog.lua | 2 ++ src/models/RolePlugin.lua | 9 ++------- src/models/Store.lua | 16 +++++----------- src/shared/functions.lua | 6 ++++++ 7 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 7984b66..6bbaadb 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -154,6 +154,7 @@ ItemId = { AdvKey = 80, -- 冒险钥匙 AdvPower = 4701, -- 拾荒体力 CrisisScore = 8010, -- 积分 + MonthCard = 31000, --兑换月卡的物品 } TimeReset = { diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 03f4c18..7e93ef2 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -59,6 +59,7 @@ actionCodes = { Role_runeBuyRpc = 142, -- 铭文购买 Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍 Role_setBgRpc = 144, -- 设置看板娘 + Role_itemExchangeRpc = 145, -- 道具兑换 Adv_startAdvRpc = 151, Adv_startHangRpc = 152, diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 667b795..c2abca3 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -1710,4 +1710,36 @@ function _M.setBgRpc(agent, data) return true end +function _M.itemExchangeRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local itemId = msg.item_id + local typ = msg.typ + local count = msg.count + local exchangeId = msg.change_id + + if not ItemId[itemId] then return 1 end + + if not role:checkItemEnough({[itemId] = count}) then return 2 end + role:costItems({[itemId] = count}, {log = {desc = "itemConvertmonthCard", int1 = count, int2 = count}}) + + local rechargeData = csvdb["shop_rechargeCsv"][exchangeId] + if not rechargeData then + skynet.error("[recharge] recharge id not exist", exchangeId) + return 3 + end + local reward = {} + for i = 1, count do + local tmpreward, _ = role.storeData:onBuyCard(rechargeData.type, rechargeData.id , rechargeData.activity_id) + if tmpreward then + table.rewardMerge(reward, tmpreward) + else + return + end + end + + SendPacket(actionCodes.Role_itemExchangeRpc, MsgPack.pack(role:packReward(reward))) + return status +end + return _M \ No newline at end of file diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index 0e3becc..e44ceb2 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -66,6 +66,8 @@ local ItemReason = { shopBuy = 150, -- 商店购买 monthCardReward = 151, --月卡奖励 smonthCardReward = 152, --特刊奖励 + itemConvertmonthCard = 153, --兑换月卡 + itemConvertsmonthCard = 154, --兑换特刊 advHang = 301, -- 拾荒挂机 hangBattle = 302, -- 挂机战斗 diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 4da4c2d..2643f1d 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -2393,15 +2393,10 @@ function RolePlugin.bind(Role) end self:gainDiamond({count = diamondCount, isRecharge = true, sid = params.sid, log = {desc = "recharge", int1 = id}}) elseif rechargeData.shop == 2 then --通行证商店 - --订阅奖励 - reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) - - --签收奖励 + --签收 + 订阅奖励 local tmpreward, _ = self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id) if tmpreward then - for k, v in pairs(tmpreward) do - reward[k] = (reward[k] or 0) + v - end + table.rewardMerge(reward, tmpreward) end elseif rechargeData.shop == 3 then -- 礼包商店 reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) diff --git a/src/models/Store.lua b/src/models/Store.lua index 02d26ac..daeae7f 100644 --- a/src/models/Store.lua +++ b/src/models/Store.lua @@ -404,21 +404,15 @@ function Store:onBuyCard(type, duration, id, actid) end self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30}) + local reward = {} --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅" - local reward = {} local tmpreward, _ = self:firstBuyMonthCard(id) - if tmpreward then - for k, v in pairs(tmpreward) do - reward[k] = (reward[k] or 0) + v - end - end + if tmpreward then table.rewardMerge(reward, tmpreward) end + --订阅奖励 tmpreward = SuperMonthCard["itemFirst"](self, id) - if next(tmpreward) then - for k, v in pairs(tmpreward) do - reward[k] = (reward[k] or 0) + v - end - end + if next(tmpreward) then table.rewardMerge(reward, tmpreward) end + return reward elseif type == CardType.SuperMonthCard then if SuperMonthCard["buy"](self, id) then diff --git a/src/shared/functions.lua b/src/shared/functions.lua index edabaa8..800a7e6 100644 --- a/src/shared/functions.lua +++ b/src/shared/functions.lua @@ -865,3 +865,9 @@ function table.array2Table(arr) return ret end + +function table.rewardMerge(dest, src) + for k, v in pairs(src) do + dest[k] = (dest[k] or 0) + v + end +end \ No newline at end of file -- libgit2 0.21.2