安装

python3

lcu-driver

1
pip install lcu-driver

python脚本

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from lcu_driver import Connector

connector = Connector()


# -----------------------------------------------------------------------------
# 获得召唤师数据
# -----------------------------------------------------------------------------
async def get_summoner_data(connection):
data = await connection.request('GET', '/lol-summoner/v1/current-summoner')
summoner = await data.json()
print(summoner)
print(f"displayName: {summoner['displayName']}")
print(f"summonerId: {summoner['summonerId']}")
print(f"puuid: {summoner['puuid']}")
print("-")


# -----------------------------------------------------------------------------
# lockfile
# -----------------------------------------------------------------------------
async def get_lockfile(connection):
import os
path = os.path.join(connection.installation_path.encode('gbk').decode('utf-8'), 'lockfile')
if os.path.isfile(path):
file = open(path, 'r')
text = file.readline().split(':')
file.close()
print(connection.address)
print(f'riot {text[3]}')
return text[3]
return None


# -----------------------------------------------------------------------------
# 创建训练模式 5V5 自定义房间
# gameMode -> 游戏模式。自定义模式为 'CLASSIC', 训练模式为 'PRACTICETOOL' (仅召唤师峡谷) 其他开放的游戏模式通过查询
# mapId -> 地图ID。召唤师峡谷:11, 嚎哭深渊:12
# mutators -> 游戏模式。自定义模式为 'CLASSIC', 训练模式为 'PRACTICETOOL' (仅召唤师峡谷)
# teamSize -> 队伍规模
# lobbyName -> 房间名称
# lobbyPassword -> 房间密码
# -----------------------------------------------------------------------------
async def create_custom_lobby(connection):
custom = {
'customGameLobby': {
'configuration': {
'gameMode': 'TUTORIAL_MODULE_1',
'gameMutator': '',
'gameServerRegion': '',
'mapId': 11,
'mutators': {'id': 1},
'spectatorPolicy': 'AllAllowed',
'teamSize': 5
},
'lobbyName': 'PRACTICETOOL',
'lobbyPassword': ''
},
'isCustom': True
}
await connection.request('POST', '/lol-lobby/v2/lobby', data=custom)


# -----------------------------------------------------------------------------
# 添加单个机器人
# championId -> 英雄Id
# teamId -> 100:是指蓝色方(左下角) 200:是指紫色方(右上角)
# botDifficulty -> 机器人难度,目前国服只有 EASY MEDIUM
# -----------------------------------------------------------------------------
async def add_bots_team1(connection):
soraka = {
'championId': 102,
'botDifficulty': 'MEDIUM',
'teamId': '100'
}
await connection.request('POST', '/lol-lobby/v1/lobby/custom/bots', data=soraka)


# -----------------------------------------------------------------------------
# 批量添加机器人
# -----------------------------------------------------------------------------
async def add_bots_team2(connection):
# 获取自定义模式电脑玩家列表
activedata = await connection.request('GET', '/lol-lobby/v2/lobby/custom/available-bots')
champions = {
bot['name']: bot['id'] for bot in await activedata.json()
}

print("获取可使用的召唤师 :id--->name")
for champion in champions:
print(str(champions[champion]) + '--->' + champion)

team2 = ['诺克萨斯之手', '牛头酋长', '曙光女神', '武器大师', '瓦洛兰之盾']
for name in team2:
bot = {'championId': champions[name],
'botDifficulty': 'MEDIUM',
'teamId': '200'}
await connection.request('POST', '/lol-lobby/v1/lobby/custom/bots', data=bot)


# -----------------------------------------------------------------------------
# websocket
# -----------------------------------------------------------------------------
@connector.ready
async def connect(connection):
await get_summoner_data(connection)
await get_lockfile(connection)
await create_custom_lobby(connection)
await add_bots_team1(connection)
await add_bots_team2(connection)


# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
connector.start()