-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathskill.py
More file actions
204 lines (193 loc) · 5.57 KB
/
skill.py
File metadata and controls
204 lines (193 loc) · 5.57 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import config
import re
import xml.etree.ElementTree as ET
import os
class Skill:
"""The class used for holding, and processing, the data for skills"""
def __init__(self, root,cl):
self.classlevel=cl
self.name = "filler_name"
self.row = 0
self.col = 0
self.spreq = 0
self.duration = None
self.cooldown = None
self.reqlevel = None
self.buyInCost = 3
self.startranks = 0
self.numranks = 0
self.limit = 1
self.isult = False
self.desc = "filler \\nskill name"
self.reqskills = None
self.vars = dict()
self.icons = None
if 'dataVersion' in root.attrib:
temp = root.attrib['dataVersion']
if temp == '1':
self.initV1(root)
else:
self.initV1(root)
def getDesc(self):
if self.numranks >= 1:
s1 = self.getText(self.desc,self.vars,self.numranks-1)
s2 = self.getText(self.desc,self.vars,self.numranks)
else:
s1 = self.getText(self.desc,self.vars,self.numranks)
s2 = self.getText(self.desc,self.vars,self.numranks+1)
if s1 != s2:
return s1 + '\n' + '-'*15 + '\n' + s2
return s1
def initV1(self, root):
attr = root.attrib
self.row = int(attr['row'])
self.col = int(attr['col'])
self.name = attr['name']
self.limit = int(attr['limit'])
self.desc = root.find('desc').text
if 'spreq' in attr:
self.spreq= int(attr['spreq'])
elif self.classlevel > 0:
if self.classlevel == 2:
self.spreq=65
else:
self.spreq = self.row*5 + 20
if 'isult' in attr:
self.isult = attr['isult'] == 'True'
if 'startranks' in attr:
self.startranks = int(attr['startranks'])
self.numranks=self.startranks
if 'buyInCost' in attr:
self.buyInCost = int(attr['buyInCost'])
if root.find('duration') is not None:
self.duration = VarList(node=root.find('duration'))
if root.find('cooldown') is not None:
self.cooldown = VarList(node=root.find('cooldown'))
if root.find('icon') is not None:
self.icons = VarList(node=root.find('icon'))
else:
temparr = []
if os.path.isfile('./icons/' + self.name.replace(' ','_') + '_gray.jpg'):
temparr.append(self.name.replace(' ','_') + '_gray.jpg')
if os.path.isfile('./icons/' + self.name.replace(' ','_') + '.jpg'):
temparr.append(self.name.replace(' ','_') + '.jpg')
self.icons = VarList(arr=temparr)
for x in root.findall('var'):
self.vars[x.attrib['id']] = VarList(node=x)
if root.find('reqlevel') is not None:
self.reqlevel=VarList(node=root.find('reqlevel'),type='yes')
if root.find('reqskills') != None:
self.reqskills = []
for x in root.find('reqskills').text.split(','):
self.reqskills.append(PreReq(x,self,self.classlevel))
def minimize(self):
self.numranks = self.startranks
def maximize(self):
self.numranks = self.limit
def getText(self, string, vars, level):
while string.find('{') >= 0:
start = string.find('{')
end = string.find('}')
string = string[0:start] + vars[string[start+1:end]][level] + string[end+1:]
string = string.replace("\\n","\n")
return string
def rankUp(self):
self.numranks = min(self.limit,self.numranks+1)
def rankDown(self):
self.numranks = max(self.startranks,self.numranks-1)
def getreqlevel(self, forleveling=True):
if self.reqlevel is None:
return 1
if forleveling:
return self.reqlevel[self.numranks]
if self.numranks is 0:
return 1
return self.reqlevel[max(self.numranks-1,0)]
def sp(self):
if self.numranks > 0:
if self.numranks > 1:
return self.buyInCost + self.numranks - 1
return self.buyInCost
return 0
def getcd(self):
if self.cooldown is None:
return None
return self.cooldown[self.numranks-1 if self.numranks > 1 else 0]
def levelreq(self):
if self.numranks is self.limit:
return None
rlevel = self.getreqlevel()
self.rankUp()
nspused = self.sp()
self.rankDown()
return [rlevel, nspused - self.sp()]
def geticon(self):
if self.icons is None:
return None
return self.icons[self.numranks]
def enoughsp(self):
if self.classlevel is 0 or self.spreq is 0:
return True
return config.control.nums[self.classlevel-1] >= self.spreq
class VarList:
def __init__(self, node=None,fromstr=None,arr=None, type='nope'):
self.predict = False
self.vals = []
self.predict = type is 'yes'
if node is not None:
if 'type' in node.attrib:
self.predict = node.attrib['type'] == 'yes'
if self.predict:
for q in node.text.split(','):
self.vals.append(int(q))
else:
for q in node.text.split(','):
self.vals.append(q)
elif fromstr is not None:
for q in node.split(','):
self.vals.append(q)
elif arr is not None:
self.vals=arr
def __getitem__(self, dex):
if len(self.vals) is 0:
return None
if self.predict:
return self.getPredictedVal(self.vals,dex)
return self.getCutoffVal(self.vals,dex)
def getCutoffVal(self, nums, index):
if len(nums) <= index:
return nums[-1]
return nums[index]
def getPredictedVal(self, nums, index):
if index < len(nums):
return nums[index]
if len(nums) == 1:
return nums[0]
perLevel = nums[-1] - nums[-2]
diff = index - len(nums) + 1
return nums[-1] + perLevel*diff
class PreReq:
def __init__(self,pr,skill,cl):
self.classlevel=cl
self.row=skill.row
self.col=skill.col
self.numranks=1
temp = pr.split(':')
if re.match('[nsew].*',pr):
if temp[0] == 'n':
self.row-=1
elif temp[0] == 's':
self.row+= 1
elif temp[0] == 'e':
self.col+= 1
elif temp[0] == 'w':
self.col-= 1
if ':' in pr:
self.numranks = int(temp[-1])
else:
#if it uses a non-default # of ranks
if re.match('\\d+:\\d+:\\d+:\\d+',pr):
self.numranks = int(temp[-1])
self.classlevel=int(temp[0])
self.row=int(temp[1])
self.col=int(temp[2])