implemented Summer Mist, fixed weather messages interacting with voices

This commit is contained in:
Sakimori 2021-03-28 16:14:54 -04:00
parent f05e1eb9c2
commit 3f029b799d
3 changed files with 50 additions and 16 deletions

View file

@ -520,12 +520,7 @@ class game(object):
scores_to_add = 0 scores_to_add = 0
if "twopart" not in self.last_update[0]: if "twopart" not in self.last_update[0]:
result = self.at_bat() result = self.at_bat()
self.weather.activate(self, result) # possibly modify result in-place
if "text_only" in result:
return (result, 0)
if self.top_of_inning: if self.top_of_inning:
offense_team = self.teams["away"] offense_team = self.teams["away"]
@ -545,6 +540,7 @@ class game(object):
if "advance" in result.keys() and self.bases[3] is not None: if "advance" in result.keys() and self.bases[3] is not None:
result["outcome"] = appearance_outcomes.sacrifice result["outcome"] = appearance_outcomes.sacrifice
result["runner"] = self.bases[3].name result["runner"] = self.bases[3].name
text_list = getattr(self.voice, result["outcome"].name) text_list = getattr(self.voice, result["outcome"].name)
voice_index = random.randrange(0, len(text_list)) voice_index = random.randrange(0, len(text_list))
result["voiceindex"] = voice_index result["voiceindex"] = voice_index
@ -553,6 +549,12 @@ class game(object):
self.voice.activate(self.last_update[0], result, self) self.voice.activate(self.last_update[0], result, self)
if "twopart" not in result:
self.weather.activate(self, result) # possibly modify result in-place
if "text_only" in result:
return (result, 0)
if "twopart" in result: if "twopart" in result:
if self.voice.post_format != []: if self.voice.post_format != []:
format_list = [] format_list = []

View file

@ -231,7 +231,8 @@ def update_loop():
state["update_text"] = f"{updatestring}" state["update_text"] = f"{updatestring}"
this_game.weather.modify_atbat_message(this_game, state) if "twopart" not in this_game.last_update[0].keys():
this_game.weather.modify_atbat_message(this_game, state)
state["bases"] = this_game.named_bases() state["bases"] = this_game.named_bases()
@ -255,4 +256,4 @@ def update_loop():
socket_thread = threading.Thread(target=socketio.emit, args=("states_update", game_states)) socket_thread = threading.Thread(target=socketio.emit, args=("states_update", game_states))
socket_thread.start() socket_thread.start()
#socketio.emit("states_update", game_states) #socketio.emit("states_update", game_states)
time.sleep(1) time.sleep(8)

View file

