-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
260 lines (240 loc) · 9.54 KB
/
main.py
File metadata and controls
260 lines (240 loc) · 9.54 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import xml.etree.ElementTree as ET
masterPassivesList = [
('ReflexExpert', 4, 6),
('WillExpert', 4, 6),
('FortitudeExpert', 4, 6),
('WeaponExpert', 4, 6),
('SpellExpert', 4, 6),
('ACExpert', 4, 6),
('ReflexMaster', 6, 8),
('WillMaster', 6, 8),
('FortitudeMaster', 6, 8),
('WeaponMaster', 6, 8),
('SpellMaster', 6, 8),
('ACMaster', 6, 8),
('ReflexLegend', 8, 15),
('WillLegend', 8, 15),
('FortitudeLegend', 8, 15),
('WeaponLegend', 8, 15),
('SpellLegend', 8, 15),
('ACLegend', 8, 15),
('PerceptionIncrease', 4, 15),
('PerceptionIncrease2', 6, 15),
('PerceptionIncrease3', 8, 15)
]
masterSkillList = ['Acrobatics', 'AnimalHandling', 'Arcana', 'Athletics',
'Deception', 'History', 'Insight', 'Intimidation',
'Investigation', 'Medicine', 'Nature', 'Performance',
'Persuasion', 'Religion', 'SleightOfHand', 'Stealth',
'Survival']
def get_proficiency(target):
usingTarget = ''
returnValue = -1, True, False
localValueFound = False
localValue = 0
localFields = target.find('fields').findall('field')
# Check for a locally defined proficiency value
for current in localFields:
if current.attrib['name'] == 'ProficiencyBonus':
try:
returnValue = int(current.attrib['value']), False, False
# Note the value so that we can check for underwritten values later
localValueFound = True
localValue = int(current.attrib['value'])
except:
# Catches locally defined "" values
returnValue = -1, True, False
# Find the UUID of the parent
for current in localFields:
if current.attrib['name'] == 'Using':
usingTarget = current.attrib['value']
# Search for that UUID
for base in allStats:
baseFields = base.find('fields').findall('field')
for baseField in baseFields:
if baseField.attrib['name'] == 'UUID':
if baseField.attrib['value'] == usingTarget:
# Recursive call to check further inheritance
result = get_proficiency(base)
if not localValueFound:
returnValue = result[0], result[1], True
else:
# If a local value was found, use that, unless it was an underwrite
if result[0] > localValue:
returnValue = localValue, True, False
break
return returnValue
def get_passives(target):
usingTarget = ''
localFields = target.find('fields').findall('field')
for current in localFields:
if current.attrib['name'] == 'Passives':
try:
return current, current.attrib['value'], False, 0
except:
return 0, '', True, 0
for current in localFields:
if current.attrib['name'] == 'Using':
usingTarget = current.attrib['value']
for base in allStats:
baseFields = base.find('fields').findall('field')
for baseField in baseFields:
if baseField.attrib['name'] == 'UUID':
if baseField.attrib['value'] == usingTarget:
result = get_passives(base)
return 0, result[1], result[2], result[3] + 1
return 0, '', True, 0
def get_skills(target):
usingTarget = ''
localFields = target.find('fields').findall('field')
for current in localFields:
if current.attrib['name'] == 'DefaultBoosts':
try:
return current, current.attrib['value'], False, 0
except:
return 0, '', True, 0
for current in localFields:
if current.attrib['name'] == 'Using':
usingTarget = current.attrib['value']
for base in allStats:
baseFields = base.find('fields').findall('field')
for baseField in baseFields:
if baseField.attrib['name'] == 'UUID':
if baseField.attrib['value'] == usingTarget:
result = get_skills(base)
return 0, result[1], result[2], result[3] + 1
return 0, '', True, 0
if __name__ == '__main__':
print('Opening Character.stats as XMl file')
tree = ET.parse('D:\Pathfinder2eModBG3\Editor\Mods\Pathfinder2ndEdition_dda83752-5c01-30f9-6a09-824c7e182090\Stats\Stats\Character.stats')
root = tree.getroot()
allStats = root.find('stat_objects').findall('stat_object')
changesList = []
# Iterating every character entry
for each in allStats:
# Will hold which skills the character is proficient in
updateSkillList = []
currentFields = each.find('fields').findall('field')
# Finds if a proficiency value is specified, and then recursively checks for inheritance.
proficiencyCheck = get_proficiency(each)
# Obtain name so that we can log failed entries easily. Obtain UUID to make our changesList.
for field in currentFields:
if field.attrib['name'] == 'Name':
currentName = field.attrib['value']
if field.attrib['name'] == 'UUID':
currentUUID = field.attrib['value']
try:
proficiency = proficiencyCheck[0]
# Entries with inherited proficiency don't need it to be updated
inheritedProficiency = proficiencyCheck[2]
if proficiencyCheck[1]:
if proficiencyCheck[0] == -1:
print(currentName + " skipped due to bad proficiency value.")
else:
print(currentName + " skipped due to underwriting inherited value. Should be " + str(proficiencyCheck[0]))
continue
except:
print(currentName + " had no proficiency value inheritable within file.")
continue
# Finds the passives field, recursively checking inheritance
passivesResult = get_passives(each)
if passivesResult[2]:
print(currentName + " skipped due to bad passives value.")
continue
# Finds the skills field (default boosts), recursively checking inheritance
skillsResult = get_skills(each)
if skillsResult[2]:
print(currentName + " skipped due to bad skills value.")
continue
# Proficiencies that are less than 3 don't need any expertise or mastery passives added
if proficiency < 3:
continue
# Create a list of (inheritance depth, UUID, new proficiency)
changesList.append((max(passivesResult[3], skillsResult[3]), currentUUID, (proficiency, inheritedProficiency)))
# Sort the changes list by the inheritance depth, such that base classes are at the top
changesList.sort(key=lambda tup: tup[0])
# Iterate all entries again, this time looking for UUID matches to our ordered changes list
for change in changesList:
for each in allStats:
currentFields = each.find('fields').findall('field')
match = False
# Check for a UUID match
for field in currentFields:
if field.attrib['name'] == 'UUID':
if field.attrib['value'] == change[1]:
match = True
# If found, make the needed changes
if match:
if not change[2][1]:
# Proficiency was not inherited
for field in currentFields:
if field.attrib['name'] == 'ProficiencyBonus':
field.attrib['value'] = '2'
break
passivesResult = get_passives(each)
skillsResult = get_skills(each)
passiveChangesMade = False
skillChangesMade = False
# Check every passive and append if within defined level bracket
passivesString = passivesResult[1]
for option in masterPassivesList:
if (change[2][0] >= option[1]) and (change[2][0] < option[2]):
if passivesString.find(option[0]) == -1:
# Sometimes stats from toolkit lack trailing semicolons
if passivesString[-1] != ';':
passivesString = passivesString + ';'
passivesString = passivesString + option[0] + ';'
passiveChangesMade = True
# Check every skill and append if needed
skillsString = skillsResult[1]
for option in masterSkillList:
if change[2][0] >= 4:
if (skillsString.find('ProficiencyBonus(Skill, ' + option) != -1) and (skillsString.find('ExpertiseBonus(' + option) == -1):
# If the proficiency bonus is present, add the relevant expertise
# Sometimes stats from toolkit lack trailing semicolons
if skillsString[-1] != ';':
skillsString = skillsString + ';'
skillsString = skillsString + 'ExpertiseBonus(' + option + ');'
skillChangesMade = True
if change[2][0] >= 6:
if (skillsString.find('ProficiencyBonus(Skill, ' + option) != -1) and (passivesString.find(option + 'Increase') == -1):
# If the proficiency bonus is present, add the relevant mastery
# Sometimes stats from toolkit lack trailing semicolons
if passivesString[-1] != ';':
passivesString = passivesString + ';'
passivesString = passivesString + option + 'Increase;'
passiveChangesMade = True
if change[2][0] >= 8:
if (skillsString.find('ProficiencyBonus(Skill, ' + option) != -1) and (passivesString.find(option + 'Increase2') == -1):
# If the proficiency bonus is present, add the relevant legend
# Sometimes stats from toolkit lack trailing semicolons
if passivesString[-1] != ';':
passivesString = passivesString + ';'
passivesString = passivesString + option + 'Increase2;'
passiveChangesMade = True
# If no changes were needed for the passives we do not need to write
if passiveChangesMade:
if passivesResult[0] == 0:
# Passive field was inherited, but needs to be modified, so make a new passives field to populate
passives = ET.Element('field')
passives.attrib['name'] = 'Passives'
passives.attrib['type'] = 'StringTableFieldDefinition'
each.append(passives)
else:
passives = passivesResult[0]
passives.attrib['value'] = passivesString
# If no changes were needed for the skills we do not need to write
if skillChangesMade:
if skillsResult[0] == 0:
# Skill field was inherited, but needs to be modified, so make a new skills field to populate
skills = ET.Element('field')
skills.attrib['name'] = 'DefaultBoosts'
skills.attrib['type'] = 'StringTableFieldDefinition'
each.append(skills)
else:
skills = skillsResult[0]
skills.attrib['value'] = skillsString
break
with open('new.stats', 'wb') as f:
tree.write(f, encoding='utf-8')
print('File handled successfully')