From 1a30bb25b00d5aa9f3dd5f2522fdcf0b999a5057 Mon Sep 17 00:00:00 2001 From: KevinVG207 <19467234+KevinVG207@users.noreply.github.com> Date: Mon, 31 Jul 2023 11:56:28 +0200 Subject: [PATCH 1/6] Avoid crash when random support card does not exist on GT (#151) --- umalauncher/carrotjuicer.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/umalauncher/carrotjuicer.py b/umalauncher/carrotjuicer.py index 03a7d0e..843c318 100644 --- a/umalauncher/carrotjuicer.py +++ b/umalauncher/carrotjuicer.py @@ -342,10 +342,19 @@ def handle_response(self, message): if event_data['event_contents_info']['support_card_id'] and event_data['event_contents_info']['support_card_id'] not in supports: # Random support card event logger.debug("Random support card detected") + self.browser.execute_script("""document.getElementById("boxSupportExtra").click();""") self.browser.execute_script( """ - document.getElementById(arguments[0].toString()).click(); + var cont = document.getElementById("30021").parentElement.parentElement; + + var ele = cont.getElementById(arguments[0].toString()); + + if (ele) { + ele.click(); + } else { + cont.querySelector("img[src=\"/images/ui/close.png\"]").click(); + } """, event_data['event_contents_info']['support_card_id'] ) From e9d0d96ae43edf866969278b068e9d5fbd1ed193 Mon Sep 17 00:00:00 2001 From: KevinVG207 <19467234+KevinVG207@users.noreply.github.com> Date: Mon, 31 Jul 2023 11:57:31 +0200 Subject: [PATCH 2/6] Add team building support to rich presence (#152) Scouting event --- umalauncher/carrotjuicer.py | 10 ++++++++++ umalauncher/constants.py | 33 ++++++++++++++++++++++++++++++++ umalauncher/screenstate.py | 1 + umalauncher/screenstate_utils.py | 12 ++++++++++++ umalauncher/util.py | 11 ++++++++++- 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/umalauncher/carrotjuicer.py b/umalauncher/carrotjuicer.py index 843c318..3783821 100644 --- a/umalauncher/carrotjuicer.py +++ b/umalauncher/carrotjuicer.py @@ -231,6 +231,16 @@ def handle_response(self, message): self.screen_state_handler.carrotjuicer_state = new_state return + # Team Building + if 'scout_ranking_state' in data: + if data.get("own_team_info") and data['own_team_info'].get('team_score') and self.screen_state_handler: + team_score = data['own_team_info'].get('team_score') + leader_chara_id = data['own_team_info'].get('entry_chara_array',[{}])[0].get('trained_chara', {}).get('card_id') + + if team_score and leader_chara_id: + logger.debug(f"Team score: {team_score}, leader chara id: {leader_chara_id}") + self.screen_state_handler.carrotjuicer_state = screenstate_utils.make_scouting_state(self.screen_state_handler, team_score, leader_chara_id) + # League of Heroes if 'heroes_id' in data: if data.get("own_team_info") and data['own_team_info']['team_name'] and data['own_team_info']['league_score'] and self.screen_state_handler: diff --git a/umalauncher/constants.py b/umalauncher/constants.py index 2e436a9..f6f8db5 100644 --- a/umalauncher/constants.py +++ b/umalauncher/constants.py @@ -134,4 +134,37 @@ 23000: "Platinum 2", 26000: "Platinum 3", 30000: "Platinum 4" +} + +SCOUTING_SCORE_TO_RANK_DICT = { + 0: "No rank", + 60000: "E", + 63000: "E1", + 66000: "E2", + 69000: "E3", + 72000: "D", + 76000: "D1", + 80000: "D2", + 85000: "D3", + 90000: "C", + 95000: "C1", + 100000: "C2", + 105000: "C3", + 110000: "B", + 115000: "B1", + 120000: "B2", + 125000: "B3", + 130000: "A", + 135000: "A1", + 140000: "A2", + 145000: "A3", + 150000: "A4", + 155000: "A5", + 160000: "S", + 165000: "S1", + 170000: "S2", + 180000: "S3", + 190000: "S4", + 200000: "S5", + 210000: "SS" } \ No newline at end of file diff --git a/umalauncher/screenstate.py b/umalauncher/screenstate.py index a33fc0d..e673523 100644 --- a/umalauncher/screenstate.py +++ b/umalauncher/screenstate.py @@ -22,6 +22,7 @@ class Location(Enum): TRAINING = 3 EVENT = 4 LEAGUE_OF_HEROES = 5 + SCOUTING_EVENT = 6 class ScreenState: location = None diff --git a/umalauncher/screenstate_utils.py b/umalauncher/screenstate_utils.py index 66bd860..170c51f 100644 --- a/umalauncher/screenstate_utils.py +++ b/umalauncher/screenstate_utils.py @@ -44,4 +44,16 @@ def make_league_of_heroes_state(handler, team_name, league_score) -> ss.ScreenSt new_state.location = ss.Location.LEAGUE_OF_HEROES new_state.main = f"League of Heroes - {team_name}" new_state.sub = get_league_of_heroes_substate(league_score) + return new_state + +def make_scouting_state(handler: ss.ScreenStateHandler, team_score, outfit_id) -> ss.ScreenState: + new_state = ss.ScreenState(handler) + new_state.location = ss.Location.SCOUTING_EVENT + new_state.main = f"Team Building - {team_score} pt." + new_state.sub = f"Rank: {util.scouting_score_to_rank_string(team_score)}" + + chara_id = str(outfit_id)[:-2] + + new_state.set_chara(chara_id, outfit_id=int(outfit_id), small_text="Team Leader") + return new_state \ No newline at end of file diff --git a/umalauncher/util.py b/umalauncher/util.py index c412118..21e10b0 100644 --- a/umalauncher/util.py +++ b/umalauncher/util.py @@ -434,4 +434,13 @@ def heroes_score_to_league_string(score): current_league = league else: break - return current_league \ No newline at end of file + return current_league + +def scouting_score_to_rank_string(score): + current_rank = list(constants.SCOUTING_SCORE_TO_RANK_DICT.keys())[0] + for score_threshold, rank in constants.SCOUTING_SCORE_TO_RANK_DICT.items(): + if score >= score_threshold: + current_rank = rank + else: + break + return current_rank \ No newline at end of file From 7e1dbcc931f3023aebc98c1bb27cf17b99f8a3c4 Mon Sep 17 00:00:00 2001 From: KevinVG207 <19467234+KevinVG207@users.noreply.github.com> Date: Mon, 31 Jul 2023 16:04:29 +0200 Subject: [PATCH 3/6] Added fans warning under next scheduled race if needed. (#153) --- umalauncher/helper_table.py | 2 ++ umalauncher/helper_table_elements.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/umalauncher/helper_table.py b/umalauncher/helper_table.py index 6ccb001..b899635 100644 --- a/umalauncher/helper_table.py +++ b/umalauncher/helper_table.py @@ -268,6 +268,7 @@ def calc_bond_gain(partner_id, amount): scheduled_races.append({ "turn": turn, + "fans": program_data['need_fan_count'], "thumb_url": thumb_url }) @@ -292,6 +293,7 @@ def calc_bond_gain(partner_id, amount): "scenario_id": data['chara_info']['scenario_id'], "energy": data['chara_info']['vital'], "max_energy": data['chara_info']['max_vital'], + "fans": data['chara_info']['fans'], "scheduled_races": scheduled_races, "gm_fragments": gm_fragments, "gl_stats": gl_stats, diff --git a/umalauncher/helper_table_elements.py b/umalauncher/helper_table_elements.py index 8379570..0e61523 100644 --- a/umalauncher/helper_table_elements.py +++ b/umalauncher/helper_table_elements.py @@ -242,7 +242,14 @@ def generate_schedule(self, main_info): turns_left = next_race['turn'] - cur_turn text = f"
{turns_left} turn{'' if turns_left == 1 else 's'} until
" img = f"" - return f"""{fans_needed} more fans needed!
""" + + return f"""