From 4b3921695de78d991f73e328a9eb4367510bef34 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Mon, 8 Mar 2021 15:03:10 -0500 Subject: [PATCH] implemented weather events (just supernova to start) --- league_storage.py | 1 + leagues.py | 25 ++++++++++++++++++++++++- the_prestige.py | 12 ++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/league_storage.py b/league_storage.py index 1e34dd2..443aead 100644 --- a/league_storage.py +++ b/league_storage.py @@ -146,6 +146,7 @@ def save_league(league): state_dic = { "season" : league.season, "day" : league.day, + "last_weather_event" : league.last_weather_event_day, "constraints" : league.constraints, "game_length" : league.game_length, "series_length" : league.series_length, diff --git a/leagues.py b/leagues.py index 828aea5..762c9de 100644 --- a/leagues.py +++ b/leagues.py @@ -18,6 +18,9 @@ class league_structure(object): self.autoplay = -1 self.champion = None self.weather_forecast = {} + self.weather_override = None #set to a weather for league-wide weather effects + self.last_weather_event_day = 0 + self.weather_event_duration = 0 def setup(self, league_dic, division_games = 1, inter_division_games = 1, inter_league_games = 1, games_per_hour = 2): self.league = league_dic # { subleague name : { division name : [team object] } } @@ -466,7 +469,23 @@ class league_structure(object): return this_embed def get_weather_now(self, team_name): - return all_weathers()[self.weather_forecast[team_name][self.day - 1]] + if self.weather_override is None or self.weather_event_duration <= 0: #if no override set or if past event expired + return all_weathers()[self.weather_forecast[team_name][self.day - 1]] + else: + if self.weather_event_duration == 1 and random.random() < 0.1: #once per weather event, roll for forecast regen + self.new_weathers_midseason(team_name) + return self.weather_override + + def weather_event_check(self): #2 for new event, 1 for continued event, 0 for no event + if self.day - self.last_weather_event_day > 12: #arbitrary cooldown between weather events + if random.random() < 0.1: #10% chance for weather event? + self.weather_override = all_weathers()["Supernova"] + self.last_weather_event_day = self.day + self.weather_event_duration = random.randint(self.weather_override.duration_range[0], self.weather_override.duration_range[1]) + return 2 + else: + self.weather_event_duration -= 1 + return 1 if self.weather_event_duration > 0 else 0 class tournament(object): @@ -621,4 +640,8 @@ def load_league_file(league_name): for this_team in this_league.teams_in_league(): #give them all fresh forecasts starting at current day this_league.new_weathers_midseason(this_team.name) save_league(this_league) + try: + this_league.last_weather_event_day = state_dic["last_weather_event"] + except: + this_league.last_weather_event_day = 0 return this_league \ No newline at end of file diff --git a/the_prestige.py b/the_prestige.py index 836a39f..5e19213 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -2146,6 +2146,8 @@ async def start_league_day(channel, league, partial = False): else: game_length = league.game_length + weather_check_result = league.weather_event_check() + for pair in games_to_start: if pair[0] is not None and pair[1] is not None: away = get_team_fuzzy_search(pair[0]) @@ -2170,6 +2172,11 @@ async def start_league_day(channel, league, partial = False): main_controller.master_games_dic[id] = (this_game, state_init, discrim_string) ext = "?league=" + urllib.parse.quote_plus(league.name) + + if weather_check_result == 2: + await channel.send(f"The entire league is struck by a {league.weather_override.emoji} {league.weather_override.name}! The games must go on.") + elif weather_check_result == 1: + await channel.send(f"The {league.weather_override.emoji} {league.weather_override.name} continues to afflict the league.") if league.last_series_check(): #if finals await channel.send(f"The final series of the {league.name} regular season is starting now, at {config()['simmadome_url']+ext}") @@ -2270,6 +2277,11 @@ async def league_day_watcher(channel, league, games_list, filter_url, last = Fal leagues.save_league(league) active_standings[league] = await channel.send(embed=league.standings_embed()) await channel.send(f"The day {league.day} games for the {league.name} will start in {math.ceil(wait_seconds/60)} minutes.") + weather_check_result = league.weather_event_check() + if weather_check_result == 2: + await channel.send(f"The entire league is struck by a {league.weather_override.emoji} {league.weather_override.name}! The games must go on.") + elif weather_check_result == 1: + await channel.send(f"The {league.weather_override.emoji} {league.weather_override.name} continues to afflict the league.") await asyncio.sleep(wait_seconds) await channel.send(f"A {league.name} series is continuing now at {filter_url}") games_list = await continue_league_series(league, queued_games, games_list, series_results, missed)