cards go to the right discard piles

This commit is contained in:
Lexi Quinn 2023-07-05 22:19:18 +10:00
parent c506b5c55f
commit b7d2ff0dfe
10 changed files with 176 additions and 30 deletions

View File

@ -4,6 +4,7 @@ extends Node2D
var player_info = {} var player_info = {}
var workers = [] var workers = []
var roster = [] var roster = []
signal clients_discarded(cards: Array[NodePath])
@export var poor_deck: Deck @export var poor_deck: Deck
@export var good_deck: Deck @export var good_deck: Deck
@export var great_deck: Deck @export var great_deck: Deck
@ -38,3 +39,52 @@ func draw_client():
var card = shift_deck.draw_card() var card = shift_deck.draw_card()
card.slide_to_position(position.x, position.y, 0.0, 0.3) card.slide_to_position(position.x, position.y, 0.0, 0.3)
card.turn_front() 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)

View File

@ -40,8 +40,9 @@ size = Vector2(60.7945, 58.1036)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_70vuu"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_70vuu"]
size = Vector2(350, 250) size = Vector2(350, 250)
[node name="Card" type="Node2D"] [node name="Card" type="Node2D" node_paths=PackedStringArray("watch")]
script = ExtResource("1_bvmvn") script = ExtResource("1_bvmvn")
watch = NodePath("watch")
[node name="front" type="TextureRect" parent="."] [node name="front" type="TextureRect" parent="."]
visible = false visible = false
@ -187,6 +188,14 @@ offset_right = 309.0
offset_bottom = 223.0 offset_bottom = 223.0
texture = ExtResource("6_6ba24") 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")] [node name="Bonus1" parent="front" instance=ExtResource("7_24rgf")]
visible = false visible = false
position = Vector2(156, 109) position = Vector2(156, 109)
@ -277,7 +286,6 @@ texture = ExtResource("17_3rk3r")
[node name="CollisionShape2D" type="CollisionShape2D" parent="watch/Area2D2"] [node name="CollisionShape2D" type="CollisionShape2D" parent="watch/Area2D2"]
position = Vector2(212.509, 120.249) position = Vector2(212.509, 120.249)
rotation = 0.306916 rotation = 0.306916
scale = Vector2(1, 1)
shape = SubResource("RectangleShape2D_obgb8") shape = SubResource("RectangleShape2D_obgb8")
[node name="Area2D3" type="Area2D" parent="watch"] [node name="Area2D3" type="Area2D" parent="watch"]
@ -285,7 +293,6 @@ shape = SubResource("RectangleShape2D_obgb8")
[node name="CollisionShape2D" type="CollisionShape2D" parent="watch/Area2D3"] [node name="CollisionShape2D" type="CollisionShape2D" parent="watch/Area2D3"]
position = Vector2(187.897, 177.388) position = Vector2(187.897, 177.388)
rotation = 0.349425 rotation = 0.349425
scale = Vector2(1, 1)
shape = SubResource("RectangleShape2D_055ge") shape = SubResource("RectangleShape2D_055ge")
[node name="Area2D4" type="Area2D" parent="watch"] [node name="Area2D4" type="Area2D" parent="watch"]

View File

@ -221,6 +221,12 @@ size_flags_vertical = 3
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/UI/VBoxContainer"] [node name="LineEdit" type="LineEdit" parent="CanvasLayer/UI/VBoxContainer"]
layout_mode = 2 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/Confirm" to="." method="_on_confirm_pressed"]
[connection signal="pressed" from="CanvasLayer/UI/HBoxContainer/LobbyReadyButton" to="." method="_on_lobby_ready_button_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"] [connection signal="text_submitted" from="CanvasLayer/UI/VBoxContainer/LineEdit" to="." method="_on_line_edit_text_submitted"]

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=5 format=3 uid="uid://baoec8cqmedf6"] [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"] [ext_resource type="Texture2D" uid="uid://cpitf556hf0g" path="res://Assets/worker_slot.png" id="1_fxq0t"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1gv0f"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_1gv0f"]

View File

@ -94,9 +94,17 @@ func start_turn():
super() super()
func end_of_round():
super()
$CanvasLayer/UI/Reputation.text = str(reputation_points) + " / 100 Reputation"
func select_workspace(workspace): func select_workspace(workspace):
super(workspace) if not super(workspace):
return
await current_client.time_slots_selected
ready_button.visible = true ready_button.visible = true
current_workspace.evaluate_match()
@rpc("call_local", "reliable") @rpc("call_local", "reliable")

View File

@ -16,6 +16,7 @@ var draft_pick_amount = 0
var reputation_points = 0 var reputation_points = 0
var board: PlayerBoard var board: PlayerBoard
var current_client: Client var current_client: Client
var current_workspace: Workspace
func draft(cards, pick): func draft(cards, pick):
@ -25,7 +26,8 @@ func draft(cards, pick):
var card = cards[x] var card = cards[x]
var ratio = float(x) / float(cards.size() - 1) var ratio = float(x) / float(cards.size() - 1)
var xx = lerpf(-1 * xxx, xxx, ratio) 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) hand.append(card)
card.card_clicked.connect(select_card) card.card_clicked.connect(select_card)
@ -53,18 +55,21 @@ func networked_select_card(add, card_path):
func select_workspace(workspace): func select_workspace(workspace):
if not is_multiplayer_authority(): if not is_multiplayer_authority():
return return false
if current_client == null: if current_client == null or workspace.worker == null:
return 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()) rpc("networked_select_workspace", workspace.get_path(), current_client.get_path())
#workspace.add_client(current_client)
current_client.show_time_selector() current_client.show_time_selector()
current_client = null return true
#rpc("end_turn")
func on_poor_discard_deck_clicked(): func on_poor_discard_deck_clicked():
if not is_multiplayer_authority(): if not is_multiplayer_authority() or current_client == null:
return return
rpc("turn_away_client") rpc("turn_away_client")
@ -72,12 +77,16 @@ func on_poor_discard_deck_clicked():
@rpc("call_local", "reliable") @rpc("call_local", "reliable")
func turn_away_client(): func turn_away_client():
board.poor_deck.place(current_client) board.poor_deck.place(current_client)
current_client.set_satisfaction(0)
if current_workspace != null:
current_workspace.remove_client()
current_client = null current_client = null
@rpc("call_local", "reliable") @rpc("call_local", "reliable")
func networked_select_workspace(workspace_path, current_client_path): func networked_select_workspace(workspace_path, current_client_path):
get_node(workspace_path).add_client(get_node(current_client_path)) get_node(workspace_path).add_client(get_node(current_client_path))
get_node(workspace_path).evaluate_match()
@rpc("call_local", "reliable") @rpc("call_local", "reliable")
@ -100,12 +109,23 @@ func confirm_draft():
func start_turn(): func start_turn():
current_client = board.shift_deck.draw_card() current_client = board.shift_deck.draw_card()
if current_client == null: if current_client == null:
round_finished.emit() end_of_round()
return else:
current_client.slide_to_position(board.global_position.x, board.global_position.y, 0.0, 0.3) current_client.slide_to_position(board.global_position.x, board.global_position.y, 0.0, 0.3)
current_client.turn_front() 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") @rpc("call_local", "reliable")
func end_turn(): func end_turn():
board.time_step(false)
current_client = null
current_workspace = null
turn_finished.emit() turn_finished.emit()

