Minor Update
- Refactor the Player.gd - Attempt to fix joining the available room, via Room ID
This commit is contained in:
@@ -43,7 +43,7 @@ func grab_item(grid_position: Vector2i) -> bool:
|
||||
var target_slot = find_best_goal_slot_for_item(item)
|
||||
if target_slot == -1:
|
||||
print("Player: No valid slot found for item.")
|
||||
return false # no space
|
||||
return false # no space
|
||||
|
||||
if not player.is_multiplayer_authority():
|
||||
return false
|
||||
@@ -191,44 +191,44 @@ func auto_put_item() -> bool:
|
||||
|
||||
# Now scan playerboard
|
||||
for i in range(player.playerboard.size()):
|
||||
var item = player.playerboard[i]
|
||||
if item == -1:
|
||||
var current_item = player.playerboard[i]
|
||||
if current_item == -1:
|
||||
continue
|
||||
|
||||
# Case 1: Item is not in goals at all → definitely junk
|
||||
if not item in player.goals:
|
||||
if not current_item in player.goals:
|
||||
put_slot = i
|
||||
break
|
||||
|
||||
# Case 2: Item is in goals, but we already have enough in correct spots
|
||||
var current_count = 0
|
||||
for r in range(1, 4): # central rows 1-3 (5x5 board)
|
||||
for c in range(1, 4): # central cols 1-3
|
||||
for r in range(1, 4): # central rows 1-3 (5x5 board)
|
||||
for c in range(1, 4): # central cols 1-3
|
||||
var idx = r * 5 + c
|
||||
if player.playerboard[idx] == item:
|
||||
if player.playerboard[idx] == current_item:
|
||||
current_count += 1
|
||||
|
||||
# If we already have all needed copies in central area, this is extra
|
||||
if current_count >= goal_counts.get(item, 0):
|
||||
if current_count >= goal_counts.get(current_item, 0):
|
||||
put_slot = i
|
||||
break
|
||||
|
||||
# If no junk found, fall back to any non-goal-matching tile outside center
|
||||
if put_slot == -1:
|
||||
for i in range(player.playerboard.size()):
|
||||
var item = player.playerboard[i]
|
||||
if item == -1:
|
||||
var board_item = player.playerboard[i]
|
||||
if board_item == -1:
|
||||
continue
|
||||
var row = i / 5
|
||||
var col = i % 5
|
||||
# If it's outside the central 3x3, it shouldn't be there
|
||||
if row < 1 or row > 3 or col < 1 or col > 3:
|
||||
if not item in player.goals or player.playerboard[i] != player.goals[(row - 1) * 3 + (col - 1)]:
|
||||
if not board_item in player.goals or player.playerboard[i] != player.goals[(row - 1) * 3 + (col - 1)]:
|
||||
put_slot = i
|
||||
break
|
||||
|
||||
if put_slot == -1:
|
||||
return false # Nothing suitable to put
|
||||
return false # Nothing suitable to put
|
||||
|
||||
# Step 3: Perform the put
|
||||
var target_pos = valid_put_positions[0]
|
||||
@@ -256,7 +256,7 @@ func arrange_playerboard_item(slot_index: int):
|
||||
if player.action_points < 2 or player.playerboard[slot_index] == -1:
|
||||
return
|
||||
|
||||
var selected_item = player.playerboard[slot_index]
|
||||
#var selected_item = player.playerboard[slot_index]
|
||||
var adjacent_slots = get_adjacent_playerboard_slots(slot_index)
|
||||
|
||||
var main = player.get_tree().get_root().get_node_or_null("Main")
|
||||
@@ -273,11 +273,11 @@ func arrange_playerboard_item(slot_index: int):
|
||||
|
||||
# Highlight valid adjacent slots
|
||||
for adj_slot in adjacent_slots:
|
||||
if player.playerboard[adj_slot] == -1: # Only highlight empty adjacent slots
|
||||
if player.playerboard[adj_slot] == -1: # Only highlight empty adjacent slots
|
||||
var adj_slot_ui = main.ui_manager.playerboard_ui.get_child(adj_slot)
|
||||
if adj_slot_ui.get_child_count() > 2:
|
||||
adj_slot_ui.get_child(2).show()
|
||||
player.highlighted_cells.append(adj_slot)
|
||||
player.action_manager.highlighted_cells.append(adj_slot)
|
||||
|
||||
# Connect to slot click signals
|
||||
for i in range(player.playerboard.size()):
|
||||
@@ -336,10 +336,10 @@ func find_best_goal_slot_for_item(item: int) -> int:
|
||||
for i in range(3):
|
||||
for j in range(3):
|
||||
if goals_2d[i][j] == item:
|
||||
var board_row = i + 1 # offset to center in 5x5
|
||||
var board_row = i + 1 # offset to center in 5x5
|
||||
var board_col = j + 1
|
||||
var slot_index = board_row * 5 + board_col
|
||||
if player.playerboard[slot_index] == -1: # only if empty
|
||||
if player.playerboard[slot_index] == -1: # only if empty
|
||||
return slot_index
|
||||
|
||||
# No ideal slot? Return any empty slot
|
||||
@@ -377,7 +377,7 @@ func find_best_put_candidate() -> Dictionary:
|
||||
|
||||
# Is it already in the correct central position?
|
||||
var is_in_correct_central_spot = false
|
||||
if board_i in [1,2,3] and board_j in [1,2,3]:
|
||||
if board_i in [1, 2, 3] and board_j in [1, 2, 3]:
|
||||
var goal_i = board_i - 1
|
||||
var goal_j = board_j - 1
|
||||
if goals_2d[goal_i][goal_j] == item:
|
||||
@@ -424,7 +424,7 @@ func find_best_put_candidate() -> Dictionary:
|
||||
if not valid_cells.is_empty():
|
||||
return {
|
||||
"slot_index": cand.slot,
|
||||
"grid_position": valid_cells[0] # pick first valid cell
|
||||
"grid_position": valid_cells[0] # pick first valid cell
|
||||
}
|
||||
|
||||
# Fallback: just put any candidate item
|
||||
@@ -446,9 +446,9 @@ func get_adjacent_playerboard_slots(slot_index) -> Array:
|
||||
return adjacent
|
||||
|
||||
func is_valid_arrangement_slot(from_slot: int, to_slot: int) -> bool:
|
||||
var from_row = from_slot / 5
|
||||
var from_row = int(from_slot / 5)
|
||||
var from_col = from_slot % 5
|
||||
var to_row = to_slot / 5
|
||||
var to_row = int(to_slot / 5)
|
||||
var to_col = to_slot % 5
|
||||
|
||||
var row_diff = abs(from_row - to_row)
|
||||
|
||||
Reference in New Issue
Block a user