4
0
Fork 0
WolfBox/scripts/test_game_manager.gd

137 lines
4.3 KiB
GDScript

extends GameManager
class_name TestGameManager
var simulations_remaining: int = 0
var simulating: bool = false
var town_wins: int = 0
var wolf_wins: int = 0
var draws: int = 0
# Suspicion behaviour:
# - Voting for someone who reveals as innocent makes you more suspicious (and vice versa)
# - Investigator results make someone 100% or 0% suspicious
# - Psychic results make someone a fair bit more (killer) or less (harmless) suspicious
# - Claiming a role that you know exists makes someone much more suspicious
# - Accusing someone of being guilty/innocent when you know the opposite makes them more suspicious
# Voting behaviour:
# - Town should vote for the most suspicious player
# - Werewolves should vote for power roles if they know them, otherwise random townspeople
# Night action behaviour:
# - Protection (doctor, bodyguard) should be prioritised to the least suspicious/most powerful
# - Murder should be targeted at enemies
# - Roleblock should target the most suspicious/most powerful
# - Other actions targeted randomly
# Communication behaviour:
func _ready() -> void:
await get_tree().create_timer(1).timeout
set_player_count(7)
func init_simulation() -> void:
$"../VBoxContainer/LogLabel".text = ""
print_line("INITIALISING SIMULATION")
for player in game_state.get_wolf_players(false):
if player.team == null:
player.team = preload("res://teams/town.tres")
if player.role == null:
player.role = preload("res://roles/townie.tres")
#player.game_reset()
game_state.game_reset()
game_state.game_in_progress = true
func start_simulating() -> void:
init_simulation()
simulating = true
func simulate_repeatedly(count: int) -> void:
town_wins = 0
wolf_wins = 0
draws = 0
simulations_remaining = count
func _process(delta: float) -> void:
if !simulating and simulations_remaining > 0:
simulations_remaining -= 1
start_simulating()
if simulating:
simulate_day()
if simulating:
simulate_night()
func next_phase() -> void:
if !game_state.game_in_progress:
init_simulation()
elif game_state.phase == GameState.GameTime.NIGHT:
simulate_day()
elif game_state.phase == GameState.GameTime.DAY:
simulate_night()
func simulate_day() -> void:
start_day()
print_line("--- DAY %d ---" % game_state.day_number)
for player in game_state.get_wolf_players():
var pb: Bot = player as Bot
pb.chatter()
force_vote()
resolve_vote()
check_endgame()
func simulate_night() -> void:
start_night()
print_line("--- NIGHT %d ---" % game_state.day_number)
force_night_actions()
resolve_night_actions()
check_endgame()
func check_endgame() -> void:
var winner: Team = check_game_won()
if winner != null:
print_line("=== %s WIN! ===" % winner.name.to_upper())
simulating = false
game_state.game_in_progress = false
if winner.name == "Town":
town_wins += 1
else:
wolf_wins += 1
elif game_state.get_wolf_players().is_empty() or game_state.day_number >= 100:
print_line("=== DRAW! ===")
simulating = false
game_state.game_in_progress = false
draws += 1
$"../VBoxContainer/Menu/WinCountLabel".text = "Town: %d - Werewolves: %d - Draws: %d" % [town_wins,wolf_wins,draws]
func set_player_count(value: float) -> void:
players.clear_all_players()
for i in range(floori(value)):
var bot: Bot = players.create_bot(i)
bot.playing = true
bot.connect("prompt_answered", _bot_answered_prompt.bind(bot))
bot.connect("alive_changed", _bot_alive_changed.bind(bot))
bot.connect("message_spoken", _bot_message_spoken.bind(bot) )
func _bot_alive_changed(alive: bool, bot: Bot) -> void:
if !alive:
var message: String = "%s is dead! They were the %s %s" % [bot.player_name, bot.team.name, bot.role.name]
print_line(message)
send_bots_message(message, null)
func _bot_message_spoken(message: String, bot: Bot) -> void:
print_line("%s says: %s" % [bot.player_name, message])
send_bots_message(message, bot)
func send_bots_message(message: String, source: Bot) -> void:
for player in game_state.get_wolf_players():
var pb: Bot = player as Bot
if pb != null and pb != source:
pb.process_message(message, source)
func _bot_answered_prompt(prompt: Prompt, answer: String, bot: Bot) -> void:
print_line("%s: \"%s\" -> %s" % [bot.player_name, prompt.format_text(), answer])
func print_line(line: String) -> void:
$"../VBoxContainer/LogLabel".text = $"../VBoxContainer/LogLabel".text + "\n" + line