From bd0a1af03eef3dc80cabd04712d5481806be2341 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Thu, 25 Feb 2021 19:27:11 -0500 Subject: [PATCH] implemented meteor shower --- games.py | 7 +++++++ weather.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/games.py b/games.py index f38ffeb..88a22be 100644 --- a/games.py +++ b/games.py @@ -225,6 +225,13 @@ class game(object): self.weather = weather.Weather(self) self.current_batter = None + def occupied_bases(self): + occ_dic = {} + for base in self.bases.keys(): + if self.bases[base] is not None: + occ_dic[base] = self.bases[base] + return occ_dic + def choose_next_batter(self): if self.top_of_inning: bat_team = self.teams["away"] diff --git a/weather.py b/weather.py index bfd6beb..a1f7bf1 100644 --- a/weather.py +++ b/weather.py @@ -293,6 +293,33 @@ class Breezy(Weather): "weather_message": True }) +class MeteorShower(Weather): + def __init__(self, game): + self.name = "Meteor Shower" + self.emoji = "🌠" + self.activation_chance = 1 + + def activate(self, game, result): + if random.random() < self.activation_chance and game.occupied_bases() != {}: + base, runner = random.choice(list(game.occupied_bases().items())) + runner = game.bases[base] + game.bases[base] = None + + if game.top_of_inning: + bat_team = game.teams["away"] + else: + bat_team = game.teams["home"] + + bat_team.score += 1 + result.clear() + result.update({ + "text": f"{runner.name} wished upon one of the shooting stars, and was warped to None base!! 1 runs score!", + "text_only": True, + "weather_message": True + }) + + + def all_weathers(): weathers_dic = { "Supernova" : Supernova, @@ -304,7 +331,8 @@ def all_weathers(): "Heat Wave" : HeatWave, "Drizzle" : Drizzle, "Breezy": Breezy, - "Starlight" : Starlight + "Starlight" : Starlight, + "Meteor Shower" : MeteorShower } return weathers_dic