diff --git a/games.py b/games.py index 9240cb7..ab6cad2 100644 --- a/games.py +++ b/games.py @@ -520,12 +520,7 @@ class game(object): scores_to_add = 0 if "twopart" not in self.last_update[0]: - result = self.at_bat() - self.weather.activate(self, result) # possibly modify result in-place - - if "text_only" in result: - return (result, 0) - + result = self.at_bat() if self.top_of_inning: offense_team = self.teams["away"] @@ -545,6 +540,7 @@ class game(object): if "advance" in result.keys() and self.bases[3] is not None: result["outcome"] = appearance_outcomes.sacrifice result["runner"] = self.bases[3].name + text_list = getattr(self.voice, result["outcome"].name) voice_index = random.randrange(0, len(text_list)) result["voiceindex"] = voice_index @@ -553,6 +549,12 @@ class game(object): self.voice.activate(self.last_update[0], result, self) + if "twopart" not in result: + self.weather.activate(self, result) # possibly modify result in-place + + if "text_only" in result: + return (result, 0) + if "twopart" in result: if self.voice.post_format != []: format_list = [] diff --git a/main_controller.py b/main_controller.py index 60bdc69..943e6c8 100644 --- a/main_controller.py +++ b/main_controller.py @@ -231,7 +231,8 @@ def update_loop(): state["update_text"] = f"{updatestring}" - this_game.weather.modify_atbat_message(this_game, state) + if "twopart" not in this_game.last_update[0].keys(): + this_game.weather.modify_atbat_message(this_game, state) state["bases"] = this_game.named_bases() @@ -255,4 +256,4 @@ def update_loop(): socket_thread = threading.Thread(target=socketio.emit, args=("states_update", game_states)) socket_thread.start() #socketio.emit("states_update", game_states) - time.sleep(1) \ No newline at end of file + time.sleep(8) \ No newline at end of file diff --git a/weather.py b/weather.py index 5a721a3..85fc8e7 100644 --- a/weather.py +++ b/weather.py @@ -1,5 +1,5 @@ import random, math, roman -from gametext import appearance_outcomes, base_string +from gametext import appearance_outcomes, game_strings_base, base_string class Weather: name = "Sunny" @@ -426,7 +426,36 @@ class Downpour(Weather): def modify_game_end_message(self, game, state): state["update_emoji"] = self.emoji state["update_text"] = f"{self.target} runs are reached, pleasing the gods. The storm clears." - + +class SummerMist(Weather): + name = "Summer Mist" + emoji = "🌁" + duration_range = [1,3] + substances = ["yellow mustard", "cat fur", "dread", "caramel", "nacho cheese", "mud", "dirt", "justice", "a green goo", "water, probably", "antimatter", "something not of this world", "live ferrets", "snow", "leaves", + "yarn", "seaweed", "sawdust", "stardust", "code fragments", "milk", "lizards", "a large tarp", "feathers"] + + def __init__(self, game): + self.missing_players = {game.teams["home"].name: None, game.teams["away"].name: None} + self.text = "" + + def activate(self, game, result): + if result["outcome"] in [appearance_outcomes.flyout, appearance_outcomes.groundout, appearance_outcomes.sacrifice]: + roll = random.random() + if roll < .3: #get lost + result["mist"] = True + self.text = f" {result['batter'].name} gets lost in the mist on the way back to the dugout." + if self.missing_players[result["offense_team"].name] is not None: + self.text += f" {self.missing_players[result['offense_team'].name].name} wanders back, covered in {random.choice(self.substances)}!" + result["offense_team"].lineup[result["offense_team"].lineup_position % len(result["offense_team"].lineup)] = self.missing_players[result["offense_team"].name] + else: + result["offense_team"].lineup.pop(result["offense_team"].lineup_position % len(result["offense_team"].lineup)) + self.missing_players[result["offense_team"].name] = result["batter"] + + def modify_atbat_message(self, game, state): + if "mist" in game.last_update[0]: + state["update_emoji"] = self.emoji + state["update_text"] += self.text + self.text = "" def all_weathers(): weathers_dic = { @@ -443,31 +472,33 @@ def all_weathers(): "Meteor Shower" : MeteorShower, "Hurricane" : Hurricane, "Tornado" : Tornado, - "Torrential Downpour" : Downpour + "Torrential Downpour" : Downpour, + "Summer Mist" : SummerMist } return weathers_dic class WeatherChains(): - light = [SlightTailwind, Twilight, Breezy, Drizzle] #basic starting points for weather, good comfortable spots to return to + light = [SlightTailwind, Twilight, Breezy, Drizzle, SummerMist] #basic starting points for weather, good comfortable spots to return to magic = [Twilight, ThinnedVeil, MeteorShower, Starlight] #weathers involving breaking the fabric of spacetime sudden = [Tornado, Hurricane, Twilight, Starlight, Midnight, Downpour] #weathers that always happen and leave over 1-3 games disaster = [Hurricane, Tornado, Downpour, Blizzard] #storms - aftermath = [Midnight, Starlight, MeteorShower] #calm epilogues + aftermath = [Midnight, Starlight, MeteorShower, SummerMist] #calm epilogues dictionary = { #Supernova : (magic + sudden + disaster, None), supernova happens leaguewide and shouldn't need a chain, but here just in case - Midnight : ([SlightTailwind, Breezy, Drizzle, Starlight, MeteorShower, HeatWave],[2,2,2,4,4,1]), + Midnight : ([SlightTailwind, Breezy, Drizzle, Starlight, MeteorShower, HeatWave, SummerMist],[2,2,2,4,4,1,2]), SlightTailwind : ([Breezy, Drizzle, Tornado], [3,3,1]), Blizzard : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]), - Twilight : ([ThinnedVeil, Midnight, MeteorShower, SlightTailwind], [2,4,2,1]), + Twilight : ([ThinnedVeil, Midnight, MeteorShower, SlightTailwind, SummerMist], [2,4,2,1,2]), ThinnedVeil : (light, None), - HeatWave : ([Tornado, Hurricane, SlightTailwind, Breezy],[4,4,1,1]), + HeatWave : ([Tornado, Hurricane, SlightTailwind, Breezy, SummerMist],[4,4,1,1,2]), Drizzle : ([Hurricane, Downpour, Blizzard],[2,2,1]), Breezy : ([Drizzle, HeatWave, Blizzard, Tornado], [3,3,1,1]), Starlight : ([SlightTailwind, Twilight, Breezy, Drizzle, ThinnedVeil, HeatWave], None), MeteorShower : ([Starlight, ThinnedVeil, HeatWave], None), Hurricane : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]), Tornado : ([Midnight, Starlight, MeteorShower, Twilight, Downpour],[2,2,2,2,4]), + SummerMist : ([Drizzle, Breezy, Hurricane, Downpour],[2, 1, 1, 1]), Downpour : (aftermath, None) }