shuffle sync works, chat boxes work, initial hand draw works, players cant share a username
This commit is contained in:
@ -1,2 +1,4 @@
|
||||
class_name BotController
|
||||
extends PlayerController
|
||||
|
||||
|
||||
|
@ -1,25 +1,42 @@
|
||||
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
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
canvas.visible = false
|
||||
return
|
||||
$Camera2D.make_current()
|
||||
$UI.visible = true
|
||||
|
||||
|
||||
@rpc("call_local")
|
||||
func ready_player():
|
||||
game.ready_player(own_id)
|
||||
func ready_self():
|
||||
ready_button_pressed.emit(player_info["id"])
|
||||
|
||||
|
||||
@rpc("any_peer")
|
||||
func update_ready_label():
|
||||
$UI/LobbyReadyLabel.text = str(game.readied_players.size()) + "/" + str(game.players.size())
|
||||
func update_ready_label(readied_players, total_players):
|
||||
ready_label.text = str(readied_players) + "/" + str(total_players)
|
||||
|
||||
|
||||
func _on_lobby_ready_button_pressed() -> void:
|
||||
rpc("ready_player")
|
||||
$UI/LobbyReadyButton.visible = false
|
||||
update_ready_label()
|
||||
rpc("ready_self")
|
||||
ready_button.visible = false
|
||||
|
||||
|
||||
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)
|
||||
|
@ -1,6 +1,16 @@
|
||||
class_name PlayerController
|
||||
extends Node
|
||||
|
||||
var game: Game
|
||||
var board: PlayerBoard
|
||||
var own_id: int
|
||||
var player_info
|
||||
@export var hand_position: Node2D
|
||||
var hand = []
|
||||
|
||||
|
||||
func draft(cards, _pick):
|
||||
var xxx = (250.0 * cards.size()) / 2.0
|
||||
for x in cards.size():
|
||||
var card = cards[x]
|
||||
var ratio = float(x) / float(cards.size() - 1)
|
||||
var xx = lerpf(-1 * xxx, xxx, ratio)
|
||||
card.slide_to_position(hand_position.global_position.x + xx, hand_position.global_position.y, 0.0, 0.2)
|
||||
hand.append(card)
|
||||
|
@ -36,7 +36,7 @@ func _on_area_2d_mouse_exited() -> void:
|
||||
mouse_exited.emit()
|
||||
|
||||
|
||||
func draw() -> Card:
|
||||
func draw_card() -> Card:
|
||||
return cards.pop_back()
|
||||
|
||||
|
||||
@ -51,3 +51,9 @@ func place(card: Card) -> void:
|
||||
|
||||
func shuffle() -> void:
|
||||
cards.shuffle()
|
||||
|
||||
|
||||
func order(node_paths) -> void:
|
||||
cards = []
|
||||
for path in node_paths:
|
||||
cards.append(get_node(path))
|
||||
|
@ -21,8 +21,9 @@ const CLIENT_DECK_SAVE_PATH = "user://client_deck.json"
|
||||
@export var seat4: Node2D
|
||||
|
||||
var networked_controllers: Array[HumanController] = []
|
||||
var players = []
|
||||
var readied_players = []
|
||||
var current_player := 0
|
||||
var players: Array[PlayerController] = []
|
||||
var readied_players: Array[int] = []
|
||||
|
||||
var _worker_scene = preload("res://Scenes/worker_card.tscn")
|
||||
var _client_scene = preload("res://Scenes/client_card.tscn")
|
||||
@ -96,17 +97,30 @@ func add_player(id: int, username: String, type: PlayerType) -> void:
|
||||
PlayerType.HUMAN:
|
||||
controller = _human_scene.instantiate()
|
||||
networked_controllers.append(controller)
|
||||
controller.ready_button_pressed.connect(ready_player)
|
||||
controller.chat_message_submitted.connect(message)
|
||||
var player_info = {}
|
||||
player_info["id"] = id
|
||||
player_info["username"] = username
|
||||
controller.player_info = player_info
|
||||
PlayerType.BOT:
|
||||
controller = _bot_scene.instantiate()
|
||||
controller.name = str(id)
|
||||
controller.set_multiplayer_authority(id)
|
||||
controller.own_id = id
|
||||
controller.game = self as Game
|
||||
controller.board = board as PlayerBoard
|
||||
board.add_child(controller)
|
||||
players.append(id)
|
||||
players.append(controller)
|
||||
for player in networked_controllers:
|
||||
player.rpc("update_ready_label")
|
||||
player.rpc("update_ready_label", readied_players.size(), players.size())
|
||||
|
||||
|
||||
@rpc("call_local", "any_peer") #called from message() by player signals
|
||||
func relay_chat_message(msg):
|
||||
for player in networked_controllers:
|
||||
player.add_chat_line(msg)
|
||||
|
||||
|
||||
func message(msg):
|
||||
rpc("relay_chat_message", msg)
|
||||
|
||||
|
||||
func ready_player(id):
|
||||
@ -115,8 +129,40 @@ func ready_player(id):
|
||||
if readied_players.size() == players.size():
|
||||
start_game()
|
||||
for player in networked_controllers:
|
||||
player.rpc("update_ready_label")
|
||||
player.rpc("update_ready_label", readied_players.size(), players.size())
|
||||
|
||||
|
||||
func start_game():
|
||||
print("Game started!")
|
||||
#Only the host should shuffle the decks
|
||||
if is_multiplayer_authority():
|
||||
randomize()
|
||||
var deck_order = []
|
||||
for card in worker_deck.cards:
|
||||
deck_order.append(card.get_path())
|
||||
rpc("send_worker_order", deck_order)
|
||||
deck_order = []
|
||||
for card in client_deck.cards:
|
||||
deck_order.append(card.get_path())
|
||||
rpc("send_client_order", deck_order)
|
||||
for player in players:
|
||||
rpc("draft_workers", player.player_info["username"], 4, 2)
|
||||
|
||||
|
||||
@rpc
|
||||
func send_worker_order(node_paths):
|
||||
worker_deck.order(node_paths)
|
||||
|
||||
|
||||
@rpc
|
||||
func send_client_order(node_paths):
|
||||
client_deck.order(node_paths)
|
||||
|
||||
|
||||
@rpc("call_local")
|
||||
func draft_workers(player, draw_amount, pick_amount):
|
||||
var cards = []
|
||||
for x in draw_amount:
|
||||
cards.append(worker_deck.draw_card())
|
||||
for x in players:
|
||||
if x.player_info["username"] == player:
|
||||
x.draft(cards, pick_amount)
|
||||
|
@ -15,7 +15,6 @@ var players_connected = 0
|
||||
|
||||
func _ready() -> void:
|
||||
game = game_scene.instantiate() as Game
|
||||
|
||||
|
||||
|
||||
func host_server() -> void:
|
||||
@ -28,12 +27,10 @@ func host_server() -> void:
|
||||
|
||||
player_info[1] = $UI/Username.text
|
||||
add_player(1, player_info[1])
|
||||
game.get_node("LobbyCamera/LineEdit").text_submitted.connect(text_message)
|
||||
|
||||
multiplayer.peer_connected.connect(
|
||||
func(new_peer_id):
|
||||
rpc_id(new_peer_id, "add_previous_players", connected_players)
|
||||
#rpc("add_new_player", new_peer_id)
|
||||
)
|
||||
|
||||
|
||||
@ -48,6 +45,7 @@ func connect_to_server() -> void:
|
||||
add_child(game)
|
||||
player_info[multiplayer.get_unique_id()] = $UI/Username.text
|
||||
|
||||
|
||||
func add_player(peer_id, username):
|
||||
connected_players[peer_id] = username
|
||||
game.add_player(peer_id, username, game.PlayerType.HUMAN)
|
||||
@ -58,15 +56,11 @@ func add_new_player(peer_id, username):
|
||||
add_player(peer_id, username)
|
||||
|
||||
|
||||
func text_message(new_text):
|
||||
game.get_node("LobbyCamera/RichTextLabel").rpc("add_line", player_info[multiplayer.get_unique_id()], new_text)
|
||||
game.get_node("LobbyCamera/LineEdit").text = ""
|
||||
|
||||
|
||||
@rpc
|
||||
func add_previous_players(players):
|
||||
for key in players:
|
||||
if players[key] == player_info[multiplayer.get_unique_id()]:
|
||||
player_info[multiplayer.get_unique_id()] += "_"
|
||||
add_player(key, players[key])
|
||||
rpc_id(key, "add_new_player", multiplayer.get_unique_id(), player_info[multiplayer.get_unique_id()])
|
||||
add_player(multiplayer.get_unique_id(), player_info[multiplayer.get_unique_id()])
|
||||
game.get_node("LobbyCamera/LineEdit").text_submitted.connect(text_message)
|
||||
|
@ -168,22 +168,6 @@ func select_slot(slot):
|
||||
selected_worker.slide_to_position(slot.position.x, slot.position.y, 0.0, 0.3)
|
||||
selected_worker = null
|
||||
|
||||
#Shift Phase
|
||||
#1. Swap 1 time token on each worker over to the stress side
|
||||
#2. Pick up the next client card in the deck, and either assign it to
|
||||
# a worker or place it in the no service pile
|
||||
#3. If a worker both has no client, and at least one stress token, remove
|
||||
# a stress token
|
||||
|
||||
#Management Phase
|
||||
#Market Research
|
||||
#Look at the 10 clients, and place them back in the same order
|
||||
#Targeted Advertising
|
||||
#Search through the client discard deck, and add all clients
|
||||
#with one extra type to your shift deck
|
||||
#Roster Worker
|
||||
#Add 1 worker from your hand into the next open slot on your board
|
||||
|
||||
|
||||
func _on_area_2d_input_event(_viewport, event, _shape_idx):
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
|
Reference in New Issue
Block a user