implemented weather forecast failure modes

This commit is contained in:
Sakimori 2021-03-08 15:55:05 -05:00
parent 4b3921695d
commit 0cf9d03626
3 changed files with 33 additions and 11 deletions

View file

@ -470,6 +470,13 @@ class league_structure(object):
def get_weather_now(self, team_name): 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.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]] return all_weathers()[self.weather_forecast[team_name][self.day - 1]]
else: else:
if self.weather_event_duration == 1 and random.random() < 0.1: #once per weather event, roll for forecast regen 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 return self.weather_override
def weather_event_check(self): #2 for new event, 1 for continued event, 0 for no event 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 self.day - self.last_weather_event_day > 20: #arbitrary cooldown between weather events
if random.random() < 0.1: #10% chance for weather event? if random.random() < 0.05: #5% chance for weather event?
self.weather_override = all_weathers()["Supernova"] self.weather_override = all_weathers()["Supernova"]
self.last_weather_event_day = self.day 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]) self.weather_event_duration = random.randint(self.weather_override.duration_range[0], self.weather_override.duration_range[1])

View file

@ -1036,7 +1036,10 @@ class LeagueScheduleCommand(Command):
schedule_text = "" schedule_text = ""
teams = league.team_names_in_league() teams = league.team_names_in_league()
for game in league.schedule[str(current_series+day)]: 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[0]))
teams.pop(teams.index(game[1])) teams.pop(teams.index(game[1]))
if len(teams) > 0: if len(teams) > 0:
@ -1073,9 +1076,14 @@ class LeagueTeamScheduleCommand(Command):
for day in days: for day in days:
if str(current_series+day) in league.schedule.keys(): if str(current_series+day) in league.schedule.keys():
schedule_text = "" schedule_text = ""
for game in league.schedule[str(current_series+day)]: for game in league.schedule[str(current_series+day)]:
if team.name in game: 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 == "": if schedule_text == "":
schedule_text += "Resting" 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) 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)

View file

@ -68,7 +68,7 @@ class Midnight(Weather):
class SlightTailwind(Weather): class SlightTailwind(Weather):
name = "Slight Tailwind" name = "Slight Tailwind"
emoji = "🏌️‍♀️" emoji = "🏌️‍♀️"
duration_range = [2,4] duration_range = [1,2]
def activate(self, game, result): def activate(self, game, result):
@ -118,7 +118,7 @@ class Starlight(Weather):
class Blizzard(Weather): class Blizzard(Weather):
name = "Blizzard" name = "Blizzard"
emoji = "" emoji = ""
duration_range = [3,6] duration_range = [2,3]
def __init__(self, game): def __init__(self, game):
self.counter_away = random.randint(0,len(game.teams['away'].lineup)-1) self.counter_away = random.randint(0,len(game.teams['away'].lineup)-1)
@ -186,7 +186,7 @@ class Twilight(Weather):
class ThinnedVeil(Weather): class ThinnedVeil(Weather):
name = "Thinned Veil" name = "Thinned Veil"
emoji = "🌌" emoji = "🌌"
duration_range = [2,4] duration_range = [1,3]
def activate(self, game, result): def activate(self, game, result):
if result["ishit"]: if result["ishit"]:
@ -201,7 +201,7 @@ class ThinnedVeil(Weather):
class HeatWave(Weather): class HeatWave(Weather):
name = "Heat Wave" name = "Heat Wave"
emoji = "🌄" emoji = "🌄"
duration_range = [3,6] duration_range = [2,3]
def __init__(self,game): def __init__(self,game):
self.counter_away = random.randint(2,4) self.counter_away = random.randint(2,4)
@ -269,7 +269,7 @@ class Drizzle(Weather):
class Breezy(Weather): class Breezy(Weather):
name = "Breezy" name = "Breezy"
emoji = "🎐" emoji = "🎐"
duration_range = [1,4] duration_range = [1,3]
def __init__(self, game): def __init__(self, game):
self.activation_chance = 0.08 self.activation_chance = 0.08
@ -313,7 +313,7 @@ class Breezy(Weather):
class MeteorShower(Weather): class MeteorShower(Weather):
name = "Meteor Shower" name = "Meteor Shower"
emoji = "🌠" emoji = "🌠"
duration_range = [3,6] duration_range = [1,3]
def __init__(self, game): def __init__(self, game):
self.activation_chance = 0.13 self.activation_chance = 0.13
@ -449,7 +449,7 @@ class WeatherChains():
aftermath = [Midnight, Starlight, MeteorShower] #calm epilogues aftermath = [Midnight, Starlight, MeteorShower] #calm epilogues
dictionary = { 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]), Midnight : ([SlightTailwind, Breezy, Drizzle, Starlight, MeteorShower, HeatWave],[2,2,2,4,4,1]),
SlightTailwind : ([Breezy, Drizzle, Tornado], [3,3,1]), SlightTailwind : ([Breezy, Drizzle, Tornado], [3,3,1]),
Blizzard : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]), Blizzard : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]),
@ -475,6 +475,13 @@ class WeatherChains():
options, weight = WeatherChains.dictionary[weather_type] options, weight = WeatherChains.dictionary[weather_type]
return random.choices(options, weights = weight)[0] 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(): def starting_weather():
return random.choice(WeatherChains.light + WeatherChains.magic) return random.choice(WeatherChains.light + WeatherChains.magic)