From 0cf9d03626195cd6c11829b27bcba89abb672f87 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Mon, 8 Mar 2021 15:55:05 -0500 Subject: [PATCH] implemented weather forecast failure modes --- leagues.py | 11 +++++++++-- the_prestige.py | 12 ++++++++++-- weather.py | 21 ++++++++++++++------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/leagues.py b/leagues.py index 762c9de..845aa8d 100644 --- a/leagues.py +++ b/leagues.py @@ -470,6 +470,13 @@ class league_structure(object): def get_weather_now(self, team_name): if self.weather_override is None or self.weather_event_duration <= 0: #if no override set or if past event expired + if self.day < len(self.weather_forecast[team_name]) and random.random() < 0.08: #8% chance the forcast was wrong + if random.random() < 0.33: + return all_weathers()[self.weather_forecast[team_name][self.day]] #next weather came a day early + elif random.random() < 0.66: + return random.choice(WeatherChains.parent_weathers(all_weathers()[self.weather_forecast[team_name][self.day]])) #pivot to different parent weather to lead in + else: + return WeatherChains.chain_weather(all_weathers()[self.weather_forecast[team_name][self.day - 1]]) #jump to a child weather for a day 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 @@ -477,8 +484,8 @@ class league_structure(object): 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? + if self.day - self.last_weather_event_day > 20: #arbitrary cooldown between weather events + if random.random() < 0.05: #5% 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]) diff --git a/the_prestige.py b/the_prestige.py index 5e19213..0d1cdb8 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -1036,7 +1036,10 @@ class LeagueScheduleCommand(Command): schedule_text = "" teams = league.team_names_in_league() for game in league.schedule[str(current_series+day)]: - schedule_text += f"**{game[0]}** @ **{game[1]}**\n" + emojis = "" + for day_offset in range((current_series+day - 1)*league.series_length, (current_series+day)*(league.series_length)): + emojis += weather.all_weathers()[league.weather_forecast[game[1]][day_offset]].emoji + " " + schedule_text += f"**{game[0]}** @ **{game[1]}** {emojis}\n" teams.pop(teams.index(game[0])) teams.pop(teams.index(game[1])) if len(teams) > 0: @@ -1073,9 +1076,14 @@ class LeagueTeamScheduleCommand(Command): for day in days: if str(current_series+day) in league.schedule.keys(): schedule_text = "" + + for game in league.schedule[str(current_series+day)]: if team.name in game: - schedule_text += f"**{game[0]}** @ **{game[1]}**" + emojis = "" + for day_offset in range((current_series+day - 1)*league.series_length, (current_series+day)*(league.series_length)): + emojis += weather.all_weathers()[league.weather_forecast[game[1]][day_offset]].emoji + " " + schedule_text += f"**{game[0]}** @ **{game[1]}** {emojis}" if schedule_text == "": schedule_text += "Resting" sched_embed.add_field(name=f"Days {((current_series+day-1)*league.series_length) + 1} - {(current_series+day)*(league.series_length)}", value=schedule_text, inline = False) diff --git a/weather.py b/weather.py index b6dce32..7c28fbb 100644 --- a/weather.py +++ b/weather.py @@ -68,7 +68,7 @@ class Midnight(Weather): class SlightTailwind(Weather): name = "Slight Tailwind" emoji = "🏌️‍♀️" - duration_range = [2,4] + duration_range = [1,2] def activate(self, game, result): @@ -118,7 +118,7 @@ class Starlight(Weather): class Blizzard(Weather): name = "Blizzard" emoji = "❄" - duration_range = [3,6] + duration_range = [2,3] def __init__(self, game): self.counter_away = random.randint(0,len(game.teams['away'].lineup)-1) @@ -186,7 +186,7 @@ class Twilight(Weather): class ThinnedVeil(Weather): name = "Thinned Veil" emoji = "🌌" - duration_range = [2,4] + duration_range = [1,3] def activate(self, game, result): if result["ishit"]: @@ -201,7 +201,7 @@ class ThinnedVeil(Weather): class HeatWave(Weather): name = "Heat Wave" emoji = "🌄" - duration_range = [3,6] + duration_range = [2,3] def __init__(self,game): self.counter_away = random.randint(2,4) @@ -269,7 +269,7 @@ class Drizzle(Weather): class Breezy(Weather): name = "Breezy" emoji = "🎐" - duration_range = [1,4] + duration_range = [1,3] def __init__(self, game): self.activation_chance = 0.08 @@ -313,7 +313,7 @@ class Breezy(Weather): class MeteorShower(Weather): name = "Meteor Shower" emoji = "🌠" - duration_range = [3,6] + duration_range = [1,3] def __init__(self, game): self.activation_chance = 0.13 @@ -449,7 +449,7 @@ class WeatherChains(): aftermath = [Midnight, Starlight, MeteorShower] #calm epilogues dictionary = { - Supernova : (magic + sudden + disaster, None), #supernova happens leaguewide and shouldn't need a chain, but here just in case + #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]), SlightTailwind : ([Breezy, Drizzle, Tornado], [3,3,1]), Blizzard : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]), @@ -475,6 +475,13 @@ class WeatherChains(): options, weight = WeatherChains.dictionary[weather_type] return random.choices(options, weights = weight)[0] + def parent_weathers(weather_type): + parents = [] + for this_weather, (children, _) in WeatherChains.dictionary.items(): + if weather_type in children: + parents.append(this_weather) + return parents + def starting_weather(): return random.choice(WeatherChains.light + WeatherChains.magic)