-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLL.py
More file actions
133 lines (119 loc) · 6.9 KB
/
LL.py
File metadata and controls
133 lines (119 loc) · 6.9 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
#! /usr/bin/env python3
import json
import re
from os.path import isfile
from num2words import num2words
import util
from globals import DATA, DIFFICULTIES, MOVE_TYPE, WEAPON_TYPE
from Reverse import reverseLostLore
from reward import parseReward
from mapUtil import InOtherLanguage, Availability
extraTeams = [20,60]
def LLInfobox(data: dict, strikes: list):
foes = []
for strike in strikes: foes += [util.getName(f"MID_TRIP_ENEMY_{strike['id_tag']}_{enemy['name_id']}") for enemy in strike['units']]
return "{{Lost Lore Infobox\n" + \
f"|name={util.getName('MID_TRIP_TITLE_' + data['id_tag'])}\n" + \
f"|world={util.getName('MID_TRIP_WORLD_'+'_'.join([str(d) for d in data['bonusEntry']][:data['entryCount']]))}\n" + \
f"|locations={','.join([util.getName('MID_TRIP_PLACE_'+d['id_tag']) for d in data['maps']])}\n" + \
f"|strikeFoes=" + ",".join(list(dict.fromkeys(foes))) + "\n" + \
f"|startTime={data['avail']['start']}\n" + \
f"|endTime={util.timeDiff(data['avail']['finish'])}"+"\n}}"
def LLIntro(data: dict):
query = util.cargoQuery('LostLore','World',group='_pageName')
entries = list(map(str,sorted([d for d in data['bonusEntry']][:data['entryCount']])))
world = util.getName('MID_TRIP_WORLD_'+'_'.join(entries))
nb = len(query)
nb2 = len([True for o in query if o['World'] == world])
return f"The {num2words(nb+1, to='ordinal')} [[Lost Lore]] event, " + \
f"and the {num2words(nb2+1, to='ordinal')} taking place in" + \
'{{EntryIcon|' + ','.join(entries) + '}}' + ('the ' if world[:4] != 'The ' else '') + world + '.'
def LLRewards(data: dict):
s = "==Rewards==\n{{#invoke:Reward/LostLore|lines|extraTeams=" + ",".join([str(t) for t in extraTeams]) + "\n"
for r in data['loreRewards']:
if int(r['lines'] / 3600) in extraTeams: r['reward'] += [{"kind": "Lost Lore Team", "count": 1}]
#First format will transform it into {:<nb}, second format will return the number right padded to nb spaces
score = "{{:<{}}}".format(len(str(int(data['loreRewards'][-1]['lines']/3600)))).format(int(r['lines']/3600))
s += f" | {score} = " + parseReward(r['reward']) + "\n"
return s + "}}"
def LLSaga(data: dict, tag: str):
s = "==Heroes' Saga==\n{| class=\"wikitable\" style=\"text-align: center;font-family:feh\"\n" + \
"!rowspan=\"2\"|Act\n!colspan=\"2\"|Heroes' Saga\n!rowspan=\"2\"|Image\n|-\n" + \
"!style=\"width:20em;\"|English\n!style=\"width:20em;\"|Japanese\n|-\n"
name = util.cleanStr(util.getName('MID_TRIP_TITLE_'+data['id_tag']))
fileJPJA = {d['key']: d['value'] for d in util.readFehData("JPJA/Message/Data/Data_" + tag + ".json")}
messageJp = fileJPJA['MID_TRIP_SAGA_'+data['id_tag']+'_PROLOGUE'].replace('\n', '<br>')
s += "|Prologue\n|"+util.getName('MID_TRIP_SAGA_'+data['id_tag']+'_PROLOGUE').replace('\n', '<br>')+"\n" + \
f"|lang=\"ja\"|{messageJp}\n" + \
f"|rowspan=\"2\"|[[File:{name} Prologue.png|300px]]\n"
s += f"|-\n|1st Act\n|\n|lang=\"ja\"|\n"
s += f"|-\n|2nd Act\n|\n|lang=\"ja\"|\n|[[File:{name} Act 2.png|300px]]\n"
s += f"|-\n|3rd Act\n|\n|lang=\"ja\"|\n|rowspan=\"2\"|[[File:{name} Act 3.png|300px]]\n"
s += f"|-\n|4th Act\n|\n|lang=\"ja\"|\n"
s += f"|-\n|Final Act\n|\n|lang=\"ja\"|\n|[[File:{name} Final Act.png|300px]]\n"
return s + "|}"
def LLLocation(data: dict):
require = {}
for location in data["maps"]:
loc = {
"name": util.getName(f"MID_TRIP_PLACE_{location['id_tag']}"),
"image": re.sub(r".+[/\\]([^\\/]+)[/\\]([^\\/]+)\..*", r"\1 \2.webp", location['backgroundPath']),
("linesReq" if location['lines'] != 0 else "isCombat"): int(location['lines'] / 3600) if location['lines'] != 0 else 1,
"rewards": parseReward(location['clearReward'] + [{"kind": -1, "_type": "Saga's " + util.getName(f"MID_TRIP_SAGA_SECTION_{data['maps'].index(location)+1}"), "count": 1}])
.replace('<!--','').replace('-->','')
}
#Convert a json object into lua object
loc = re.sub('": "?', "=", re.sub(r'"?, "', ";", json.dumps(loc).replace("{\"", "{").replace("\"}", "}")))
req = ",".join([str(d["map_idx"]) for d in location['required'] if d["map_idx"] != -1])
if (req or "") in require: require[req or ""] += [loc]
else: require[req or ""] = [loc]
locations = list(require.values())
for i in range(len(locations)):
if len(locations[i]) == 1:
locations[i] = "[" + locations[i][0] + "]"
else:
locations[i] = "[\n " + ";\n ".join(locations[i]) + ";\n ]"
return "==Locations==\n{{#invoke:Reward/LostLore|location|extraTeams=" + ",".join([str(t) for t in extraTeams]) + "\n" + \
"|locations=[\n " + ";\n ".join(locations) + ";\n]}}"
def LLUnit(data: dict, strikes: list):
s = "==Unit data==\n"
for i, strike in enumerate(strikes):
if len(strikes) != 1: s += f"===Strike {i+1}===\n"
s += "{|class=\"wikitable\" style=\"text-align:center;\"\n!Foe!!HP!!Atk!!Spd!!Def!!Res\n"
for foe in strike['units']:
s += "|-\n|{{LostLoreEnemy\n|file=Trip_" + re.sub(r".*/([^/]*)\..*", r"\1.webp", foe["facePath"]) + "|size=100\n"
s += f"|rarity={foe['rarity']}\n|weapon={WEAPON_TYPE[foe['weapon']]}\n|move={MOVE_TYPE[foe['move']]}\n}}}}\n"
s += ("[[" if foe['rarity'] != 3 else "") + util.getName(f"MID_TRIP_ENEMY_{strike['id_tag']}_{foe['name_id']}") + ("]]" if foe['rarity'] != 3 else "") + "\n"
s += f"|{foe['HP']}\n|{foe['Atk']}\n|{foe['Spd']}\n|{foe['Def']}\n|{foe['Res']}\n"
return s + "|-\n|colspan=\"6\"|<nowiki/>*The order of foes is randomized at the start of every strike.\n|}"
def LostLore(tag: str):
datas = reverseLostLore(tag)
ret = {}
for data in datas:
if data['isSpoil']:
print(util.TODO + "New Lost Lore Spoils: " + str(data['avail']))
continue
enemies = [d['strike'] for d in data['maps'] if d['strike']]
s = LLInfobox(data, enemies) + "\n"
s += LLIntro(data) + "\n"
s += Availability(data['avail'], f"Lost Lore ({util.getName('MID_TRIP_TITLE_' + data['id_tag'])}) (Notification)", "[[Lost Lore]] event") + "\n"
s += LLRewards(data) + "\n"
s += LLSaga(data, tag) + "\n"
s += LLLocation(data) + "\n"
s += LLUnit(data, enemies) + "\n"
s += InOtherLanguage('MID_TRIP_TITLE_' + data['id_tag'])
s += "{{Main Events Navbox}}"
ret[util.getName('MID_TRIP_TITLE_' + data['id_tag'])] = s
return ret
from sys import argv
if __name__ == '__main__':
if len(argv) <= 1:
print("Enter at least one update tag")
exit(1)
for arg in argv[1:]:
if not isfile(util.BINLZ_ASSETS_DIR_PATH + 'Common/Trip/Terms/' + arg + '.bin.lz'):
print(f'No Lost Lore are related to the tag "{arg}"')
continue
ls = LostLore(arg)
for l in ls:
print(l, ls[l])