From df9ba9beda67c1283d56540537c25e041f77e6c2 Mon Sep 17 00:00:00 2001 From: UncleJim Date: Mon, 20 Nov 2023 04:40:32 +0000 Subject: [PATCH] Update titles/idac/season2.py --- titles/idac/season2.py | 144 ++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 90 deletions(-) diff --git a/titles/idac/season2.py b/titles/idac/season2.py index 78c859a..4a6e849 100644 --- a/titles/idac/season2.py +++ b/titles/idac/season2.py @@ -588,6 +588,58 @@ class IDACSeason2(IDACBase): user_id, self.version, updated_stock_data ) + def _update_vs_info(self, user_id: int, battle_mode: int, data: Dict) -> Dict: + vs_info = self.data.item.get_vs_infos_by_mode(user_id, battle_mode) + + if vs_info is not None: + vs_info["vs_cnt"] += 1 + vs_info["vs_win"] = vs_info["vs_win"] + data.get("win_flg") + vs_info["invalid"] = vs_info["invalid"] + data.get("result") + vs_info["str_now"] = vs_info["str_now"] + data.get("win_flg") if data.get("win_flg") == 1 else 0 + vs_info["str"] = vs_info["str"] if vs_info["str"] > vs_info["str_now"] else vs_info["str_now"] + vs_info["lose_now"] += 1 if data.get("win_flg") == 0 else 0 + vs_info["break_count"] += data.get("break_count") + vs_info["break_penalty_flag"] = data.get("break_penalty_flag") + + course_not_exists = True + for course in vs_info["vsinfo_course_data"]: + if course["course_id"] == data.get("course_id"): + course["vs_cnt"] += 1 + course["vs_win"] += data.get("win_flg") + course_not_exists = False + + if course_not_exists: + course = {} + course["course_id"] = data.get("course_id") + course["vs_cnt"] = 1 + course["vs_win"] = data.get("win_flg") + vs_info["vsinfo_course_data"].append(course) + else: + vs_info = { + "battle_mode": battle_mode, + "vs_cnt": 1, + "vs_win": data.get("win_flg"), + "invalid": data.get("result"), + "str": data.get("win_flg"), + "str_now": data.get("win_flg"), + "lose_now": 1 if data.get("win_flg") == 0 else 0, + "break_count": data.get("break_count"), + "break_penalty_flag": data.get("break_penalty_flag") + "vsinfo_course_data": [ + { + "course_id": data.get("course_id"), + "vs_cnt": 1, + "vs_win": data.get("win_flg") + } + ], + } + + self.data.item.put_vs_info(user_id, battle_mode, vs_info) + + vs_info["vs_history"] = data.get("vs_history") + vs_info["course_select_priority"] = data.get("course_select_priority") + return vs_info + def handle_user_getdata_request(self, data: Dict, headers: Dict): user_id = int(headers["session"]) @@ -2372,51 +2424,7 @@ class IDACSeason2(IDACBase): }, ) - vs_info = self.data.item.get_vs_infos_by_mode(user_id, 0) - if vs_info is not None: - vs_info["vs_cnt"] = vs_info["vs_cnt"] + 1 - vs_info["vs_win"] = vs_info["vs_win"] + data.get("win_flg") - vs_info["invalid"] = vs_info["invalid"] + data.get("result") - vs_info["str"] = vs_info["str"] if vs_info["str"] > vs_info["str_now"] else vs_info["str_now"] - vs_info["str_now"] = vs_info["str_now"] + data.get("win_flg") if data.get("win_flg") == 1 else 0 - vs_info["lose_now"] += 1 if data.get("win_flg") == 0 else 0 - vs_info["break_count"] += data.get("break_count") - vs_info["break_penalty_flag"] = data.get("break_penalty_flag") - course_exists = 0 - for course in vs_info["vsinfo_course_data"]: - if course["course_id"] == data.get("course_id"): - course["vs_cnt"] += 1 - course["vs_win"] += data.get("win_flg") - course_exists = 1 - if course_exists == 0: - course = {} - course["course_id"] = data.get("course_id") - course["vs_cnt"] = 1 - course["vs_win"] = data.get("win_flg") - vs_info["vsinfo_course_data"].append(course) - self.data.item.put_vs_info(user_id, 0, vs_info) - else: - vs_info = { - "battle_mode": 0, - "vs_cnt": 1, - "vs_win": data.get("win_flg"), - "invalid": data.get("result"), - "str": data.get("win_flg"), - "str_now": data.get("win_flg"), - "lose_now": 1 if data.get("win_flg") == 0 else 0, - "break_count": data.get("break_count"), - "break_penalty_flag": data.get("break_penalty_flag") - #"vs_history": data.get("vs_history"), - #"course_select_priority": data.get("course_select_priority"), - "vsinfo_course_data": [ - { - "course_id": data.get("course_id"), - "vs_cnt": 1, - "vs_win": data.get("win_flg"), - } - ], - } - self.data.item.put_vs_info(user_id, 0, vs_info) + vs_info = _update_vs_info(user_id, 0, data) return { "status_code": "0", @@ -2495,51 +2503,7 @@ class IDACSeason2(IDACBase): ) # save vs_info in database - vs_info = self.data.item.get_vs_infos_by_mode(user_id, 1) - if vs_info is not None: - vs_info["vs_cnt"] = vs_info["vs_cnt"] + 1 - vs_info["vs_win"] = vs_info["vs_win"] + data.get("win_flg") - vs_info["invalid"] = vs_info["invalid"] + data.get("result") - vs_info["str"] = vs_info["str"] if vs_info["str"] > vs_info["str_now"] else vs_info["str_now"] - vs_info["str_now"] = vs_info["str_now"] + data.get("win_flg") if data.get("win_flg") == 1 else 0 - vs_info["lose_now"] += 1 if data.get("win_flg") == 0 else 0 - vs_info["break_count"] += data.get("break_count") - vs_info["break_penalty_flag"] = data.get("break_penalty_flag") - course_exists = 0 - for course in vs_info["vsinfo_course_data"]: - if course["course_id"] == data.get("course_id"): - course["vs_cnt"] += 1 - course["vs_win"] += data.get("win_flg") - course_exists = 1 - if course_exists == 0: - course = {} - course["course_id"] = data.get("course_id") - course["vs_cnt"] = 1 - course["vs_win"] = data.get("win_flg") - vs_info["vsinfo_course_data"].append(course) - self.data.item.put_vs_info(user_id, 1, vs_info) - else: - vs_info = { - "battle_mode": 0, - "vs_cnt": 1, - "vs_win": data.get("win_flg"), - "invalid": data.get("result"), - "str": data.get("win_flg"), - "str_now": data.get("win_flg"), - "lose_now": 1 if data.get("win_flg") == 0 else 0, - "break_count": data.get("break_count"), - "break_penalty_flag": data.get("break_penalty_flag") - #"vs_history": data.get("vs_history"), - #"course_select_priority": data.get("course_select_priority"), - "vsinfo_course_data": [ - { - "course_id": data.get("course_id"), - "vs_cnt": 1, - "vs_win": data.get("win_flg"), - } - ], - } - self.data.item.put_vs_info(user_id, 1, vs_info) + vs_info = _update_vs_info(user_id, 1, data) return { "status_code": "0",