local ipairs = ipairs local table = table local math = math local redisproxy = redisproxy local MsgPack = MsgPack local _M = {} function _M.addSellRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local slot = msg.slot if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then return end slot = tostring(slot) local dish = msg.dish local dishSet = csvdb["diner_dishCsv"][dish] if not dishSet then return end local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) if dishLevel == 0 then return end local dishData = dishSet[dishLevel] if not dishData then return end local calSell = role.dinerData:updateSell(slot, true) or { deltaCount = 0, deltaTime = 0, lastCount = 0, } local count = msg.count local maxDishCount = role.dinerData:getMaxDishs() if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then return end local cost = dishData.material:toNumMap() for _, n in pairs(cost) do n = n * count end if not role:checkItemEnough(cost) then return end role:costItems(cost) role.dinerData:updateSell(slot) local sells = json.decode(role.dinerData:getProperty("sells")) if not sells[slot] then sells[slot] = { dish = dish, level = dishLevel, reward = "", count = 0, } end local sell = sells[slot] sell.count = sell.count + count sell.time = skynet.timex() - calSell.deltaTime sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) SendPacket(actionCodes.Diner_addSellRpc, "") return true end function _M.getSellRewardRpc( agent, data ) end function _M.levelUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local index = msg.index local buildingData = csvdb["diner_buildingCsv"][index] if not buildingData then return end local buildL = role.dinerData:getProperty("buildL") local curLevel = buildL:getv(index, 1) if curLevel >= #buildingData then return end local cost = buildingData[curLevel].starCost:toNumMap() if not role:checkItemEnough(cost) then return end role:costItems(cost) role.dinerData:updateProperty({field = "level", value = buildL:setv(index, curLevel + 1)}) SendPacket(actionCodes.Diner_levelUpRpc, '') return true end function _M.talentUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local dish = msg.dish local dishSet = csvdb["diner_dishCsv"][dish] if not dishSet then return end local dishTree = role.dinerData:getProperty("dishTree") local dishLevel = dishTree:getv(dish, 0) local cost = {} local treePoint = {} if dishLevel == 0 then local dishData = dishSet[1] if dishData.unlock_tree > 0 then if dishTree:getv(dishData.unlock_tree, 0) == 0 then return end end if dishData.unlock_carbon > 0 then local hangPass = role:getProperty("hangPass") if not hangPass[dishData.unlock_carbon] then return end end cost = globalCsv.diner_sell_dish_talent_unlock:toNumMap() else if dishLevel >= #dishSet then return end local dishData = dishSet[dishLevel] cost = dishData.tree_material:toNumMap() treePoint = dishData.tree_point:toNumMap() end if not role:checkItemEnough(cost) then return end role:costItems(cost) role.dinerData:updateProperty({field = "dishTree", value = dishTree:setv(dish, dishLevel + 1)}) if next(treePoint) then role:award(treePoint) end SendPacket(actionCodes.Diner_talentUpRpc, '') return true end return _M