Add Literacy weather, with procedural literature types
This commit is contained in:
parent
a2c5d3cb0d
commit
d415f658b0
27
games.py
27
games.py
|
@ -214,8 +214,8 @@ class game(object):
|
|||
self.outs = 0
|
||||
self.top_of_inning = True
|
||||
self.last_update = ({},0) #this is a ({outcome}, runs) tuple
|
||||
self.play_has_begun = False
|
||||
self.owner = None
|
||||
self.ready = False
|
||||
self.victory_lap = False
|
||||
if length is not None:
|
||||
self.max_innings = length
|
||||
|
@ -653,37 +653,20 @@ class game(object):
|
|||
|
||||
|
||||
def gamestate_update_full(self):
|
||||
self.play_has_begun = True
|
||||
attempts = self.thievery_attempts()
|
||||
if attempts == False:
|
||||
self.last_update = self.batterup()
|
||||
print(self.last_update[0]) ############# DEBUG REMOVE ME #################
|
||||
else:
|
||||
self.last_update = attempts
|
||||
return self.gamestate_display_full()
|
||||
|
||||
def gamestate_display_full(self):
|
||||
if "steals" in self.last_update[0].keys():
|
||||
if not self.over:
|
||||
return "Still in progress."
|
||||
else:
|
||||
try:
|
||||
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."
|
||||
return f"""Game over! Final score: **{self.teams['away'].score} - {self.teams['home'].score}**"""
|
||||
|
||||
def add_stats(self):
|
||||
players = self.get_stats()
|
||||
|
|
|
@ -141,7 +141,7 @@ def update_loop():
|
|||
state["away_score"] = this_game.teams["away"].score #top_of_inning = True
|
||||
state["home_score"] = this_game.teams["home"].score #update_pause = 0
|
||||
#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_text"] = "Play blall!" #they also need a timestamp
|
||||
state["start_delay"] -= 1
|
||||
|
@ -192,7 +192,11 @@ def update_loop():
|
|||
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.":
|
||||
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():
|
||||
updatestring = ""
|
||||
for attempt in this_game.last_update[0]["steals"]:
|
||||
|
@ -207,21 +211,16 @@ def update_loop():
|
|||
if this_game.last_update[0]["defender"] != "":
|
||||
punc = ", "
|
||||
|
||||
state["update_emoji"] = "🏌️♀️"
|
||||
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():
|
||||
state["update_emoji"] = "❄"
|
||||
elif "text_only" in this_game.last_update[0].keys():
|
||||
state["update_text"] = this_game.last_update[0]["text"]
|
||||
|
||||
else:
|
||||
updatestring = ""
|
||||
punc = ""
|
||||
if this_game.last_update[0]["defender"] != "":
|
||||
punc = ". "
|
||||
|
||||
|
||||
|
||||
if "fc_out" in this_game.last_update[0].keys():
|
||||
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}"
|
||||
|
@ -234,10 +233,8 @@ def update_loop():
|
|||
state["update_text"] = updatestring
|
||||
|
||||
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."
|
||||
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."
|
||||
if this_game.last_update[1] > 0:
|
||||
updatestring += f"{this_game.last_update[1]} runs scored!"
|
||||
|
|
45
weather.py
45
weather.py
|
@ -65,6 +65,7 @@ class SlightTailwind(Weather):
|
|||
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:
|
||||
result["mulligan"] = True
|
||||
result["weather_message"] = True
|
||||
|
||||
class HeavySnow(Weather):
|
||||
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():
|
||||
result.clear()
|
||||
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_only": True,
|
||||
"weather_message": True,
|
||||
})
|
||||
|
||||
def on_flip_inning(self, game):
|
||||
|
@ -111,15 +112,13 @@ class Twilight(Weather):
|
|||
def __init__(self,game):
|
||||
self.name = "Twilight"
|
||||
self.emoji = "👻" + "\uFE00"
|
||||
def activate(self, game, result):
|
||||
pass
|
||||
|
||||
|
||||
def modify_atbat_roll(self, outcome, roll, defender):
|
||||
error_line = - (math.log(defender.stlats["defense_stars"] + 1)/50) + 1
|
||||
error_roll = random.random()
|
||||
if error_roll > error_line:
|
||||
outcome["error"] = True
|
||||
outcome["weather_message"] = True
|
||||
outcome["defender"] = defender
|
||||
roll["pb_system_stat"] = 0.1
|
||||
|
||||
|
@ -132,6 +131,7 @@ class ThinnedVeil(Weather):
|
|||
if result["ishit"]:
|
||||
if result["text"] == appearance_outcomes.homerun or result["text"] == appearance_outcomes.grandslam:
|
||||
result["veil"] = True
|
||||
result["weather_message"] = True
|
||||
|
||||
class HeatWave(Weather):
|
||||
def __init__(self,game):
|
||||
|
@ -198,9 +198,10 @@ class Sun2(Weather):
|
|||
class NameSwappyWeather(Weather):
|
||||
def __init__(self, game):
|
||||
self.name = "Literacy"
|
||||
self.emoji = "📚"
|
||||
self.activation_chance = 0.01
|
||||
|
||||
def activate(self, game):
|
||||
def activate(self, game, result):
|
||||
if random.random() < self.activation_chance:
|
||||
teamtype = random.choice(["away","home"])
|
||||
team = game.teams[teamtype]
|
||||
|
@ -210,32 +211,37 @@ class NameSwappyWeather(Weather):
|
|||
names = player.name.split(" ")
|
||||
first_first_letter = names[0][0]
|
||||
last_first_letter = names[-1][0]
|
||||
names[0][0] = last_first_letter
|
||||
names[-1][0] = first_first_letter
|
||||
names[0] = last_first_letter + names[0][1:]
|
||||
names[-1] = first_first_letter + names[-1][1:]
|
||||
player.name = ' '.join(names)
|
||||
else:
|
||||
#name is one word, so turn 'bartholemew' into 'martholebew'
|
||||
first_letter = player.name[0]
|
||||
last_letter = player.name[-1]
|
||||
player.name[0] = last_letter
|
||||
player.name[-1] = first_letter
|
||||
player.name = last_letter + player.name[1:-1] + last_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.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,
|
||||
"weather_message": True
|
||||
})
|
||||
|
||||
|
||||
class Feedback(Weather):
|
||||
def __init__(self, game):
|
||||
self.name = "Feedback"
|
||||
self.activation_chance = 0.01
|
||||
self.emoji = "🎤"
|
||||
self.activation_chance = 0.25
|
||||
self.swap_batter_vs_pitcher_chance = 0.8
|
||||
|
||||
def activate(self, game, result):
|
||||
if random.random() < self.activation_chance:
|
||||
# feedback time
|
||||
result = {}
|
||||
player1 = None
|
||||
player2 = None
|
||||
if random.random() < self.swap_batter_vs_pitcher_chance:
|
||||
|
@ -260,6 +266,7 @@ class Feedback(Weather):
|
|||
result.update({
|
||||
"text": "{} and {} switched teams in the feedback!".format(player1.name,player2.name),
|
||||
"text_only": True,
|
||||
"weather_message": True,
|
||||
})
|
||||
|
||||
def all_weathers():
|
||||
|
@ -267,14 +274,14 @@ def all_weathers():
|
|||
#"Supernova" : Supernova,
|
||||
#"Midnight": Midnight,
|
||||
#"Slight Tailwind": SlightTailwind,
|
||||
"Heavy Snow": HeavySnow,
|
||||
# "Heavy Snow": HeavySnow,
|
||||
# "Twilight" : Twilight, # works
|
||||
# "Thinned Veil" : ThinnedVeil, # works
|
||||
"Heat Wave" : HeatWave,
|
||||
"Drizzle" : Drizzle, # works
|
||||
# Sun2,
|
||||
# Feedback,
|
||||
# NameSwappyWeather,
|
||||
"Thinned Veil" : ThinnedVeil, # works
|
||||
# "Heat Wave" : HeatWave,
|
||||
# "Drizzle" : Drizzle, # works
|
||||
# "Sun 2": Sun2,
|
||||
# "Feedback": Feedback,
|
||||
"Literacy": NameSwappyWeather,
|
||||
}
|
||||
return weathers_dic
|
||||
|
||||
|
|
Loading…
Reference in a new issue