276 lines
14 KiB
Python
276 lines
14 KiB
Python
import gzip
|
|
import json
|
|
import UnityPy
|
|
from loaders.KF3.charaData import get_all_stats, fill_miracle_numbers
|
|
|
|
class KF3DB:
|
|
processed_friends = {}
|
|
paramAbilities = {}
|
|
paramAbilities1 = {}
|
|
paramAbilities2 = {}
|
|
paramAlphaBases = {}
|
|
paramArts = {}
|
|
paramSpecialAttacks = {}
|
|
paramWaitActions = {}
|
|
charaData = {}
|
|
promoteData = {}
|
|
promotePresetData = {}
|
|
charaClothesData = {}
|
|
limitlevel_rising_status = {}
|
|
|
|
def __init__(self, app) -> None:
|
|
if "KF3" in app.databases:
|
|
del app.databases["KF3"]
|
|
|
|
self.parse_parameter()
|
|
|
|
with gzip.open("data/KF3/CHARA_DATA.d", mode="rt", encoding="utf-8") as file:
|
|
for entry in json.loads(file.read()):
|
|
self.charaData[entry["id"]] = entry
|
|
|
|
with gzip.open("data/KF3/CHARA_PROMOTE_DATA.d", mode="rt", encoding="utf-8") as file:
|
|
for entry in json.loads(file.read()):
|
|
self.promoteData[entry["promoteId"]] = entry
|
|
|
|
with gzip.open("data/KF3/CHARA_PROMOTE_PRESET_DATA.d", mode="rt", encoding="utf-8") as file:
|
|
for entry in json.loads(file.read()):
|
|
if entry["promotePresetId"] not in self.promotePresetData:
|
|
self.promotePresetData[entry["promotePresetId"]] = []
|
|
self.promotePresetData[entry["promotePresetId"]].append(entry)
|
|
|
|
with gzip.open("data/KF3/CHARA_CLOTHES_DATA.d", mode="rt", encoding="utf-8") as file:
|
|
for entry in json.loads(file.read()):
|
|
if entry["clothesPresetId"] not in self.charaClothesData:
|
|
self.charaClothesData[entry["clothesPresetId"]] = []
|
|
self.charaClothesData[entry["clothesPresetId"]].append(entry)
|
|
|
|
with gzip.open("data/KF3/LIMITLEVEL_RISING_STATUS.d", mode="rt", encoding="utf-8") as file:
|
|
for entry in json.loads(file.read()):
|
|
self.limitlevel_rising_status[entry["patternId"]] = entry
|
|
|
|
self.process_friends()
|
|
app.databases["KF3"] = self
|
|
|
|
def parse_parameter(self):
|
|
paramAsset = UnityPy.load("data/KF3/assets/parameter.asset")
|
|
for obj in paramAsset.objects:
|
|
data = obj.read()
|
|
if data.name.split('_')[0] == "ParamAbility":
|
|
id = int(data.name.split('_')[1])
|
|
if data.name.endswith("_1"):
|
|
self.paramAbilities1[id] = obj.read_typetree()
|
|
elif data.name.endswith("_2"):
|
|
self.paramAbilities2[id] = obj.read_typetree()
|
|
else:
|
|
self.paramAbilities[id] = obj.read_typetree()
|
|
elif data.name.split('_')[0] == "ParamAlphaBase":
|
|
id = int(data.name.split('_')[1])
|
|
self.paramAlphaBases[id] = obj.read_typetree()
|
|
elif data.name.split('_')[0] == "ParamArts":
|
|
id = int(data.name.split('_')[1])
|
|
self.paramArts[id] = obj.read_typetree()
|
|
elif data.name.split('_')[0] == "ParamSpecialAttack":
|
|
id = int(data.name.split('_')[1])
|
|
self.paramSpecialAttacks[id] = obj.read_typetree()
|
|
elif data.name.split('_')[0] == "ParamWaitAction":
|
|
id = int(data.name.split('_')[1])
|
|
self.paramWaitActions[id] = obj.read_typetree()
|
|
|
|
def process_friends(self):
|
|
self.processed_friends = {}
|
|
for charaID in self.charaData:
|
|
self.processed_friends[charaID] = self.process_chara(charaID)
|
|
|
|
def process_chara(self, id : int):
|
|
chara = {}
|
|
|
|
charaData = self.charaData[id]
|
|
alphaBase = self.paramAlphaBases[id]
|
|
|
|
wrLocked = False
|
|
promoIds = []
|
|
promotePresetId = charaData["promotePresetId"]
|
|
promos = self.promotePresetData[promotePresetId] if promotePresetId in self.promotePresetData else []
|
|
for promo in promos:
|
|
if promo["promoteStepDatetime"] == 1917860400000:
|
|
wrLocked = True
|
|
continue
|
|
else:
|
|
promoIds.append([promo["promoteId00"], promo["promoteId01"], promo["promoteId02"], promo["promoteId03"], promo["promoteId04"], promo["promoteId05"]])
|
|
|
|
promoteDatas = [[self.promoteData[id] for id in promo] for promo in promoIds]
|
|
promote_bonus = {"atk" : 0, "def" : 0, "hp" : 0, "evd" : 0, "beat" : 0, "act" : 0, "try" : 0}
|
|
for promoTier in promoteDatas:
|
|
for promoteStep in promoTier:
|
|
promote_bonus["atk"] += promoteStep["promoteAtk"]
|
|
promote_bonus["def"] += promoteStep["promoteDef"]
|
|
promote_bonus["hp"] += promoteStep["promoteHp"]
|
|
promote_bonus["evd"] += promoteStep["promoteAvoid"]
|
|
promote_bonus["act"] += promoteStep["promoteActionDamageRatio"]
|
|
promote_bonus["beat"] += promoteStep["promoteBeatDamageRatio"]
|
|
promote_bonus["try"] += promoteStep["promoteTryDamageRatio"]
|
|
|
|
clothesPresetId = charaData["clothesPresetId"]
|
|
clothesDatas = self.charaClothesData[clothesPresetId] if clothesPresetId in self.charaClothesData else []
|
|
costume_bonus = {"atk" : 0, "def" : 0, "hp" : 0, "evd" : 0, "beat" : 0, "act" : 0, "try" : 0}
|
|
for clothesData in clothesDatas:
|
|
costume_bonus["atk"] += clothesData["atkBonus"]
|
|
costume_bonus["def"] += clothesData["defBonus"]
|
|
costume_bonus["hp"] += clothesData["hpBonus"]
|
|
|
|
chara["id"] = id
|
|
chara["promoteBonus"] = promote_bonus
|
|
chara["costumeBonus"] = costume_bonus
|
|
chara["attribute"] = charaData["attribute"]
|
|
chara["nameEn"] = charaData["nameEn"]
|
|
chara["rankLow"] = charaData["rankLow"]
|
|
chara["rankHigh"] = charaData["rankHigh"]
|
|
chara["castName"] = charaData["castName"]
|
|
|
|
chara["wr"] = 4 if wrLocked else 5
|
|
chara["is_wr5"] = chara["wr"] == 5
|
|
chara["has_party_dress"] = False
|
|
for clothesData in clothesDatas:
|
|
if clothesData["clothesId"] == 8:
|
|
chara["has_party_dress"] = True
|
|
break
|
|
chara["has_rainbow_trait"] = id in self.paramAbilities2
|
|
|
|
chara["risingStatusPatternId"] = patternId = charaData["risingStatusPatternId"]
|
|
level_curve = self.limitlevel_rising_status[patternId] if patternId != 0 else None
|
|
|
|
chara["stats_min"] = get_all_stats(chara, alphaBase, max_level = False, rising_status_pattern=level_curve)
|
|
chara["stats_max"] = get_all_stats(chara, alphaBase, max_level = True, rising_status_pattern=level_curve)
|
|
chara["plasmPoint"] = alphaBase["plasmPoint"]
|
|
chara["cards"] = [
|
|
{"type":alphaBase["orderCardType00"], "value":alphaBase["orderCardValue00"]},
|
|
{"type":alphaBase["orderCardType01"], "value":alphaBase["orderCardValue01"]},
|
|
{"type":alphaBase["orderCardType02"], "value":alphaBase["orderCardValue02"]},
|
|
{"type":alphaBase["orderCardType03"], "value":alphaBase["orderCardValue03"]},
|
|
{"type":alphaBase["orderCardType04"], "value":alphaBase["orderCardValue04"]}
|
|
]
|
|
chara["synergy_flag"] = self.paramArts[id]["authParam"]["SynergyFlag"] if id in self.paramArts else 0
|
|
|
|
chara["arts"] = self.paramArts[id] if id in self.paramArts else None
|
|
chara["ability"] = self.paramAbilities[id] if id in self.paramAbilities else None
|
|
chara["ability1"] = self.paramAbilities1[id] if id in self.paramAbilities1 else None
|
|
chara["ability2"] = self.paramAbilities2[id] if id in self.paramAbilities2 else None
|
|
chara["wait_action"] = self.paramWaitActions[id] if id in self.paramWaitActions else None
|
|
chara["special_attack"] = self.paramSpecialAttacks[id] if id in self.paramSpecialAttacks else None
|
|
|
|
return chara
|
|
|
|
def get_chara(self, id : int):
|
|
if id in self.processed_friends:
|
|
return self.processed_friends[id]
|
|
else:
|
|
return None
|
|
|
|
def get_chara_wiki(self, id : int):
|
|
chara = self.get_chara(id)
|
|
|
|
lines = []
|
|
|
|
stars_word = chara["rankLow"]
|
|
stars_word = "Two" if stars_word == 2 else "Three" if stars_word == 3 else "Four" if stars_word == 4 else "Five" if stars_word == 5 else "Unknown"
|
|
|
|
attribute_word = chara["attribute"]
|
|
attribute_word = "Funny" if attribute_word == 1 else "Friendly" if attribute_word == 2 else "Relaxed" if attribute_word == 3 else "Lovely" if attribute_word == 4 else "Active" if attribute_word == 5 else "Carefree" if attribute_word == 6 else "Unknown"
|
|
|
|
categories = [
|
|
f"[[Category:{attribute_word} KF3 Friends]]",
|
|
f"[[Category:{stars_word} Star KF3 Friends]]",
|
|
f"[[Category:Missing Content]]",
|
|
f"[[Category:Needs Audio]]",
|
|
f"{{{{#vardefine:id|{str(chara['id'])}}}}}"
|
|
]
|
|
|
|
if chara['has_party_dress']:
|
|
categories.append("[[Category:Party Dress KF3 Friends]]")
|
|
if chara['is_wr5']:
|
|
categories.append("[[Category:Wild Release 5 KF3 Friends]]")
|
|
if chara['has_rainbow_trait']:
|
|
categories.append("[[Category:Rainbow Trait KF3 Friends]]")
|
|
|
|
lines.append(" ".join(categories))
|
|
lines.append("")
|
|
lines.append("{{FriendBox/KF3")
|
|
lines.append(f"|name={chara['nameEn'].replace('_', ' ')}")
|
|
lines.append(f"|apppic={chara['nameEn'].replace('_', ' ')}KF3.png")
|
|
lines.append(f"|apprarity={{{{KF3{chara['rankLow']}Star}}}}")
|
|
lines.append(f"|seiyuu={chara['castName']}")
|
|
lines.append(f"|attribute={attribute_word} {{{{KF3{attribute_word}}}}}")
|
|
lines.append(f"|implemented={0}")
|
|
lines.append(f"|id={chara['id']}")
|
|
lines.append(f"|wr5={'Yes' if chara['is_wr5'] else 'No'}")
|
|
lines.append(f"|rainbowtrait={'Yes' if chara['has_rainbow_trait'] else 'No'}")
|
|
lines.append(f"|partydress={'Yes' if chara['has_party_dress'] else 'No'}")
|
|
lines.append("}}")
|
|
lines.append("")
|
|
lines.append("{{FriendBuilder/KF3")
|
|
lines.append(f"|introduction = '''{chara['nameEn'].replace('_', ' ')}''' is a Friend that appears in the app version of [[Kemono Friends 3]].")
|
|
lines.append(f"|status={chara['stats_min']['status']}")
|
|
lines.append(f"|hp={chara['stats_min']['hp']}")
|
|
lines.append(f"|atk={chara['stats_min']['atk']}")
|
|
lines.append(f"|def={chara['stats_min']['def']}")
|
|
lines.append(f"|evd={round(chara['stats_min']['evd']/10,1)}%")
|
|
lines.append(f"|beat={chara['stats_min']['beat']}%")
|
|
lines.append(f"|action={chara['stats_min']['act']}%")
|
|
lines.append(f"|try={chara['stats_min']['try']}%")
|
|
lines.append(f"|plasm={chara['plasmPoint']}")
|
|
lines.append(f"|maxstatus={chara['stats_max']['status']}")
|
|
lines.append(f"|maxhp={chara['stats_max']['hp']}")
|
|
lines.append(f"|maxatk={chara['stats_max']['atk']}")
|
|
lines.append(f"|maxdef={chara['stats_max']['def']}")
|
|
lines.append(f"|maxevd={round(chara['stats_max']['evd']/10,1)}%")
|
|
lines.append(f"|maxbeat={chara['stats_max']['beat']}%")
|
|
lines.append(f"|maxaction={chara['stats_max']['act']}%")
|
|
lines.append(f"|maxtry={chara['stats_max']['try']}%")
|
|
cards_str = "|flags="
|
|
for card in chara["cards"]:
|
|
cards_str += " {{"
|
|
if card["type"] == 1:
|
|
cards_str += "Beat}}"
|
|
elif card["type"] == 2:
|
|
cards_str += f"Action{card['value']}}}}}"
|
|
elif card["type"] == 3:
|
|
if card["value"] == 20:
|
|
cards_str += "TryLow}}"
|
|
if card["value"] == 30:
|
|
cards_str += "TryMiddle}}"
|
|
if card["value"] == 40:
|
|
cards_str += "TryHigh}}"
|
|
lines.append(cards_str)
|
|
cardType = "Beat" if chara["synergy_flag"] == 1 else "Action20" if chara["synergy_flag"] == 2 else "TryHigh" if chara["synergy_flag"] == 3 else ""
|
|
lines.append(f"|miracleplus={{{{{cardType}}}}}")
|
|
|
|
if chara["arts"] is not None:
|
|
miracles = fill_miracle_numbers(chara)
|
|
lines.append(f"|miracle={chara['arts']['actionName']}")
|
|
for idx,miracle in enumerate(miracles):
|
|
lines.append("|miracle" + str(idx + 1) + "=" + miracle.replace("\r\n", "\n").replace("\\n", "\n").replace("\\", " "))
|
|
|
|
if chara["special_attack"] is not None:
|
|
lines.append(f"|beatname={chara['special_attack']['actionName']}")
|
|
lines.append(f"|beatskill={chara['special_attack']['actionEffect']}")
|
|
if chara["wait_action"] is not None:
|
|
lines.append(f"|standby={chara['wait_action']['skillName']}")
|
|
lines.append(f"|standbyskill={chara['wait_action']['skillEffect']}")
|
|
if chara["ability"] is not None:
|
|
lines.append(f"|unique={chara['ability']['abilityName']}")
|
|
lines.append(f"|uniqueskill={chara['ability']['abilityEffect']}")
|
|
if chara["ability1"] is not None:
|
|
lines.append(f"|miracletrait={chara['ability1']['abilityName']}")
|
|
lines.append(f"|miracletraitskill={chara['ability1']['abilityEffect']}")
|
|
else:
|
|
lines.append(f"|miracletrait=N/A")
|
|
lines.append(f"|miracletraitskill=Not Implemented.")
|
|
if chara["ability2"] is not None:
|
|
lines.append(f"|rainbowtrait={chara['ability2']['abilityName']}")
|
|
lines.append(f"|rainbowtraitskill={chara['ability2']['abilityEffect']}")
|
|
else:
|
|
lines.append(f"|rainbowtrait=N/A")
|
|
lines.append(f"|rainbowtraitskill=Not Implemented.")
|
|
lines.append("}}")
|
|
|
|
return "\n".join(lines) |