You've already forked KemoFureApi
							
							KF3: Api additions and improvements.
This commit is contained in:
		| @@ -1,44 +1,55 @@ | ||||
| import gzip | ||||
| import json | ||||
| import platform | ||||
| import UnityPy | ||||
| from loaders.KF3.charaData import get_all_stats, fill_miracle_numbers | ||||
| from datetime import datetime | ||||
| from loaders.KF3.statCalculation import get_all_stats, fill_miracle_numbers | ||||
| from endpoints.KF3.friend import KF3_Friend | ||||
| from endpoints.KF3.friends import KF3_Friends | ||||
| from endpoints.KF3.update import KF3_Update | ||||
|  | ||||
| class KF3DB: | ||||
|     processed_friends = {} | ||||
|     paramAbilities = {} | ||||
|     paramAbilities1 = {} | ||||
|     paramAbilities2 = {} | ||||
|     paramAlphaBases = {} | ||||
|     paramArts = {} | ||||
|     paramSpecialAttacks = {} | ||||
|     paramWaitActions = {} | ||||
|     charaData = {} | ||||
|     promoteData = {} | ||||
|     promotePresetData = {} | ||||
|     charaClothesData = {} | ||||
|     limitlevel_rising_status = {} | ||||
|  | ||||
|     def __init__(self, app) -> None: | ||||
|     def __init__(self, api) -> None: | ||||
|         app = api.app | ||||
|         if "KF3" in app.databases: | ||||
|             del app.databases["KF3"] | ||||
|  | ||||
|         self.parse_parameter() | ||||
|         self.reload_data() | ||||
|  | ||||
|         with gzip.open("data/KF3/CHARA_DATA.d", mode="rt", encoding="utf-8") as file: | ||||
|         app.databases["KF3"] = self | ||||
|         api.add_resource(KF3_Friend, "/KF3/Friend/<int:id>") | ||||
|         api.add_resource(KF3_Friends, "/KF3/Friends") | ||||
|         api.add_resource(KF3_Update, "/KF3/Update") | ||||
|  | ||||
|     def reload_data(self): | ||||
|         self.charaData = {} | ||||
|         self.promoteData = {} | ||||
|         self.promotePresetData = {} | ||||
|         self.charaClothesData = {} | ||||
|         self.limitlevel_rising_status = {} | ||||
|  | ||||
|         if platform.system() == "Windows": | ||||
|             path = "H:\\Apache\\Katworks\\KF\\assets\\KF3\\mst\\" | ||||
|         else: | ||||
|             path = "/media/USB2/Apache/Katworks/KF/assets/KF3/mst//" | ||||
|  | ||||
|         with gzip.open(path + "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: | ||||
|         with gzip.open(path + "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: | ||||
|         with gzip.open(path + "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: | ||||
|         with gzip.open(path + "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"]] = [] | ||||
| @@ -48,11 +59,24 @@ class KF3DB: | ||||
|             for entry in json.loads(file.read()): | ||||
|                 self.limitlevel_rising_status[entry["patternId"]] = entry | ||||
|  | ||||
|         self.parse_parameter() | ||||
|         self.process_friends() | ||||
|         app.databases["KF3"] = self | ||||
|          | ||||
|  | ||||
|     def parse_parameter(self): | ||||
|         paramAsset = UnityPy.load("data/KF3/assets/parameter.asset") | ||||
|         self.paramAbilities = {} | ||||
|         self.paramAbilities1 = {} | ||||
|         self.paramAbilities2 = {} | ||||
|         self.paramAlphaBases = {} | ||||
|         self.paramArts = {} | ||||
|         self.paramSpecialAttacks = {} | ||||
|         self.paramWaitActions = {} | ||||
|  | ||||
|         if platform.system() == "Windows": | ||||
|             path = "H:\\Apache\\Katworks\\KF\\assets\\KF3\\assets\\" | ||||
|         else: | ||||
|             path = "/media/USB2/Apache/Katworks/KF/assets/KF3/assets//" | ||||
|  | ||||
|         paramAsset = UnityPy.load(path + "parameter.asset") | ||||
|         for obj in paramAsset.objects: | ||||
|             data = obj.read() | ||||
|             if data.name.split('_')[0] == "ParamAbility": | ||||
| @@ -122,10 +146,18 @@ class KF3DB: | ||||
|         chara["promoteBonus"] = promote_bonus | ||||
|         chara["costumeBonus"] = costume_bonus | ||||
|         chara["attribute"] = charaData["attribute"] | ||||
|         chara["name"] = charaData["name"] | ||||
|         chara["nameEn"] = charaData["nameEn"] | ||||
|         chara["nickname"] = charaData["nickname"] | ||||
|         chara["rankLow"] = charaData["rankLow"] | ||||
|         chara["rankHigh"] = charaData["rankHigh"] | ||||
|         chara["castName"] = charaData["castName"] | ||||
|         chara["loginText"] = charaData["loginText"] | ||||
|         chara["flavorText"] = charaData["flavorText"] | ||||
|         chara["kizunaupText"] = charaData["kizunaupText"] | ||||
|         chara["greetingText"] = charaData["greetingText"] | ||||
|         chara["startTimeRaw"] = charaData["startTime"] | ||||
|         chara["startTime"] = datetime.fromtimestamp(charaData["startTime"]/1000.0).strftime('%A, %B %d, %Y') | ||||
|  | ||||
|         chara["wr"] = 4 if wrLocked else 5 | ||||
|         chara["is_wr5"] = chara["wr"] == 5 | ||||
| @@ -158,6 +190,8 @@ class KF3DB: | ||||
|         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 | ||||
|  | ||||
|         chara["costumes"] = self.get_costumes(id, chara["rankLow"]) | ||||
|  | ||||
|         return chara | ||||
|      | ||||
|     def get_chara(self, id : int): | ||||
| @@ -168,6 +202,8 @@ class KF3DB: | ||||
|  | ||||
|     def get_chara_wiki(self, id : int): | ||||
|         chara = self.get_chara(id) | ||||
|         if chara is None: | ||||
|             return None | ||||
|  | ||||
|         lines = [] | ||||
|          | ||||
| @@ -182,7 +218,7 @@ class KF3DB: | ||||
|             f"[[Category:{stars_word} Star KF3 Friends]]", | ||||
|             f"[[Category:Missing Content]]", | ||||
|             f"[[Category:Needs Audio]]", | ||||
|             f"{{{{#vardefine:id|{str(chara['id'])}}}}}" | ||||
|             f"{{{{#vardefine:id|{str(chara['id']).zfill(4)}}}}}" | ||||
|         ] | ||||
|          | ||||
|         if chara['has_party_dress']: | ||||
| @@ -200,7 +236,7 @@ class KF3DB: | ||||
|         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"|implemented={chara['startTime']} (App)") | ||||
|         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'}") | ||||
| @@ -226,6 +262,7 @@ class KF3DB: | ||||
|         lines.append(f"|maxbeat={chara['stats_max']['beat']}%") | ||||
|         lines.append(f"|maxaction={chara['stats_max']['act']}%") | ||||
|         lines.append(f"|maxtry={chara['stats_max']['try']}%") | ||||
|         lines.append("") | ||||
|         cards_str = "|flags=" | ||||
|         for card in chara["cards"]: | ||||
|             cards_str += " {{" | ||||
| @@ -271,6 +308,214 @@ class KF3DB: | ||||
|         else: | ||||
|             lines.append(f"|rainbowtrait=N/A") | ||||
|             lines.append(f"|rainbowtraitskill=Not Implemented.") | ||||
|  | ||||
|         lines.append("") | ||||
|         lines.append(f"|bondup={chara['kizunaupText']}") | ||||
|         lines.append(f"|profile={chara['flavorText']}") | ||||
|         lines.append(f"|greeting={chara['loginText']}") | ||||
|         lines.append(f"|selfintro={chara['greetingText']}") | ||||
|         lines.append(f"|enselfintro=") | ||||
|  | ||||
|         cos_images = "|cos = " + ",".join([costume["image_name"] for costume in chara["costumes"]]) + ",end" | ||||
|         cos_obtain = "|cosobt = " + ",".join([costume["obtain"] for costume in chara["costumes"]]) | ||||
|         cos_names = "|cosname = " + ",".join([costume["name"] for costume in chara["costumes"]]) | ||||
|  | ||||
|         lines.append("") | ||||
|         lines.append(cos_images) | ||||
|         lines.append(cos_names) | ||||
|         lines.append(cos_obtain) | ||||
|  | ||||
|         lines.append("}}") | ||||
|  | ||||
|         return "\n".join(lines) | ||||
|         return "\n".join(lines) | ||||
|      | ||||
|     def get_costumes(self, id : int, defaultRarity : int): | ||||
|         if id not in self.charaClothesData: | ||||
|             return [] | ||||
|          | ||||
|         output = [] | ||||
|         data = self.charaClothesData[id] | ||||
|         for costume in data: | ||||
|             cos = { | ||||
|                 "image_name" : f"icon dressup {costume['id']}.png", | ||||
|                 "obtain" : "Limited" | ||||
|             } | ||||
|             cosId = costume['clothesId'] | ||||
|             if cosId == 1: | ||||
|                 cos["name"] = "Default" | ||||
|                 cos["obtain"] = "Default" | ||||
|  | ||||
|             elif cosId == 2: | ||||
|                 cos["name"] = "Personal Fashion" | ||||
|                 cos["obtain"] = f"Upgrade to {costume['getRank']} Stars" if defaultRarity < costume['getRank'] else "Default" | ||||
|  | ||||
|             elif cosId == 3: | ||||
|                 cos["name"] = "Tracksuit" | ||||
|                 cos["obtain"] = f"Upgrade to {costume['getRank']} Stars" if defaultRarity < costume['getRank'] else "Default" | ||||
|                  | ||||
|             elif cosId == 4: | ||||
|                 cos["name"] = "Park Staff" | ||||
|                 cos["obtain"] = f"Upgrade to {costume['getRank']} Stars" if defaultRarity < costume['getRank'] else "Default" | ||||
|                  | ||||
|             elif cosId == 5: | ||||
|                 cos["name"] = "Café Uniform" | ||||
|                 cos["obtain"] = f"Upgrade to {costume['getRank']} Stars" if defaultRarity < costume['getRank'] else "Default" | ||||
|                  | ||||
|             elif cosId == 6: | ||||
|                 cos["name"] = "Special Outfit 1" | ||||
|                  | ||||
|             elif cosId == 8: | ||||
|                 cos["name"] = "Party Dress" | ||||
|                 cos["obtain"] = "Increase Photo Pocket level to 12" | ||||
|                  | ||||
|             elif cosId == 9: | ||||
|                 cos["name"] = "School Uniform" | ||||
|                  | ||||
|             elif cosId == 10: | ||||
|                 cos["name"] = "Gym Clothes" | ||||
|                  | ||||
|             elif cosId == 11: | ||||
|                 cos["name"] = "Raincoat" | ||||
|                  | ||||
|             elif cosId == 12: | ||||
|                 cos["name"] = "Hanamaru Animal Swimsuit" | ||||
|                  | ||||
|             elif cosId == 13: | ||||
|                 cos["name"] = "Cafe Uniform (Green)" | ||||
|                 cos["obtain"] = "Dojo reward" | ||||
|                  | ||||
|             elif cosId == 14: | ||||
|                 cos["name"] = "Cafe Uniform (Blue)" | ||||
|                 cos["obtain"] = "Dojo reward" | ||||
|                  | ||||
|             elif cosId == 15: | ||||
|                 cos["name"] = "Cafe Uniform (Pink)" | ||||
|                 cos["obtain"] = "Dojo reward" | ||||
|                  | ||||
|             elif cosId == 16: | ||||
|                 cos["name"] = "Orihime Costume" | ||||
|                  | ||||
|             elif cosId == 17: | ||||
|                 cos["name"] = "Arle's Outfit" | ||||
|                  | ||||
|             elif cosId == 18: | ||||
|                 cos["name"] = "Marine Nanoda! Swimsuit" | ||||
|                  | ||||
|             elif cosId == 19: | ||||
|                 cos["name"] = "Batten Japari Dan Swimsuit" | ||||
|                  | ||||
|             elif cosId == 20: | ||||
|                 cos["name"] = "Lifeguard Swimsuit" | ||||
|                  | ||||
|             elif cosId == 21: | ||||
|                 cos["name"] = "Harvest Festival Outfit" | ||||
|                  | ||||
|             elif cosId == 22: | ||||
|                 cos["name"] = "Halloween Costume" | ||||
|                  | ||||
|             elif cosId == 23: | ||||
|                 cos["name"] = "Classic Maid Uniform" | ||||
|                  | ||||
|             elif cosId == 24: | ||||
|                 cos["name"] = "Arle's Outfit" | ||||
|                  | ||||
|             elif cosId == 25: | ||||
|                 cos["name"] = "Swimsuit" | ||||
|                  | ||||
|             elif cosId == 26: | ||||
|                 cos["name"] = "Swimsuit" | ||||
|                  | ||||
|             elif cosId == 27: | ||||
|                 cos["name"] = "Swimsuit" | ||||
|                  | ||||
|             elif cosId == 28: | ||||
|                 cos["name"] = "Matching Clothes" | ||||
|                  | ||||
|             elif cosId == 29: | ||||
|                 cos["name"] = "Frilly Frilly PPP Bikini" | ||||
|                  | ||||
|             elif cosId == 30: | ||||
|                 cos["name"] = "Venus Flower Bikini" | ||||
|                  | ||||
|             elif cosId == 31: | ||||
|                 cos["name"] = "Christmas Dress" | ||||
|                  | ||||
|             elif cosId == 32: | ||||
|                 cos["name"] = "Chinese Shrine Maiden" | ||||
|                  | ||||
|             elif cosId == 33: | ||||
|                 cos["name"] = "Chinese Dress" | ||||
|                  | ||||
|             elif cosId == 34: | ||||
|                 cos["name"] = "Hanamaru Stage Costume" | ||||
|                  | ||||
|             elif cosId == 35: | ||||
|                 cos["name"] = "Camo Outfit" | ||||
|                  | ||||
|             elif cosId == 36: | ||||
|                 cos["name"] = "でびでび・ふりる" | ||||
|                  | ||||
|             elif cosId == 37: | ||||
|                 cos["name"] = "夜に紛れし闇の衣" | ||||
|                  | ||||
|             elif cosId == 38: | ||||
|                 cos["name"] = "Santa" | ||||
|                  | ||||
|             elif cosId == 39: | ||||
|                 cos["name"] = "Fluffy Pajamas" | ||||
|                  | ||||
|             elif cosId == 40: | ||||
|                 cos["name"] = "Japanese Armor" | ||||
|                  | ||||
|             elif cosId == 41: | ||||
|                 cos["name"] = "Miko Outfit" | ||||
|                  | ||||
|             elif cosId == 42: | ||||
|                 cos["name"] = "PPP Hoodie" | ||||
|                  | ||||
|             elif cosId == 43: | ||||
|                 cos["name"] = "Blue Tracksuit" | ||||
|                  | ||||
|             elif cosId == 44: | ||||
|                 cos["name"] = "Park Staff (beige)" | ||||
|                  | ||||
|             elif cosId == 45: | ||||
|                 cos["name"] = "Sailor School Uniform" | ||||
|                  | ||||
|             elif cosId == 46: | ||||
|                 cos["name"] = "Snow Knight Dress" | ||||
|                  | ||||
|             elif cosId == 47: | ||||
|                 cos["name"] = "Sparkling Tree Dress" | ||||
|                  | ||||
|             elif cosId == 48: | ||||
|                 cos["name"] = "Retro Detective" | ||||
|                  | ||||
|             elif cosId == 49: | ||||
|                 cos["name"] = "Steampunk Detective" | ||||
|                  | ||||
|             elif cosId == 50: | ||||
|                 cos["name"] = "鞠と花びらのはんなり和風服" | ||||
|                  | ||||
|             elif cosId == 51: | ||||
|                 cos["name"] = "Numazu Deep Sea Aquarium Clothes" | ||||
|                  | ||||
|             elif cosId == 52: | ||||
|                 cos["name"] = "たのしいことをお届け!" | ||||
|  | ||||
|             elif cosId == 53: | ||||
|                 cos["name"] = "かわいい勝負ですよ!ワンピース水着" | ||||
|  | ||||
|             elif cosId == 54: | ||||
|                 cos["name"] = "どきどき♡ずっきゅんビキニ" | ||||
|  | ||||
|             elif cosId == 55: | ||||
|                 cos["name"]= "のんほいパークの服" | ||||
|                  | ||||
|             else: | ||||
|                 print(f"{costume['clothesId']}\t{costume['id']}\t{costume['name']}") | ||||
|                 continue | ||||
|  | ||||
|             output.append(cos) | ||||
|         return output | ||||
|                  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user