implemented meteor shower

This commit is contained in:
Sakimori 2021-02-25 19:27:11 -05:00
parent fe774411a0
commit bd0a1af03e
2 changed files with 36 additions and 1 deletions

View file

@ -225,6 +225,13 @@ class game(object):
self.weather = weather.Weather(self) self.weather = weather.Weather(self)
self.current_batter = None 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): def choose_next_batter(self):
if self.top_of_inning: if self.top_of_inning:
bat_team = self.teams["away"] bat_team = self.teams["away"]

View file

@ -293,6 +293,33 @@ class Breezy(Weather):
"weather_message": True "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(): def all_weathers():
weathers_dic = { weathers_dic = {
"Supernova" : Supernova, "Supernova" : Supernova,
@ -304,7 +331,8 @@ def all_weathers():
"Heat Wave" : HeatWave, "Heat Wave" : HeatWave,
"Drizzle" : Drizzle, "Drizzle" : Drizzle,
"Breezy": Breezy, "Breezy": Breezy,
"Starlight" : Starlight "Starlight" : Starlight,
"Meteor Shower" : MeteorShower
} }
return weathers_dic return weathers_dic