diva: add stage_result, end handlers

This commit is contained in:
Kevin Trocolli
2023-10-05 23:47:50 -04:00
parent b2a01d20d5
commit 2b02ed8684
4 changed files with 222 additions and 67 deletions

View File

@@ -34,7 +34,7 @@ class DivaBase:
def handle_attend_request(self, data: bytes) -> str:
req = AttendRequest(data)
resp = AttendResponse(req.cmd, req.req_id)
resp = AttendResponse(req.req_id)
for i in [0, 3, 4, 5, 7, 9, 10, 11, 12, 13]:
resp.atnd_prm1[i] = 0
@@ -392,7 +392,7 @@ class DivaBase:
def handle_pre_start_request(self, data: bytes) -> str:
req = PreStartRequest(data)
resp = PreStartResponse(req.cmd, req.req_id, req.aime_id)
resp = PreStartResponse(req.req_id, req.aime_id)
profile = self.data.profile.get_profile(req.aime_id, self.version)
profile_shop = self.data.item.get_shop(req.aime_id, self.version)
@@ -420,7 +420,7 @@ class DivaBase:
)
if pd_id is None:
return "&cd_adm_result=-1"
return RegisterResponse(req.cmd, req.req_id, req.aime_id).make()
return RegisterResponse(req.req_id, req.aime_id).make()
def handle_start_request(self, data: bytes) -> str:
req = StartRequest(data)
@@ -429,7 +429,7 @@ class DivaBase:
if profile is None:
return
resp = StartResponse(req.cmd, req.req_id, req.pd_id, profile['player_name'])
resp = StartResponse(req.req_id, req.pd_id, profile['player_name'])
profile_dict = profile._asdict()
profile_dict.pop("id")
@@ -532,7 +532,7 @@ class DivaBase:
if profile is None:
return
resp = SpendCreditResponse(req.cmd, req.req_id)
resp = SpendCreditResponse(req.req_id)
resp.vcld_pts = profile['vcld_pts']
resp.lv_str = profile['lv_str']
resp.lv_efct_id = profile['lv_efct_id']
@@ -663,7 +663,7 @@ class DivaBase:
for x in pd_by_pv_id:
pv += x
resp = GetPvPdResponse(req.cmd, req.req_id)
resp = GetPvPdResponse(req.req_id)
resp.pd_by_pv_id = pv[:-1]
response = ""
response += f"&pd_by_pv_id={pv[:-1]}"
@@ -676,33 +676,35 @@ class DivaBase:
pass
def handle_stage_result_request(self, data: bytes) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
req = StageResultRequest(data)
resp = StageResultResponse(req.cmd, req.req_id)
profile = self.data.profile.get_profile(req.pd_id, self.version)
pd_song_list = data["stg_ply_pv_id"].split(",")
pd_song_difficulty = data["stg_difficulty"].split(",")
pd_song_edition = data["stg_edtn"].split(",")
pd_song_max_score = data["stg_score"].split(",")
pd_song_max_atn_pnt = data["stg_atn_pnt"].split(",")
pd_song_ranking = data["stg_clr_kind"].split(",")
pd_song_sort_kind = data["sort_kind"]
pd_song_cool_cnt = data["stg_cool_cnt"].split(",")
pd_song_fine_cnt = data["stg_fine_cnt"].split(",")
pd_song_safe_cnt = data["stg_safe_cnt"].split(",")
pd_song_sad_cnt = data["stg_sad_cnt"].split(",")
pd_song_worst_cnt = data["stg_wt_wg_cnt"].split(",")
pd_song_max_combo = data["stg_max_cmb"].split(",")
pd_song_list = req.stg_ply_pv_id
pd_song_difficulty = req.stg_difficulty
pd_song_edition = req.stg_edtn
pd_song_max_score = req.stg_score
pd_song_max_atn_pnt = req.stg_atn_pnt
pd_song_ranking = req.stg_clr_kind
pd_song_sort_kind = req.sort_kind
pd_song_cool_cnt = req.stg_cool_cnt
pd_song_fine_cnt = req.stg_fine_cnt
pd_song_safe_cnt = req.stg_safe_cnt
pd_song_sad_cnt = req.stg_sad_cnt
pd_song_worst_cnt = req.stg_wt_wg_cnt
pd_song_max_combo = req.stg_max_cmb
for index, value in enumerate(pd_song_list):
if "-1" not in pd_song_list[index]:
if pd_song_list[index] > 0:
profile_pd_db_song = self.data.score.get_best_user_score(
data["pd_id"],
req.pd_id,
pd_song_list[index],
pd_song_difficulty[index],
pd_song_edition[index],
)
if profile_pd_db_song is None:
self.data.score.put_best_score(
data["pd_id"],
req.pd_id,
self.version,
pd_song_list[index],
pd_song_difficulty[index],
@@ -719,7 +721,7 @@ class DivaBase:
pd_song_max_combo[index],
)
self.data.score.put_playlog(
data["pd_id"],
req.pd_id,
self.version,
pd_song_list[index],
pd_song_difficulty[index],
@@ -737,7 +739,7 @@ class DivaBase:
)
elif int(pd_song_max_score[index]) >= int(profile_pd_db_song["score"]):
self.data.score.put_best_score(
data["pd_id"],
req.pd_id,
self.version,
pd_song_list[index],
pd_song_difficulty[index],
@@ -754,7 +756,7 @@ class DivaBase:
pd_song_max_combo[index],
)
self.data.score.put_playlog(
data["pd_id"],
req.pd_id,
self.version,
pd_song_list[index],
pd_song_difficulty[index],
@@ -772,7 +774,7 @@ class DivaBase:
)
elif int(pd_song_max_score[index]) != int(profile_pd_db_song["score"]):
self.data.score.put_playlog(
data["pd_id"],
req.pd_id,
self.version,
pd_song_list[index],
pd_song_difficulty[index],
@@ -792,7 +794,7 @@ class DivaBase:
# Profile saving based on registration list
# Calculate new level
best_scores = self.data.score.get_best_scores(data["pd_id"])
best_scores = self.data.score.get_best_scores(req.pd_id)
total_atn_pnt = 0
for best_score in best_scores:
@@ -801,6 +803,18 @@ class DivaBase:
new_level = (total_atn_pnt // 13979) + 1
new_level_pnt = round((total_atn_pnt % 13979) / 13979 * 100)
resp.lv_num_old = int(profile['lv_num'])
resp.lv_pnt_old = int(profile['lv_pnt'])
resp.lv_num = new_level
resp.lv_str = profile['lv_str']
resp.lv_pnt = new_level_pnt
resp.lv_efct_id = int(profile['lv_efct_id'])
resp.lv_plt_id = int(profile['lv_plt_id'])
resp.vcld_pts = int(profile['vcld_pts'])
resp.prsnt_vcld_pts = int(profile['vcld_pts'])
if "my_qst_id" not in profile:
resp.my_qst_id = profile['my_qst_id']
response = "&chllng_kind=-1"
response += f"&lv_num_old={int(profile['lv_num'])}"
response += f"&lv_pnt_old={int(profile['lv_pnt'])}"
@@ -810,16 +824,16 @@ class DivaBase:
profile["user"],
lv_num=new_level,
lv_pnt=new_level_pnt,
vcld_pts=int(data["vcld_pts"]),
hp_vol=int(data["hp_vol"]),
btn_se_vol=int(data["btn_se_vol"]),
sldr_se_vol2=int(data["sldr_se_vol2"]),
sort_kind=int(data["sort_kind"]),
nxt_pv_id=int(data["ply_pv_id"]),
nxt_dffclty=int(data["nxt_dffclty"]),
nxt_edtn=int(data["nxt_edtn"]),
my_qst_id=data["my_qst_id"],
my_qst_sts=data["my_qst_sts"],
vcld_pts=req.vcld_pts,
hp_vol=req.hp_vol,
btn_se_vol=req.btn_se_vol,
sldr_se_vol2=req.sldr_se_vol2,
sort_kind=req.sort_kind,
nxt_pv_id=req.ply_pv_id,
nxt_dffclty=req.nxt_dffclty,
nxt_edtn=req.nxt_edtn,
my_qst_id=req.my_qst_id,
my_qst_sts=req.my_qst_sts,
)
response += f"&lv_num={new_level}"
@@ -852,15 +866,16 @@ class DivaBase:
response += "&my_ccd_r_hnd=-1,-1,-1,-1,-1"
response += "&my_ccd_r_vp=-1,-1,-1,-1,-1"
return response
return resp.make()
def handle_end_request(self, data: bytes) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
req = EndRequest(data)
profile = self.data.profile.get_profile(req.pd_id, self.version)
self.data.profile.update_profile(
profile["user"], my_qst_id=data["my_qst_id"], my_qst_sts=data["my_qst_sts"]
profile["user"], my_qst_id=req.my_qst_id, my_qst_sts=req.my_qst_sts
)
return f""
return None
def handle_shop_exit_request(self, data: bytes) -> str:
self.data.item.put_shop(