@ -1,5 +1,5 @@
import random, math, roman import random, math, roman
from gametext import appearance_outcomes, base_string from gametext import appearance_outcomes, game_strings_base, base_string
class Weather: class Weather:
name = "Sunny" name = "Sunny"
@ -426,7 +426,36 @@ class Downpour(Weather):
def modify_game_end_message(self, game, state): def modify_game_end_message(self, game, state):
state["update_emoji"] = self.emoji state["update_emoji"] = self.emoji
state["update_text"] = f"{self.target} runs are reached, pleasing the gods. The storm clears." state["update_text"] = f"{self.target} runs are reached, pleasing the gods. The storm clears."
class SummerMist(Weather):
name = "Summer Mist"
emoji = "🌁"
duration_range = [1,3]
substances = ["yellow mustard", "cat fur", "dread", "caramel", "nacho cheese", "mud", "dirt", "justice", "a green goo", "water, probably", "antimatter", "something not of this world", "live ferrets", "snow", "leaves",
"yarn", "seaweed", "sawdust", "stardust", "code fragments", "milk", "lizards", "a large tarp", "feathers"]
def __init__(self, game):
self.missing_players = {game.teams["home"].name: None, game.teams["away"].name: None}
self.text = ""
def activate(self, game, result):
if result["outcome"] in [appearance_outcomes.flyout, appearance_outcomes.groundout, appearance_outcomes.sacrifice]:
roll = random.random()
if roll < .3: #get lost
result["mist"] = True
self.text = f" {result['batter'].name} gets lost in the mist on the way back to the dugout."
if self.missing_players[result["offense_team"].name] is not None:
self.text += f" {self.missing_players[result['offense_team'].name].name} wanders back, covered in {random.choice(self.substances)}!"
result["offense_team"].lineup[result["offense_team"].lineup_position % len(result["offense_team"].lineup)] = self.missing_players[result["offense_team"].name]
else:
result["offense_team"].lineup.pop(result["offense_team"].lineup_position % len(result["offense_team"].lineup))
self.missing_players[result["offense_team"].name] = result["batter"]
def modify_atbat_message(self, game, state):
if "mist" in game.last_update[0]:
state["update_emoji"] = self.emoji
state["update_text"] += self.text
self.text = ""
def all_weathers(): def all_weathers():
weathers_dic = { weathers_dic = {
@ -443,31 +472,33 @@ def all_weathers():
"Meteor Shower" : MeteorShower, "Meteor Shower" : MeteorShower,
"Hurricane" : Hurricane, "Hurricane" : Hurricane,
"Tornado" : Tornado, "Tornado" : Tornado,
"Torrential Downpour" : Downpour "Torrential Downpour" : Downpour,
"Summer Mist" : SummerMist
} }
return weathers_dic return weathers_dic
class WeatherChains(): class WeatherChains():
light = [SlightTailwind, Twilight, Breezy, Drizzle] #basic starting points for weather, good comfortable spots to return to light = [SlightTailwind, Twilight, Breezy, Drizzle, SummerMist] #basic starting points for weather, good comfortable spots to return to
magic = [Twilight, ThinnedVeil, MeteorShower, Starlight] #weathers involving breaking the fabric of spacetime magic = [Twilight, ThinnedVeil, MeteorShower, Starlight] #weathers involving breaking the fabric of spacetime
sudden = [Tornado, Hurricane, Twilight, Starlight, Midnight, Downpour] #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 disaster = [Hurricane, Tornado, Downpour, Blizzard] #storms
aftermath = [Midnight, Starlight, MeteorShower] #calm epilogues aftermath = [Midnight, Starlight, MeteorShower, SummerMist] #calm epilogues
dictionary = { 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]), Midnight : ([SlightTailwind, Breezy, Drizzle, Starlight, MeteorShower, HeatWave, SummerMist],[2,2,2,4,4,1,2]),
SlightTailwind : ([Breezy, Drizzle, Tornado], [3,3,1]), SlightTailwind : ([Breezy, Drizzle, Tornado], [3,3,1]),
Blizzard : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]), Blizzard : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]),
Twilight : ([ThinnedVeil, Midnight, MeteorShower, SlightTailwind], [2,4,2,1]), Twilight : ([ThinnedVeil, Midnight, MeteorShower, SlightTailwind, SummerMist], [2,4,2,1,2]),
ThinnedVeil : (light, None), ThinnedVeil : (light, None),
HeatWave : ([Tornado, Hurricane, SlightTailwind, Breezy],[4,4,1,1]), HeatWave : ([Tornado, Hurricane, SlightTailwind, Breezy, SummerMist],[4,4,1,1,2]),
Drizzle : ([Hurricane, Downpour, Blizzard],[2,2,1]), Drizzle : ([Hurricane, Downpour, Blizzard],[2,2,1]),
Breezy : ([Drizzle, HeatWave, Blizzard, Tornado], [3,3,1,1]), Breezy : ([Drizzle, HeatWave, Blizzard, Tornado], [3,3,1,1]),
Starlight : ([SlightTailwind, Twilight, Breezy, Drizzle, ThinnedVeil, HeatWave], None), Starlight : ([SlightTailwind, Twilight, Breezy, Drizzle, ThinnedVeil, HeatWave], None),
MeteorShower : ([Starlight, ThinnedVeil, HeatWave], None), MeteorShower : ([Starlight, ThinnedVeil, HeatWave], None),
Hurricane : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]), Hurricane : ([Midnight, Starlight, MeteorShower, Twilight, Downpour], [2,2,2,2,4]),
Tornado : ([Midnight, Starlight, MeteorShower, Twilight, Downpour],[2,2,2,2,4]), Tornado : ([Midnight, Starlight, MeteorShower, Twilight, Downpour],[2,2,2,2,4]),
SummerMist : ([Drizzle, Breezy, Hurricane, Downpour],[2, 1, 1, 1]),
Downpour : (aftermath, None) Downpour : (aftermath, None)
} }