Add Literacy weather, with procedural literature types

This commit is contained in:
hillexed 2021-02-21 14:12:34 -05:00
parent a2c5d3cb0d
commit d415f658b0
3 changed files with 39 additions and 52 deletions

View file

@ -214,8 +214,8 @@ class game(object):
self.outs = 0 self.outs = 0
self.top_of_inning = True self.top_of_inning = True
self.last_update = ({},0) #this is a ({outcome}, runs) tuple self.last_update = ({},0) #this is a ({outcome}, runs) tuple
self.play_has_begun = False
self.owner = None self.owner = None
self.ready = False
self.victory_lap = False self.victory_lap = False
if length is not None: if length is not None:
self.max_innings = length self.max_innings = length
@ -653,37 +653,20 @@ class game(object):
def gamestate_update_full(self): def gamestate_update_full(self):
self.play_has_begun = True
attempts = self.thievery_attempts() attempts = self.thievery_attempts()
if attempts == False: if attempts == False:
self.last_update = self.batterup() self.last_update = self.batterup()
print(self.last_update[0]) ############# DEBUG REMOVE ME #################
else: else:
self.last_update = attempts self.last_update = attempts
return self.gamestate_display_full() return self.gamestate_display_full()
def gamestate_display_full(self): def gamestate_display_full(self):
if "steals" in self.last_update[0].keys(): if not self.over:
return "Still in progress." return "Still in progress."
else: else:
try: return f"""Game over! Final score: **{self.teams['away'].score} - {self.teams['home'].score}**"""
punc = ""
if self.last_update[0]["defender"] != "":
punc = "."
if not self.over:
if self.top_of_inning:
inningtext = "top"
else:
inningtext = "bottom"
updatestring = "this isn't used but i don't want to break anything"
return "this isn't used but i don't want to break anything"
else:
return f"""Game over! Final score: **{self.teams['away'].score} - {self.teams['home'].score}**
Last update: {self.last_update[0]['batter']} {self.last_update[0]['text'].value} {self.last_update[0]['defender']}{punc}"""
except TypeError:
return "Game not started."
except KeyError:
return "Game not started."
def add_stats(self): def add_stats(self):
players = self.get_stats() players = self.get_stats()

View file

