-
Notifications
You must be signed in to change notification settings - Fork 40
/
HeroData.py
142 lines (112 loc) · 4.71 KB
/
HeroData.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import os
import string
heroName = ''
shiftCount = 0
heroCount = 0
lineCount = 0
botDataProcessing = False
botLaningInfo = False
heroes = {}
def writeHeroDataLua(obj):
f = open('C:\\Program Files (x86)\\Steam\\steamapps\\common\\dota 2 beta\\game\\dota\\scripts\\vscripts\\bots\\hero_data.lua', 'w')
f.write('local X = {}\n')
st = ''
for heroName in heroes:
try:
st = '\nX.%s = {}\n' % heroName
try:
st = st + 'X.%s.%s = "%s"\n' % (heroName, 'Type', heroes[heroName]['Type'])
except KeyError as e:
print 'Error dumping [Type]: ', heroName
indx = 0
for ability in heroes[heroName]['Abilities']:
st = st + 'X.%s.SKILL_%d = "%s"\n' % (heroName, indx, ability)
indx += 1
indx = 0
for ability in heroes[heroName]['Talents']:
st = st + 'X.%s.TALENT_%d = "%s"\n' % (heroName, indx, ability)
indx += 1
try:
roles = heroes[heroName]['Role'].split(',')
rolevals = heroes[heroName]['Rolelevels'].split(',')
st = st + 'X.%s.Role = {}\n' % (heroName)
for i in range(0, len(roles)):
st = st + 'X.%s.Role.%s = %s\n' % (heroName, roles[i], rolevals[i])
except KeyError as e:
print 'Error dumping [Role]: ', heroName
try:
st = st + 'X.%s.LaneInfo = {}\n' % (heroName)
for key in heroes[heroName]['LaneInfo']:
st = st + 'X.%s.LaneInfo.%s = %s\n' % (heroName, key, heroes[heroName]['LaneInfo'][key])
except KeyError as e:
print 'Error dumping [LaneInfo]: ', heroName
f.write(st)
except KeyError as e:
print 'Generic Error: ', heroName
f.write('\nreturn X\n')
f.close()
badHeroNames = ['npc_dota_hero_base', 'npc_dota_hero_target_dummy']
if __name__ == "__main__":
fName = open('C:\\Program Files (x86)\\Steam\\steamapps\\common\\dota 2 beta\\game\\dota\\scripts\\npc\\npc_heroes.txt', 'r')
content = fName.readlines()
content = [x.strip() for x in content]
print len(content)
fName.close()
for line in content:
lineCount += 1
name = string.find(line, "npc_dota_hero_")
if name > -1 and heroName == '' and line.strip('"') not in badHeroNames and shiftCount == 1:
heroName = line[name+14:-1]
#print lineCount, 'Starting with', heroName
heroCount += 1
heroes[heroName] = {}
heroes[heroName]['Abilities'] = []
heroes[heroName]['Talents'] = []
continue
if line == '{':
shiftCount += 1
continue
if line == '}':
shiftCount -= 1
if shiftCount == 1 and heroName != '':
#print lineCount, 'Done with', heroName
heroName = ''
if shiftCount == 2 and heroName != '':
if line[1:11] == 'Rolelevels':
key, val = line.split()
heroes[heroName]['Rolelevels'] = val[1:-1]
elif line[1:5] == 'Role':
key, val = line.split()
heroes[heroName]['Role'] = val[1:-1]
if line[1:8] == 'Ability' and line[1:14] != 'AbilityLayout' and line[1:15] != 'AbilityPreview' and line[1:21] != 'AbilityDraftDisabled':
try:
key, val = line.split()
if string.find(val, "special_bonus_") >= 0:
heroes[heroName]['Talents'].append(val.strip('"'))
else:
heroes[heroName]['Abilities'].append(val.strip('"'))
except ValueError as e:
print 'Error: ', line
break
if line == '"Bot"':
botDataProcessing = True
continue
if botDataProcessing:
botDataProcessing = False
if shiftCount == 3 and botLaningInfo:
botLaningInfo = False
if shiftCount == 3 and botDataProcessing:
if line[1:9] == 'HeroType':
heroes[heroName]['Type'] = line.split("\t",1)[1][2:-1]
if line[1:11] == 'LaningInfo':
heroes[heroName]['LaneInfo'] = {}
botLaningInfo = True
if shiftCount == 4 and botDataProcessing and botLaningInfo:
try:
key, val = line.split()
heroes[heroName]['LaneInfo'][key.strip('"')] = val.strip('"')
except ValueError as e:
print 'Error: ', lineCount, line
raise e
print 'Processed %d heroes' % (heroCount)
writeHeroDataLua(heroes)