Blame view

src/rdsscripts/refreshAssist.lua 1.47 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
54
55
  local roleId = tonumber(KEYS[1])
  
  local friendKey = "role:%d:friend"
  local assistKey = "role:%d:assist"
  
  local function formatTable(tbl)
  	local t = {}
  	for _, id in ipairs(tbl) do
  		t[tonumber(id)] = 1
  	end
  	return t
  end
  
  local friendIds = redis.call("smembers", friendKey:format(roleId))
  local assistIds = formatTable(redis.call("smembers", assistKey:format(roleId)))
  
  local heroFields = {"type", "level", "star", "evolveCount", "wake", "breakLevel", "battleValue", "dress"}
  local function getLeader(id, formation)
  	for _, hero in ipairs(formation.heros) do
  		if hero.leader then
  			local heroInfo = redis.call("hmget", string.format("hero:%d:%d", id, hero.id), unpack(heroFields))
  			return {
  				type = tonumber(heroInfo[1]),
  				level = tonumber(heroInfo[2]),
  				star = tonumber(heroInfo[3]),
  				evolveCount = tonumber(heroInfo[4]),
  				wake = tonumber(heroInfo[5]),
  				breakLevel = tonumber(heroInfo[6]),
  				battleValue = tonumber(heroInfo[7]),
  				dress = tonumber(heroInfo[8]),
  			}
  		end
  	end
  end
  
  local response = {}
  for _, id in ipairs(friendIds) do
  	id = tonumber(id)
  	local dtls = redis.call("hmget", string.format("role:%d", id),
  		"name", "level", "vip", "pveFormationJson")
  	local formation = cjson.decode(dtls[4])
  	local leader = getLeader(id, formation)
  	if leader then
  		table.insert(response, {
  			roleId = id,
  			name = dtls[1],
  			level = tonumber(dtls[2]),
  			vip = tonumber(dtls[3]),
  			leader = leader,
  			used = assistIds[id] or 0,
  		})
  	end
  end
  
  return cmsgpack.pack(response)