~quf/tocs3planner

ref: dev tocs3planner/gen_data.py -rw-r--r-- 16.0 KiB
94c74418Lukas Himbert initial public version 1 year, 4 months ago
                                                                                
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# This file extracts notebook data and creates a c++ file with all data in a usable form.
# It relies on nnguyen259's ColdSteel3Tools (https://github.com/nnguyen259/ColdSteel3Tools/) to extract the data into csv tables and then reads those tables.

import csv
import pathlib

folder = pathlib.Path("tables/")

def readcsv(path):
    with open(path) as f:
        return list(csv.DictReader(f))

notechapter_data = readcsv(folder / "text/notemons/QSChapter.csv")
notemons_data = readcsv(folder / "text/notemons/QSMons.csv")
status_data = readcsv(folder / "text/mons/status.csv")
revise_data = readcsv(folder / "text/status/char_revise.csv")
status_p_data = readcsv(folder / "text/status/status_p.csv")
item_data = readcsv(folder / "text/item_en/item.csv")
quartz_data = readcsv(folder / "text/item_en/item_q.csv")
magic_data = readcsv(folder / "text/magic/magic.csv")
masterquartzbase = readcsv(folder / "text/mstqrt/MasterQuartzBase.csv")
masterquartzstatus = readcsv(folder / "text/mstqrt/MasterQuartzStatus.csv")
masterquartzdummy = readcsv(folder / "text/mstqrt/MasterQuartzDummy.csv")
slot_ep_data = readcsv(folder / "text/slot/SlotEp.csv")
slot_data = readcsv(folder / "text/orb/BaseList.csv")
game_difficulty_data = readcsv(folder / "text/status/game_difficulty.csv")
status_revise_data = readcsv(folder / "text/status/status_revise.csv")

# notebook[section] = [monster1_dict, monster2_dict, ...]
notebook = {}

for section in notechapter_data:
    section_name = section["section_name"]
    section_id = section["section_id"]
    if section_id == "65535" or section_name == "D. Knight/P. Soldat Fights":
        continue
    notebook[section_name] = []
    for row in filter(lambda m: m["section_id"] == section_id, notemons_data):
        enemy_script = row["enemy_script"]
        for monster in filter(lambda m: m["enemy_script"] == enemy_script, status_data):
            for revise in filter(lambda m: m["enemy_script"] == enemy_script, revise_data):
                monster.update({ f"{stat}_revise": x for (stat, x) in revise.items() })
                break
            notebook[section_name].append(monster)

def mon_to_str(monster):
    def revise_str(monster):
        if "hp_revise" in monster.keys():
            return f"""std::optional<Char::CharRevise>({{
.hp={monster['hp_revise']},
.str={monster['str_revise']},
.def={monster['def_revise']},
.ats={monster['ats_revise']},
.adf={monster['adf_revise']},
.spd={monster['spd_revise']},
.brk={monster['brk_revise']}
}})""".replace("\n", "")
        else:
            return "std::nullopt"
    return f"""{{
.id={monster.get('character_id', 65535)},
.name="{monster['name']}",
.level={monster['level']},
.is_female={monster.get('is_female', 127)},
.hp={{{monster['hp_base']},{monster['hp_growth']}}},
.ep={monster['max_ep']},
.str={{{monster['str_base']},{monster['str_growth']}}},
.def={{{monster['def_base']},{monster['def_growth']}}},
.ats={{{monster['ats_base']},{monster['ats_growth']}}},
.adf={{{monster['adf_base']},{monster['adf_growth']}}},
.dex={{{monster['dex_base']},{monster['dex_growth']}}},
.agl={{{monster['agi_base']},{monster['agi_growth']}}},
.eva={monster['eva']},
.spd={{{monster['spd_base']},{monster['spd_growth']}}},
.mov={{{monster['mov_base']},{monster['mov_growth']}}},
.exp={{{monster['exp_base']},{monster['exp_growth']}}},
.brk_multiplier={{{monster['break_multiplier_base']},{monster['break_multiplier_growth']}}},
.efficacy={{
.earth={monster['earth_efficacy']},
.water={monster['water_efficacy']},
.fire={monster['fire_efficacy']},
.wind={monster['wind_efficacy']},
.time={monster['time_efficacy']},
.space={monster['space_efficacy']},
.mirage={monster['mirage_efficacy']},
.psn={monster['psn_efficacy']},
.seal={monster['seal_efficacy']},
.mute={monster['mute_efficacy']},
.blnd={monster['blnd_efficacy']},
.slp={monster['slp_efficacy']},
.burn={monster['burn_efficacy']},
.frz={monster['frz_efficacy']},
.petr={monster['petr_efficacy']},
.fnt={monster['fnt_efficacy']},
.conf={monster['conf_efficacy']},
.chrm={monster['chrm_efficacy']},
.dblw={monster['dblw_efficacy']},
.nmr={monster['nmr_efficacy']},
.dly={monster['dlay_efficacy']},
.vnsh={monster['vnsh_efficacy']},
.sdown={monster['s-dwn_efficacy']},
.slash={monster['slash_efficacy']},
.thrust={monster['thurst_efficacy']},
.pierce={monster['pierce_efficacy']},
.strike={monster['strike_efficacy']}
}},
.char_revise={revise_str(monster)}
}}
""".replace("\n", "")

