-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.py
278 lines (245 loc) · 11.6 KB
/
generate.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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/python3
import sys,os,shutil,dataclasses,load,goal,args,summary,theme
ENCODING='utf-16'
DIRMEDIA='media'
DIRDUNGEONS='media/dungeons'
REFERENCE=args.reference
OPENPORTAL=''' [EFFECT]
<STRING>NAME:{}
<STRING>ACTIVATION:DYNAMIC
<STRING>DURATION:INSTANT
<STRING>TYPE:OPEN PORTAL
<BOOL>SAVE:TRUE
<FLOAT>MIN:0
<FLOAT>MAX:0
[/EFFECT]
'''
PARENT='ESTHERIANCITY'
GUIDWARNING='For extra safety make sure to check GUIDs on GUTS before publishing.'
FILES={}
NUMERALS=['I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','XIII','XIV','XV','XVI']
TIERS=len(NUMERALS)
#TODO move data to maps.yaml?
MAPS=['map_catacombs_b_66','map_estherian_a','map_icecaves_a','map_catacombs_2','map_catacombs_3','map_catacombs_a_105','map_catacombs_a_56','map_catacombs_a_66','map_catacombs_a_76','map_catacombs_a_86','map_catacombs_a_96','map_catacombs_b_105','map_catacombs_b_56','map_catacombs_b_76','map_catacombs_b_86','map_catacombs_b_96','map_catacombs_c_105','map_catacombs_c_56','map_catacombs_c_66','map_catacombs_c_76','map_catacombs_c_86','map_catacombs_c_96','map_caves_a','map_caves_a_105','map_caves_a_56','map_caves_a_66','map_caves_a_76','map_caves_a_86','map_caves_a_96','map_dragon_a','map_dragon_a105','map_dragon_a56-65','map_dragon_a66-75','map_dragon_a76-85','map_dragon_a86-95','map_dragon_a96-105','map_dwarvenlabs_a','map_dwarvenlabs_a_105','map_dwarvenlabs_a_56','map_dwarvenlabs_a_66','map_dwarvenlabs_a_76','map_dwarvenlabs_a_86','map_dwarvenlabs_a_96','map_estherian_b','map_estherian_b105','map_estherian_b56','map_estherian_b66','map_estherian_b76','map_estherian_b86','map_estherian_b96','map_estherian_c','map_estherian_c_105','map_estherian_c_56','map_estherian_c_66','map_estherian_c_76','map_estherian_c_86','map_estherian_c_96','map_icecaves_a_105','map_icecaves_a_56','map_icecaves_a_66','map_icecaves_a_76','map_icecaves_a_86','map_icecaves_a_96','map_vaults_a','map_vaults_a105','map_vaults_a56','map_vaults_a66','map_vaults_a76','map_vaults_a86','map_vaults_a96','maproom_catacombs_1']
DUNGEONS=['A3-banepits','a3werewolfcellar','desertcaves','witherways']#TODO scale NG_NW_ICELABS NG_SE_ICELABS A2Z1_CURSEDFEAR_DESERTCAVES'
BOSSES=['A3-3SISTERS','arenaofslaughter','cacklespitsrealm','cultistslair','deadshoals','jehannum','koraricave','manavent','ngbearcave','ngdwarfarmory','piratecove','riftkeep','thesawmill','a3-scrapworks','slaversden','manticorelair','swarmpoint','desertcatacombs','GOBLIN_EMBERCAVES','thegardenoftears','thing','towerofthemoon','undercurrents','vaultofsouls','a3-warforge','wellspringtreasury','crowspass_spidercave']
WILDS=['a3-battlefield','a3blightbogs','broodhive','crowspass','a3pass1','frostedhills','hauntedquarter','osseanwastes','pathofhonoreddead','a3pass2','saltbarrens','templesteppes','vulturepass']
NETHER=['nether','nether_a1z1','nether_a1z2','nether_a2z1','nether_a2z2','nether_a3z1','nether_a3z2']
CHALLENGES=['phasebeast_a1z1_all','phasebeast_a1z2_all','phasebeast_a2z1_all','phasebeast_a2z2_all','phasebeast_a2z2_JT','phasebeast_a3z1_all','phasebeast_a3z2_all','phasebeast_a3z2_lava','phasepillar','luminousarena']
@dataclasses.dataclass
class Replace:
pattern:str
replacement:str #if False, skip line
class ReplaceDescription(Replace):
def __init__(self,dungeon,tier,goal=False):
self.pattern='<TRANSLATE>DESCRIPTION:'
self.replacement=f'\t<TRANSLATE>DESCRIPTION:'
if goal:
self.replacement+=f'May contain {goal.name}.\n'
else:
self.replacement+=f'Right-click to enter {dungeon.name} (Tier {tier.name})\n'
class ReplaceDisplayName(Replace):
def __init__(self,to):
self.pattern='<TRANSLATE>DISPLAYNAME:'
self.replacement=f'\t<TRANSLATE>DISPLAYNAME:{to}\n'
class ReplaceParentDungeon(Replace):
def __init__(self):
self.pattern='<STRING>PARENT_DUNGEON:'
self.replacement=f'\t<STRING>PARENT_DUNGEON:{PARENT}\n'
class ReplaceParentTown(Replace):
def __init__(self):
self.pattern='<STRING>PARENT_TOWN:'
self.replacement=f'\t<STRING>PARENT_TOWN:{PARENT}\n'
class ReplaceMinMatchLevel(Replace):
def __init__(self,t):
self.pattern='<INTEGER>PLAYER_LVL_MATCH_MIN:'
self.replacement=f'\t<INTEGER>PLAYER_LVL_MATCH_MIN:{t.minlevel}\n'
class ReplaceMaxMatchLevel(Replace):
def __init__(self,t):
self.pattern='<INTEGER>PLAYER_LVL_MATCH_MAX:'
self.replacement=f'\t<INTEGER>PLAYER_LVL_MATCH_MAX:{t.maxlevel}\n'
class ReplaceName(Replace):
def __init__(self,to):
self.pattern='<STRING>NAME:'
self.replacement=f'\t<STRING>NAME:{to}\n'
class ReplaceRarity(Replace):
def __init__(self,tier,ratio=1):
self.pattern='<INTEGER>RARITY:'
self.replacement=f'\t<INTEGER>RARITY:{round(tier.rarity*ratio)}\n'
class ReplaceDungeon(Replace):
def __init__(self,name):
self.pattern='<STRING>DUNGEON:'
self.replacement=f'\t<STRING>DUNGEON:{name}\n'
class ReplaceGuid(Replace):
def __init__(self,name):
self.pattern='<STRING>UNIT_GUID:'
self.replacement=f'\t<STRING>UNIT_GUID:{hash(name)}\n'
class ReplaceValue(Replace):
def __init__(self,tier):
self.pattern='<INTEGER>VALUE:'
self.replacement=f'\t<INTEGER>VALUE:{tier.value}\n'
class ReplaceLevel(Replace):
def __init__(self,tier):
self.pattern='<INTEGER>LEVEL:'
self.replacement=f'\t<INTEGER>LEVEL:{tier.minlevel}\n'
class ReplaceMinLevel(Replace):
def __init__(self,tier):
self.pattern='<INTEGER>MINLEVEL:'
self.replacement=f'\t<INTEGER>MINLEVEL:{tier.mindroplevel}\n'
class ReplaceMaxLevel(Replace):
def __init__(self,tier):
self.pattern='<INTEGER>MAXLEVEL:'
self.replacement=f'\t<INTEGER>MAXLEVEL:{tier.maxdroplevel}\n'
class ReplaceUses(Replace):
def __init__(self):
self.pattern='<STRING>USES:'
self.replacement=f'\t<STRING>USES:1\n'
class ReplaceIcon(Replace):
def __init__(self,icon,tier):
self.pattern='<STRING>ICON:'
self.replacement=f'\t<STRING>ICON:{icon}_{tier.tier}\n'
'''TODO
this does not work as intended, if you enter a map scroll portal a second time, it will be as it was, see http://torchmodders.com/forums/modding-questions/weird-guts-editor-bugs/ ( https://archive.ph/wip/BdA0v )
thankfully the chance of a repeat scroll of the same tier is less than 1% for each map generated in that tier and i've never had it happen while playtesting
apparently you could make every strata in a dungeon 'don't store" and that will repopulate (but not re-generate) but the drawback from that is that you also can't teleport back into a dungeon after using a town portal scroll
i imagine that ideally this should be covered by "is map" in the sense that it'd regenerate on accessing it but not opening a portal to return? alas, if there's no documentation and VOLATILE has no effect, there's not much that can be done
'''
class ReplaceVolatile(Replace):
def __init__(self):
self.pattern='<BOOL>VOLATILE:'
self.replacement=False
class ReplaceIsMap(Replace):#removed with False then added in makedungeons
def __init__(self):
self.pattern='<BOOL>MAP:'
self.replacement=False
class ClearGoalsMinMax(Replace):
def __init__(self):
self.pattern='<FLOAT>NPCS_'
self.replacement=False
class ClearGoals(Replace):
def __init__(self):
self.pattern='<STRING>NPCSPAWNCLASS'
self.replacement=False
@dataclasses.dataclass
class Tier:
tier:int
name:str=''
minlevel:int=''
maxlevel:int=''
offset:int=0
mindroplevel:int=''
maxdroplevel:int=''
rarity:int=0
value:int=0
def __post_init__(self):
t=self.tier
self.name=NUMERALS[t]
self.minlevel=(t+1)*5
self.maxlevel=self.minlevel
if t==0:
self.minlevel=1
self.maxlevel=5
elif t==TIERS-1:
self.maxlevel=100
self.mindroplevel=1
self.maxdroplevel=self.maxlevel
self.rarity=round(2**(TIERS-t-1)/goal.factor)
self.value=t+1
@dataclasses.dataclass
class Category:
maps:list
icon:str
category:str
goals:bool=False
tiers=[Tier(i) for i in range(0,TIERS)]
categories=[Category(MAPS,'mapdg','maps',True),Category(DUNGEONS,'mapdg','dungeons',True),Category(WILDS,'mapwild','wilderness',True),
Category(NETHER,'mapnether','netherrealm'),Category(BOSSES,'mapboss','bosses'),Category(CHALLENGES,'mapphase','challenges'),]
count=0
'''
This is a shame but I have been unable to generate binary-identical .dat files with Python alone or understand 100% why I can't.
Thankfully the `unix2dos` utility (`apt-get install dos2unix` on Debian) does the job.
A workaround to this is opening the .dat files on Windows 10's `wordpad` manually and simply saving them but that's a lot of tedious, manual labor for every generated batch...
I believe this must have something to do with \r\n on Windows but I have tried adding those manually as well.
TODO solving this would be a necessary step to making this script cross-platform
'''
def convert(destination):
os.system(f'cat {destination} | unix2dos -u > {destination}.tmp')
os.system(f'mv {destination}.tmp {destination}')
def read(path):
with open(REFERENCE+path.upper(),encoding=ENCODING) as lines:
for l in lines:
yield l
def modify(path,destination,replace=[],add=[],strata='',extension='.dat'):
generated=[]
for line in read(path):
for r in replace:
if r.pattern in line:
if r.replacement:
generated.append(r.replacement)
break
else:
generated.append(line)
if len(strata)>0 and '[STRATA0]' in line:
generated.extend(f'\t\t{line}\n' for line in strata.split('\n'))
for a in add:
generated.insert(len(generated)-1,a)
if len(strata)>0:
theme.generate(destination,generated)
destination=f'{os.path.dirname(path)}/{destination}{extension}'.lower()
os.makedirs(os.path.dirname(destination),exist_ok=True)
with open(destination,'w',encoding=ENCODING) as f:
for g in generated:
f.write(g)
convert(destination)
return destination
def makedungeon(category,d,tier,goal=False):
name=f'{d.dungeonname}_{tier.tier+1}'
if goal:
name+='_'+goal.spawnclass.replace('am_spawn_prop_','').replace('am_','')
dungeonname=f'am_{name}'
r=[ReplaceDisplayName(f'{d.name} (Tier {tier.name})'),
ReplaceName(dungeonname),ReplaceParentDungeon(),
ReplaceParentTown(),ReplaceMinMatchLevel(tier),
ReplaceMaxMatchLevel(tier),ReplaceIsMap(),
ClearGoalsMinMax(),ClearGoals(),]
a=[f'\t<INTEGER>PLAYER_LVL_MATCH_OFFSET:{tier.offset}\n','\t<BOOL>MAP:true\n']
g=goal.data if goal else ''
modify(d.dungeon,dungeonname,replace=r,add=a,strata=g)
mapname=f'am_map_{name}'
rarity=goal.rarity if goal else 1
r=[ReplaceDisplayName(f'{theme.rename(d.name)} map ({tier.name})'),
ReplaceName(mapname),ReplaceDescription(d,tier,goal),
ReplaceRarity(tier,rarity),ReplaceDungeon(dungeonname),
ReplaceGuid(mapname),ReplaceValue(tier),
ReplaceLevel(tier),ReplaceMinLevel(tier),
ReplaceMaxLevel(tier),ReplaceUses(),ReplaceIcon(category.icon,tier)]
a=[OPENPORTAL.format(dungeonname)]
modify(d.scroll,mapname,replace=r,add=a)
global count
count+=1
def makedungeons(category):
for m in category.maps:
d=FILES[m.lower()]
d.dungeonname=m #TODO preserves case, probably unnecesssary
yield d
for t in tiers[:1] if args.debug else tiers:
if category.goals:
for g in goal.reward():
makedungeon(category,d,t,g)
else:
makedungeon(category,d,t)
if __name__ == '__main__':
for dungeon in load.scan():
FILES[dungeon.dungeonname.lower()]=dungeon
for c in CHALLENGES:
FILES[c.lower()].name='Challenge'
total=sum(len(c.maps) for c in categories)
progress=0
for c in [categories[0]] if args.debug else categories:
for d in makedungeons(c):
print(f'{round(100*progress/total)}% {d.name}')
progress+=1
print()
summary.show(count)
print()
print(GUIDWARNING)