@ -141,7 +141,7 @@ def update_loop():
state["away_score"] = this_game.teams["away"].score #top_of_inning = True state["away_score"] = this_game.teams["away"].score #top_of_inning = True
state["home_score"] = this_game.teams["home"].score #update_pause = 0 state["home_score"] = this_game.teams["home"].score #update_pause = 0
#victory_lap = False #victory_lap = False
if test_string == "Game not started.": #weather_emoji if not this_game.play_has_begun: #weather_emoji
state["update_emoji"] = "🍿" #weather_text state["update_emoji"] = "🍿" #weather_text
state["update_text"] = "Play blall!" #they also need a timestamp state["update_text"] = "Play blall!" #they also need a timestamp
state["start_delay"] -= 1 state["start_delay"] -= 1
@ -192,7 +192,11 @@ def update_loop():
state["update_emoji"] = "🌄" state["update_emoji"] = "🌄"
state["update_text"] += f' {this_game.weather.away_pitcher} is exhausted from the heat. {state["pitcher"]} is forced to pitch!' 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.": elif state["update_pause"] != 1 and this_game.play_has_begun:
if "weather_message" in this_game.last_update[0].keys():
state["update_emoji"] = this_game.weather.emoji
if "steals" in this_game.last_update[0].keys(): if "steals" in this_game.last_update[0].keys():
updatestring = "" updatestring = ""
for attempt in this_game.last_update[0]["steals"]: for attempt in this_game.last_update[0]["steals"]:
@ -207,21 +211,16 @@ def update_loop():
if this_game.last_update[0]["defender"] != "": if this_game.last_update[0]["defender"] != "":
punc = ", " punc = ", "
state["update_emoji"] = "🏌️‍♀️"
state["update_text"] = f"{this_game.last_update[0]['batter']} would have gone out, but they took a mulligan!" state["update_text"] = f"{this_game.last_update[0]['batter']} would have gone out, but they took a mulligan!"
elif "snow_atbat" in this_game.last_update[0].keys(): elif "text_only" in this_game.last_update[0].keys():
state["update_emoji"] = ""
state["update_text"] = this_game.last_update[0]["text"] state["update_text"] = this_game.last_update[0]["text"]
else: else:
updatestring = "" updatestring = ""
punc = "" punc = ""
if this_game.last_update[0]["defender"] != "": if this_game.last_update[0]["defender"] != "":
punc = ". " punc = ". "
if "fc_out" in this_game.last_update[0].keys(): if "fc_out" in this_game.last_update[0].keys():
name, out_at_base_string = this_game.last_update[0]['fc_out'] name, out_at_base_string = this_game.last_update[0]['fc_out']
updatestring = f"{this_game.last_update[0]['batter']} {this_game.last_update[0]['text'].value.format(name, out_at_base_string)} {this_game.last_update[0]['defender']}{punc}" updatestring = f"{this_game.last_update[0]['batter']} {this_game.last_update[0]['text'].value.format(name, out_at_base_string)} {this_game.last_update[0]['defender']}{punc}"
@ -233,11 +232,9 @@ def update_loop():
state["update_emoji"] = "🏏" state["update_emoji"] = "🏏"
state["update_text"] = updatestring state["update_text"] = updatestring
if "veil" in this_game.last_update[0].keys(): if "veil" in this_game.last_update[0].keys():
state["update_emoji"] = "🌌"
state["update_text"] += f" {this_game.last_update[0]['batter']}'s will manifests on {base_string(this_game.last_update[1])} base." state["update_text"] += f" {this_game.last_update[0]['batter']}'s will manifests on {base_string(this_game.last_update[1])} base."
elif "error" in this_game.last_update[0].keys(): elif "error" in this_game.last_update[0].keys():
state["update_emoji"] = "👻"
state["update_text"] = f"{this_game.last_update[0]['batter']}'s hit goes ethereal, and {this_game.last_update[0]['defender']} can't catch it! {this_game.last_update[0]['batter']} reaches base safely." state["update_text"] = f"{this_game.last_update[0]['batter']}'s hit goes ethereal, and {this_game.last_update[0]['defender']} can't catch it! {this_game.last_update[0]['batter']} reaches base safely."
if this_game.last_update[1] > 0: if this_game.last_update[1] > 0:
updatestring += f"{this_game.last_update[1]} runs scored!" updatestring += f"{this_game.last_update[1]} runs scored!"

View file

