diff --git a/PlayerBoard.gd b/PlayerBoard.gd index 868c3ee..f9220bc 100644 --- a/PlayerBoard.gd +++ b/PlayerBoard.gd @@ -4,6 +4,7 @@ extends Node2D var player_info = {} var workers = [] var roster = [] +signal clients_discarded(cards: Array[NodePath]) @export var poor_deck: Deck @export var good_deck: Deck @export var great_deck: Deck @@ -38,3 +39,52 @@ func draw_client(): var card = shift_deck.draw_card() card.slide_to_position(position.x, position.y, 0.0, 0.3) card.turn_front() + + +func process_decks() -> int: + var discards = [] + var points = 0 + for card in poor_deck.cards: + card.turn_back() + points -= 1 + for card in good_deck.cards: + card.turn_back() + points += 2 + for card in great_deck.cards: + card.turn_back() + points += 5 + poor_deck.shuffle() + good_deck.shuffle() + great_deck.shuffle() + #print("Cards in poor deck: " + str(poor_deck.cards.size())) + #print("Cards discarded from poor deck: " + str(poor_deck.cards.size() - 1)) + #print("Cards in good deck: " + str(good_deck.cards.size())) + #print("Cards discarded from good deck: " + str(ceil(good_deck.cards.size() / 2.0))) + #print("Cards in great deck: " + str(great_deck.cards.size())) + #print("Cards discarded from great deck: " + str(min(great_deck.cards.size(), 1))) + for card in poor_deck.draw_cards(poor_deck.cards.size() - 1): + discards.append(card.get_path()) + for card in good_deck.draw_cards(ceil(good_deck.cards.size() / 2.0)): + discards.append(card.get_path()) + for card in great_deck.draw_cards(min(great_deck.cards.size(), 1)): + discards.append(card.get_path()) + for card in poor_deck.draw_cards(poor_deck.cards.size()): + shift_deck.place(card) + for card in good_deck.draw_cards(good_deck.cards.size()): + shift_deck.place(card) + for card in great_deck.draw_cards(great_deck.cards.size()): + shift_deck.place(card) + clients_discarded.emit(discards) + return points + + +func time_step(skip_ahead: bool): + for x in 4: + var result : Client = slots[x].time_step(skip_ahead) + if result != null: + if result.satisfaction < result.medium_threshold: + poor_deck.place(result) + elif result.satisfaction < result.good_threshold: + good_deck.place(result) + elif result.satisfaction >= result.good_threshold: + great_deck.place(result) diff --git a/Scenes/client_card.tscn b/Scenes/client_card.tscn index 856872a..32b7491 100644 --- a/Scenes/client_card.tscn +++ b/Scenes/client_card.tscn @@ -40,8 +40,9 @@ size = Vector2(60.7945, 58.1036) [sub_resource type="RectangleShape2D" id="RectangleShape2D_70vuu"] size = Vector2(350, 250) -[node name="Card" type="Node2D"] +[node name="Card" type="Node2D" node_paths=PackedStringArray("watch")] script = ExtResource("1_bvmvn") +watch = NodePath("watch") [node name="front" type="TextureRect" parent="."] visible = false @@ -187,6 +188,14 @@ offset_right = 309.0 offset_bottom = 223.0 texture = ExtResource("6_6ba24") +[node name="ColorRect" type="ColorRect" parent="front"] +layout_mode = 0 +offset_left = 134.0 +offset_top = 211.0 +offset_right = 144.0 +offset_bottom = 221.0 +color = Color(0, 0.588235, 0.682353, 1) + [node name="Bonus1" parent="front" instance=ExtResource("7_24rgf")] visible = false position = Vector2(156, 109) @@ -277,7 +286,6 @@ texture = ExtResource("17_3rk3r") [node name="CollisionShape2D" type="CollisionShape2D" parent="watch/Area2D2"] position = Vector2(212.509, 120.249) rotation = 0.306916 -scale = Vector2(1, 1) shape = SubResource("RectangleShape2D_obgb8") [node name="Area2D3" type="Area2D" parent="watch"] @@ -285,7 +293,6 @@ shape = SubResource("RectangleShape2D_obgb8") [node name="CollisionShape2D" type="CollisionShape2D" parent="watch/Area2D3"] position = Vector2(187.897, 177.388) rotation = 0.349425 -scale = Vector2(1, 1) shape = SubResource("RectangleShape2D_055ge") [node name="Area2D4" type="Area2D" parent="watch"] diff --git a/Scenes/human_player.tscn b/Scenes/human_player.tscn index 2d0c088..400b195 100644 --- a/Scenes/human_player.tscn +++ b/Scenes/human_player.tscn @@ -221,6 +221,12 @@ size_flags_vertical = 3 [node name="LineEdit" type="LineEdit" parent="CanvasLayer/UI/VBoxContainer"] layout_mode = 2 +[node name="Reputation" type="Label" parent="CanvasLayer/UI"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "0 / 100 Reputation" + [connection signal="pressed" from="CanvasLayer/UI/Confirm" to="." method="_on_confirm_pressed"] [connection signal="pressed" from="CanvasLayer/UI/HBoxContainer/LobbyReadyButton" to="." method="_on_lobby_ready_button_pressed"] [connection signal="text_submitted" from="CanvasLayer/UI/VBoxContainer/LineEdit" to="." method="_on_line_edit_text_submitted"] diff --git a/Scenes/worker_slot.tscn b/Scenes/worker_slot.tscn index 72698b6..3911d46 100644 --- a/Scenes/worker_slot.tscn +++ b/Scenes/worker_slot.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=3 uid="uid://baoec8cqmedf6"] -[ext_resource type="Script" path="res://Scripts/worker_slot.gd" id="1_0xyh3"] +[ext_resource type="Script" path="res://Scripts/workspace.gd" id="1_0xyh3"] [ext_resource type="Texture2D" uid="uid://cpitf556hf0g" path="res://Assets/worker_slot.png" id="1_fxq0t"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_1gv0f"] diff --git a/Scripts/PlayerStateMachine/human_controller.gd b/Scripts/PlayerStateMachine/human_controller.gd index f8155da..8692465 100644 --- a/Scripts/PlayerStateMachine/human_controller.gd +++ b/Scripts/PlayerStateMachine/human_controller.gd @@ -94,9 +94,17 @@ func start_turn(): super() +func end_of_round(): + super() + $CanvasLayer/UI/Reputation.text = str(reputation_points) + " / 100 Reputation" + + func select_workspace(workspace): - super(workspace) + if not super(workspace): + return + await current_client.time_slots_selected ready_button.visible = true + current_workspace.evaluate_match() @rpc("call_local", "reliable") diff --git a/Scripts/PlayerStateMachine/player_controller.gd b/Scripts/PlayerStateMachine/player_controller.gd index 86f17a6..cc77938 100644 --- a/Scripts/PlayerStateMachine/player_controller.gd +++ b/Scripts/PlayerStateMachine/player_controller.gd @@ -16,6 +16,7 @@ var draft_pick_amount = 0 var reputation_points = 0 var board: PlayerBoard var current_client: Client +var current_workspace: Workspace func draft(cards, pick): @@ -25,7 +26,8 @@ func draft(cards, pick): 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 - 125.0, hand_position.global_position.y - 175.0, 0.0, 0.2) + var h = hand_position.global_position + card.slide_to_position(h.x + xx - 125.0, h.y - 175.0, 0.0, 0.2) hand.append(card) card.card_clicked.connect(select_card) @@ -53,18 +55,21 @@ func networked_select_card(add, card_path): func select_workspace(workspace): if not is_multiplayer_authority(): - return - if current_client == null: - return + return false + if current_client == null or workspace.worker == null: + return false + if workspace == current_workspace or workspace.client != null: + return false + if current_workspace != null: + current_workspace.remove_client() + current_workspace = workspace rpc("networked_select_workspace", workspace.get_path(), current_client.get_path()) - #workspace.add_client(current_client) current_client.show_time_selector() - current_client = null - #rpc("end_turn") + return true func on_poor_discard_deck_clicked(): - if not is_multiplayer_authority(): + if not is_multiplayer_authority() or current_client == null: return rpc("turn_away_client") @@ -72,12 +77,16 @@ func on_poor_discard_deck_clicked(): @rpc("call_local", "reliable") func turn_away_client(): board.poor_deck.place(current_client) + current_client.set_satisfaction(0) + if current_workspace != null: + current_workspace.remove_client() current_client = null @rpc("call_local", "reliable") func networked_select_workspace(workspace_path, current_client_path): get_node(workspace_path).add_client(get_node(current_client_path)) + get_node(workspace_path).evaluate_match() @rpc("call_local", "reliable") @@ -100,12 +109,23 @@ func confirm_draft(): 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() + end_of_round() + else: + current_client.slide_to_position(board.global_position.x, board.global_position.y, 0.0, 0.3) + current_client.turn_front() + + +func end_of_round(): + board.time_step(true) + reputation_points += board.process_decks() + if reputation_points < 0: + reputation_points = 0 + round_finished.emit() @rpc("call_local", "reliable") func end_turn(): + board.time_step(false) + current_client = null + current_workspace = null turn_finished.emit() diff --git a/Scripts/client.gd b/Scripts/client.gd index 5e9770a..bbbf4ef 100644 --- a/Scripts/client.gd +++ b/Scripts/client.gd @@ -19,6 +19,7 @@ var watch_on := false @export var pip_sprites: Array[TextureRect] = [] @export var time_button_sprites: Array[TextureRect] = [] @export var time_hovered_sprites: Array[TextureRect] = [] +@export var watch: TextureRect func _ready(): @@ -106,7 +107,7 @@ func setup(_title, _initial_stress, _time_slots, _services): func show_time_selector(): watch_on = true - $watch.visible = true + watch.visible = true func update_counter(): @@ -116,7 +117,7 @@ func update_counter(): func _on_turn_pressed(num): turns_left = num update_counter() - $watch.visible = false + watch.visible = false watch_on = false time_slots_selected.emit() @@ -131,6 +132,11 @@ func turn_back(): $front.visible = false +func set_satisfaction(num): + satisfaction = 1 + num + $front/ColorRect.position.x = 134 + ((satisfaction - 1) * 20.0) + + func _on_watch_segment_mouse_entered(extra_arg_0: int) -> void: if not watch_on or not time_slots[extra_arg_0]: return @@ -138,11 +144,11 @@ func _on_watch_segment_mouse_entered(extra_arg_0: int) -> void: time_hovered_sprites[x].visible = true -func _on_watch_segment_mouse_exited(extra_arg_0: int) -> void: +func _on_watch_segment_mouse_exited(_extra_arg_0: int) -> void: for sprite in time_hovered_sprites: sprite.visible = false -func _on_watch_segment_input_event(viewport: Node, event: InputEvent, shape_idx: int, extra_arg_0: int) -> void: +func _on_watch_segment_input_event(_viewport: Node, event: InputEvent, _shape_idx: int, extra_arg_0: int) -> void: if event is InputEventMouseButton and event.pressed: _on_turn_pressed(extra_arg_0 + 1) diff --git a/Scripts/deck.gd b/Scripts/deck.gd index 8d93963..c15d197 100644 --- a/Scripts/deck.gd +++ b/Scripts/deck.gd @@ -42,6 +42,18 @@ func draw_card() -> Card: return cards.pop_back() +func draw_cards(num) -> Array[Card]: + var x = 0 + var array: Array[Card] = [] + for i in range(cards.size() - 1, -1, -1): + if x == num: + break; + array.append(cards[i]) + cards.remove_at(i) + x += 1 + return array + + func place(card: Card) -> void: cards.append(card) match type: diff --git a/Scripts/game.gd b/Scripts/game.gd index b0a9560..c3315e3 100644 --- a/Scripts/game.gd +++ b/Scripts/game.gd @@ -121,6 +121,7 @@ func add_player(id: int, username: String, type: PlayerType) -> void: board.slots[2].clicked.connect(controller.select_workspace) board.slots[3].clicked.connect(controller.select_workspace) board.poor_deck.clicked.connect(controller.on_poor_discard_deck_clicked) + board.clients_discarded.connect(discard_clients) board.name = "board " + str(player_boards.size()) player_boards.append(board) players.append(controller) @@ -223,15 +224,21 @@ func discard_workers(node_paths): @rpc("call_local", "reliable") func draft_clients(player): - var cards = [] - for x in 2 + (2 * round_number): - cards.append(client_deck.draw_card()) - for x in player_boards: - if x.player_info["username"] == player: - for card in cards: - x.shift_deck.place(card) + var controller: PlayerController = null + for player_controller in players: + if player_controller.player_info["username"] == player: + controller = player_controller + var cards_to_draw = 4 + if controller.reputation_points >= 30: + cards_to_draw += 4 + if controller.reputation_points >= 60: + cards_to_draw += 4 + for x in cards_to_draw - controller.board.shift_deck.cards.size(): + controller.board.shift_deck.place(client_deck.draw_card()) @rpc("call_local", "reliable") -func discard_clients(_node_paths): - pass +func discard_clients(node_paths): + for path in node_paths: + var card = get_node(path) + client_discard.place(card) diff --git a/Scripts/worker_slot.gd b/Scripts/workspace.gd similarity index 56% rename from Scripts/worker_slot.gd rename to Scripts/workspace.gd index 449f8e0..b9caee5 100644 --- a/Scripts/worker_slot.gd +++ b/Scripts/workspace.gd @@ -25,6 +25,36 @@ func add_client(card: Client) -> bool: return true +func remove_client(): + var c = client + client = null + return c + + +func evaluate_match(): + if worker == null or client == null: + return + var points = -1 + for service in client.services: + if worker.services.has(service): + points += 1 + points += client.turns_left + client.set_satisfaction(points) + + +func time_step(skip_ahead: bool): + if worker == null or client == null: + return null + client.turns_left -= 1 + if skip_ahead: + client.turns_left = 0 + client.update_counter() + if client.turns_left > 0: + return null + else: + return remove_client() + + func _on_area2d_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: if event is InputEventMouseButton and event.pressed and worker != null: emit_signal("clicked", self)