From 0d2d64bc0145c9739293d7538895e32ec27ea85d Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 28 Feb 2021 19:20:40 -0500 Subject: [PATCH] implemented hurricane and tornado --- main_controller.py | 4 ++-- weather.py | 53 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/main_controller.py b/main_controller.py index eb7719c..b666684 100644 --- a/main_controller.py +++ b/main_controller.py @@ -186,9 +186,9 @@ def update_loop(): if "weather_message" in this_game.last_update[0].keys(): state["update_emoji"] = this_game.weather.emoji - elif "ishit" in this_game.last_update[0] and this_game.last_update[0]["ishit"]: + elif "ishit" in this_game.last_update[0].keys() and this_game.last_update[0]["ishit"]: state["update_emoji"] = "🏏" - elif this_game.last_update[0]["text"] == gametext.appearance_outcomes.walk: + elif "text" in this_game.last_update[0].keys() and this_game.last_update[0]["text"] == gametext.appearance_outcomes.walk: state["update_emoji"] = "👟" else: state["update_emoji"] = "🗞" diff --git a/weather.py b/weather.py index 8f0e8b2..cf2b189 100644 --- a/weather.py +++ b/weather.py @@ -318,6 +318,55 @@ class MeteorShower(Weather): "text_only": True, "weather_message": True }) + +class Hurricane(Weather): + def __init__(self, game): + self.name = "Hurricane" + self.emoji = "🌀" + self.swaplength = random.randint(2,4) + self.swapped = False + + def on_flip_inning(self, game): + if game.top_of_inning and (game.inning % self.swaplength) == 0: + self.swaplength = random.randint(2,4) + self.swapped = True + + def modify_top_of_inning_message(self, game, state): + if self.swapped: + game.teams["home"].score, game.teams["away"].score = (game.teams["away"].score, game.teams["home"].score) #swap scores + state["away_score"], state["home_score"] = (game.teams["away"].score, game.teams["home"].score) + state["update_emoji"] = self.emoji + state["update_text"] += " The hurricane rages on, flipping the scoreboard!" + self.swapped = False + +class Tornado(Weather): + def __init__(self, game): + self.name = "Tornado" + self.emoji = "🌪" + self.activation_chance = 1 + self.counter = 0 + + def activate(self, game, result): + if self.counter == 0 and random.random() < self.activation_chance and game.occupied_bases() != {}: + runners = list(game.bases.values()) + current_runners = runners.copy() + self.counter = 5 + while runners == current_runners and self.counter > 0: + random.shuffle(runners) + self.counter -= 1 + for index in range(1,4): + game.bases[index] = runners[index-1] + + result.clear() + result.update({ + "text": f"The tornado sweeps across the field and pushes {'the runners' if len(game.occupied_bases().values())>1 else list(game.occupied_bases().values())[0].name} to a different base!", + "text_only": True, + "weather_message": True + }) + self.counter = 2 + + elif self.counter > 0: + self.counter -= 1 @@ -333,7 +382,9 @@ def all_weathers(): "Drizzle" : Drizzle, "Breezy": Breezy, "Starlight" : Starlight, - "Meteor Shower" : MeteorShower + "Meteor Shower" : MeteorShower, + "Hurricane" : Hurricane, + "Tornado" : Tornado } return weathers_dic