diff --git a/games.py b/games.py index 02ec27e..0773eb8 100644 --- a/games.py +++ b/games.py @@ -191,7 +191,7 @@ class team(object): def set_pitcher(self, rotation_slot = None, use_lineup = False): temp_rotation = self.rotation.copy() if use_lineup: - for batter in self.rotation: + for batter in self.lineup: temp_rotation.append(batter) if rotation_slot is None: self.pitcher = random.choice(temp_rotation) @@ -638,6 +638,25 @@ class game(object): offense_team.lineup_position += 1 #put next batter up if self.outs >= 3: self.flip_inning() + if self.weather.name == "Heat Wave": + if self.top_of_inning: + self.weather.home_pitcher = self.get_pitcher() + if self.inning >= self.weather.counter_home: + self.weather.counter_home = self.weather.counter_home - (self.weather.counter_home % 5) + 5 + random.randint(1,4) #rounds down to last 5, adds up to next 5. then adds a random number 2<=x<=5 to determine next pitcher + tries = 0 + while self.get_pitcher() == self.weather.home_pitcher and tries < 3: + self.teams["home"].set_pitcher(use_lineup = True) + tries += 1 + + + else: + self.weather.away_pitcher = self.get_pitcher() + if self.inning >= self.weather.counter_away: + self.weather.counter_away = self.weather.counter_away - (self.weather.counter_away % 5) + 5 + random.randint(1,4) + tries = 0 + while self.get_pitcher() == self.weather.away_pitcher and tries < 3: + self.teams["away"].set_pitcher(use_lineup = True) + tries += 1 return (result, scores_to_add) #returns ab information and scores diff --git a/league_storage.py b/league_storage.py index 183003e..a6a5a37 100644 --- a/league_storage.py +++ b/league_storage.py @@ -168,6 +168,13 @@ def season_save(league): if "." in item.name: os.rename(os.path.join(data_dir, league_dir, league.name, item.name), os.path.join(new_dir, item.name)) +def season_restart(league): + if league_exists(league.name): + with os.scandir(os.path.join(data_dir, league_dir, league.name)) as folder: + for item in folder: + if "." in item.name: + os.remove(os.path.join(data_dir, league_dir, league.name, item.name)) + def get_past_standings(league_name, season_num): if league_exists(league_name): with os.scandir(os.path.join(data_dir, league_dir, league_name)) as folder: diff --git a/main_controller.py b/main_controller.py index 2dc824d..176c28f 100644 --- a/main_controller.py +++ b/main_controller.py @@ -175,6 +175,10 @@ def update_loop(): if this_game.weather.name == "Drizzle": state["update_emoji"] = "🌧" state["update_text"] += f' Due to inclement weather, {this_game.teams["away"].lineup[(this_game.teams["away"].lineup_position-1) % len(this_game.teams["away"].lineup)].name} is placed on second base.' + elif this_game.weather.name == "Heat Wave" and hasattr(this_game.weather, "home_pitcher") and this_game.weather.home_pitcher.name != state["pitcher"]: + state["update_emoji"] = "🌄" + state["update_text"] += f' {this_game.weather.home_pitcher} is exhausted from the heat. {state["pitcher"]} is forced to pitch!' + else: if this_game.inning >= this_game.max_innings: if this_game.teams["home"].score > this_game.teams["away"].score: @@ -183,6 +187,9 @@ def update_loop(): if this_game.weather.name == "Drizzle": state["update_emoji"] = "🌧" state["update_text"] += f' Due to inclement weather, {this_game.teams["home"].lineup[(this_game.teams["home"].lineup_position-1) % len(this_game.teams["home"].lineup)].name} is placed on second base.' + elif this_game.weather.name == "Heat Wave" and hasattr(this_game.weather, "away_pitcher") and this_game.weather.away_pitcher.name != state["pitcher"]: + state["update_emoji"] = "🌄" + state["update_text"] += f' {this_game.weather.away_pitcher} is exhausted from the heat. {state["pitcher"]} is forced to pitch!' elif state["update_pause"] != 1 and test_string != "Game not started.": if "steals" in this_game.last_update[0].keys(): diff --git a/the_prestige.py b/the_prestige.py index fe1c37f..aa69409 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -1,7 +1,7 @@ import discord, json, math, os, roman, games, asyncio, random, main_controller, threading, time, urllib, leagues, datetime import database as db import onomancer as ono -from league_storage import league_exists, season_save +from league_storage import league_exists, season_save, season_restart from the_draft import Draft, DRAFT_ROUNDS from flask import Flask from uuid import uuid4 @@ -1045,6 +1045,19 @@ class LeagueTeamScheduleCommand(Command): else: await msg.channel.send("We can't find that league. Typo?") +class LeagueRegenerateScheduleCommand(Command): + name = "leagueseasonreset" + template = "m;leagueseasonreset [league name]" + description = "Completely scraps the given league's current season, resetting everything to day 1 of the current season. Requires ownership." + + async def execute(self, msg, command): + league_name = command.split("\n")[0].strip() + if league_exists(league_name): + league = leagues.load_league_file(league_name) + if (league.owner is not None and msg.author.id in league.owner) or (league.owner is not None and msg.author.id in config()["owners"]): + season_restart(league) + league.season -= 1 + league.season_reset() commands = [ IntroduceCommand(), @@ -1077,6 +1090,7 @@ commands = [ LeagueWildcardCommand(), LeagueScheduleCommand(), LeagueTeamScheduleCommand(), + LeagueRegenerateScheduleCommand(), CreditCommand(), RomanCommand(), HelpCommand(), @@ -1344,6 +1358,9 @@ def prepare_game(newgame, league = None, weather_name = None): if newgame.weather.name == "Heavy Snow": newgame.weather.counter_away = random.randint(0,len(newgame.teams['away'].lineup)-1) newgame.weather.counter_home = random.randint(0,len(newgame.teams['home'].lineup)-1) + elif newgame.weather.name == "Heat Wave": + newgame.weather.counter_away = random.randint(2,4) + newgame.weather.counter_home = random.randint(2,4) return newgame, state_init async def start_tournament_round(channel, tourney, seeding = None):