@ -65,6 +65,7 @@ class SlightTailwind(Weather):
mulligan_roll_target = -((((self.get_batter().stlats["batting_stars"])-5)/6)**2)+1 mulligan_roll_target = -((((self.get_batter().stlats["batting_stars"])-5)/6)**2)+1
if random.random() > mulligan_roll_target and self.get_batter().stlats["batting_stars"] <= 5: if random.random() > mulligan_roll_target and self.get_batter().stlats["batting_stars"] <= 5:
result["mulligan"] = True result["mulligan"] = True
result["weather_message"] = True
class HeavySnow(Weather): class HeavySnow(Weather):
def __init__(self, game): def __init__(self, game):
@ -84,9 +85,9 @@ 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,
}) })
def on_flip_inning(self, game): def on_flip_inning(self, game):
@ -111,15 +112,13 @@ class Twilight(Weather):
def __init__(self,game): def __init__(self,game):
self.name = "Twilight" self.name = "Twilight"
self.emoji = "👻" + "\uFE00" self.emoji = "👻" + "\uFE00"
def activate(self, game, result):
pass
def modify_atbat_roll(self, outcome, roll, defender): def modify_atbat_roll(self, outcome, roll, defender):
error_line = - (math.log(defender.stlats["defense_stars"] + 1)/50) + 1 error_line = - (math.log(defender.stlats["defense_stars"] + 1)/50) + 1
error_roll = random.random() error_roll = random.random()
if error_roll > error_line: if error_roll > error_line:
outcome["error"] = True outcome["error"] = True
outcome["weather_message"] = True
outcome["defender"] = defender outcome["defender"] = defender
roll["pb_system_stat"] = 0.1 roll["pb_system_stat"] = 0.1
@ -132,6 +131,7 @@ class ThinnedVeil(Weather):
if result["ishit"]: if result["ishit"]:
if result["text"] == appearance_outcomes.homerun or result["text"] == appearance_outcomes.grandslam: if result["text"] == appearance_outcomes.homerun or result["text"] == appearance_outcomes.grandslam:
result["veil"] = True result["veil"] = True
result["weather_message"] = True
class HeatWave(Weather): class HeatWave(Weather):
def __init__(self,game): def __init__(self,game):
@ -198,9 +198,10 @@ class Sun2(Weather):
class NameSwappyWeather(Weather): class NameSwappyWeather(Weather):
def __init__(self, game): def __init__(self, game):
self.name = "Literacy" self.name = "Literacy"
self.emoji = "📚"
self.activation_chance = 0.01 self.activation_chance = 0.01
def activate(self, game): def activate(self, game, result):
if random.random() < self.activation_chance: if random.random() < self.activation_chance:
teamtype = random.choice(["away","home"]) teamtype = random.choice(["away","home"])
team = game.teams[teamtype] team = game.teams[teamtype]
@ -210,32 +211,37 @@ class NameSwappyWeather(Weather):
names = player.name.split(" ") names = player.name.split(" ")
first_first_letter = names[0][0] first_first_letter = names[0][0]
last_first_letter = names[-1][0] last_first_letter = names[-1][0]
names[0][0] = last_first_letter names[0] = last_first_letter + names[0][1:]
names[-1][0] = first_first_letter names[-1] = first_first_letter + names[-1][1:]
player.name = ' '.join(names) player.name = ' '.join(names)
else: else:
#name is one word, so turn 'bartholemew' into 'martholebew' #name is one word, so turn 'bartholemew' into 'martholebew'
first_letter = player.name[0] first_letter = player.name[0]
last_letter = player.name[-1] last_letter = player.name[-1]
player.name[0] = last_letter player.name = last_letter + player.name[1:-1] + last_letter
player.name[-1] = first_letter
book_adjectives = ["action-packed", "historical", "friendly", "rude", "mystery", "thriller", "horror", "sci-fi", "fantasy", "spooky","romantic"]
book_types = ["novel","novella","poem","anthology","fan fiction","tablet","carving", "autobiography"]
book = "{} {}".format(random.choice(book_adjectives),random.choice(book_types))
result.clear() result.clear()
result.update({ result.update({
"text": "{} is Literate! {} is now {}!".format(old_player_name,old_player_name, player.name), "text": "{} stopped to read a {} and became Literate! {} is now {}!".format(old_player_name, book, old_player_name, player.name),
"text_only": True, "text_only": True,
"weather_message": True
}) })
class Feedback(Weather): class Feedback(Weather):
def __init__(self, game): def __init__(self, game):
self.name = "Feedback" self.name = "Feedback"
self.activation_chance = 0.01 self.emoji = "🎤"
self.activation_chance = 0.25
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):
if random.random() < self.activation_chance: if random.random() < self.activation_chance:
# feedback time # feedback time
result = {}
player1 = None player1 = None
player2 = None player2 = None
if random.random() < self.swap_batter_vs_pitcher_chance: if random.random() < self.swap_batter_vs_pitcher_chance:
@ -260,6 +266,7 @@ class Feedback(Weather):
result.update({ result.update({
"text": "{} and {} switched teams in the feedback!".format(player1.name,player2.name), "text": "{} and {} switched teams in the feedback!".format(player1.name,player2.name),
"text_only": True, "text_only": True,
"weather_message": True,
}) })
def all_weathers(): def all_weathers():
@ -267,14 +274,14 @@ def all_weathers():
#"Supernova" : Supernova, #"Supernova" : Supernova,
#"Midnight": Midnight, #"Midnight": Midnight,
#"Slight Tailwind": SlightTailwind, #"Slight Tailwind": SlightTailwind,
"Heavy Snow": HeavySnow, # "Heavy Snow": HeavySnow,
# "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
# Sun2, # "Sun 2": Sun2,
# Feedback, # "Feedback": Feedback,
# NameSwappyWeather, "Literacy": NameSwappyWeather,
} }
return weathers_dic return weathers_dic