Blame view

src/rdsscripts/assistInfo.lua 1.6 KB
314bc5df   zhengshouren   提交服务器初始代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  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 {}