Implement Feedback weather

This commit is contained in:
hillexed 2021-02-21 14:56:27 -05:00
parent d415f658b0
commit f021cb4ea4

View file

@ -85,6 +85,7 @@ class HeavySnow(Weather):
if weather_count == offense_team.lineup_position and "snow_atbat" not in game.last_update[0].keys(): if weather_count == offense_team.lineup_position and "snow_atbat" not in game.last_update[0].keys():
result.clear() result.clear()
result.update({ result.update({
"snow_atbat": True,
"text": f"{offense_team.lineup[offense_team.lineup_position % len(offense_team.lineup)].name}'s hands are too cold! {game.get_batter().name} is forced to bat!", "text": f"{offense_team.lineup[offense_team.lineup_position % len(offense_team.lineup)].name}'s hands are too cold! {game.get_batter().name} is forced to bat!",
"text_only": True, "text_only": True,
"weather_message": True, "weather_message": True,
@ -152,7 +153,7 @@ class HeatWave(Weather):
should_change_pitcher = False should_change_pitcher = False
if game.inning >= counter: if game.inning >= counter:
change_pitcher = True should_change_pitcher = True
if game.top_of_inning: if game.top_of_inning:
self.counter_home = self.counter_home - (self.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 self.counter_home = self.counter_home - (self.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
else: else:
@ -236,7 +237,7 @@ class Feedback(Weather):
def __init__(self, game): def __init__(self, game):
self.name = "Feedback" self.name = "Feedback"
self.emoji = "🎤" self.emoji = "🎤"
self.activation_chance = 0.25 self.activation_chance = 0.02
self.swap_batter_vs_pitcher_chance = 0.8 self.swap_batter_vs_pitcher_chance = 0.8
def activate(self, game, result): def activate(self, game, result):
@ -244,23 +245,28 @@ class Feedback(Weather):
# feedback time # feedback time
player1 = None player1 = None
player2 = None player2 = None
team1 = game.teams["home"]
team2 = game.teams["away"]
if random.random() < self.swap_batter_vs_pitcher_chance: if random.random() < self.swap_batter_vs_pitcher_chance:
# swapping batters # swapping batters
# theoretically this could swap players already on base :( # theoretically this could swap players already on base :(
homePlayerIndex = random.randint(len(teams["home"].lineup)) team1 = game.teams["home"]
awayPlayerIndex = random.randint(len(teams["away"].lineup)) team2 = game.teams["away"]
homePlayerIndex = random.randint(0,len(team1.lineup)-1)
awayPlayerIndex = random.randint(0,len(team2.lineup)-1)
homePlayer = teams["home"].lineup[homePlayerIndex] player1 = team1.lineup[homePlayerIndex]
awayPlayer = teams["away"].lineup[awayPlayerIndex] player2 = team2.lineup[awayPlayerIndex]
teams["home"].lineup[homePlayerIndex] = awayPlayer team1.lineup[homePlayerIndex] = player2
teams["away"].lineup[awayPlayerIndex] = homePlayer team2.lineup[awayPlayerIndex] = player1
else: else:
# swapping pitchers # swapping pitchers
player1 = teams["home"].pitcher player1 = team1.pitcher
player2 = teams["away"].pitcher player2 = team2.pitcher
teams["home"].set_pitcher(player2)
teams["away"].set_pitcher(player1) team1.pitcher = player2
team2.pitcher = player1
result.clear() result.clear()
result.update({ result.update({
@ -274,13 +280,13 @@ def all_weathers():
#"Supernova" : Supernova, #"Supernova" : Supernova,
#"Midnight": Midnight, #"Midnight": Midnight,
#"Slight Tailwind": SlightTailwind, #"Slight Tailwind": SlightTailwind,
# "Heavy Snow": HeavySnow, "Heavy Snow": HeavySnow, # works
# "Twilight" : Twilight, # works "Twilight" : Twilight, # works
"Thinned Veil" : ThinnedVeil, # works "Thinned Veil" : ThinnedVeil, # works
# "Heat Wave" : HeatWave, "Heat Wave" : HeatWave,
# "Drizzle" : Drizzle, # works "Drizzle" : Drizzle, # works
# "Sun 2": Sun2, # "Sun 2": Sun2,
# "Feedback": Feedback, "Feedback": Feedback,
"Literacy": NameSwappyWeather, "Literacy": NameSwappyWeather,
} }
return weathers_dic return weathers_dic