From 0d2d64bc0145c9739293d7538895e32ec27ea85d Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 28 Feb 2021 19:20:40 -0500 Subject: [PATCH 01/19] implemented hurricane and tornado --- main_controller.py | 4 ++-- weather.py | 53 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/main_controller.py b/main_controller.py index eb7719c..b666684 100644 --- a/main_controller.py +++ b/main_controller.py @@ -186,9 +186,9 @@ def update_loop(): if "weather_message" in this_game.last_update[0].keys(): 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"] = "🏏" - 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"] = "👟" else: state["update_emoji"] = "🗞" diff --git a/weather.py b/weather.py index 8f0e8b2..cf2b189 100644 --- a/weather.py +++ b/weather.py @@ -318,6 +318,55 @@ class MeteorShower(Weather): "text_only": 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 @@ -333,7 +382,9 @@ def all_weathers(): "Drizzle" : Drizzle, "Breezy": Breezy, "Starlight" : Starlight, - "Meteor Shower" : MeteorShower + "Meteor Shower" : MeteorShower, + "Hurricane" : Hurricane, + "Tornado" : Tornado } return weathers_dic From 0a222888eeac5f26a3595fe7d9d9ac29f9e706df Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 28 Feb 2021 19:52:16 -0500 Subject: [PATCH 02/19] changed tornado activation chance --- weather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weather.py b/weather.py index cf2b189..508c745 100644 --- a/weather.py +++ b/weather.py @@ -343,7 +343,7 @@ class Tornado(Weather): def __init__(self, game): self.name = "Tornado" self.emoji = "🌪" - self.activation_chance = 1 + self.activation_chance = 0.25 self.counter = 0 def activate(self, game, result): From e63f08cce05694e4c142be7289b9e89284eefc4b Mon Sep 17 00:00:00 2001 From: Sakimori Date: Mon, 1 Mar 2021 19:38:38 -0500 Subject: [PATCH 03/19] increased tornado proc rate --- weather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weather.py b/weather.py index 508c745..858cf90 100644 --- a/weather.py +++ b/weather.py @@ -343,7 +343,7 @@ class Tornado(Weather): def __init__(self, game): self.name = "Tornado" self.emoji = "🌪" - self.activation_chance = 0.25 + self.activation_chance = 0.33 self.counter = 0 def activate(self, game, result): From 317ef782a2b38e1bc6377fcaefca58d830d2221c Mon Sep 17 00:00:00 2001 From: Sakimori Date: Mon, 1 Mar 2021 19:39:16 -0500 Subject: [PATCH 04/19] added some 16-related easter eggs --- database.py | 23 +++++++++++++++++++---- games.py | 8 +++++++- the_prestige.py | 4 +++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/database.py b/database.py index fe563f5..69afb31 100644 --- a/database.py +++ b/database.py @@ -371,7 +371,7 @@ def add_team_obl(team): conn.commit() conn.close() -def save_obl_results(winning_team, losing_team): +def save_obl_results(winning_team, losing_team, xvi_team = None): conn = create_connection() if conn is not None: c=conn.cursor() @@ -392,7 +392,22 @@ def save_obl_results(winning_team, losing_team): obl_points += 1 c.execute("UPDATE one_big_league SET teams_beaten_list = ?, current_opponent_pool = ?, obl_points = ? WHERE team_name = ?", (list_to_newline_string(beaten_teams), list_to_newline_string(opponent_teams), obl_points, winning_team.name)) + conn.commit() + conn.close() + if xvi_team is not None: + add_obl_point(xvi_team) + return + +def add_obl_point(team): + conn = create_connection() + if conn is not None: + c=conn.cursor() + + c.execute("SELECT obl_points FROM one_big_league WHERE team_name = ?", (team.name,)) + xvi_obl_points = c.fetchone()[0] + xvi_obl_points += 1 + c.execute("UPDATE one_big_league SET obl_points = ? WHERE team_name = ?", (xvi_obl_points, team.name)) conn.commit() conn.close() return @@ -403,15 +418,15 @@ def get_obl_stats(team, full = False): c=conn.cursor() opponents_string = None while opponents_string is None: - c.execute("SELECT teams_beaten_list, current_opponent_pool, rival_name FROM one_big_league WHERE team_name = ?", (team.name,)) + c.execute("SELECT teams_beaten_list, current_opponent_pool, rival_name, obl_points FROM one_big_league WHERE team_name = ?", (team.name,)) try: - beaten_string, opponents_string, rival_name = c.fetchone() + beaten_string, opponents_string, rival_name, obl_points = c.fetchone() except TypeError: #add team to OBL + obl_points = 0 add_team_obl(team) beaten_teams = newline_string_to_list(beaten_string) opponent_teams = opponents_string - obl_points = len(beaten_teams) teams_list = [name for name, points in obl_leaderboards()] rank = teams_list.index(team.name) + 1 diff --git a/games.py b/games.py index 88a22be..84dae73 100644 --- a/games.py +++ b/games.py @@ -635,7 +635,13 @@ class game(object): if self.inning > self.max_innings and self.teams["home"].score != self.teams["away"].score: #game over self.over = True if self.max_innings >= 9: - db.save_obl_results(self.teams["home"] if self.teams["home"].score > self.teams["away"].score else self.teams["away"], self.teams["home"] if self.teams["home"].score < self.teams["away"].score else self.teams["away"]) + if self.teams["home"].score == 16: + this_xvi_team = self.teams["home"] + elif self.teams["away"].score == 16: + this_xvi_team = self.teams["away"] + else: + this_xvi_team = None + db.save_obl_results(self.teams["home"] if self.teams["home"].score > self.teams["away"].score else self.teams["away"], self.teams["home"] if self.teams["home"].score < self.teams["away"].score else self.teams["away"], xvi_team=this_xvi_team) def end_of_game_report(self): diff --git a/the_prestige.py b/the_prestige.py index 37c9646..b20a3e8 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -2112,7 +2112,9 @@ def game_over_embed(game): title_string += ".\n" winning_team = game.teams['home'].name if game.teams['home'].score > game.teams['away'].score else game.teams['away'].name - winstring = f"{game.teams['away'].score} to {game.teams['home'].score}\n" + homestring = str(game.teams["home"].score) + ("☄" if game.teams["home"].score == 16 else "") + awaystring = ("☄" if game.teams["away"].score == 16 else "") + str(game.teams["away"].score) + winstring = f"{awaystring} to {homestring}\n" if game.victory_lap and winning_team == game.teams['home'].name: winstring += f"{winning_team} wins with a victory lap!" elif winning_team == game.teams['home'].name: From a1c3bf410884add12fb6bb1415c0c9c057fd7626 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Wed, 3 Mar 2021 17:32:35 -0500 Subject: [PATCH 05/19] implemented downpour --- main_controller.py | 2 ++ weather.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/main_controller.py b/main_controller.py index b666684..f7c335a 100644 --- a/main_controller.py +++ b/main_controller.py @@ -147,6 +147,8 @@ def update_loop(): state["display_top_of_inning"] = state["top_of_inning"] + this_game.weather.modify_gamestate(this_game, state) + if state["start_delay"] <= 0: if this_game.top_of_inning != state["top_of_inning"]: state["update_pause"] = 2 diff --git a/weather.py b/weather.py index 858cf90..d2fca67 100644 --- a/weather.py +++ b/weather.py @@ -37,6 +37,9 @@ class Weather: def modify_atbat_message(self, game, state): pass + def modify_gamestate(self, game, state): + pass + class Supernova(Weather): def __init__(self, game): @@ -370,6 +373,23 @@ class Tornado(Weather): +class Downpour(Weather): + def __init__(self, game): + self.name = "Torrential Downpour" + self.emoji = '⛈' + self.target = game.max_innings + + def on_flip_inning(self, game): + high_score = game.teams["home"].score if game.teams["home"].score > game.teams["away"].score else game.teams["away"].score + if high_score >= self.target and game.teams["home"].score != game.teams["away"].score: + game.max_innings = 0 + else: + game.max_innings = game.inning + 1 + + def modify_gamestate(self, game, state): + state["max_innings"] = "∞" + + def all_weathers(): weathers_dic = { "Supernova" : Supernova, @@ -384,7 +404,8 @@ def all_weathers(): "Starlight" : Starlight, "Meteor Shower" : MeteorShower, "Hurricane" : Hurricane, - "Tornado" : Tornado + "Tornado" : Tornado, + "Torrential Downpour" : Downpour } return weathers_dic From 1e38c8c4ec0e53f4a2a6a1432b4e535d29829bd3 Mon Sep 17 00:00:00 2001 From: Genderdruid Date: Wed, 3 Mar 2021 14:39:22 -0800 Subject: [PATCH 06/19] updated weathers in the readme for the new patch --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 12cb7b4..7a187d4 100644 --- a/README.md +++ b/README.md @@ -172,8 +172,11 @@ accepting pull requests, check the issues for to-dos. - drizzle 🌧: causes each inning to start with the previous inning's final batter on second base. - heat wave 🌄: occasionally causes pitchers to be relieved by a random player from the lineup. - breezy 🎐: occasionally swaps letters of a player's name, altering their name for the remainder of the game and changing their stats. - - starlight 🌃: current patch weather, effects will be revealed the next time weathers are added. - - meteor shower 🌠: current patch weather, effects will be revealed the next time weathers are added. + - starlight 🌃: the stars are displeased with dingers and will cancel most of them out by pulling them foul. + - meteor shower 🌠: has a chance to warp runners on base to none base causing them to score. + - hurricane 🌀: current patch weather, its effects will be revealed when new weathers are added. + - tornado 🌪: current patch weather, its effects will be revealed when new weathers are added. + - torrential downpour ⛈: current patch weather, its effects will be revealed when new weathers are added. ## patreon! From f0026a4de8bf3e62bc99cd51c796ecbe5a96f02b Mon Sep 17 00:00:00 2001 From: Sakimori Date: Wed, 3 Mar 2021 17:46:15 -0500 Subject: [PATCH 07/19] finished implementing downpour --- weather.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/weather.py b/weather.py index d2fca67..60c8257 100644 --- a/weather.py +++ b/weather.py @@ -1,5 +1,4 @@ -import random -import math +import random, math, roman from gametext import appearance_outcomes, base_string class Weather: @@ -375,14 +374,15 @@ class Tornado(Weather): class Downpour(Weather): def __init__(self, game): - self.name = "Torrential Downpour" - self.emoji = '⛈' self.target = game.max_innings + self.name = f"Torrential Downpour: {roman.roman_convert(str(self.target))}" + self.emoji = '⛈' + def on_flip_inning(self, game): high_score = game.teams["home"].score if game.teams["home"].score > game.teams["away"].score else game.teams["away"].score if high_score >= self.target and game.teams["home"].score != game.teams["away"].score: - game.max_innings = 0 + game.max_innings = game.inning else: game.max_innings = game.inning + 1 From 56ffbc1888b3479fbcef08343d872d1679353596 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Wed, 3 Mar 2021 18:26:21 -0500 Subject: [PATCH 08/19] added the ability to modify game end messages on site --- main_controller.py | 2 ++ weather.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/main_controller.py b/main_controller.py index f7c335a..feb2c9f 100644 --- a/main_controller.py +++ b/main_controller.py @@ -172,6 +172,8 @@ def update_loop(): state["update_text"] = f"{winning_team} wins!" state["pitcher"] = "-" state["batter"] = "-" + + this_game.weather.modify_game_end_message(this_game, state) else: if this_game.top_of_inning: state["update_text"] = f"Top of {this_game.inning}. {this_game.teams['away'].name} batting!" diff --git a/weather.py b/weather.py index 60c8257..5a8aa67 100644 --- a/weather.py +++ b/weather.py @@ -39,6 +39,9 @@ class Weather: def modify_gamestate(self, game, state): pass + def modify_game_end_message(self, game, state): + pass + class Supernova(Weather): def __init__(self, game): @@ -388,6 +391,14 @@ class Downpour(Weather): def modify_gamestate(self, game, state): state["max_innings"] = "∞" + + def modify_top_of_inning_message(self, game, state): + state["update_emoji"] = self.emoji + state["update_text"] = "The gods are not yet pleased. Play continues through the storm." + + 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." def all_weathers(): From 2c105ccc177aae06e5b3e17fb6f75bf0273c0376 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Thu, 4 Mar 2021 15:16:03 -0500 Subject: [PATCH 09/19] renamed heavy snow to blizzard --- weather.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/weather.py b/weather.py index 5a8aa67..2750b33 100644 --- a/weather.py +++ b/weather.py @@ -109,9 +109,9 @@ class Starlight(Weather): state["update_text"] = f"The stars enjoy watching dragons play baseball, and allow {result['batter']} to hit a dinger! {game.last_update[1]} runs scored!" -class HeavySnow(Weather): +class Blizzard(Weather): def __init__(self, game): - self.name = "Heavy Snow" + self.name = "Blizzard" self.emoji = "❄" self.counter_away = random.randint(0,len(game.teams['away'].lineup)-1) self.counter_home = random.randint(0,len(game.teams['home'].lineup)-1) @@ -406,7 +406,7 @@ def all_weathers(): "Supernova" : Supernova, "Midnight": Midnight, "Slight Tailwind": SlightTailwind, - "Heavy Snow": HeavySnow, + "Blizzard": Blizzard, "Twilight" : Twilight, "Thinned Veil" : ThinnedVeil, "Heat Wave" : HeatWave, @@ -420,3 +420,6 @@ def all_weathers(): } return weathers_dic +class WeatherChains(): + light = [SlightTailwind, Twilight, Breezy, Drizzle] + disaster = [Hurricane, Tornado, Downpour, Blizzard] \ No newline at end of file From fecb8078f6bb3971b6bcda9a046c31ecb8717313 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Thu, 4 Mar 2021 15:34:30 -0500 Subject: [PATCH 10/19] implemented weather groups --- weather.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/weather.py b/weather.py index 2750b33..5da0fb4 100644 --- a/weather.py +++ b/weather.py @@ -47,6 +47,7 @@ class Supernova(Weather): def __init__(self, game): self.name = "Supernova" self.emoji = "🌟" + self.duration = random.randint(1,2) def modify_atbat_stats(self, roll): roll["pitch_stat"] *= 0.8 @@ -55,6 +56,7 @@ class Midnight(Weather): def __init__(self, game): self.name = "Midnight" self.emoji = "🕶" + self.duration = 1 def modify_steal_stats(self, roll): roll["run_stars"] *= 2 @@ -63,6 +65,7 @@ class SlightTailwind(Weather): def __init__(self, game): self.name = "Slight Tailwind" self.emoji = "🏌️‍♀️" + self.duration = random.randint(2,4) def activate(self, game, result): @@ -81,6 +84,7 @@ class Starlight(Weather): def __init__(self, game): self.name = "Starlight" self.emoji = "🌃" + self.duration = 2 def activate(self, game, result): @@ -113,6 +117,8 @@ class Blizzard(Weather): def __init__(self, game): self.name = "Blizzard" self.emoji = "❄" + self.duration = random.randint(3,6) + self.counter_away = random.randint(0,len(game.teams['away'].lineup)-1) self.counter_home = random.randint(0,len(game.teams['home'].lineup)-1) @@ -158,6 +164,7 @@ class Twilight(Weather): def __init__(self,game): self.name = "Twilight" self.emoji = "👻" + self.duration = random.randint(2,3) def modify_atbat_roll(self, outcome, roll, defender): error_line = - (math.log(defender.stlats["defense_stars"] + 1)/50) + 1 @@ -179,6 +186,7 @@ class ThinnedVeil(Weather): def __init__(self,game): self.name = "Thinned Veil" self.emoji = "🌌" + self.duration = random.randint(2,4) def activate(self, game, result): if result["ishit"]: @@ -194,6 +202,7 @@ class HeatWave(Weather): def __init__(self,game): self.name = "Heat Wave" self.emoji = "🌄" + self.duration = random.randint(3,6) self.counter_away = random.randint(2,4) self.counter_home = random.randint(2,4) @@ -236,6 +245,7 @@ class Drizzle(Weather): def __init__(self,game): self.name = "Drizzle" self.emoji = "🌧" + self.duration = random.randint(2,3) def on_flip_inning(self, game): if game.top_of_inning: @@ -261,6 +271,7 @@ class Breezy(Weather): def __init__(self, game): self.name = "Breezy" self.emoji = "🎐" + self.duration = random.randint(1,4) self.activation_chance = 0.08 def activate(self, game, result): @@ -303,6 +314,7 @@ class MeteorShower(Weather): def __init__(self, game): self.name = "Meteor Shower" self.emoji = "🌠" + self.duration = random.randint(3,6) self.activation_chance = 0.13 def activate(self, game, result): @@ -328,6 +340,8 @@ class Hurricane(Weather): def __init__(self, game): self.name = "Hurricane" self.emoji = "🌀" + self.duration = 1 + self.swaplength = random.randint(2,4) self.swapped = False @@ -348,6 +362,8 @@ class Tornado(Weather): def __init__(self, game): self.name = "Tornado" self.emoji = "🌪" + self.duration = random.randint(1,2) + self.activation_chance = 0.33 self.counter = 0 @@ -380,6 +396,7 @@ class Downpour(Weather): self.target = game.max_innings self.name = f"Torrential Downpour: {roman.roman_convert(str(self.target))}" self.emoji = '⛈' + self.duration = random.randint(2,5) def on_flip_inning(self, game): @@ -421,5 +438,8 @@ def all_weathers(): return weathers_dic class WeatherChains(): - light = [SlightTailwind, Twilight, Breezy, Drizzle] - disaster = [Hurricane, Tornado, Downpour, Blizzard] \ No newline at end of file + light = [SlightTailwind, Twilight, Breezy, Drizzle] #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, Supernova] #weathers that always happen and leave over 1-3 games + disaster = [Hurricane, Tornado, Downpour, Blizzard] #storms + aftermath = [Midnight, Starlight, MeteorShower] #calm epilogues \ No newline at end of file From 69064257ad64054b1bbff85865684821c1701835 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Thu, 4 Mar 2021 17:34:35 -0500 Subject: [PATCH 11/19] implemented weighted weather markov chain --- the_prestige.py | 4 +- weather.py | 103 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 86 insertions(+), 21 deletions(-) diff --git a/the_prestige.py b/the_prestige.py index b20a3e8..6ed8399 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -2450,5 +2450,5 @@ async def league_postseason(channel, league): league.season_reset() - -client.run(config()["token"]) +weather.WeatherChains.debug_weathers() +client.run(config()["token"]) \ No newline at end of file diff --git a/weather.py b/weather.py index 5da0fb4..b2593c0 100644 --- a/weather.py +++ b/weather.py @@ -44,15 +44,19 @@ class Weather: class Supernova(Weather): + name = "Supernova" + emoji = "🌟" + def __init__(self, game): - self.name = "Supernova" - self.emoji = "🌟" self.duration = random.randint(1,2) def modify_atbat_stats(self, roll): roll["pitch_stat"] *= 0.8 class Midnight(Weather): + name = "Midnight" + emoji = "🕶" + def __init__(self, game): self.name = "Midnight" self.emoji = "🕶" @@ -62,6 +66,9 @@ class Midnight(Weather): roll["run_stars"] *= 2 class SlightTailwind(Weather): + name = "Slight Tailwind" + emoji = "🏌️‍♀️" + def __init__(self, game): self.name = "Slight Tailwind" self.emoji = "🏌️‍♀️" @@ -81,6 +88,9 @@ class SlightTailwind(Weather): }) class Starlight(Weather): + name = "Starlight" + emoji = "🌃" + def __init__(self, game): self.name = "Starlight" self.emoji = "🌃" @@ -114,6 +124,9 @@ class Starlight(Weather): class Blizzard(Weather): + name = "Blizzard" + emoji = "❄" + def __init__(self, game): self.name = "Blizzard" self.emoji = "❄" @@ -161,9 +174,10 @@ class Blizzard(Weather): game.current_batter = bat_team.pitcher class Twilight(Weather): + name = "Twilight" + emoji = "👻" + def __init__(self,game): - self.name = "Twilight" - self.emoji = "👻" self.duration = random.randint(2,3) def modify_atbat_roll(self, outcome, roll, defender): @@ -183,9 +197,10 @@ class Twilight(Weather): state["update_text"] += f" {this_game.last_update[1]} runs scored!" class ThinnedVeil(Weather): + name = "Thinned Veil" + emoji = "🌌" + def __init__(self,game): - self.name = "Thinned Veil" - self.emoji = "🌌" self.duration = random.randint(2,4) def activate(self, game, result): @@ -199,6 +214,9 @@ class ThinnedVeil(Weather): state["update_text"] += f" {game.last_update[0]['batter']}'s will manifests on {base_string(game.last_update[1])} base." class HeatWave(Weather): + name = "Heat Wave" + emoji = "🌄" + def __init__(self,game): self.name = "Heat Wave" self.emoji = "🌄" @@ -242,9 +260,10 @@ class HeatWave(Weather): class Drizzle(Weather): + name = "Drizzle" + emoji = "🌧" + def __init__(self,game): - self.name = "Drizzle" - self.emoji = "🌧" self.duration = random.randint(2,3) def on_flip_inning(self, game): @@ -268,9 +287,10 @@ class Drizzle(Weather): state["update_text"] += f' Due to inclement weather, {placed_player.name} is placed on second base.' class Breezy(Weather): + name = "Breezy" + emoji = "🎐" + def __init__(self, game): - self.name = "Breezy" - self.emoji = "🎐" self.duration = random.randint(1,4) self.activation_chance = 0.08 @@ -311,9 +331,10 @@ class Breezy(Weather): }) class MeteorShower(Weather): + name = "Meteor Shower" + emoji = "🌠" + def __init__(self, game): - self.name = "Meteor Shower" - self.emoji = "🌠" self.duration = random.randint(3,6) self.activation_chance = 0.13 @@ -337,9 +358,10 @@ class MeteorShower(Weather): }) class Hurricane(Weather): + name = "Hurricane" + emoji = "🌀" + def __init__(self, game): - self.name = "Hurricane" - self.emoji = "🌀" self.duration = 1 self.swaplength = random.randint(2,4) @@ -359,9 +381,10 @@ class Hurricane(Weather): self.swapped = False class Tornado(Weather): + name = "Tornado" + emoji = "🌪" + def __init__(self, game): - self.name = "Tornado" - self.emoji = "🌪" self.duration = random.randint(1,2) self.activation_chance = 0.33 @@ -392,11 +415,14 @@ class Tornado(Weather): class Downpour(Weather): + name = "Torrential Downpour" + emoji = '⛈' + def __init__(self, game): self.target = game.max_innings self.name = f"Torrential Downpour: {roman.roman_convert(str(self.target))}" self.emoji = '⛈' - self.duration = random.randint(2,5) + self.duration = 1 def on_flip_inning(self, game): @@ -440,6 +466,45 @@ def all_weathers(): class WeatherChains(): light = [SlightTailwind, Twilight, Breezy, Drizzle] #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, Supernova] #weathers that always happen and leave over 1-3 games + 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 \ No newline at end of file + 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 + 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]), + Twilight : ([ThinnedVeil, Midnight, MeteorShower, SlightTailwind], [2,4,2,1]), + ThinnedVeil : (light, None), + HeatWave : ([Tornado, Hurricane, SlightTailwind, Breezy],[4,4,1,1]), + 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]), + Downpour : (aftermath, None) + } + + chains = [ + [Hurricane, Drizzle, Hurricane] + ] + + def chain_weather(weather_instance): + #weather_type = type(weather_instance) + weather_type = weather_instance + options, weight = WeatherChains.dictionary[weather_type] + return random.choices(options, weights = weight)[0] + + def debug_weathers(): + names = ["a.txt", "b.txt", "c.txt"] + for name in names: + current = random.choice(list(all_weathers().values())) + out = "" + for i in range(0,50): + out += f"{current.name} {current.emoji}\n" + current = WeatherChains.chain_weather(current) + + with open("data/"+name, "w", encoding='utf-8') as file: + file.write(out) \ No newline at end of file From 3161d67ebb7bdf73d266ce6f57757c31c09d75de Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 7 Mar 2021 12:51:17 -0500 Subject: [PATCH 12/19] adjusted weather base class to fit with its children --- weather.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/weather.py b/weather.py index b2593c0..7e4ce4c 100644 --- a/weather.py +++ b/weather.py @@ -2,9 +2,11 @@ import random, math, roman from gametext import appearance_outcomes, base_string class Weather: + self.name = "Sunny" + self.emoji = "🌞" + def __init__(self, game): - self.name = "Sunny" - self.emoji = "🌞" + pass def __str__(self): return f"{self.emoji} {self.name}" From 2e74bac6fe102dccc6da60b686d5133ea5a9f3d7 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 7 Mar 2021 12:51:39 -0500 Subject: [PATCH 13/19] oops --- weather.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weather.py b/weather.py index 7e4ce4c..55d46de 100644 --- a/weather.py +++ b/weather.py @@ -2,8 +2,8 @@ import random, math, roman from gametext import appearance_outcomes, base_string class Weather: - self.name = "Sunny" - self.emoji = "🌞" + name = "Sunny" + emoji = "🌞" def __init__(self, game): pass From 24195e9a2f759d58daebdea8bd44b3ae2d2fd5de Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 7 Mar 2021 13:14:52 -0500 Subject: [PATCH 14/19] moved duration to class attributes --- weather.py | 65 ++++++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/weather.py b/weather.py index 55d46de..b6dce32 100644 --- a/weather.py +++ b/weather.py @@ -4,6 +4,7 @@ from gametext import appearance_outcomes, base_string class Weather: name = "Sunny" emoji = "🌞" + duration_range = [3,5] def __init__(self, game): pass @@ -11,6 +12,9 @@ class Weather: def __str__(self): return f"{self.emoji} {self.name}" + def set_duration(self): + pass + def modify_atbat_stats(self, player_rolls): # Activates before batting pass @@ -48,9 +52,7 @@ class Weather: class Supernova(Weather): name = "Supernova" emoji = "🌟" - - def __init__(self, game): - self.duration = random.randint(1,2) + duration_range = [1,2] def modify_atbat_stats(self, roll): roll["pitch_stat"] *= 0.8 @@ -58,11 +60,7 @@ class Supernova(Weather): class Midnight(Weather): name = "Midnight" emoji = "🕶" - - def __init__(self, game): - self.name = "Midnight" - self.emoji = "🕶" - self.duration = 1 + duration_range = [1,1] def modify_steal_stats(self, roll): roll["run_stars"] *= 2 @@ -70,11 +68,7 @@ class Midnight(Weather): class SlightTailwind(Weather): name = "Slight Tailwind" emoji = "🏌️‍♀️" - - def __init__(self, game): - self.name = "Slight Tailwind" - self.emoji = "🏌️‍♀️" - self.duration = random.randint(2,4) + duration_range = [2,4] def activate(self, game, result): @@ -92,11 +86,7 @@ class SlightTailwind(Weather): class Starlight(Weather): name = "Starlight" emoji = "🌃" - - def __init__(self, game): - self.name = "Starlight" - self.emoji = "🌃" - self.duration = 2 + duration_range = [2,2] def activate(self, game, result): @@ -128,12 +118,9 @@ class Starlight(Weather): class Blizzard(Weather): name = "Blizzard" emoji = "❄" + duration_range = [3,6] def __init__(self, game): - self.name = "Blizzard" - self.emoji = "❄" - self.duration = random.randint(3,6) - self.counter_away = random.randint(0,len(game.teams['away'].lineup)-1) self.counter_home = random.randint(0,len(game.teams['home'].lineup)-1) @@ -178,9 +165,7 @@ class Blizzard(Weather): class Twilight(Weather): name = "Twilight" emoji = "👻" - - def __init__(self,game): - self.duration = random.randint(2,3) + duration_range = [2,3] def modify_atbat_roll(self, outcome, roll, defender): error_line = - (math.log(defender.stlats["defense_stars"] + 1)/50) + 1 @@ -201,9 +186,7 @@ class Twilight(Weather): class ThinnedVeil(Weather): name = "Thinned Veil" emoji = "🌌" - - def __init__(self,game): - self.duration = random.randint(2,4) + duration_range = [2,4] def activate(self, game, result): if result["ishit"]: @@ -218,12 +201,9 @@ class ThinnedVeil(Weather): class HeatWave(Weather): name = "Heat Wave" emoji = "🌄" + duration_range = [3,6] def __init__(self,game): - self.name = "Heat Wave" - self.emoji = "🌄" - self.duration = random.randint(3,6) - self.counter_away = random.randint(2,4) self.counter_home = random.randint(2,4) @@ -264,9 +244,7 @@ class HeatWave(Weather): class Drizzle(Weather): name = "Drizzle" emoji = "🌧" - - def __init__(self,game): - self.duration = random.randint(2,3) + duration_range = [2,3] def on_flip_inning(self, game): if game.top_of_inning: @@ -291,9 +269,9 @@ class Drizzle(Weather): class Breezy(Weather): name = "Breezy" emoji = "🎐" + duration_range = [1,4] - def __init__(self, game): - self.duration = random.randint(1,4) + def __init__(self, game): self.activation_chance = 0.08 def activate(self, game, result): @@ -335,9 +313,9 @@ class Breezy(Weather): class MeteorShower(Weather): name = "Meteor Shower" emoji = "🌠" + duration_range = [3,6] def __init__(self, game): - self.duration = random.randint(3,6) self.activation_chance = 0.13 def activate(self, game, result): @@ -362,10 +340,9 @@ class MeteorShower(Weather): class Hurricane(Weather): name = "Hurricane" emoji = "🌀" + duration_range = [1,1] def __init__(self, game): - self.duration = 1 - self.swaplength = random.randint(2,4) self.swapped = False @@ -385,10 +362,9 @@ class Hurricane(Weather): class Tornado(Weather): name = "Tornado" emoji = "🌪" + duration_range = [1,2] def __init__(self, game): - self.duration = random.randint(1,2) - self.activation_chance = 0.33 self.counter = 0 @@ -419,12 +395,12 @@ class Tornado(Weather): class Downpour(Weather): name = "Torrential Downpour" emoji = '⛈' + duration_range = [1,1] def __init__(self, game): self.target = game.max_innings self.name = f"Torrential Downpour: {roman.roman_convert(str(self.target))}" self.emoji = '⛈' - self.duration = 1 def on_flip_inning(self, game): @@ -499,6 +475,9 @@ class WeatherChains(): options, weight = WeatherChains.dictionary[weather_type] return random.choices(options, weights = weight)[0] + def starting_weather(): + return random.choice(WeatherChains.light + WeatherChains.magic) + def debug_weathers(): names = ["a.txt", "b.txt", "c.txt"] for name in names: From 16fffb4401534b9609d91368351bf3a7beb9a514 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 7 Mar 2021 14:05:28 -0500 Subject: [PATCH 15/19] implemented weather forecasts + saving --- league_storage.py | 5 +++-- leagues.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/league_storage.py b/league_storage.py index 0dcee16..1e34dd2 100644 --- a/league_storage.py +++ b/league_storage.py @@ -147,13 +147,14 @@ def save_league(league): "season" : league.season, "day" : league.day, "constraints" : league.constraints, - "schedule" : league.schedule, "game_length" : league.game_length, "series_length" : league.series_length, "games_per_hour" : league.games_per_hour, "owner" : league.owner, "champion" : league.champion, - "historic" : league.historic + "schedule" : league.schedule, + "forecasts" : league.weather_forecast, + "historic" : league.historic } with open(os.path.join(data_dir, league_dir, league.name, f"{league.name}.state"), "w") as state_file: json.dump(state_dic, state_file, indent=4) diff --git a/leagues.py b/leagues.py index f4dd135..0cfc04c 100644 --- a/leagues.py +++ b/leagues.py @@ -1,5 +1,6 @@ import time, asyncio, json, jsonpickle, random, math, os import league_storage as league_db +from weather import WeatherChains, all_weathers from itertools import chain from copy import deepcopy from games import team, game @@ -16,6 +17,7 @@ class league_structure(object): self.season = 1 self.autoplay = -1 self.champion = None + self.weather_forecast = {} 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] } } @@ -32,6 +34,9 @@ class league_structure(object): self.game_length = None self.active = False self.games_per_hour = games_per_hour + + + def season_reset(self): self.season += 1 @@ -256,6 +261,33 @@ class league_structure(object): scheduled = True day += 1 + #now do forecasts + for this_team in self.teams_in_league(): + start_weather = WeatherChains.starting_weather() #gets a random starting weather class + start_weather_duration = random.randint(start_weather.duration_range[0], start_weather.duration_range[1]) + self.weather_forecast[this_team.name] = [start_weather.name] * start_weather_duration + forecasted_days = [] + for i in range(start_weather_duration, len(self.schedule.keys())): + if i not in forecasted_days: + prev_weather = self.weather_forecast[this_team.name][i-1] #get last weather name + next_weather = WeatherChains.chain_weather(all_weathers()[prev_weather]) #ask weatherchains for next weather + next_weather_duration = random.randint(next_weather.duration_range[0], next_weather.duration_range[1]) + self.weather_forecast[this_team.name] += [next_weather.name] * next_weather_duration + forecasted_days = [n for n in range(i, i + next_weather_duration)] + + def new_weathers_midseason(self, team_name): #generate new forecast for specific team + start_weather = WeatherChains.starting_weather() #gets a random starting weather class + start_weather_duration = self.day - 1 if self.day > 1 else random.randint(start_weather.duration_range[0], start_weather.duration_range[1]) + self.weather_forecast[team_name] = [start_weather.name] * start_weather_duration + forecasted_days = [] + for i in range(start_weather_duration, len(self.schedule.keys())): + if i not in forecasted_days: + prev_weather = self.weather_forecast[team_name][i-1] #get last weather name + next_weather = WeatherChains.chain_weather(all_weathers()[prev_weather]) #ask weatherchains for next weather + next_weather_duration = random.randint(next_weather.duration_range[0], next_weather.duration_range[1]) + self.weather_forecast[team_name] += [next_weather.name] * next_weather_duration + forecasted_days = [n for n in range(i, i + next_weather_duration)] + def division_standings(self, division, standings): def sorter(team_in_list): if team_in_list[2] == 0 and team_in_list[1] == 0: @@ -579,4 +611,11 @@ def load_league_file(league_name): this_league.champion = state_dic["champion"] except: this_league.champion = None + try: + this_league.weather_forecast = state_dic["forecasts"] #handles legacy leagues + except: + this_league.weather_forecast = {} + 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) return this_league \ No newline at end of file From b9be2a481f0fb3558063da8e1ea1fee13d3a8146 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 7 Mar 2021 18:39:20 -0500 Subject: [PATCH 16/19] hooked weather forecast into league games --- leagues.py | 3 +++ the_prestige.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/leagues.py b/leagues.py index 0cfc04c..828aea5 100644 --- a/leagues.py +++ b/leagues.py @@ -465,6 +465,9 @@ class league_structure(object): this_embed.add_field(name=player_name, value=content_string, inline=False) return this_embed + def get_weather_now(self, team_name): + return all_weathers()[self.weather_forecast[team_name][self.day - 1]] + class tournament(object): def __init__(self, name, team_dic, series_length = 5, finals_series_length = 7, max_innings = 9, id = None, secs_between_games = 300, secs_between_rounds = 600): diff --git a/the_prestige.py b/the_prestige.py index 6ed8399..836a39f 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -2154,6 +2154,7 @@ async def start_league_day(channel, league, partial = False): home.set_pitcher(rotation_slot=league.day) this_game = games.game(away.finalize(), home.finalize(), length = game_length) + this_game.weather = league.get_weather_now(home.name)(this_game) this_game, state_init = prepare_game(this_game) state_init["is_league"] = True @@ -2356,6 +2357,7 @@ async def continue_league_series(league, queue, games_list, series_results, miss home_team = games.get_team(oldgame.teams["home"].name) home_team.set_pitcher(rotation_slot=league.day) this_game = games.game(away_team.finalize(), home_team.finalize(), length = league.game_length) + this_game.weather = league.get_weather_now(home_team.name)(this_game) this_game, state_init = prepare_game(this_game) state_init["is_league"] = True @@ -2449,6 +2451,4 @@ async def league_postseason(channel, league): season_save(league) league.season_reset() - -weather.WeatherChains.debug_weathers() client.run(config()["token"]) \ No newline at end of file From 4b3921695de78d991f73e328a9eb4367510bef34 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Mon, 8 Mar 2021 15:03:10 -0500 Subject: [PATCH 17/19] 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) From 0cf9d03626195cd6c11829b27bcba89abb672f87 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Mon, 8 Mar 2021 15:55:05 -0500 Subject: [PATCH 18/19] 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) From 6a1ab6f2c940c47c6f836d21844e8dd7092c0775 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Tue, 9 Mar 2021 12:52:59 -0500 Subject: [PATCH 19/19] added the uh, gametext? to the solution --- the-prestige.pyproj | 1 + 1 file changed, 1 insertion(+) diff --git a/the-prestige.pyproj b/the-prestige.pyproj index 7ad6158..515b29f 100644 --- a/the-prestige.pyproj +++ b/the-prestige.pyproj @@ -46,6 +46,7 @@ Code +