implemented hurricane and tornado

This commit is contained in:
Sakimori 2021-02-28 19:20:40 -05:00
parent f83a385b53
commit 0d2d64bc01
2 changed files with 54 additions and 3 deletions

View file

@ -186,9 +186,9 @@ def update_loop():
if "weather_message" in this_game.last_update[0].keys(): if "weather_message" in this_game.last_update[0].keys():
state["update_emoji"] = this_game.weather.emoji 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"] = "🏏" 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"] = "👟" state["update_emoji"] = "👟"
else: else:
state["update_emoji"] = "🗞" state["update_emoji"] = "🗞"

View file

@ -319,6 +319,55 @@ class MeteorShower(Weather):
"weather_message": 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
def all_weathers(): def all_weathers():
@ -333,7 +382,9 @@ def all_weathers():
"Drizzle" : Drizzle, "Drizzle" : Drizzle,
"Breezy": Breezy, "Breezy": Breezy,
"Starlight" : Starlight, "Starlight" : Starlight,
"Meteor Shower" : MeteorShower "Meteor Shower" : MeteorShower,
"Hurricane" : Hurricane,
"Tornado" : Tornado
} }
return weathers_dic return weathers_dic