Commit eae157a4416e524d99c982fcf07dabd0cb97192e
1 parent
c9c0150d
feat: 月卡 + 特刊的道具兑换
Showing
7 changed files
with
49 additions
and
18 deletions
Show diff stats
src/GlobalVar.lua
@@ -154,6 +154,7 @@ ItemId = { | @@ -154,6 +154,7 @@ ItemId = { | ||
154 | AdvKey = 80, -- 冒险钥匙 | 154 | AdvKey = 80, -- 冒险钥匙 |
155 | AdvPower = 4701, -- 拾荒体力 | 155 | AdvPower = 4701, -- 拾荒体力 |
156 | CrisisScore = 8010, -- 积分 | 156 | CrisisScore = 8010, -- 积分 |
157 | + MonthCard = 31000, --兑换月卡的物品 | ||
157 | } | 158 | } |
158 | 159 | ||
159 | TimeReset = { | 160 | TimeReset = { |
src/ProtocolCode.lua
@@ -59,6 +59,7 @@ actionCodes = { | @@ -59,6 +59,7 @@ actionCodes = { | ||
59 | Role_runeBuyRpc = 142, -- 铭文购买 | 59 | Role_runeBuyRpc = 142, -- 铭文购买 |
60 | Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍 | 60 | Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍 |
61 | Role_setBgRpc = 144, -- 设置看板娘 | 61 | Role_setBgRpc = 144, -- 设置看板娘 |
62 | + Role_itemExchangeRpc = 145, -- 道具兑换 | ||
62 | 63 | ||
63 | Adv_startAdvRpc = 151, | 64 | Adv_startAdvRpc = 151, |
64 | Adv_startHangRpc = 152, | 65 | Adv_startHangRpc = 152, |
src/actions/RoleAction.lua
@@ -1710,4 +1710,36 @@ function _M.setBgRpc(agent, data) | @@ -1710,4 +1710,36 @@ function _M.setBgRpc(agent, data) | ||
1710 | return true | 1710 | return true |
1711 | end | 1711 | end |
1712 | 1712 | ||
1713 | +function _M.itemExchangeRpc(agent, data) | ||
1714 | + local role = agent.role | ||
1715 | + local msg = MsgPack.unpack(data) | ||
1716 | + local itemId = msg.item_id | ||
1717 | + local typ = msg.typ | ||
1718 | + local count = msg.count | ||
1719 | + local exchangeId = msg.change_id | ||
1720 | + | ||
1721 | + if not ItemId[itemId] then return 1 end | ||
1722 | + | ||
1723 | + if not role:checkItemEnough({[itemId] = count}) then return 2 end | ||
1724 | + role:costItems({[itemId] = count}, {log = {desc = "itemConvertmonthCard", int1 = count, int2 = count}}) | ||
1725 | + | ||
1726 | + local rechargeData = csvdb["shop_rechargeCsv"][exchangeId] | ||
1727 | + if not rechargeData then | ||
1728 | + skynet.error("[recharge] recharge id not exist", exchangeId) | ||
1729 | + return 3 | ||
1730 | + end | ||
1731 | + local reward = {} | ||
1732 | + for i = 1, count do | ||
1733 | + local tmpreward, _ = role.storeData:onBuyCard(rechargeData.type, rechargeData.id , rechargeData.activity_id) | ||
1734 | + if tmpreward then | ||
1735 | + table.rewardMerge(reward, tmpreward) | ||
1736 | + else | ||
1737 | + return | ||
1738 | + end | ||
1739 | + end | ||
1740 | + | ||
1741 | + SendPacket(actionCodes.Role_itemExchangeRpc, MsgPack.pack(role:packReward(reward))) | ||
1742 | + return status | ||
1743 | +end | ||
1744 | + | ||
1713 | return _M | 1745 | return _M |
1714 | \ No newline at end of file | 1746 | \ No newline at end of file |
src/models/RoleLog.lua
@@ -66,6 +66,8 @@ local ItemReason = { | @@ -66,6 +66,8 @@ local ItemReason = { | ||
66 | shopBuy = 150, -- 商店购买 | 66 | shopBuy = 150, -- 商店购买 |
67 | monthCardReward = 151, --月卡奖励 | 67 | monthCardReward = 151, --月卡奖励 |
68 | smonthCardReward = 152, --特刊奖励 | 68 | smonthCardReward = 152, --特刊奖励 |
69 | + itemConvertmonthCard = 153, --兑换月卡 | ||
70 | + itemConvertsmonthCard = 154, --兑换特刊 | ||
69 | 71 | ||
70 | advHang = 301, -- 拾荒挂机 | 72 | advHang = 301, -- 拾荒挂机 |
71 | hangBattle = 302, -- 挂机战斗 | 73 | hangBattle = 302, -- 挂机战斗 |
src/models/RolePlugin.lua
@@ -2393,15 +2393,10 @@ function RolePlugin.bind(Role) | @@ -2393,15 +2393,10 @@ function RolePlugin.bind(Role) | ||
2393 | end | 2393 | end |
2394 | self:gainDiamond({count = diamondCount, isRecharge = true, sid = params.sid, log = {desc = "recharge", int1 = id}}) | 2394 | self:gainDiamond({count = diamondCount, isRecharge = true, sid = params.sid, log = {desc = "recharge", int1 = id}}) |
2395 | elseif rechargeData.shop == 2 then --通行证商店 | 2395 | elseif rechargeData.shop == 2 then --通行证商店 |
2396 | - --订阅奖励 | ||
2397 | - reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) | ||
2398 | - | ||
2399 | - --签收奖励 | 2396 | + --签收 + 订阅奖励 |
2400 | local tmpreward, _ = self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id) | 2397 | local tmpreward, _ = self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id) |
2401 | if tmpreward then | 2398 | if tmpreward then |
2402 | - for k, v in pairs(tmpreward) do | ||
2403 | - reward[k] = (reward[k] or 0) + v | ||
2404 | - end | 2399 | + table.rewardMerge(reward, tmpreward) |
2405 | end | 2400 | end |
2406 | elseif rechargeData.shop == 3 then -- 礼包商店 | 2401 | elseif rechargeData.shop == 3 then -- 礼包商店 |
2407 | reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) | 2402 | reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) |
src/models/Store.lua
@@ -404,21 +404,15 @@ function Store:onBuyCard(type, duration, id, actid) | @@ -404,21 +404,15 @@ function Store:onBuyCard(type, duration, id, actid) | ||
404 | end | 404 | end |
405 | self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30}) | 405 | self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30}) |
406 | 406 | ||
407 | + local reward = {} | ||
407 | --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅" | 408 | --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅" |
408 | - local reward = {} | ||
409 | local tmpreward, _ = self:firstBuyMonthCard(id) | 409 | local tmpreward, _ = self:firstBuyMonthCard(id) |
410 | - if tmpreward then | ||
411 | - for k, v in pairs(tmpreward) do | ||
412 | - reward[k] = (reward[k] or 0) + v | ||
413 | - end | ||
414 | - end | 410 | + if tmpreward then table.rewardMerge(reward, tmpreward) end |
415 | 411 | ||
412 | + --订阅奖励 | ||
416 | tmpreward = SuperMonthCard["itemFirst"](self, id) | 413 | tmpreward = SuperMonthCard["itemFirst"](self, id) |
417 | - if next(tmpreward) then | ||
418 | - for k, v in pairs(tmpreward) do | ||
419 | - reward[k] = (reward[k] or 0) + v | ||
420 | - end | ||
421 | - end | 414 | + if next(tmpreward) then table.rewardMerge(reward, tmpreward) end |
415 | + | ||
422 | return reward | 416 | return reward |
423 | elseif type == CardType.SuperMonthCard then | 417 | elseif type == CardType.SuperMonthCard then |
424 | if SuperMonthCard["buy"](self, id) then | 418 | if SuperMonthCard["buy"](self, id) then |
src/shared/functions.lua
@@ -865,3 +865,9 @@ function table.array2Table(arr) | @@ -865,3 +865,9 @@ function table.array2Table(arr) | ||
865 | return ret | 865 | return ret |
866 | end | 866 | end |
867 | 867 | ||
868 | + | ||
869 | +function table.rewardMerge(dest, src) | ||
870 | + for k, v in pairs(src) do | ||
871 | + dest[k] = (dest[k] or 0) + v | ||
872 | + end | ||
873 | +end | ||
868 | \ No newline at end of file | 874 | \ No newline at end of file |