diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 8e8e47e..fa12c7a 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -53,6 +53,7 @@ actionCodes = { Role_accuseRpc = 137, -- 举报 Role_loadSparks = 138, Role_updateSpark = 139, -- 更新火花 + Role_diamondConvertRpc = 140, -- 钻石兑换成别的物品 Adv_startAdvRpc = 151, Adv_startHangRpc = 152, diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index d9e2802..7b49144 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -1395,6 +1395,46 @@ function _M.goldBuyRpc(agent, data) return true end +function _M.diamondConvertRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local oper = msg.oper + if oper ~= 1 and oper ~= 2 then return 0 end + + local cost = math.ceil(msg.cost or 0) + if cost <= 0 then return 1 end + if role:getAllDiamond() < cost then return 2 end + + local get = globalCsv.legal_tender_cost * cost + role:costDiamond({count = cost, log = {desc = "convert", int1 = ItemType.Jade, int2 = get}}) + local reward, change + if oper == 1 then -- 钻石兑换成虹光玉 + reward, change = role:award({[ItemId.Jade] = get}, {log = {desc = "convert"}}) + elseif oper == 2 then -- 钻石兑换成虹光玉再兑换成招募券 + local quan = math.floor(get/globalCsv.recruit_cost) + reward[ItemType.Jade] = reward[ItemType.Jade] - quan * globalCsv.recruit_cost + if reward[ItemType.Jade] == 0 then + reward[ItemType.Jade] = nil + end + if quan > 0 then + local tReward, tChange = role:award({[70] = quan}, {log = {desc = "convert"}}) + for id, value in pairs(tReward) do + reward[id] = reward[id] + value + end + if tChange then + change = change or {} + for id, value in pairs(tChange) do + change[id] = change[id] + value + end + end + end + end + + SendPacket(actionCodes.Role_diamondConvertRpc, MsgPack.pack(role:packReward(reward, change))) + return true +end + function _M.getDownloadCvRewardRpc(agent, data) local role = agent.role local flag = role:getProperty("downCvR") or 0 diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index 2e8a5b0..2303769 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -58,7 +58,7 @@ local ItemReason = { newSign = 142,-- 新的活动签到 advLevelStage = 143, -- 拾荒活动阶段奖励 towerBnous = 144, -- 爬塔到一定层数对某些功能的奖励 - + convert = 145, -- 钻石兑换其他物品 advHang = 301, -- 拾荒挂机 hangBattle = 302, -- 挂机战斗 -- libgit2 0.21.2