local roleId = tonumber(KEYS[1]) local formationJson = redis.call("hget", string.format("role:%d", roleId), "pveFormationJson") local formation = cjson.decode(formationJson) local function formatAttrEx(str) local tb = {} for k, v in str:gmatch("([%d.]+)=([%d.]+)") do tb[#tb+1] = {tonumber(k), tonumber(v)} end return tb end local function formatEquips(str) local tb = {} for k, v in str:gmatch("([%d.]+)=([%d.]+)") do tb[tonumber(k)] = tonumber(v) end return tb end local heroFields = {"type", "level", "star", "evolveCount", "wake", "breakLevel", "equips"} local equipFields = {"type", "level", "evolCount", "attrEx"} for _, hero in ipairs(formation.heros) do if hero.leader then local heroInfo = redis.call("hmget", string.format("hero:%d:%d", roleId, hero.id), unpack(heroFields)) local equipstr = heroInfo[7] local equips = {} for part, equipId in equipstr:gmatch("(%d+)=(%d+)") do part, equipId = tonumber(part), tonumber(equipId) if equipId ~= 0 then local equipInfo = redis.call("hmget", string.format("equip:%d:%d", roleId, equipId), unpack(equipFields)) equips[equipId] = {} for index, value in ipairs(equipInfo) do equips[equipId][equipFields[index]] = index ~= 4 and tonumber(value) or formatAttrEx(equipInfo[4] or "") end end end return cmsgpack.pack { type = tonumber(heroInfo[1]), level = tonumber(heroInfo[2]), star = tonumber(heroInfo[3]), evolveCount = tonumber(heroInfo[4]), wake = tonumber(heroInfo[5]), breakLevel = tonumber(heroInfo[6]), equips = formatEquips(heroInfo[7]), equipDtls = equips, } end end return cmsgpack.pack {}