change ruleset
This commit is contained in:
+82
-138
@@ -57,35 +57,58 @@ func _ready():
|
||||
# Initialize behavior tree for bots
|
||||
var behavior_tree = $BehaviorTree
|
||||
|
||||
|
||||
if is_in_group("Bots") and behavior_tree:
|
||||
behavior_tree.enabled = true
|
||||
behavior_tree.actor = self
|
||||
# Early setup for bots
|
||||
if is_bot or is_in_group("Bots"):
|
||||
# Set Input process to false for bots immediately
|
||||
set_process_input(false)
|
||||
set_process_unhandled_input(false)
|
||||
|
||||
# Disable visual highlights for bots
|
||||
highlighted_cells.clear()
|
||||
|
||||
if behavior_tree:
|
||||
behavior_tree.enabled = is_multiplayer_authority()
|
||||
behavior_tree.actor = self
|
||||
|
||||
rpc("sync_bot_status", true)
|
||||
|
||||
# Rest of initialization
|
||||
# Initialize bot-specific components
|
||||
if enhanced_gridmap:
|
||||
current_position = find_valid_starting_position()
|
||||
update_player_position(current_position)
|
||||
append_random_goals()
|
||||
playerboard.resize(25)
|
||||
playerboard.fill(-1)
|
||||
return
|
||||
|
||||
# Rest of initialization (only for human players)
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.initialize_astar()
|
||||
enhanced_gridmap.set_diagonal_movement(use_diagonal_movement)
|
||||
|
||||
current_position = find_valid_starting_position()
|
||||
update_player_position(current_position)
|
||||
|
||||
set_process_unhandled_input(not is_in_group("Bots") and is_multiplayer_authority())
|
||||
|
||||
append_random_goals()
|
||||
playerboard.resize(25)
|
||||
playerboard.fill(-1)
|
||||
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func sync_bot_status(is_bot_status: bool):
|
||||
is_bot = is_bot_status
|
||||
if is_bot:
|
||||
add_to_group("Bots", true) # Persistent group addition
|
||||
add_to_group("Bots", true)
|
||||
set_process_input(false)
|
||||
set_process_unhandled_input(false)
|
||||
|
||||
# Clear any existing highlights
|
||||
highlighted_cells.clear()
|
||||
#clear_highlights()
|
||||
#clear_playerboard_highlights()
|
||||
|
||||
var behavior_tree = get_node_or_null("BehaviorTree")
|
||||
if behavior_tree:
|
||||
behavior_tree.enabled = true
|
||||
behavior_tree.enabled = is_multiplayer_authority()
|
||||
behavior_tree.actor = self
|
||||
if not is_multiplayer_authority():
|
||||
behavior_tree.set_physics_process(false)
|
||||
@@ -96,8 +119,10 @@ func _physics_process(_delta):
|
||||
rpc("remote_set_position", global_position)
|
||||
|
||||
func _unhandled_input(event):
|
||||
#if is_in_group("Bots"):
|
||||
#return
|
||||
if is_bot or is_in_group("Bots"):
|
||||
set_process_unhandled_input(false)
|
||||
set_process_input(false)
|
||||
return
|
||||
|
||||
# Use get_node_or_null for safer node access
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
@@ -108,6 +133,10 @@ func _unhandled_input(event):
|
||||
return
|
||||
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
if is_bot or is_in_group("Bots"):
|
||||
set_process_unhandled_input(false)
|
||||
set_process_input(false)
|
||||
return
|
||||
var camera = get_viewport().get_camera_3d()
|
||||
var from = camera.project_ray_origin(event.position)
|
||||
var to = from + camera.project_ray_normal(event.position) * 1000
|
||||
@@ -137,6 +166,8 @@ func _on_slot_gui_input(event, slot_index, slot_ui) -> int:
|
||||
return -1
|
||||
|
||||
func handle_grid_click(grid_position: Vector2i):
|
||||
if is_bot or is_in_group("Bots"):
|
||||
return
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
if not main:
|
||||
push_error("Main node not found")
|
||||
@@ -252,15 +283,18 @@ func move_player_to_clicked_position(grid_position: Vector2i):
|
||||
break
|
||||
|
||||
if valid_path:
|
||||
|
||||
path.pop_front()
|
||||
rpc("start_movement_along_path", path)
|
||||
action_points -= 1
|
||||
clear_highlights()
|
||||
if not is_bot:
|
||||
clear_highlights()
|
||||
|
||||
else:
|
||||
print("Path is blocked by other players")
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func start_movement_along_path(path: Array):
|
||||
func start_movement_along_path(path: Array, clear_visual: bool = true):
|
||||
is_player_moving = true
|
||||
var tween = create_tween()
|
||||
tween.set_trans(Tween.TRANS_CUBIC)
|
||||
@@ -272,7 +306,10 @@ func start_movement_along_path(path: Array):
|
||||
tween.tween_callback(func():
|
||||
current_position = Vector2i(path[-1].x, path[-1].y)
|
||||
is_player_moving = false
|
||||
enhanced_gridmap.clear_path_visualization()
|
||||
|
||||
if clear_visual:
|
||||
enhanced_gridmap.clear_path_visualization()
|
||||
|
||||
has_moved_this_turn = path.size() <= movement_range
|
||||
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
@@ -369,7 +406,7 @@ func grab_item(grid_position: Vector2i = current_position) -> bool:
|
||||
if item == -1:
|
||||
return false
|
||||
|
||||
if is_in_group("Bots"):
|
||||
if is_in_group("Bots") or is_bot:
|
||||
var empty_slot = playerboard.find(-1)
|
||||
if empty_slot == -1:
|
||||
return false
|
||||
@@ -428,8 +465,9 @@ func put_item(grid_position: Vector2i = current_position) -> bool:
|
||||
|
||||
has_performed_action = true
|
||||
consume_action_points(1)
|
||||
clear_highlights()
|
||||
clear_playerboard_highlights()
|
||||
if not is_bot:
|
||||
clear_highlights()
|
||||
clear_playerboard_highlights()
|
||||
selected_playerboard_slot = -1
|
||||
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
@@ -442,9 +480,10 @@ func handle_put_action():
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
if not main or action_points < 1:
|
||||
return
|
||||
|
||||
clear_highlights()
|
||||
clear_playerboard_highlights()
|
||||
|
||||
if not is_bot:
|
||||
clear_highlights()
|
||||
clear_playerboard_highlights()
|
||||
|
||||
# Highlight non-empty slots in playerboard
|
||||
for i in range(playerboard.size()):
|
||||
@@ -477,8 +516,9 @@ func handle_playerboard_slot_selected(slot_index: int):
|
||||
|
||||
has_performed_action = true
|
||||
consume_action_points(1)
|
||||
clear_highlights()
|
||||
clear_playerboard_highlights()
|
||||
if not is_bot:
|
||||
clear_highlights()
|
||||
clear_playerboard_highlights()
|
||||
selected_gridmap_position = Vector2i(-1, -1)
|
||||
main.set_action_state(main.ActionState.NONE)
|
||||
_after_action_completed()
|
||||
@@ -492,52 +532,9 @@ func handle_put_slot_selected(slot_index: int):
|
||||
if slot_index in highlighted_cells and playerboard[slot_index] in goals:
|
||||
selected_playerboard_slot = slot_index
|
||||
clear_highlights()
|
||||
highlight_empty_adjacent_cells()
|
||||
if not is_bot:
|
||||
highlight_empty_adjacent_cells()
|
||||
|
||||
#func arrange_playerboard_item(slot_index: int):
|
||||
#if action_points < 2 or playerboard[slot_index] == -1:
|
||||
#return
|
||||
#
|
||||
#var selected_item = playerboard[slot_index]
|
||||
#var adjacent_slots = get_adjacent_playerboard_slots(slot_index)
|
||||
#
|
||||
#var main = get_tree().get_root().get_node_or_null("Main")
|
||||
#if not main or not main.playerboard_ui:
|
||||
#return
|
||||
#
|
||||
#var selected_slot_ui = main.playerboard_ui.get_child(slot_index)
|
||||
#if selected_slot_ui.get_child_count() > 1:
|
||||
#selected_slot_ui.get_child(1).show()
|
||||
#
|
||||
#for adj_slot in adjacent_slots:
|
||||
#if playerboard[adj_slot] == -1 or is_valid_arrangement_slot(slot_index, adj_slot):
|
||||
#var adj_slot_ui = main.playerboard_ui.get_child(adj_slot)
|
||||
#if adj_slot_ui.get_child_count() > 2:
|
||||
#adj_slot_ui.get_child(2).show()
|
||||
#
|
||||
#main.update_playerboard_highlights(adjacent_slots)
|
||||
#
|
||||
#var target_slot = await _on_slot_gui_input(null, slot_index, selected_slot_ui)
|
||||
#
|
||||
#if selected_slot_ui.get_child_count() > 1:
|
||||
#selected_slot_ui.get_child(1).hide()
|
||||
#
|
||||
#for adj_slot in adjacent_slots:
|
||||
#var adj_slot_ui = main.playerboard_ui.get_child(adj_slot)
|
||||
#if adj_slot_ui.get_child_count() > 2:
|
||||
#adj_slot_ui.get_child(2).hide()
|
||||
#
|
||||
#if target_slot != -1 and (playerboard[target_slot] == -1 or is_valid_arrangement_slot(slot_index, target_slot)):
|
||||
#var temp_item = playerboard[target_slot]
|
||||
#playerboard[target_slot] = selected_item
|
||||
#playerboard[slot_index] = temp_item
|
||||
#
|
||||
#if is_multiplayer_authority():
|
||||
#rpc("sync_playerboard", playerboard)
|
||||
#consume_action_points(2)
|
||||
#has_performed_action = true
|
||||
#_after_action_completed()
|
||||
#main.update_playerboard_ui()
|
||||
|
||||
func arrange_playerboard_item(slot_index: int):
|
||||
if action_points < 2 or playerboard[slot_index] == -1:
|
||||
@@ -573,7 +570,7 @@ func arrange_playerboard_item(slot_index: int):
|
||||
slot.gui_input.connect(_on_slot_clicked.bind(i))
|
||||
|
||||
func _on_slot_clicked(event: InputEvent, slot_index: int):
|
||||
if not event is InputEventMouseButton or not event.pressed or event.button_index != MOUSE_BUTTON_LEFT:
|
||||
if not event is InputEventMouseButton or is_bot or not event.pressed or event.button_index != MOUSE_BUTTON_LEFT:
|
||||
return
|
||||
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
@@ -596,8 +593,8 @@ func _on_slot_clicked(event: InputEvent, slot_index: int):
|
||||
has_performed_action = true
|
||||
|
||||
# Clear highlights
|
||||
clear_highlights()
|
||||
clear_playerboard_highlights()
|
||||
clear_highlights()
|
||||
clear_playerboard_highlights()
|
||||
|
||||
# Reset selection
|
||||
selected_playerboard_slot = -1
|
||||
@@ -606,30 +603,6 @@ func _on_slot_clicked(event: InputEvent, slot_index: int):
|
||||
main.update_playerboard_ui()
|
||||
main.set_action_state(main.ActionState.NONE)
|
||||
|
||||
|
||||
#func check_playerboard_arrangement(bot: Node) -> bool:
|
||||
#var goal_indices = [] # Store indices of non-empty goals
|
||||
#var goal_items = [] # Store the actual goal items
|
||||
#
|
||||
## Get all valid goals (non -1)
|
||||
#for i in range(goals.size()):
|
||||
#if goals[i] != -1:
|
||||
#goal_indices.append(i)
|
||||
#goal_items.append(goals[i])
|
||||
#
|
||||
## Check if current arrangement matches goals
|
||||
#var current_items = []
|
||||
#for i in range(playerboard.size()):
|
||||
#if playerboard[i] in goal_items:
|
||||
#current_items.append(playerboard[i])
|
||||
#
|
||||
## Compare current order with goal order
|
||||
#for i in range(min(current_items.size(), goal_items.size())):
|
||||
#if current_items[i] != goal_items[i]:
|
||||
#return true
|
||||
#
|
||||
#return false
|
||||
|
||||
func is_valid_arrangement_slot(from_slot: int, to_slot: int) -> bool:
|
||||
var from_row = from_slot / 5
|
||||
var from_col = from_slot % 5
|
||||
@@ -653,39 +626,6 @@ func get_adjacent_playerboard_slots(slot_index) -> Array:
|
||||
|
||||
return adjacent
|
||||
|
||||
#func find_best_arrangement_slot() -> int:
|
||||
#for i in range(playerboard.size()):
|
||||
#if playerboard[i] != -1:
|
||||
#var neighbors = get_adjacent_playerboard_slots(i)
|
||||
#for adj_slot in neighbors:
|
||||
#if playerboard[adj_slot] == -1 and playerboard[i] in goals:
|
||||
#return adj_slot
|
||||
#return playerboard.find(-1)
|
||||
|
||||
#func find_best_put_position(bot: Node) -> Vector2i:
|
||||
## Find the first empty cell adjacent to a matching item in the playerboard
|
||||
#for i in range(playerboard.size()):
|
||||
#if playerboard[i] in goals:
|
||||
#var neighbors = enhanced_gridmap.get_neighbors(current_position, 1)
|
||||
#for neighbor in neighbors:
|
||||
#var cell = Vector3i(neighbor.position.x, 1, neighbor.position.y)
|
||||
#if enhanced_gridmap.get_cell_item(cell) == -1:
|
||||
#return neighbor.position
|
||||
#return Vector2i(-1, -1)
|
||||
|
||||
#func find_best_grab_position() -> Vector2i:
|
||||
## Find the first matching item in the grid or adjacent cells
|
||||
#var current_cell = Vector3i(current_position.x, 1, current_position.y)
|
||||
#if enhanced_gridmap.get_cell_item(current_cell) in goals:
|
||||
#return current_position
|
||||
#
|
||||
#var neighbors = enhanced_gridmap.get_neighbors(current_position, 1)
|
||||
#for neighbor in neighbors:
|
||||
#var cell = Vector3i(neighbor.position.x, 1, neighbor.position.y)
|
||||
#if enhanced_gridmap.get_cell_item(cell) in goals:
|
||||
#return neighbor.position
|
||||
#
|
||||
#return Vector2i(-1, -1)
|
||||
|
||||
func has_item_at_current_position() -> bool:
|
||||
var current_cell = Vector3i(current_position.x, 1, current_position.y)
|
||||
@@ -698,8 +638,8 @@ func playerboard_is_full() -> bool:
|
||||
return playerboard.find(-1) == -1
|
||||
|
||||
func highlight_movement_range():
|
||||
#if is_in_group("Bots"):
|
||||
#return
|
||||
if is_bot or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
for x in range(enhanced_gridmap.columns):
|
||||
for z in range(enhanced_gridmap.rows):
|
||||
@@ -711,8 +651,8 @@ func highlight_movement_range():
|
||||
enhanced_gridmap.set_cell_item(Vector3i(x, 0, z), enhanced_gridmap.hover_item)
|
||||
|
||||
func highlight_adjacent_cells():
|
||||
#if is_in_group("Bots"):
|
||||
#return
|
||||
if is_bot or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
var current_cell = Vector3i(current_position.x, 1, current_position.y)
|
||||
if enhanced_gridmap.get_cell_item(current_cell) != -1:
|
||||
@@ -729,8 +669,8 @@ func highlight_adjacent_cells():
|
||||
|
||||
|
||||
func highlight_empty_adjacent_cells():
|
||||
#if is_in_group("Bots"):
|
||||
#return
|
||||
if is_bot or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
# Clear previous highlights
|
||||
clear_highlights()
|
||||
@@ -754,8 +694,8 @@ func highlight_empty_adjacent_cells():
|
||||
enhanced_gridmap.hover_item)
|
||||
|
||||
func highlight_random_valid_cells():
|
||||
#if is_in_group("Bots"):
|
||||
#return
|
||||
if is_bot or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
var valid_cells = []
|
||||
for x in range(enhanced_gridmap.columns):
|
||||
@@ -775,8 +715,8 @@ func highlight_random_valid_cells():
|
||||
valid_cells.remove_at(index)
|
||||
|
||||
func highlight_occupied_playerboard_slots():
|
||||
#if is_in_group("Bots"):
|
||||
#return
|
||||
if is_bot or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
if not main or not main.playerboard_ui:
|
||||
@@ -800,6 +740,8 @@ func highlight_occupied_playerboard_slots():
|
||||
main.update_playerboard_ui()
|
||||
|
||||
func clear_highlights():
|
||||
if is_bot or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
return
|
||||
if not enhanced_gridmap:
|
||||
return
|
||||
|
||||
@@ -817,6 +759,8 @@ func clear_highlights():
|
||||
child.hide()
|
||||
|
||||
func clear_playerboard_highlights():
|
||||
if is_bot or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
return
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
if main and main.playerboard_ui:
|
||||
for i in range(main.playerboard_ui.get_child_count()):
|
||||
|
||||
Reference in New Issue
Block a user