Commit eae157a4416e524d99c982fcf07dabd0cb97192e

Authored by zhangqijia
1 parent c9c0150d

feat: 月卡 + 特刊的道具兑换

src/GlobalVar.lua
... ... @@ -154,6 +154,7 @@ ItemId = {
154 154 AdvKey = 80, -- 冒险钥匙
155 155 AdvPower = 4701, -- 拾荒体力
156 156 CrisisScore = 8010, -- 积分
  157 + MonthCard = 31000, --兑换月卡的物品
157 158 }
158 159  
159 160 TimeReset = {
... ...
src/ProtocolCode.lua
... ... @@ -59,6 +59,7 @@ actionCodes = {
59 59 Role_runeBuyRpc = 142, -- 铭文购买
60 60 Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍
61 61 Role_setBgRpc = 144, -- 设置看板娘
  62 + Role_itemExchangeRpc = 145, -- 道具兑换
62 63  
63 64 Adv_startAdvRpc = 151,
64 65 Adv_startHangRpc = 152,
... ...
src/actions/RoleAction.lua
... ... @@ -1710,4 +1710,36 @@ function _M.setBgRpc(agent, data)
1710 1710 return true
1711 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 1745 return _M
1714 1746 \ No newline at end of file
... ...
src/models/RoleLog.lua
... ... @@ -66,6 +66,8 @@ local ItemReason = {
66 66 shopBuy = 150, -- 商店购买
67 67 monthCardReward = 151, --月卡奖励
68 68 smonthCardReward = 152, --特刊奖励
  69 + itemConvertmonthCard = 153, --兑换月卡
  70 + itemConvertsmonthCard = 154, --兑换特刊
69 71  
70 72 advHang = 301, -- 拾荒挂机
71 73 hangBattle = 302, -- 挂机战斗
... ...
src/models/RolePlugin.lua
... ... @@ -2393,15 +2393,10 @@ function RolePlugin.bind(Role)
2393 2393 end
2394 2394 self:gainDiamond({count = diamondCount, isRecharge = true, sid = params.sid, log = {desc = "recharge", int1 = id}})
2395 2395 elseif rechargeData.shop == 2 then --通行证商店
2396   - --订阅奖励
2397   - reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}})
2398   -
2399   - --签收奖励
  2396 + --签收 + 订阅奖励
2400 2397 local tmpreward, _ = self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id)
2401 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 2400 end
2406 2401 elseif rechargeData.shop == 3 then -- 礼包商店
2407 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 404 end
405 405 self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30})
406 406  
  407 + local reward = {}
407 408 --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅"
408   - local reward = {}
409 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 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 416 return reward
423 417 elseif type == CardType.SuperMonthCard then
424 418 if SuperMonthCard["buy"](self, id) then
... ...
src/shared/functions.lua
... ... @@ -865,3 +865,9 @@ function table.array2Table(arr)
865 865 return ret
866 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 874 \ No newline at end of file
... ...