bordello/Scripts/human_controller.gd

144 lines
3.5 KiB
GDScript3
Raw Normal View History

class_name HumanController
extends PlayerController
signal ready_button_pressed(int)
signal chat_message_submitted(String)
@onready var ready_button = $CanvasLayer/UI/HBoxContainer/LobbyReadyButton
@onready var ready_label = $CanvasLayer/UI/HBoxContainer/LobbyReadyLabel
@onready var canvas = $CanvasLayer
@onready var chat_box = $CanvasLayer/UI/VBoxContainer/RichTextLabel
@onready var cam_top = $CanvasLayer/UI/top_line
@onready var cam_bottom = $CanvasLayer/UI/bottom_line
@onready var cam_left = $CanvasLayer/UI/left_line
@onready var cam_right = $CanvasLayer/UI/right_line
@onready var cam_name = $CanvasLayer/UI/top_line/Label
#So this is fucked but basically starting the first round requires hitting
#the ready_self function exactly twice.
var game_started = 0
2023-06-07 01:24:11 +10:00
func _ready() -> void:
if not is_multiplayer_authority():
canvas.visible = false
2023-06-07 01:24:11 +10:00
return
$Camera2D.make_current()
func spectate_player(player_path):
var player = get_node(player_path) as PlayerController
if player.player_info["username"] == player_info["username"]:
cam_top.visible = false
cam_left.visible = false
cam_right.visible = false
cam_bottom.visible = false
else:
cam_top.visible = true
cam_left.visible = true
cam_right.visible = true
cam_bottom.visible = true
cam_name.text = player.player_info["username"]
player.player_cam.make_current()
@rpc("call_local", "reliable")
func ready_self():
ready_button_pressed.emit(player_info["id"])
2023-06-07 01:24:11 +10:00
@rpc("any_peer", "call_local", "reliable")
func update_ready_label(readied_players, total_players):
2023-06-09 01:47:36 +10:00
if readied_players == total_players:
ready_label.visible = false
ready_label.text = str(readied_players) + "/" + str(total_players)
2023-06-07 01:24:11 +10:00
func _on_lobby_ready_button_pressed() -> void:
ready_button.visible = false
if game_started < 2:
rpc("ready_self")
game_started += 1
else:
rpc("end_turn")
func on_poor_discard_deck_clicked():
super()
ready_button.visible = true
func add_chat_line(line: String) -> void:
chat_box.text += line
func _on_line_edit_text_submitted(new_text: String) -> void:
var msg = "[" + player_info["username"] + "] " + new_text + "\n"
$CanvasLayer/UI/VBoxContainer/LineEdit.text = ""
chat_message_submitted.emit(msg)
2023-06-09 01:47:36 +10:00
func select_card(card):
super(card)
if draft_picked.size() == draft_pick_amount:
$CanvasLayer/UI/Confirm.visible = true
else:
$CanvasLayer/UI/Confirm.visible = false
func _on_confirm_pressed() -> void:
$CanvasLayer/UI/Confirm.visible = false
rpc("confirm_draft")
@rpc("call_local", "reliable")
func turn_away_client():
super()
money_delta = 0
update_money()
func start_turn():
super()
@rpc("call_local", "reliable")
func end_turn():
super()
update_money()
2023-07-05 22:19:18 +10:00
func end_of_round():
super()
$CanvasLayer/UI/Reputation.text = str(reputation_points) + " / 100 Reputation"
2023-07-07 17:46:11 +10:00
game_started = 1
ready_button.visible = true
ready_label.visible = true
2023-07-05 22:19:18 +10:00
func update_money():
$CanvasLayer/UI/Cash.text = "$" + str(money)
$CanvasLayer/UI/Cash2.visible = true
$CanvasLayer/UI/Cash2.text = "$" + str(money_delta)
if money_delta == 0:
$CanvasLayer/UI/Cash2.visible = false
if money_delta > 0:
$CanvasLayer/UI/Cash2.modulate = Color(0, 1, 0)
if money_delta < 0:
$CanvasLayer/UI/Cash2.modulate = Color(1, 0, 0)
func select_workspace(workspace):
2023-07-05 22:19:18 +10:00
if not super(workspace):
return
await current_client.time_slots_selected
ready_button.visible = true
2023-07-05 22:19:18 +10:00
current_workspace.evaluate_match()
money_delta = current_workspace.evaluate_revenue()
update_money()
@rpc("call_local", "reliable")
func confirm_draft():
super()
ready_button.visible = true