From 9c525cf9006f91873396f2688792a16352571fe5 Mon Sep 17 00:00:00 2001 From: gaofengduan Date: Fri, 21 Jun 2019 18:25:10 +0800 Subject: [PATCH] add car smithy --- src/ProtocolCode.lua | 4 +++- src/actions/CarAction.lua | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/actions/DinerAction.lua | 36 ------------------------------------ src/csvdata | 2 +- src/models/Hero.lua | 3 ++- 5 files changed, 98 insertions(+), 39 deletions(-) create mode 100644 src/actions/CarAction.lua diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index e59ca7b..a0311c6 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -69,7 +69,9 @@ actionCodes = { Diner_refreshTaskRpc = 309, Diner_expediteSellRpc = 310, Diner_getGreenhouseRpc = 311, - Diner_makePotionRpc = 312, + + Car_makePotionRpc = 400, + Car_equipUpRpc = 401, } rpcResponseBegin = 10000 diff --git a/src/actions/CarAction.lua b/src/actions/CarAction.lua new file mode 100644 index 0000000..d0508cf --- /dev/null +++ b/src/actions/CarAction.lua @@ -0,0 +1,92 @@ +local ipairs = ipairs +local table = table +local math = math +local redisproxy = redisproxy +local MsgPack = MsgPack + +local _M = {} + +function _M.makePotionRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + local potionId = msg.id + local count = msg.count + if count < 1 then return 0 end + local potionBag = role:getProperty("potionBag") + local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0) + if potionLv < 1 then return 1 end + + local potionSet = csvdb["adv_potionCsv"][potionId] + if not potionSet then return 2 end + + local potionData = potionSet[potionLv] + if not potionData then return 3 end + + local own = potionBag[potionId] or 0 + if own+count > potionData.limit then + return 4 + end + + local cost = potionData.material:toNumMap() + for _, n in pairs(cost) do + n = n * count + end + if not role:checkItemEnough(cost) then + return 5 + end + + role:costItems(cost) + potionBag[potionId] = own + count + role:updateProperty({field = "potionBag", value = potionBag}) + SendPacket(actionCodes.Car_makePotionRpc, MsgPack.pack({potionBag = potionBag})) + return true +end + +function _M.equipUpRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + local id = msg.id + local count = msg.count + if count < 1 then return 0 end + local typ = math.floor((id-7000)/100) + local lv = (id-7000)%100 + + local dataSet = csvdb["equipCsv"][typ] + if not dataSet then return 1 end + local equipData = dataSet[lv] + if not equipData then return 21 end + if equipData.merge < 1 then return 22 end + local maxLv = 3 + local nextLv = lv+1 + if nextLv%10 > maxLv then + nextLv = nextLv+10-maxLv + end + local nextEquip = dataSet[nextLv] + if not nextEquip then return 23 end + + local own = role:getItemCount(id) + if own < count then + return 3 + end + + local cost = equipData.cost:toNumMap() + for _, n in pairs(cost) do + n = n * count + end + if not role:checkItemEnough(cost) then + return 4 + end + + local merge = {[id]=equipData.merge*count} + if not role:checkItemEnough(merge) then + return 5 + end + + role:costItems(cost) + role:costItems(merge) + role:addItem({itemId = nextEquip.id,count = count}) + SendPacket(actionCodes.Car_equipUpRpc, '') + return true +end + +return _M \ No newline at end of file diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 21c32cd..6b5133f 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -505,40 +505,4 @@ function _M.getGreenhouseRpc( agent, data ) return true end -function _M.makePotionRpc( agent, data ) - local role = agent.role - local msg = MsgPack.unpack(data) - local potionId = msg.id - local count = msg.count - if count < 1 then return 0 end - local potionBag = role:getProperty("potionBag") - local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0) - if potionLv < 1 then return 1 end - - local potionSet = csvdb["adv_potionCsv"][potionId] - if not potionSet then return 2 end - - local potionData = potionSet[potionLv] - if not potionData then return 3 end - - local own = potionBag[potionId] or 0 - if own+count > potionData.limit then - return 4 - end - - local cost = potionData.material:toNumMap() - for _, n in pairs(cost) do - n = n * count - end - if not role:checkItemEnough(cost) then - return 5 - end - - role:costItems(cost) - potionBag[potionId] = own + count - role:updateProperty({field = "potionBag", value = potionBag}) - SendPacket(actionCodes.Diner_makePotionRpc, MsgPack.pack({potionBag = potionBag})) - return true -end - return _M \ No newline at end of file diff --git a/src/csvdata b/src/csvdata index 1807df3..a1b5d35 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit 1807df3783895d92aa5b85851aef9c5f222187cb +Subproject commit a1b5d35f852b178c50c4c570c86c7a2066188f62 diff --git a/src/models/Hero.lua b/src/models/Hero.lua index 7ac0b65..2e5d5b9 100644 --- a/src/models/Hero.lua +++ b/src/models/Hero.lua @@ -14,7 +14,8 @@ Hero.schema = { battleV = {"number", 0}, -- 保存战斗力 loveExp = {"number", 0}, --好感度经验 loveL = {"number", 0}, --好感度等级 - skin = {"number", 0}, --皮肤 0 、 1、 2、 3 + skin = {"number", 0}, --皮肤 0 、 1、 2、 3 + equip = {"string",""}, --装备 type=level } function Hero:ctor( properties ) -- libgit2 0.21.2