Commit 1ab9458f4c0df3b659357a88a3e7fda0e63d25dc

Authored by gaofengduan
1 parent 3619ff6f

add 下菜操作

Showing 2 changed files with 43 additions and 0 deletions   Show diff stats
src/ProtocolCode.lua
... ... @@ -63,6 +63,7 @@ actionCodes = {
63 63 Diner_levelUpRpc = 303,
64 64 Diner_talentUpRpc = 304,
65 65 Diner_skillUpRpc = 305,
  66 + Diner_removeSellRpc = 306,
66 67 }
67 68  
68 69 rpcResponseBegin = 10000
... ...
src/actions/DinerAction.lua
... ... @@ -72,6 +72,48 @@ function _M.addSellRpc( agent, data )
72 72 return true
73 73 end
74 74  
  75 +function _M.removeSellRpc( agent, data )
  76 + local role = agent.role
  77 + local msg = MsgPack.unpack(data)
  78 +
  79 + local slot = msg.slot
  80 + if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then
  81 + return 1
  82 + end
  83 + slot = tostring(slot)
  84 + local sells = json.decode(role.dinerData:getProperty("sells"))
  85 + local sell = sells[slot]
  86 + if not sell then
  87 + return 2
  88 + end
  89 +
  90 + local dish = sell.dish
  91 + local dishSet = csvdb["diner_dishCsv"][dish]
  92 + if not dishSet then
  93 + return 3
  94 + end
  95 + local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0)
  96 + if dishLevel == 0 then
  97 + return 4
  98 + end
  99 + local dishData = dishSet[dishLevel]
  100 + if not dishData then
  101 + return 5
  102 + end
  103 +
  104 + local reward = {}
  105 + local cost = dishData.material:toNumMap()
  106 + for k, n in pairs(cost) do
  107 + local sum = n*sell.count
  108 + role:addItem({itemId = k,count = sum})
  109 + reward[k] = sum
  110 + end
  111 + sells[slot] = nil
  112 + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  113 + SendPacket(actionCodes.Diner_removeSellRpc, MsgPack.pack({reward = reward}))
  114 + return true
  115 +end
  116 +
75 117 function _M.getSellRewardRpc( agent, data )
76 118  
77 119 end
... ...