implemented smog
This commit is contained in:
parent
f73e0590f4
commit
9959348322
24
games.py
24
games.py
|
@ -219,6 +219,7 @@ class game(object):
|
||||||
|
|
||||||
def __init__(self, team1, team2, length=None):
|
def __init__(self, team1, team2, length=None):
|
||||||
self.over = False
|
self.over = False
|
||||||
|
self.random_weather_flag = False
|
||||||
self.teams = {"away" : team1, "home" : team2}
|
self.teams = {"away" : team1, "home" : team2}
|
||||||
self.inning = 1
|
self.inning = 1
|
||||||
self.outs = 0
|
self.outs = 0
|
||||||
|
@ -693,6 +694,9 @@ class game(object):
|
||||||
|
|
||||||
self.top_of_inning = not self.top_of_inning
|
self.top_of_inning = not self.top_of_inning
|
||||||
|
|
||||||
|
if self.random_weather_flag and self.top_of_inning:
|
||||||
|
setattr(self, "weather", random.choice(list(weather.safe_weathers().values()))(self))
|
||||||
|
|
||||||
self.weather.on_flip_inning(self)
|
self.weather.on_flip_inning(self)
|
||||||
|
|
||||||
self.choose_next_batter()
|
self.choose_next_batter()
|
||||||
|
@ -701,14 +705,18 @@ class game(object):
|
||||||
self.inning += 1
|
self.inning += 1
|
||||||
if self.inning > self.max_innings and self.teams["home"].score != self.teams["away"].score: #game over
|
if self.inning > self.max_innings and self.teams["home"].score != self.teams["away"].score: #game over
|
||||||
self.over = True
|
self.over = True
|
||||||
if self.max_innings >= 9 or self.weather.name in ["Leaf Eddies", "Torrential Downpour"]:
|
try: #if something goes wrong with OBL don't erase game
|
||||||
if self.teams["home"].score == 16:
|
if self.max_innings >= 9 or self.weather.name in ["Leaf Eddies", "Torrential Downpour"]:
|
||||||
this_xvi_team = self.teams["home"]
|
if self.teams["home"].score == 16:
|
||||||
elif self.teams["away"].score == 16:
|
this_xvi_team = self.teams["home"]
|
||||||
this_xvi_team = self.teams["away"]
|
elif self.teams["away"].score == 16:
|
||||||
else:
|
this_xvi_team = self.teams["away"]
|
||||||
this_xvi_team = None
|
else:
|
||||||
db.save_obl_results(self.teams["home"] if self.teams["home"].score > self.teams["away"].score else self.teams["away"], self.teams["home"] if self.teams["home"].score < self.teams["away"].score else self.teams["away"], xvi_team=this_xvi_team)
|
this_xvi_team = None
|
||||||
|
db.save_obl_results(self.teams["home"] if self.teams["home"].score > self.teams["away"].score else self.teams["away"], self.teams["home"] if self.teams["home"].score < self.teams["away"].score else self.teams["away"], xvi_team=this_xvi_team)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def end_of_game_report(self):
|
def end_of_game_report(self):
|
||||||
|
|
|
@ -190,13 +190,17 @@ def update_loop():
|
||||||
else:
|
else:
|
||||||
if this_game.top_of_inning:
|
if this_game.top_of_inning:
|
||||||
state["update_text"] = f"Top of {this_game.inning}. {this_game.teams['away'].name} batting!"
|
state["update_text"] = f"Top of {this_game.inning}. {this_game.teams['away'].name} batting!"
|
||||||
|
this_game.weather.modify_top_of_inning_message(this_game, state)
|
||||||
|
if this_game.random_weather_flag:
|
||||||
|
this_game.weather.weather_report(this_game, state)
|
||||||
else:
|
else:
|
||||||
if this_game.inning >= this_game.max_innings:
|
if this_game.inning >= this_game.max_innings:
|
||||||
if this_game.teams["home"].score > this_game.teams["away"].score:
|
if this_game.teams["home"].score > this_game.teams["away"].score:
|
||||||
this_game.victory_lap = True
|
this_game.victory_lap = True
|
||||||
state["update_text"] = f"Bottom of {this_game.inning}. {this_game.teams['home'].name} batting!"
|
state["update_text"] = f"Bottom of {this_game.inning}. {this_game.teams['home'].name} batting!"
|
||||||
|
this_game.weather.modify_top_of_inning_message(this_game, state)
|
||||||
|
|
||||||
this_game.weather.modify_top_of_inning_message(this_game, state)
|
|
||||||
|
|
||||||
|
|
||||||
elif state["update_pause"] != 1 and this_game.play_has_begun:
|
elif state["update_pause"] != 1 and this_game.play_has_begun:
|
||||||
|
@ -256,4 +260,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(8)
|
time.sleep(3)
|
38
weather.py
38
weather.py
|
@ -57,6 +57,11 @@ class Weather:
|
||||||
def modify_game_end_message(self, game, state):
|
def modify_game_end_message(self, game, state):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def weather_report(self, game, state):
|
||||||
|
game.weather = random.choice(list(safe_weathers().values()))(game)
|
||||||
|
state["update_emoji"] = "🚌"
|
||||||
|
state["update_text"] += f" Weather report: {game.weather.name} {game.weather.emoji}"
|
||||||
|
|
||||||
|
|
||||||
class Supernova(Weather):
|
class Supernova(Weather):
|
||||||
name = "Supernova"
|
name = "Supernova"
|
||||||
|
@ -545,6 +550,18 @@ class LeafEddies(Weather):
|
||||||
if game.inning == 1:
|
if game.inning == 1:
|
||||||
state["weather_text"] = self.name
|
state["weather_text"] = self.name
|
||||||
|
|
||||||
|
class Smog(Weather):
|
||||||
|
name = "Smog"
|
||||||
|
emoji = "🚌"
|
||||||
|
duration_range = [1,1]
|
||||||
|
|
||||||
|
def __init__(self, game):
|
||||||
|
game.random_weather_flag = True
|
||||||
|
setattr(game, "weather", random.choice(list(safe_weathers().values()))(game))
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def all_weathers():
|
def all_weathers():
|
||||||
weathers_dic = {
|
weathers_dic = {
|
||||||
"Supernova" : Supernova,
|
"Supernova" : Supernova,
|
||||||
|
@ -562,7 +579,26 @@ def all_weathers():
|
||||||
"Tornado" : Tornado,
|
"Tornado" : Tornado,
|
||||||
"Torrential Downpour" : Downpour,
|
"Torrential Downpour" : Downpour,
|
||||||
"Summer Mist" : SummerMist,
|
"Summer Mist" : SummerMist,
|
||||||
"Leaf Eddies" : LeafEddies
|
"Leaf Eddies" : LeafEddies,
|
||||||
|
"Smog" : Smog
|
||||||
|
}
|
||||||
|
return weathers_dic
|
||||||
|
|
||||||
|
def safe_weathers():
|
||||||
|
"""weathers safe to swap in mid-game"""
|
||||||
|
weathers_dic = {
|
||||||
|
"Supernova" : Supernova,
|
||||||
|
"Midnight": Midnight,
|
||||||
|
"Slight Tailwind": SlightTailwind,
|
||||||
|
"Twilight" : Twilight,
|
||||||
|
"Thinned Veil" : ThinnedVeil,
|
||||||
|
"Drizzle" : Drizzle,
|
||||||
|
"Breezy": Breezy,
|
||||||
|
"Starlight" : Starlight,
|
||||||
|
"Meteor Shower" : MeteorShower,
|
||||||
|
"Hurricane" : Hurricane,
|
||||||
|
"Tornado" : Tornado,
|
||||||
|
"Summer Mist" : SummerMist
|
||||||
}
|
}
|
||||||
return weathers_dic
|
return weathers_dic
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue