1
0
forked from Hay1tsme/artemis

Stage progression done for SAO

This commit is contained in:
Midorica 2023-06-24 18:48:48 -04:00
parent 402e753469
commit d5bff0e891
4 changed files with 168 additions and 39 deletions

View File

@ -437,7 +437,7 @@ python dbutils.py --game SDEW upgrade
``` ```
### Notes ### Notes
- Stages are currently force unlocked, no progression - Tower Quests currently force unlocked, no progression
- Co-Op (matching) is not supported - Co-Op (matching) is not supported
- Shop is not functionnal - Shop is not functionnal
- Player title is currently static and cannot be changed in-game - Player title is currently static and cannot be changed in-game

View File

@ -101,6 +101,10 @@ class SaoBase:
self.game_data.item.put_equipment_data(user_id, 101000016, 1, 200, 0, 0, 0) self.game_data.item.put_equipment_data(user_id, 101000016, 1, 200, 0, 0, 0)
self.game_data.item.put_equipment_data(user_id, 103000006, 1, 200, 0, 0, 0) self.game_data.item.put_equipment_data(user_id, 103000006, 1, 200, 0, 0, 0)
self.game_data.item.put_equipment_data(user_id, 112000009, 1, 200, 0, 0, 0) self.game_data.item.put_equipment_data(user_id, 112000009, 1, 200, 0, 0, 0)
self.game_data.item.put_player_quest(user_id, 1001, True, 300, 0, 0, 1)
# Force the tutorial stage to be completed due to potential crash in-game
self.logger.info(f"User Authenticated: { access_code } | { user_id }") self.logger.info(f"User Authenticated: { access_code } | { user_id }")
@ -116,6 +120,10 @@ class SaoBase:
self.game_data.item.put_equipment_data(user_id, 101000016, 1, 200, 0, 0, 0) self.game_data.item.put_equipment_data(user_id, 101000016, 1, 200, 0, 0, 0)
self.game_data.item.put_equipment_data(user_id, 103000006, 1, 200, 0, 0, 0) self.game_data.item.put_equipment_data(user_id, 103000006, 1, 200, 0, 0, 0)
self.game_data.item.put_equipment_data(user_id, 112000009, 1, 200, 0, 0, 0) self.game_data.item.put_equipment_data(user_id, 112000009, 1, 200, 0, 0, 0)
self.game_data.item.put_player_quest(user_id, 1001, True, 300, 0, 0, 1)
# Force the tutorial stage to be completed due to potential crash in-game
profile_data = self.game_data.profile.get_profile(user_id) profile_data = self.game_data.profile.get_profile(user_id)
@ -304,8 +312,20 @@ class SaoBase:
def handle_c900(self, request: Any) -> bytes: def handle_c900(self, request: Any) -> bytes:
#quest/get_quest_scene_user_data_list // QuestScene.csv #quest/get_quest_scene_user_data_list // QuestScene.csv
questIdsData = self.game_data.static.get_quests_ids(0, True) req = bytes.fromhex(request)[24:]
resp = SaoGetQuestSceneUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, questIdsData)
req_struct = Struct(
Padding(16),
"user_id_size" / Rebuild(Int32ub, len_(this.user_id) * 2), # calculates the length of the user_id
"user_id" / PaddedString(this.user_id_size, "utf_16_le"), # user_id is a (zero) padded string
)
req_data = req_struct.parse(req)
user_id = req_data.user_id
quest_data = self.game_data.item.get_quest_logs(user_id)
resp = SaoGetQuestSceneUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, quest_data)
return resp.make() return resp.make()
def handle_c400(self, request: Any) -> bytes: def handle_c400(self, request: Any) -> bytes:
@ -678,8 +698,21 @@ class SaoBase:
req_data = req_struct.parse(req) req_data = req_struct.parse(req)
# Add stage progression to database
user_id = req_data.user_id
episode_id = req_data.episode_id
quest_clear_flag = bool(req_data.score_data[0].boss_destroying_num)
clear_time = req_data.score_data[0].clear_time
combo_num = req_data.score_data[0].combo_num
total_damage = req_data.score_data[0].total_damage
concurrent_destroying_num = req_data.score_data[0].concurrent_destroying_num
if quest_clear_flag is True:
# Save stage progression - to be revised to avoid saving worse score
self.game_data.item.put_player_quest(user_id, episode_id, quest_clear_flag, clear_time, combo_num, total_damage, concurrent_destroying_num)
# Update the profile # Update the profile
profile = self.game_data.profile.get_profile(req_data.user_id) profile = self.game_data.profile.get_profile(user_id)
exp = int(profile["rank_exp"]) + 100 #always 100 extra exp for some reason exp = int(profile["rank_exp"]) + 100 #always 100 extra exp for some reason
col = int(profile["own_col"]) + int(req_data.base_get_data[0].get_col) col = int(profile["own_col"]) + int(req_data.base_get_data[0].get_col)
@ -703,7 +736,7 @@ class SaoBase:
# Update profile # Update profile
updated_profile = self.game_data.profile.put_profile( updated_profile = self.game_data.profile.put_profile(
req_data.user_id, user_id,
profile["user_type"], profile["user_type"],
profile["nick_name"], profile["nick_name"],
player_level, player_level,
@ -715,8 +748,8 @@ class SaoBase:
) )
# Update heroes from the used party # Update heroes from the used party
play_session = self.game_data.item.get_session(req_data.user_id) play_session = self.game_data.item.get_session(user_id)
session_party = self.game_data.item.get_hero_party(req_data.user_id, play_session["user_party_team_id"]) session_party = self.game_data.item.get_hero_party(user_id, play_session["user_party_team_id"])
hero_list = [] hero_list = []
hero_list.append(session_party["user_hero_log_id_1"]) hero_list.append(session_party["user_hero_log_id_1"])
@ -724,12 +757,12 @@ class SaoBase:
hero_list.append(session_party["user_hero_log_id_3"]) hero_list.append(session_party["user_hero_log_id_3"])
for i in range(0,len(hero_list)): for i in range(0,len(hero_list)):
hero_data = self.game_data.item.get_hero_log(req_data.user_id, hero_list[i]) hero_data = self.game_data.item.get_hero_log(user_id, hero_list[i])
log_exp = int(hero_data["log_exp"]) + int(req_data.base_get_data[0].get_hero_log_exp) log_exp = int(hero_data["log_exp"]) + int(req_data.base_get_data[0].get_hero_log_exp)
self.game_data.item.put_hero_log( self.game_data.item.put_hero_log(
req_data.user_id, user_id,
hero_data["user_hero_log_id"], hero_data["user_hero_log_id"],
hero_data["log_level"], hero_data["log_level"],
log_exp, log_exp,
@ -752,11 +785,11 @@ class SaoBase:
itemList = self.game_data.static.get_item_id(commonRewardId) itemList = self.game_data.static.get_item_id(commonRewardId)
if heroList: if heroList:
self.game_data.item.put_hero_log(req_data.user_id, commonRewardId, 1, 0, 101000016, 0, 30086, 1001, 1002, 0, 0) self.game_data.item.put_hero_log(user_id, commonRewardId, 1, 0, 101000016, 0, 30086, 1001, 1002, 0, 0)
if equipmentList: if equipmentList:
self.game_data.item.put_equipment_data(req_data.user_id, commonRewardId, 1, 200, 0, 0, 0) self.game_data.item.put_equipment_data(user_id, commonRewardId, 1, 200, 0, 0, 0)
if itemList: if itemList:
self.game_data.item.put_item(req_data.user_id, commonRewardId) self.game_data.item.put_item(user_id, commonRewardId)
# Generate random hero(es) based off the response # Generate random hero(es) based off the response
for a in range(0,req_data.get_unanalyzed_log_tmp_reward_data_list_length): for a in range(0,req_data.get_unanalyzed_log_tmp_reward_data_list_length):
@ -773,11 +806,11 @@ class SaoBase:
equipmentList = self.game_data.static.get_equipment_id(randomized_unanalyzed_id['CommonRewardId']) equipmentList = self.game_data.static.get_equipment_id(randomized_unanalyzed_id['CommonRewardId'])
itemList = self.game_data.static.get_item_id(randomized_unanalyzed_id['CommonRewardId']) itemList = self.game_data.static.get_item_id(randomized_unanalyzed_id['CommonRewardId'])
if heroList: 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) self.game_data.item.put_hero_log(user_id, randomized_unanalyzed_id['CommonRewardId'], 1, 0, 101000016, 0, 30086, 1001, 1002, 0, 0)
if equipmentList: if equipmentList:
self.game_data.item.put_equipment_data(req_data.user_id, randomized_unanalyzed_id['CommonRewardId'], 1, 200, 0, 0, 0) self.game_data.item.put_equipment_data(user_id, randomized_unanalyzed_id['CommonRewardId'], 1, 200, 0, 0, 0)
if itemList: if itemList:
self.game_data.item.put_item(req_data.user_id, randomized_unanalyzed_id['CommonRewardId']) self.game_data.item.put_item(user_id, randomized_unanalyzed_id['CommonRewardId'])
# Send response # Send response

View File

@ -1707,25 +1707,44 @@ class SaoGetQuestSceneUserDataListRequest(SaoBaseRequest):
super().__init__(data) super().__init__(data)
class SaoGetQuestSceneUserDataListResponse(SaoBaseResponse): class SaoGetQuestSceneUserDataListResponse(SaoBaseResponse):
def __init__(self, cmd, questIdsData) -> None: def __init__(self, cmd, quest_data) -> None:
super().__init__(cmd) super().__init__(cmd)
self.result = 1 self.result = 1
# quest_scene_user_data_list_size # quest_scene_user_data_list_size
self.quest_type = [1] * len(questIdsData) self.quest_type = []
self.quest_scene_id = questIdsData self.quest_scene_id = []
self.clear_flag = [1] * len(questIdsData) self.clear_flag = []
# quest_scene_best_score_user_data # quest_scene_best_score_user_data
self.clear_time = 300 self.clear_time = []
self.combo_num = 0 self.combo_num = []
self.total_damage = "0" self.total_damage = [] #string
self.concurrent_destroying_num = 1 self.concurrent_destroying_num = []
for i in range(len(quest_data)):
self.quest_type.append(1)
self.quest_scene_id.append(quest_data[i][2])
self.clear_flag.append(int(quest_data[i][3]))
self.clear_time.append(quest_data[i][4])
self.combo_num.append(quest_data[i][5])
self.total_damage.append(0) #totally absurd but Int16ul[1] is a big problem due to different lenghts...
self.concurrent_destroying_num.append(quest_data[i][7])
# quest_scene_ex_bonus_user_data_list # quest_scene_ex_bonus_user_data_list
self.achievement_flag = [[1, 1, 1],[1, 1, 1]] self.achievement_flag = [[1, 1, 1],[1, 1, 1]]
self.ex_bonus_table_id = [[1, 2, 3],[4, 5, 6]] self.ex_bonus_table_id = [[1, 2, 3],[4, 5, 6]]
self.quest_type = list(map(int,self.quest_type)) #int
self.quest_scene_id = list(map(int,self.quest_scene_id)) #int
self.clear_flag = list(map(int,self.clear_flag)) #int
self.clear_time = list(map(int,self.clear_time)) #int
self.combo_num = list(map(int,self.combo_num)) #int
self.total_damage = list(map(str,self.total_damage)) #string
self.concurrent_destroying_num = list(map(int,self.combo_num)) #int
def make(self) -> bytes: def make(self) -> bytes:
#new stuff #new stuff
quest_scene_ex_bonus_user_data_list_struct = Struct( quest_scene_ex_bonus_user_data_list_struct = Struct(
@ -1737,7 +1756,7 @@ class SaoGetQuestSceneUserDataListResponse(SaoBaseResponse):
"clear_time" / Int32ub, # big endian "clear_time" / Int32ub, # big endian
"combo_num" / Int32ub, # big endian "combo_num" / Int32ub, # big endian
"total_damage_size" / Int32ub, # big endian "total_damage_size" / Int32ub, # big endian
"total_damage" / Int16ul[len(self.total_damage)], "total_damage" / Int16ul[1],
"concurrent_destroying_num" / Int16ub, "concurrent_destroying_num" / Int16ub,
) )
@ -1765,7 +1784,7 @@ class SaoGetQuestSceneUserDataListResponse(SaoBaseResponse):
))) )))
for i in range(len(self.quest_scene_id)): for i in range(len(self.quest_scene_id)):
quest_data = dict( quest_resp_data = dict(
quest_type=self.quest_type[i], quest_type=self.quest_type[i],
quest_scene_id=self.quest_scene_id[i], quest_scene_id=self.quest_scene_id[i],
clear_flag=self.clear_flag[i], clear_flag=self.clear_flag[i],
@ -1776,22 +1795,16 @@ class SaoGetQuestSceneUserDataListResponse(SaoBaseResponse):
quest_scene_ex_bonus_user_data_list=[], quest_scene_ex_bonus_user_data_list=[],
) )
quest_data["quest_scene_best_score_user_data"].append(dict( quest_resp_data["quest_scene_best_score_user_data"].append(dict(
clear_time=self.clear_time, clear_time=self.clear_time[i],
combo_num=self.combo_num, combo_num=self.combo_num[i],
total_damage_size=len(self.total_damage) * 2, total_damage_size=len(self.total_damage[i]) * 2,
total_damage=[ord(x) for x in self.total_damage], total_damage=[ord(x) for x in self.total_damage[i]],
concurrent_destroying_num=self.concurrent_destroying_num, concurrent_destroying_num=self.concurrent_destroying_num[i],
)) ))
'''
quest_data["quest_scene_ex_bonus_user_data_list"].append(dict(
ex_bonus_table_id=self.ex_bonus_table_id[i],
achievement_flag=self.achievement_flag[i],
))
'''
resp_data.quest_scene_user_data_list.append(quest_data) resp_data.quest_scene_user_data_list.append(quest_resp_data)
# finally, rebuild the resp_data # finally, rebuild the resp_data
resp_data = resp_struct.build(resp_data) resp_data = resp_struct.build(resp_data)