with open("data/notemons.c++", "w") as f:
    print("// this file has been automatically generated", file=f)
    print("// do not edit", file=f)
    print("#include <array>", file=f)
    print('#include "data.h"', file=f)
    for (i, (section, monsters)) in enumerate(notebook.items()):
        mon_strs = []
        for monster in monsters:
            #print(f"{section}: {monster['name']} LV {monster['level']}", file=f)
            mon_strs.append(mon_to_str(monster))
        print(f"static const std::array<Char, {len(monsters)}> section_array_{i} = {{{{" + ", ".join(mon_strs) + "}};", file=f)
    print(f"static const std::array<std::tuple<std::string_view, std::span<const Char>>, {len(notebook)}> sections_array = {{" + ", ".join(f"std::make_tuple(\"{section}\", std::span(section_array_{i}))" for (i, section) in enumerate(notebook.keys())) + "};", file=f)
    print("const std::span<const std::tuple<std::string_view, std::span<const Char>>> notemons = std::span(sections_array);", file=f)

chars = []
for char in status_p_data:
    if int(char["character_id"]) <= 24 or char["character_id"] == "200":
        #char.update({f"{x}_revise": "100" for x in ["hp", "str", "def", "ats", "adf", "spd", "brk"]})
        chars.append(char)

with open("data/chars.c++", "w") as f:
    print("// this file has been automatically generated", file=f)
    print("// do not edit", file=f)
    print("#include <array>", file=f)
    print('#include "data.h"', file=f)
    print(f"static const std::array<Char, {len(chars)}> characters_array = {{{{", file=f)
    for char in chars:
        print(mon_to_str(char) + ",", file=f)
    print("}};", file=f)
    print("const std::span<const Char> characters = std::span(characters_array);", file=f);

def effects_str(item):
    return f"""{{{{
{{.id={item['effect1_id']},
.arg_1={item['effect1_data1']},
.arg_2={item['effect1_data2']},
.arg_3={item['effect1_data3']}}},
{{.id={item['effect2_id']},
.arg_1={item['effect2_data1']},
.arg_2={item['effect2_data2']},
.arg_3={item['effect2_data3']}}},
{{.id={item['effect3_id']},
.arg_1={item['effect3_data1']},
.arg_2={item['effect3_data2']},
.arg_3={item['effect3_data3']}}},
{{.id={item['effect4_id']},
.arg_1={item['effect4_data1']},
.arg_2={item['effect4_data2']},
.arg_3={item['effect4_data3']}}},
{{.id={item['effect5_id']},
.arg_1={item['effect5_data1']},
.arg_2={item['effect5_data2']},
.arg_3={item['effect5_data3']}}},
}}}}
""".replace("\n", "")

def item_str(item):
    return f"""{{
.id={item['id']},
.character_restriction={item['character_restriction']},
.flags=Flags(\"{''.join(sorted(item['flags']))}\"),
.type={item['type']},
.element={item['element']},
.slash={item['slash']},
.thrust={item['thrust']},
.pierce={item['pierce']},
.strike={item['strike']},
.target_type={item['target_type']},
.range={item['range']},
.area={item['area']},
.effects={effects_str(item)},
.str={item['str']},
.def={item['def']},
.ats={item['ats']},
.adf={item['adf']},
.acc={item['acc']},
.eva={item['eva']},
.spd={item['spd']},
.mov={item['mov']},
.hp={item['hp']},
.ep={item['ep']},
.sort_id={item['sort_id']},
.name="{item['name']}",
.description=""
}}
""".replace("\n", "")

with open("data/items.c++", "w") as f:
    print("// this file has been automatically generated", file=f)
    print("// do not edit", file=f)
    print("#include <array>", file=f)
    print('#include "data.h"', file=f)
    print(f"static const std::array<Item, {len(item_data)}> items_array = {{{{", file=f)
    for item in item_data:
        if item["type"] in ("140", "190", "191", "192", "201", "897", "979", "980", "1665"):
            print(item_str(item) + ",", file=f)
    print("}};", file=f)
    print("const std::span<const Item> items = std::span(items_array);", file=f);

