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 k, n in pairs(cost) do cost[k] = 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 ownSet = role.equipBag[typ] if not ownSet then return 31 end local ownData = ownSet[lv] if not ownData then return 32 end local own = role:getEquipCount(typ,lv) local costCount = equipData.merge*count if own < costCount then return 3 end local cost = equipData.cost:toNumMap() for k, n in pairs(cost) do cost[k] = n * count end if not role:checkItemEnough(cost) then return 4 end role:costItems(cost) role:addEquip({type=typ,level=lv,count=-costCount}) role:addEquip({type=typ,level=nextLv,count=count}) SendPacket(actionCodes.Car_equipUpRpc, '') return true end function _M.runeUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local uid = msg.uid local ownRune = role.runeBag[uid] if not ownRune then return 1 end if ownRune:getProperty("refer") ~= 0 then return 2 end local typ = ownRune:getProperty("type") local id = ownRune:getProperty("id") local level = ownRune:getProperty("level") local runeSet = csvdb["runeCsv"][typ] if not runeSet then return 4 end local runeData = runeSet[id] if not runeData then return 5 end local maxLv = #csvdb["rune_buildCsv"] if level >= maxLv then return 6 end local lvData = csvdb["rune_buildCsv"][level+1] local cost = lvData.cost:toNumMap() if not role:checkItemEnough(cost) then return 7 end role:costItems(cost) ownRune:updateProperty({field = "level",value = level+1}) SendPacket(actionCodes.Car_runeUpRpc, '') return true end return _M