From 3ad19fe42ce7c022290d5f769259cd1f8138c44e Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Wed, 8 Sep 2021 17:57:58 +0800 Subject: [PATCH] feat: 贴纸兑换功能 --- src/ProtocolCode.lua | 1 + src/actions/HeroAction.lua | 23 +++++++++++++++++++++++ src/models/RoleLog.lua | 1 + 3 files changed, 25 insertions(+), 0 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 33c2ea0..dcbf3f5 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -117,6 +117,7 @@ actionCodes = { Hero_setWishPoolRpc = 226, Hero_changeSparkRpc = 227, Hero_saveGeniusTreeRpc = 228, + Hero_stickersConvertRpc = 229, --兑换英雄贴纸 Hang_startRpc = 251, Hang_checkRpc = 252, diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index a065d5e..cf10b7c 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -1389,4 +1389,27 @@ function _M.saveGeniusTreeRpc(agent, data) return true end +function _M.stickersConvertRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local itemId = msg.itemId + local heroType = msg.heroType -- heroId-300 举例 [泡泡]= {[heroType] = 120, [heroId]= 420} + + local itemData = csvdb[itemCsv][itemId] + if not itemData then return 1 end + + local useEffect = itemData["use_effect"]:toNumMap() + if not useEffect[heroType] then return 2 end + + if not role:isHaveHero(heroType) then return 3 end + + local cost = {[itemId] = 1} + if not role:checkItemEnough(cost) then return 4 end + role:costItems({[heroType] = cost}, {log = {desc = "heroStickers"}}) + local reward, change = role:award({[heroType] = 1}, {log = {desc = "heroStickers"}}) + + SendPacket(actionCodes.Hero_stickersConvertRpc, MsgPack.pack(role:packReward(reward, change))) + return true +end + return _M diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index ca1890e..b613a7d 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -146,6 +146,7 @@ local ItemReason = { sparkLvlUp = 1214, -- 火花强化 sparkQualityUp = 1215, -- 火花升华 heroGenius = 1216, -- 英雄天赋点 + heroStickers = 1217, -- 英雄贴纸 -- pvp pvpCHead = 1301, -- pvp 跨服竞技场头像 -- libgit2 0.21.2