def quartz_str(quartz):
    return f"""{{
.id={quartz['id']},
.flags=Flags(\"{''.join(sorted(quartz['flags']))}\"),
.element={quartz['element']},
.quartz_type={quartz['quartz_type']},
.rating={quartz['rating']},
.effects={effects_str(quartz)},
.str={quartz['str']},
.def={quartz['def']},
.ats={quartz['ats']},
.adf={quartz['adf']},
.acc={quartz['acc']},
.eva={quartz['eva']},
.spd={quartz['spd']},
.mov={quartz['mov']},
.hp={quartz['hp']},
.ep={quartz['ep']},
.sort_id={quartz['sort_id']},
.name="{quartz['name']}",
.description="",
.art_ids={{
{quartz['art1_id']},
{quartz['art2_id']},
{quartz['art3_id']},
{quartz['art4_id']},
{quartz['art5_id']}
}}
}}
""".replace("\n", "")

with open("data/quartz.c++", "w") as f:
    print("// this file has been automatically generated", file=f)
    print("// do not edit", file=f)
    print("#include <array>", file=f)
    print('#include "data.h"', file=f)
    print(f"static const std::array<Quartz, {len(quartz_data)}> quartzes_array = {{{{", file=f)
    for quartz in quartz_data:
        print(quartz_str(quartz) + ",", file=f)
    print("}};", file=f)
    print("const std::span<const Quartz> quartzes = std::span(quartzes_array);", file=f);

def magic_str(magic):
    return f"""{{
.id={magic['id']},
.character_restriction={magic['character_restriction']},
.flags=Flags(\"{''.join(sorted(magic['flags']))}\"),
.category={magic['category']},
.type={magic['type']},
.element={magic['element']},
.juna_gunner={magic['juna_specific']},
.effects={effects_str(magic)},
.cast_delay={magic['cast_delay']},
.recovery_delay={magic['recovery_delay']},
.cost={magic['cost']},
.unbalance_bonus={magic['unbalance_bonus']},
.break_bonus={magic['break_bonus']},
.sort_id={magic['sort_id']},
.name="{magic['name']}",
.description=""
}}
""".replace("\n", "")

with open("data/magic.c++", "w") as f:
    arts = [magic for magic in magic_data if magic["category"] == "20"]
    crafts = [magic for magic in magic_data if magic["category"] in ("1", "2", "3", "4", "5", "30", "31")] # TODO: 10, 11 for link support?
    orders = [magic for magic in magic_data if magic["category"] == "32"]

    print("// this file has been automatically generated", file=f)
    print("// do not edit", file=f)
    print("#include <array>", file=f)
    print('#include "data.h"', file=f)
    print(f"static const std::array<Magic, {len(arts)}> arts_array = {{{{", file=f)
    for art in arts:
        print(magic_str(art) + ",", file=f)
    print("}};", file=f)
    print(f"static const std::array<Magic, {len(crafts)}> crafts_array = {{{{", file=f)
    for craft in crafts:
        print(magic_str(craft) + ",", file=f)
    print("}};", file=f)
    print(f"static const std::array<Magic, {len(orders)}> brave_orders_array = {{{{", file=f)
    for order in orders:
        print(magic_str(order) + ",", file=f)
    print("}};", file=f)
    print("const std::span<const Magic> arts = std::span(arts_array);", file=f);
    print("const std::span<const Magic> crafts = std::span(crafts_array);", file=f);
    print("const std::span<const Magic> brave_orders= std::span(brave_orders_array);", file=f);

mq_dummy_ids = [mq["dummy_id"] for mq in masterquartzdummy]

def mq_str(mq_item, mq_data, mq_base, mainpatterns, subpatterns):
    mainstats = []
    substats = []
    effects = []
    for row in sorted(mq_data, key=lambda row: row["mq_level"]):
        mainstats.append({x: mainpatterns[(mq_base[f"{x}_pattern"], row["mq_level"])][x] for x in ["hp", "ep", "str", "def", "ats", "adf", "spd"]})
        substats.append({x: subpatterns[(mq_base[f"{x}_pattern"], row["mq_level"])][x] for x in ["hp", "ep", "str", "def", "ats", "adf", "spd"]})
        effects.append([row[f"effect_{i}"] for i in range(1, 9+1)])
    def statarrstr(stats):
        return "{" + ",".join("{" + ",".join(f".{x}={v}" for (x,v) in s.items()) + "}" for s in stats) + "}"
    def effarrstr(stats):
        return "{{" + ",".join("{{" + ",".join(effs) + "}}" for effs in effects) + "}}"
    return f"""{{
.id={mq_item['id']},
.element={mq_item['element']},
.sort_id={mq_item['sort_id']},
.name="{mq_item['name']}",
.stats_main={{{statarrstr(mainstats)}}},
.stats_sub={{{statarrstr(substats)}}},
.effects={effarrstr(effects)},
}}
""".replace("\n", "")

