From a0b25e2b7b2cc687e5066ef69a1c4b4d4199c167 Mon Sep 17 00:00:00 2001 From: Midorica Date: Sat, 3 Jun 2023 11:42:50 -0400 Subject: [PATCH] Adding rare drops saving to SAO --- titles/sao/base.py | 33 ++++++++++++++++++++++++++++++- titles/sao/read.py | 24 +++++++++++++++++++++++ titles/sao/schema/static.py | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/titles/sao/base.py b/titles/sao/base.py index ef3879a..098b9c3 100644 --- a/titles/sao/base.py +++ b/titles/sao/base.py @@ -675,6 +675,22 @@ class SaoBase: hero_data["skill_slot4_skill_id"], hero_data["skill_slot5_skill_id"] ) + + # Grab the rare loot from the table, match it with the right item and then push to the player profile + for r in range(0,req_data.get_rare_drop_data_list_length): + rewardList = self.game_data.static.get_rare_drop_id(int(req_data.get_rare_drop_data_list[r].quest_rare_drop_id)) + commonRewardId = rewardList["commonRewardId"] + + heroList = self.game_data.static.get_hero_id(commonRewardId) + equipmentList = self.game_data.static.get_equipment_id(commonRewardId) + itemList = self.game_data.static.get_item_id(commonRewardId) + + if heroList: + self.game_data.item.put_hero_log(req_data.user_id, commonRewardId, 1, 0, 101000016, 0, 30086, 1001, 1002, 0, 0) + if equipmentList: + self.game_data.item.put_equipment_data(req_data.user_id, commonRewardId, 1, 200, 0, 0, 0) + if itemList: + self.game_data.item.put_item(req_data.user_id, commonRewardId) # Generate random hero(es) based off the response for a in range(0,req_data.get_unanalyzed_log_tmp_reward_data_list_length): @@ -825,7 +841,6 @@ class SaoBase: player_level = int(data[i][0]) break - # Update profile updated_profile = self.game_data.profile.put_profile( req_data.user_id, profile["user_type"], @@ -866,6 +881,22 @@ class SaoBase: hero_data["skill_slot5_skill_id"] ) + # Grab the rare loot from the table, match it with the right item and then push to the player profile + for r in range(0,req_data.get_rare_drop_data_list_length): + rewardList = self.game_data.static.get_rare_drop_id(int(req_data.get_rare_drop_data_list[r].quest_rare_drop_id)) + commonRewardId = rewardList["commonRewardId"] + + heroList = self.game_data.static.get_hero_id(commonRewardId) + equipmentList = self.game_data.static.get_equipment_id(commonRewardId) + itemList = self.game_data.static.get_item_id(commonRewardId) + + if heroList: + self.game_data.item.put_hero_log(req_data.user_id, commonRewardId, 1, 0, 101000016, 0, 30086, 1001, 1002, 0, 0) + if equipmentList: + self.game_data.item.put_equipment_data(req_data.user_id, commonRewardId, 1, 200, 0, 0, 0) + if itemList: + self.game_data.item.put_item(req_data.user_id, commonRewardId) + # Generate random hero(es) based off the response for a in range(0,req_data.get_unanalyzed_log_tmp_reward_data_list_length): diff --git a/titles/sao/read.py b/titles/sao/read.py index 5fc9804..d70c275 100644 --- a/titles/sao/read.py +++ b/titles/sao/read.py @@ -228,3 +228,27 @@ class SaoReader(BaseReader): continue except: self.logger.warn(f"Couldn't read csv file in {self.bin_dir}, skipping") + + self.logger.info("Now reading RareDropTable.csv") + try: + fullPath = bin_dir + "/RareDropTable.csv" + with open(fullPath, encoding="UTF-8") as fp: + reader = csv.DictReader(fp) + for row in reader: + questRareDropId = row["QuestRareDropId"] + commonRewardId = row["CommonRewardId"] + enabled = True + + self.logger.info(f"Added rare drop {questRareDropId} | Reward: {commonRewardId}") + + try: + self.data.static.put_rare_drop( + 0, + questRareDropId, + commonRewardId, + enabled + ) + except Exception as err: + print(err) + except: + self.logger.warn(f"Couldn't read csv file in {self.bin_dir}, skipping") diff --git a/titles/sao/schema/static.py b/titles/sao/schema/static.py index 7323fc8..670e3b2 100644 --- a/titles/sao/schema/static.py +++ b/titles/sao/schema/static.py @@ -96,6 +96,20 @@ support = Table( mysql_charset="utf8mb4", ) +rare_drop = Table( + "sao_static_rare_drop_list", + metadata, + Column("id", Integer, primary_key=True, nullable=False), + Column("version", Integer), + Column("questRareDropId", Integer), + Column("commonRewardId", Integer), + Column("enabled", Boolean), + UniqueConstraint( + "version", "questRareDropId", "commonRewardId", name="sao_static_rare_drop_list_uk" + ), + mysql_charset="utf8mb4", +) + title = Table( "sao_static_title_list", metadata, @@ -215,6 +229,23 @@ class SaoStaticData(BaseData): if result is None: return None return result.lastrowid + + def put_rare_drop( self, version: int, questRareDropId: int, commonRewardId: int, enabled: bool ) -> Optional[int]: + sql = insert(rare_drop).values( + version=version, + questRareDropId=questRareDropId, + commonRewardId=commonRewardId, + enabled=enabled, + ) + + conflict = sql.on_duplicate_key_update( + questRareDropId=questRareDropId, commonRewardId=commonRewardId, version=version + ) + + result = self.execute(conflict) + if result is None: + return None + return result.lastrowid def put_title( self, version: int, titleId: int, displayName: str, requirement: int, rank: int, imageFilePath: str, enabled: bool ) -> Optional[int]: sql = insert(title).values( @@ -289,6 +320,14 @@ class SaoStaticData(BaseData): if result is None: return None return result.fetchone() + + def get_rare_drop_id(self, questRareDropId: int) -> Optional[Dict]: + sql = rare_drop.select(rare_drop.c.questRareDropId == questRareDropId) + + result = self.execute(sql) + if result is None: + return None + return result.fetchone() def get_item_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = item.select(item.c.version == version and item.c.enabled == enabled).order_by(