diff --git a/titles/sao/base.py b/titles/sao/base.py index 9626647..62fa367 100644 --- a/titles/sao/base.py +++ b/titles/sao/base.py @@ -3,7 +3,9 @@ import json, logging from typing import Any, Dict import random import struct -import csv +from csv import * +from random import choice +import random as rand from core.data import Data from core import CoreConfig @@ -495,6 +497,25 @@ class SaoBase: hero_data["skill_slot4_skill_id"], hero_data["skill_slot5_skill_id"] ) + + # Generate random hero(es) based off the response + for a in range(0,req_data.get_unanalyzed_log_tmp_reward_data_list_length): + + with open('titles/sao/data/RewardTable.csv', 'r') as f: + keys_unanalyzed = next(f).strip().split(',') + data_unanalyzed = list(DictReader(f, fieldnames=keys_unanalyzed)) + + randomized_unanalyzed_id = choice(data_unanalyzed) + while int(randomized_unanalyzed_id['UnanalyzedLogGradeId']) != req_data.get_unanalyzed_log_tmp_reward_data_list[a].unanalyzed_log_grade_id: + randomized_unanalyzed_id = choice(data_unanalyzed) + + heroList = self.game_data.static.get_hero_id(randomized_unanalyzed_id['CommonRewardId']) + if heroList: + self.game_data.item.put_hero_log(req_data.user_id, randomized_unanalyzed_id['CommonRewardId'], 1, 0, 101000016, 0, 30086, 1001, 1002, 0, 0) + + # Item and Equipments saving will be done later here + + # Send response resp = SaoEpisodePlayEndResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) return resp.make() @@ -511,4 +532,4 @@ class SaoBase: def handle_c90a(self, request: Any) -> bytes: #should be tweaked for proper item unlock #quest/episode_play_end_unanalyzed_log_fixed resp = SaoEpisodePlayEndUnanalyzedLogFixedResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) - return resp.make() + return resp.make() \ No newline at end of file diff --git a/titles/sao/data/RewardTable.csv b/titles/sao/data/RewardTable.csv new file mode 100644 index 0000000..acce5bd Binary files /dev/null and b/titles/sao/data/RewardTable.csv differ diff --git a/titles/sao/index.py b/titles/sao/index.py index 2c903ce..b74e500 100644 --- a/titles/sao/index.py +++ b/titles/sao/index.py @@ -113,5 +113,4 @@ class SaoServlet(resource.Resource): self.logger.info(f"Handler {req_url} - {sao_request[:4]} request") self.logger.debug(f"Request: {request.content.getvalue().hex()}") - self.logger.debug(f"Response: {handler(sao_request).hex()}") return handler(sao_request) \ No newline at end of file diff --git a/titles/sao/schema/static.py b/titles/sao/schema/static.py index 9e96aaf..ca000b8 100644 --- a/titles/sao/schema/static.py +++ b/titles/sao/schema/static.py @@ -246,6 +246,14 @@ class SaoStaticData(BaseData): return None return [list[2] for list in result.fetchall()] + def get_hero_id(self, heroLogId: int) -> Optional[Dict]: + sql = hero.select(hero.c.heroLogId == heroLogId) + + result = self.execute(sql) + if result is None: + return None + return result.fetchone() + def get_hero_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = hero.select(hero.c.version == version and hero.c.enabled == enabled).order_by( hero.c.heroLogId.asc()