mq_mainstatpatterns = {}
mq_substatpatterns = {}
for row in masterquartzstatus:
    mqstats = ["hp", "ep", "str", "def", "ats", "adf", "spd"]
    mq_mainstatpatterns[(row["pattern_id"], row["level"])] = { x: row[x] for x in mqstats }
    mq_substatpatterns[(row["pattern_id"], row["level"])] = { x: row[f"sub_{x}"] for x in mqstats }

mstqrt_items = []

for mq_item in list(filter(lambda m: m["type"] == "201", item_data)):
    if mq_item["id"] in mq_dummy_ids:
        continue
    else:
        mstqrt_items.append(mq_item)

with open("data/mstqrt.c++", "w") as f:
    print("// this file has been automatically generated", file=f)
    print("// do not edit", file=f)
    print("#include <array>", file=f)
    print('#include "data.h"', file=f)
    print(f"static const std::array<MasterQuartz, {len(mstqrt_items)}> mstqrt_array = {{{{", file=f)
    for mq_item in mstqrt_items:
        mq_id = mq_item["id"]
        for mq_base in filter(lambda m: m["item_id"] == mq_id, masterquartzbase):
            mq_data = readcsv(folder / f"text/mstqrt/MasterQuartzData/{mq_id}.csv")
            print(mq_str(mq_item, mq_data, mq_base, mq_mainstatpatterns, mq_substatpatterns) + ",", file=f)
    print("}};", file=f)
    print("const std::span<const MasterQuartz> master_quartzes = std::span(mstqrt_array);", file=f);

ep_increase = {}
for row in slot_ep_data:
    ep_increase[row["character_id"]] = { i: row[f"increase_{i}"] for i in range(1, 7+1) }
    ep_increase[row["character_id"]]["base"] = row["base_ep"]

def slotstr(id, slot):
    return f"""{{
.open=false,
.element={slot['element']},
.ep={slot['ep']}
}}""".replace("\n", "")

def orbstr(base_row, slots):
    slotstrs = [slotstr(base_row["character_id"], slot) for slot in slots]
    return f"""{{
.id={base_row['character_id']},
.base_ep={ep_increase[base_row['character_id']]['base']},
.slots={{{{{','.join(slotstrs)}}}}}
}}
""".replace("\n", "")

with open("data/orb.c++", "w") as f:
    print("// this file has been automatically generated", file=f)
    print("// do not edit", file=f)
    print("#include <array>", file=f)
    print('#include "data.h"', file=f)
    orbments = list(filter(lambda row: int(row["character_id"]) < 25, slot_data))
    print(f"static const std::array<Orbment, {len(orbments)}> orbment_array = {{{{", file=f)
    for base_row in orbments:
        id = base_row["character_id"]
        elems = [base_row[f"slot_{i}_element"] for i in range(1, 7+1)]
        line_data = readcsv(folder / f"text/orb/OrbLineList/{id}.csv")
        slots = []
        i = 0
        for line in line_data:
            for s in range(1, 7+1):
                if line[f"slot_{s}_order"] != "65535":
                    i += 1
                    slots.append({
                        "ep": ep_increase[id][s],
                        "element": elems[int(line[f"slot_{s}_order"])-2]
                    })
        assert(i == 7)
        print(orbstr(base_row, slots) + ",", file=f)
    print("}};", file=f)
    print("const std::span<const Orbment> orbments = std::span(orbment_array);", file=f);

difficulty_multipliers = {}
for row in game_difficulty_data:
    difficulty_multipliers[row["difficulty_id"]] = row["difficulty_multiplier"]

status_revise = {}
for row in status_revise_data:
    status_revise[row["difficulty_id"]] = {stat: row[stat] for stat in ("hp", "str", "def", "ats", "adf", "spd", "brk")}

with open("data/difficulty.c++", "w") as f:
    print("// this file has been automatically generated", file=f)
    print("// do not edit", file=f)
    print("#include <array>", file=f)
    print('#include "data.h"', file=f)
    print(f"const std::array<DifficultyModifiers, 5> difficulty_modifiers = {{{{", file=f)
    for difficulty in ("1", "2", "0", "3", "4"): # very easy to nightmare in order
        print(f"{{.global={difficulty_multipliers[difficulty]}," + ",".join(f".{stat}={status_revise[difficulty][stat]}" for stat in ("hp", "str", "def", "ats", "adf", "spd", "brk")) + "},", file=f)
    print("}};", file=f)