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, 1) 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 cost = potionData.material: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, {log = {desc = "makePotion", int1 = potionId, int2 = count}}) local own = potionBag[potionId] or 0 potionBag[potionId] = own + count role:updateProperty({field = "potionBag", value = potionBag}) role:checkTaskEnter("PotionMake", {count = count, id = potionId}) role:log("carriage_cook", { item_id = potionId, -- 道具id item_level = potionLv, -- 道具等级 item_type = 0, -- 道具类型,具体见枚举表中道具类型枚举表 carriage_cook_amount = count, -- 制作总量 carriage_cook_cost = cost, -- 制作消耗道具,json格式记录,{'itemid1':10,'itemid2':5,…………..} }) role:mylog("role_action", {desc = "makePotion", int1 = potionId, int2 = count}) 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 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 limit = csvdb["itemCsv"][nextEquip.id].limit ~= 0 and csvdb["itemCsv"][nextEquip.id].limit or math.huge if math.illegalNum(count, 1, limit) then return 0 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, {log = {desc = "equipUp", int1 = id, int2 = count}}) role:addEquip(typ, lv, -costCount, {log = {desc = "equipUp"}}) role:addEquip(typ, nextLv ,count, {log = {desc = "equipUp"}}) role:checkTaskEnter("EquipUp", {count = count}) role:log("equip_upgrade", { equip_upgrade_part = typ, -- 升级部位,记录部位ID equip_id = nextLv, -- 升级后的装备ID equip_upgrade_amount = count, -- 升级获取的装备数量 equip_upgrade_usedid = lv, -- 升级消耗的装备ID equip_upgrade_cost = costCount, -- 升级操作消耗装备数量 equip_upgrade_current = cost, -- 升级消耗的货币类型 }) role:mylog("role_action", {desc = "equipUp", int1 = id, int2 = 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 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 >= runeData.lvLimit then return 6 end local lvData = csvdb["rune_buildCsv"][level] local cost = lvData.cost:toNumMap() if not role:checkItemEnough(cost) then return 7 end role:costItems(cost, {log = {desc = "runeUp", int1 = uid, int2 = level}}) ownRune:updateProperty({field = "level",value = level+1}) role:checkTaskEnter("RuneUp") if ownRune:getProperty("refer") ~= 0 then local hero = role.heros[ownRune:getProperty("refer")] if hero then hero:updateProperty({field = "battleV", value = hero:getBattleValue()}) end end ownRune:mylog({desc = "runeUp", int1 = level + 1}) SendPacket(actionCodes.Car_runeUpRpc, '') return true end function _M.saleEquipRpc(agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local backs = msg.backs if not backs then return end for id, count in pairs(backs) do if not csvdb["itemCsv"][id] then return end local typ = math.floor((id-7000)/100) local lv = (id-7000)%100 local own = role:getEquipCount(typ,lv) if math.illegalNum(count, 1, own) then return end end local reward, change = {} local allCount = 0 for id, count in pairs(backs) do allCount = allCount + count local itemData = csvdb["itemCsv"][id] local typ = math.floor((id-7000)/100) local lv = (id-7000)%100 role:addEquip(typ, lv, -count, {log = {desc = "saleEquip"}}) -- 删掉装备 -- 发奖励 local one = itemData.sell_effect:toNumMap() for k ,v in pairs(one) do reward[k] = (reward[k] or 0) + v * count end end role:checkTaskEnter("SaleEquip", {count = allCount}) reward, change = role:award(reward, {log = {desc = "saleEquip"}}) role:mylog("role_action", {desc = "saleEquip", int1 = allCount}) SendPacket(actionCodes.Car_saleEquipRpc, MsgPack.pack(role:packReward(reward, change))) return true end function _M.saleRuneRpc(agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local backs = msg.backs if not backs then return end local reward, change = {} local count = 0 for _, uid in pairs(backs) do count = count + 1 local rune = role.runeBag[uid] if not rune then return end if rune:getProperty("refer") ~= 0 then return end local itemData = csvdb["itemCsv"][rune:getProperty("id")] if not itemData then return end local one = itemData.sell_effect:toNumMap() for k ,v in pairs(one) do reward[k] = (reward[k] or 0) + v end end role:delRunes(backs, {log = {desc = "saleRune"}}) role:checkTaskEnter("DecoRune", {count = count}) reward, change = role:award(reward, {log = {desc = "saleRune"}}) SendPacket(actionCodes.Car_saleRuneRpc, MsgPack.pack(role:packReward(reward, change))) return true end function _M.sparkQualityUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local uid = msg.uid local ownSpark = role.sparkBag[uid] if not ownSpark then return 1 end local cfg_id = ownSpark:getProperty("cfg_id") local level = ownSpark:getProperty("level") local sparkSet = csvdb["sparkCsv"][cfg_id] if not sparkSet then return 4 end local sparkData = sparkSet[level] if not sparkData then return 5 end if sparkData.star_up == 0 then return 6 end local cost = sparkData.star_item:toNumMap() if not role:checkItemEnough(cost) then return 7 end role:costItems(cost, {log = {desc = "sparkQualityUp", int1 = uid, int2 = level}}) local newSet = csvdb["sparkCsv"][sparkData.star_up] if not newSet then return 8 end local newSparkData = newSet[0] if not newSparkData then return 9 end local attrs = newSparkData.attr:toNumMap() ownSpark:addAttr(attrs) ownSpark:updateProperty({field = "level",value = 0}) ownSpark:updateProperty({field = "cfg_id",value = sparkData.star_up}) --role:checkTaskEnter("SparkQualityUp") ownSpark:mylog({desc = "sparkQualityUp", int1 = sparkData.id , int2 = sparkData.star_up}) SendPacket(actionCodes.Car_sparkQualityUpRpc, '') return true end function _M.sparkLvlUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local uid = msg.uid local ownSpark = role.sparkBag[uid] if not ownSpark then return 1 end local cfg_id = ownSpark:getProperty("cfg_id") local level = ownSpark:getProperty("level") local sparkSet = csvdb["sparkCsv"][cfg_id] if not sparkSet then return 4 end local sparkData = sparkSet[level] if not sparkData then return 5 end if level >= #sparkSet then return 6 end local cost = sparkData.lv_up_item:toNumMap() if not role:checkItemEnough(cost) then return 7 end local weight = math.random(0, 100) local addLvl = 1 if weight < sparkData.probability then addLvl = 2 end role:costItems(cost, {log = {desc = "sparkLvlUp", int1 = uid, int2 = level}}) local attrs = {} for i = 1, addLvl do local cfg = sparkSet[level + i] if not cfg then break end for k, v in pairs(cfg.attr:toNumMap()) do attrs[k] = (attrs[k] or 0) + v end end ownSpark:addAttr(attrs) ownSpark:updateProperty({field = "level",value = level+addLvl}) --role:checkTaskEnter("SparkLvlUp") ownSpark:mylog({desc = "sparkLvlUp", int1 = level + addLvl}) SendPacket(actionCodes.Car_sparkLvlUpRpc, MsgPack.pack({big = (addLvl == 2)})) return true end return _M