2023-06-07 00:13:37 +10:00
|
|
|
class_name PlayerController
|
|
|
|
extends Node
|
2023-06-07 01:24:11 +10:00
|
|
|
|
2023-06-09 01:47:36 +10:00
|
|
|
signal workers_discarded
|
|
|
|
signal workers_kept
|
2023-06-11 02:08:09 +10:00
|
|
|
signal turn_finished
|
|
|
|
signal round_finished
|
2023-06-09 01:47:36 +10:00
|
|
|
|
2023-06-08 15:44:43 +10:00
|
|
|
var player_info
|
|
|
|
@export var hand_position: Node2D
|
2023-06-11 02:08:09 +10:00
|
|
|
@export var client_position: Vector2
|
2023-06-13 00:59:02 +10:00
|
|
|
@export var player_cam: Camera2D
|
2023-06-08 15:44:43 +10:00
|
|
|
var hand = []
|
2023-06-09 01:47:36 +10:00
|
|
|
var draft_picked = []
|
|
|
|
var draft_pick_amount = 0
|
2023-06-11 02:08:09 +10:00
|
|
|
var reputation_points = 0
|
|
|
|
var board: PlayerBoard
|
|
|
|
var current_client: Client
|
2023-06-08 15:44:43 +10:00
|
|
|
|
|
|
|
|
2023-06-09 01:47:36 +10:00
|
|
|
func draft(cards, pick):
|
|
|
|
draft_pick_amount = pick
|
2023-06-08 15:44:43 +10:00
|
|
|
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)
|
2023-06-09 01:47:36 +10:00
|
|
|
card.slide_to_position(hand_position.global_position.x + xx - 125.0, hand_position.global_position.y - 175.0, 0.0, 0.2)
|
2023-06-08 15:44:43 +10:00
|
|
|
hand.append(card)
|
2023-06-09 01:47:36 +10:00
|
|
|
card.card_clicked.connect(select_card)
|
|
|
|
|
|
|
|
|
|
|
|
func select_card(card):
|
2023-06-13 00:59:02 +10:00
|
|
|
if not is_multiplayer_authority():
|
|
|
|
return
|
2023-06-09 01:47:36 +10:00
|
|
|
if not draft_picked.has(card) and draft_picked.size() < draft_pick_amount:
|
|
|
|
draft_picked.append(card)
|
2023-06-13 00:59:02 +10:00
|
|
|
rpc("networked_select_card", true, card.get_path())
|
2023-06-09 01:47:36 +10:00
|
|
|
card.slide_to_position(card.position.x, card.position.y - 50.0, 0.0, 0.1)
|
|
|
|
elif draft_picked.has(card):
|
|
|
|
draft_picked.remove_at(draft_picked.find(card))
|
2023-06-13 00:59:02 +10:00
|
|
|
rpc("networked_select_card", false, card.get_path())
|
2023-06-09 01:47:36 +10:00
|
|
|
card.slide_to_position(card.position.x, card.position.y + 50.0, 0.0, 0.1)
|
|
|
|
|
|
|
|
|
2023-06-13 00:59:02 +10:00
|
|
|
@rpc("reliable")
|
|
|
|
func networked_select_card(add, card_path):
|
|
|
|
if add:
|
|
|
|
draft_picked.append(get_node(card_path))
|
|
|
|
else:
|
|
|
|
draft_picked.remove_at(draft_picked.find(get_node(card_path)))
|
|
|
|
|
|
|
|
|
2023-06-11 02:08:09 +10:00
|
|
|
func select_workspace(workspace):
|
2023-06-13 00:59:02 +10:00
|
|
|
if not is_multiplayer_authority():
|
|
|
|
return
|
2023-06-11 02:08:09 +10:00
|
|
|
if current_client == null:
|
|
|
|
return
|
2023-06-13 00:59:02 +10:00
|
|
|
rpc("networked_select_workspace", workspace.get_path(), current_client.get_path())
|
|
|
|
#workspace.add_client(current_client)
|
|
|
|
current_client = null
|
|
|
|
#rpc("end_turn")
|
|
|
|
|
|
|
|
|
|
|
|
func on_poor_discard_deck_clicked():
|
|
|
|
if not is_multiplayer_authority():
|
|
|
|
return
|
|
|
|
rpc("turn_away_client")
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("call_local", "reliable")
|
|
|
|
func turn_away_client():
|
|
|
|
board.poor_deck.place(current_client)
|
2023-06-11 02:08:09 +10:00
|
|
|
current_client = null
|
2023-06-13 00:59:02 +10:00
|
|
|
|
|
|
|
|
|
|
|
@rpc("call_local", "reliable")
|
|
|
|
func networked_select_workspace(workspace_path, current_client_path):
|
|
|
|
get_node(workspace_path).add_client(get_node(current_client_path))
|
2023-06-11 02:08:09 +10:00
|
|
|
|
|
|
|
|
|
|
|
@rpc("call_local", "reliable")
|
2023-06-09 01:47:36 +10:00
|
|
|
func confirm_draft():
|
|
|
|
var discarded_cards = []
|
|
|
|
var kept_cards = []
|
|
|
|
for card in hand:
|
|
|
|
if not draft_picked.has(card):
|
|
|
|
discarded_cards.append(card.get_path())
|
|
|
|
else:
|
|
|
|
kept_cards.append(card.get_path())
|
2023-06-11 02:08:09 +10:00
|
|
|
card.card_clicked.disconnect(select_card)
|
2023-06-09 01:47:36 +10:00
|
|
|
workers_discarded.emit(discarded_cards)
|
|
|
|
workers_kept.emit(kept_cards)
|
2023-06-11 02:08:09 +10:00
|
|
|
draft_picked = []
|
|
|
|
hand = []
|
|
|
|
draft_pick_amount = 0
|
|
|
|
|
|
|
|
|
|
|
|
func start_turn():
|
|
|
|
current_client = board.shift_deck.draw_card()
|
|
|
|
if current_client == null:
|
|
|
|
round_finished.emit()
|
|
|
|
return
|
|
|
|
current_client.slide_to_position(board.global_position.x, board.global_position.y, 0.0, 0.3)
|
|
|
|
current_client.turn_front()
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("call_local", "reliable")
|
|
|
|
func end_turn():
|
|
|
|
turn_finished.emit()
|