View File

@ -19,6 +19,7 @@ var watch_on := false
@export var pip_sprites: Array[TextureRect] = [] @export var pip_sprites: Array[TextureRect] = []
@export var time_button_sprites: Array[TextureRect] = [] @export var time_button_sprites: Array[TextureRect] = []
@export var time_hovered_sprites: Array[TextureRect] = [] @export var time_hovered_sprites: Array[TextureRect] = []
@export var watch: TextureRect
func _ready(): func _ready():
@ -106,7 +107,7 @@ func setup(_title, _initial_stress, _time_slots, _services):
func show_time_selector(): func show_time_selector():
watch_on = true watch_on = true
$watch.visible = true watch.visible = true
func update_counter(): func update_counter():
@ -116,7 +117,7 @@ func update_counter():
func _on_turn_pressed(num): func _on_turn_pressed(num):
turns_left = num turns_left = num
update_counter() update_counter()
$watch.visible = false watch.visible = false
watch_on = false watch_on = false
time_slots_selected.emit() time_slots_selected.emit()
@ -131,6 +132,11 @@ func turn_back():
$front.visible = false $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: func _on_watch_segment_mouse_entered(extra_arg_0: int) -> void:
if not watch_on or not time_slots[extra_arg_0]: if not watch_on or not time_slots[extra_arg_0]:
return return
@ -138,11 +144,11 @@ func _on_watch_segment_mouse_entered(extra_arg_0: int) -> void:
time_hovered_sprites[x].visible = true 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: for sprite in time_hovered_sprites:
sprite.visible = false 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: if event is InputEventMouseButton and event.pressed:
_on_turn_pressed(extra_arg_0 + 1) _on_turn_pressed(extra_arg_0 + 1)

View File

@ -42,6 +42,18 @@ func draw_card() -> Card:
return cards.pop_back() 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: func place(card: Card) -> void:
cards.append(card) cards.append(card)
match type: match type:

View File

@ -121,6 +121,7 @@ func add_player(id: int, username: String, type: PlayerType) -> void:
board.slots[2].clicked.connect(controller.select_workspace) board.slots[2].clicked.connect(controller.select_workspace)
board.slots[3].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.poor_deck.clicked.connect(controller.on_poor_discard_deck_clicked)
board.clients_discarded.connect(discard_clients)
board.name = "board " + str(player_boards.size()) board.name = "board " + str(player_boards.size())
player_boards.append(board) player_boards.append(board)
players.append(controller) players.append(controller)
@ -223,15 +224,21 @@ func discard_workers(node_paths):
@rpc("call_local", "reliable") @rpc("call_local", "reliable")
func draft_clients(player): func draft_clients(player):
var cards = [] var controller: PlayerController = null
for x in 2 + (2 * round_number): for player_controller in players:
cards.append(client_deck.draw_card()) if player_controller.player_info["username"] == player:
for x in player_boards: controller = player_controller
if x.player_info["username"] == player: var cards_to_draw = 4
for card in cards: if controller.reputation_points >= 30:
x.shift_deck.place(card) 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") @rpc("call_local", "reliable")
func discard_clients(_node_paths): func discard_clients(node_paths):
pass for path in node_paths:
var card = get_node(path)
client_discard.place(card)

View File

@ -25,6 +25,36 @@ func add_client(card: Client) -> bool:
return true 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: func _on_area2d_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event is InputEventMouseButton and event.pressed and worker != null: if event is InputEventMouseButton and event.pressed and worker != null:
emit_signal("clicked", self) emit_signal("clicked", self)