-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathskillXmlEditor.py
91 lines (81 loc) · 2.91 KB
/
skillXmlEditor.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
#!/usr/bin/env python3
"""
Python 3.x.x
Used for modifying skill XMLs (from Skill.wz) to change skill values
(in the "level" nodes) Supports adding/subtracting, multiplying, setting,
but could easily be tweaked for a lot of things.
Prints the number of individual values changed, for verification purposes.
"""
import re
skillendre = re.compile(r'<imgdir name="[A-Za-z]+">')
filename = input(
"Enter the filename, or absolute/relative file path " +
"if not in this folder, of the skill XML: ")
skillid = int(input("Enter the ID of the skill you wish to edit: "))
attribute = input(
"Enter the attribute you wish to modify " +
"(e.g. \"mad\" for magic attack damage): ")
add = int(input(
"Enter how much you would like to add " +
"to the attribute at every level of the skill (can be negative): "))
multi = float(input(
"Enter how much you would like to " +
"multiply the attribute by at every level: "))
setto = 0
try:
setto = int(input(
"Enter what you would like to set the attribute to at all levels " +
"(enter anything that is not an integer to ignore): "))
except:
setto = -60001 # Magic number that I assume no one will enter
line = ""
out = ""
attributeschangedcount = 0
with open(filename, "r", encoding="utf8") as f:
lines = f.readlines()
if len(lines) > 1:
raise IOError("XML file is not all in one line.")
line = lines[0]
skillstartindex = line.find("<imgdir name=\"" + str(skillid) + "\">")
if skillstartindex == -1:
raise ValueError("Could not find specified skill ID.")
skillstartindex = line.find("<imgdir name=\"level\">", skillstartindex + 5)
"""
skillendindex = line.find("<imgdir name=\"effect\">", skillstartindex + 5)
"""
skillendmatch = skillendre.search(line, skillstartindex + 5)
if skillendmatch:
skillendindex = skillendmatch.start()
else:
skillendindex = len(line)
"""
if skillendindex == -1:
skillendindex = len(line)
"""
attributeindex = line.find(
"name=\"" + attribute + "\"", skillstartindex + 5)
while attributeindex != -1 and attributeindex < skillendindex:
valuestart = line.find("value=\"", attributeindex)
beginning = line[:valuestart + 7]
valueend = line.find("\"/", valuestart + 7)
value = line[valuestart + 7:valueend]
end = line[valueend:]
newvalue = 0
if setto != -60001:
newvalue = setto
else:
newvalue = int(int(value) * multi)
newvalue += add
newvalue = str(newvalue)
if len(newvalue) != len(value):
difference = len(newvalue) - len(value)
skillendindex += difference
value = newvalue
line = beginning + value + end
attributeschangedcount += 1
attributeindex = line.find(
"name=\"" + attribute + "\"", attributeindex + 2)
out = line
with open(filename, "w", encoding="utf8") as f:
f.write(out)
print(attributeschangedcount)