forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_hunt_data.py
executable file
·157 lines (122 loc) · 4.63 KB
/
gen_hunt_data.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
#!/usr/bin/env python
import argparse
import coinach
import csv
import csv_util
import os
_OUTPUT_FILE = "hunt.ts"
def update_german(list, search, replace):
output = []
for name in list:
if search not in name:
output.append(name)
continue
for repl in replace:
output.append(name.replace(search, repl))
return output
def parse_data(monsters, notorious, lang, name_map):
print(f"Processing {lang} hunt names language...")
for nm_id, nm_info in notorious.items():
base = nm_info["BNpcBase"]
rank_id = nm_info["Rank"]
name_id = nm_info["BNpcName"]
if not name_id:
continue
if name_map is None:
name = name_id
else:
name = name_map[name_id]["Singular"]
if not name:
continue
if lang == "de":
name = [name.replace("[p]", "")]
name = update_german(name, "[t]", ["der", "die", "das"])
name = update_german(name, "[a]", ["e", "er", "es"])
name = update_german(name, "[A]", ["e", "er", "es"])
if len(name) == 1:
name = name[0]
# SaintCoinach prefaces ids with a comment
# Other dumps just have the int.
base = base.replace("BNpcBase#", "")
if base in ["10422", "13775"]:
rank = "SS+"
elif base in ["10755", "13938"]:
rank = "SS-"
elif rank_id == "3":
rank = "S"
elif rank_id == "2":
rank = "A"
else:
rank = "B"
if nm_id in monsters:
assert monsters[nm_id]["id"] == name_id
assert monsters[nm_id]["rank"] == rank
else:
monsters[nm_id] = {"id": name_id, "rank": rank, "name": {}}
monsters[nm_id]["name"][lang] = name
def update_coinach(monsters, reader):
notorious_keys = ["#", "BNpcBase", "Rank", "BNpcName"]
notorious = csv_util.make_map(reader.rawexd("NotoriousMonster"), notorious_keys)
languages = ["en", "de", "fr", "ja"]
for locale in languages:
name_map = csv_util.make_map(reader.exd("BNpcName", lang=locale), ["#", "Singular"])
parse_data(monsters, notorious, locale, name_map)
return monsters
def update_raw_csv(monsters, locale):
notorious_keys = ["#", "BNpcBase", "Rank", "BNpcName"]
notorious = csv_util.get_locale_table("NotoriousMonster", locale, notorious_keys)
name_map = csv_util.get_locale_table("BNpcName", locale, ["#", "Singular"])
parse_data(monsters, notorious, locale, name_map)
def get_from_coinach(_ffxiv_game_path, _saint_conainch_cmd_path, _cactbot_path):
reader = coinach.CoinachReader(
coinach_path=_saint_conainch_cmd_path, ffxiv_path=_ffxiv_game_path
)
monsters = {}
update_coinach(monsters, reader)
update_raw_csv(monsters, "cn")
update_raw_csv(monsters, "ko")
all_monsters = {}
for (_, info) in monsters.items():
all_monsters[info["name"]["en"]] = info
writer = coinach.CoinachWriter(cactbot_path=_cactbot_path)
header = """import { LocaleObject } from '../types/trigger';
type LocaleTextOrArray = LocaleObject<string | string[]>;
export type Rank = 'S' | 'SS+' | 'SS-' | 'A' | 'B';
// Optional values are supported in `Options.CustomMonsters`.
export type HuntEntry = {
id: string;
name: LocaleTextOrArray | string | string[];
rank?: Rank;
regex?: RegExp;
hp?: number;
};
export type HuntMap = {
[huntName: string]: HuntEntry;
};"""
writer.writeTypeScript(
filename=os.path.join("resources", _OUTPUT_FILE),
scriptname=os.path.basename(os.path.abspath(__file__)),
header=header,
type="HuntMap",
as_const=False,
data=all_monsters,
)
print(f"File '{_OUTPUT_FILE}' successfully created.")
if __name__ == "__main__":
example_usage = r"python .\gen_hunt_data.py -fp 'E:\FINAL FANTASY XIV - A Realm Reborn' -scp 'F:\SaintCoinach\SaintCoinach.Cmd\bin\Release' -cp 'F:\cactbot'"
parser = argparse.ArgumentParser(
description="Creates hunt.js for the Radar overlay",
epilog=example_usage,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"-fp", "--ffxiv-path", help="Path to FFXIV installation (None == Default location)"
)
parser.add_argument(
"-scp",
"--saint-coinach-cmd-path",
help="Path to SaintCoinach.cmd (None == Default location)",
)
parser.add_argument("-cp", "--cactbot-path", help="Path to CACTBOT (None == Default location)")
args = parser.parse_args()
get_from_coinach(args.ffxiv_path, args.saint_coinach_cmd_path, args.cactbot_path)