View File

@ -84,6 +84,26 @@ hero_party = Table(
mysql_charset="utf8mb4", mysql_charset="utf8mb4",
) )
quest = Table(
"sao_player_quest",
metadata,
Column("id", Integer, primary_key=True, nullable=False),
Column(
"user",
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
nullable=False,
),
Column("episode_id", Integer, nullable=False),
Column("quest_clear_flag", Boolean, nullable=False),
Column("clear_time", Integer, nullable=False),
Column("combo_num", Integer, nullable=False),
Column("total_damage", Integer, nullable=False),
Column("concurrent_destroying_num", Integer, nullable=False),
Column("play_date", TIMESTAMP, nullable=False, server_default=func.now()),
UniqueConstraint("user", "episode_id", name="sao_player_quest_uk"),
mysql_charset="utf8mb4",
)
sessions = Table( sessions = Table(
"sao_play_sessions", "sao_play_sessions",
metadata, metadata,
@ -227,6 +247,34 @@ class SaoItemData(BaseData):
return result.lastrowid return result.lastrowid
def put_player_quest(self, user_id: int, episode_id: int, quest_clear_flag: bool, clear_time: int, combo_num: int, total_damage: int, concurrent_destroying_num: int) -> Optional[int]:
sql = insert(quest).values(
user=user_id,
episode_id=episode_id,
quest_clear_flag=quest_clear_flag,
clear_time=clear_time,
combo_num=combo_num,
total_damage=total_damage,
concurrent_destroying_num=concurrent_destroying_num
)
conflict = sql.on_duplicate_key_update(
quest_clear_flag=quest_clear_flag,
clear_time=clear_time,
combo_num=combo_num,
total_damage=total_damage,
concurrent_destroying_num=concurrent_destroying_num
)
result = self.execute(conflict)
if result is None:
self.logger.error(
f"{__name__} failed to insert quest! user: {user_id}, episode_id: {episode_id}"
)
return None
return result.lastrowid
def get_user_equipment(self, user_id: int, equipment_id: int) -> Optional[Dict]: def get_user_equipment(self, user_id: int, equipment_id: int) -> Optional[Dict]:
sql = equipment_data.select(equipment_data.c.user == user_id and equipment_data.c.equipment_id == equipment_id) sql = equipment_data.select(equipment_data.c.user == user_id and equipment_data.c.equipment_id == equipment_id)
@ -319,6 +367,41 @@ class SaoItemData(BaseData):
return None return None
return result.fetchone() return result.fetchone()
def get_quest_log(
self, user_id: int, episode_id: int = None
) -> Optional[List[Row]]:
"""
A catch-all quest lookup given a profile and episode_id
"""
sql = quest.select(
and_(
quest.c.user == user_id,
quest.c.episode_id == episode_id if episode_id is not None else True,
)
)
result = self.execute(sql)
if result is None:
return None
return result.fetchone()
def get_quest_logs(
self, user_id: int
) -> Optional[List[Row]]:
"""
A catch-all quest lookup given a profile
"""
sql = quest.select(
and_(
quest.c.user == user_id,
)
)
result = self.execute(sql)
if result is None:
return None
return result.fetchall()
def get_session( def get_session(
self, user_id: int = None self, user_id: int = None
) -> Optional[List[Row]]: ) -> Optional[List[Row]]: