Add the ActionState. Random
This commit is contained in:
+44
-55
@@ -523,44 +523,6 @@ func grab_item(grid_position: Vector2i = current_position) -> bool:
|
||||
|
||||
return false
|
||||
|
||||
# func put_item(grid_position: Vector2i = current_position) -> bool:
|
||||
# if not enhanced_gridmap or action_points <= 0 or selected_playerboard_slot == -1:
|
||||
# return false
|
||||
|
||||
# var cell = Vector3i(grid_position.x, 1, grid_position.y)
|
||||
# if enhanced_gridmap.get_cell_item(cell) != -1:
|
||||
# return false
|
||||
|
||||
# # Check if position is adjacent or current position
|
||||
# if grid_position != current_position:
|
||||
# var is_adjacent = false
|
||||
# var neighbors = enhanced_gridmap.get_neighbors(current_position, 0)
|
||||
# for neighbor in neighbors:
|
||||
# if neighbor.position == grid_position:
|
||||
# is_adjacent = true
|
||||
# break
|
||||
# if not is_adjacent:
|
||||
# return false
|
||||
|
||||
# var item = playerboard[selected_playerboard_slot]
|
||||
# if is_multiplayer_authority():
|
||||
# rpc("sync_grid_item", cell.x, cell.y, cell.z, item)
|
||||
# playerboard[selected_playerboard_slot] = -1
|
||||
# rpc("sync_playerboard", playerboard)
|
||||
|
||||
# has_performed_action = true
|
||||
# consume_action_points(1)
|
||||
# if not is_bot == true:
|
||||
# clear_highlights()
|
||||
# clear_playerboard_highlights()
|
||||
# selected_playerboard_slot = -1
|
||||
|
||||
# var main = get_tree().get_root().get_node_or_null("Main")
|
||||
# if main:
|
||||
# main.set_action_state(main.ActionState.NONE)
|
||||
# _after_action_completed()
|
||||
# return true
|
||||
|
||||
func put_item(grid_position: Vector2i = current_position) -> bool:
|
||||
if not enhanced_gridmap or action_points <= 0 or selected_playerboard_slot == -1:
|
||||
return false
|
||||
@@ -915,28 +877,51 @@ func highlight_empty_adjacent_cells():
|
||||
func sync_action_points(points: int):
|
||||
action_points = points
|
||||
|
||||
|
||||
#func highlight_random_valid_cells():
|
||||
#if is_bot == true or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
#return
|
||||
#
|
||||
#var valid_cells = []
|
||||
#for x in range(enhanced_gridmap.columns):
|
||||
#for z in range(enhanced_gridmap.rows):
|
||||
#var cell_pos = Vector2i(x, z)
|
||||
#var cell_item = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
|
||||
#if cell_item != -1 and not (cell_item in enhanced_gridmap.non_walkable_items):
|
||||
#valid_cells.append(cell_pos)
|
||||
#
|
||||
#var rng = RandomNumberGenerator.new()
|
||||
#rng.randomize()
|
||||
#for _i in range(min(5, valid_cells.size())):
|
||||
#var index = rng.randi() % valid_cells.size()
|
||||
#var cell = valid_cells[index]
|
||||
#highlighted_cells.append(cell)
|
||||
#enhanced_gridmap.set_cell_item(Vector3i(cell.x, 0, cell.y), enhanced_gridmap.hover_item)
|
||||
#valid_cells.remove_at(index)
|
||||
|
||||
func highlight_random_valid_cells():
|
||||
if is_bot == true or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
var valid_cells = []
|
||||
for x in range(enhanced_gridmap.columns):
|
||||
for z in range(enhanced_gridmap.rows):
|
||||
var cell_pos = Vector2i(x, z)
|
||||
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
|
||||
if cell_item != -1 and not (cell_item in enhanced_gridmap.non_walkable_items):
|
||||
valid_cells.append(cell_pos)
|
||||
|
||||
var rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
for _i in range(min(5, valid_cells.size())):
|
||||
var index = rng.randi() % valid_cells.size()
|
||||
var cell = valid_cells[index]
|
||||
highlighted_cells.append(cell)
|
||||
enhanced_gridmap.set_cell_item(Vector3i(cell.x, 0, cell.y), enhanced_gridmap.hover_item)
|
||||
valid_cells.remove_at(index)
|
||||
clear_highlights()
|
||||
|
||||
# First check the current position
|
||||
var current_cell = Vector3i(current_position.x, 1, current_position.y)
|
||||
var current_item = enhanced_gridmap.get_cell_item(current_cell)
|
||||
if current_item != -1:
|
||||
highlighted_cells.append(current_position)
|
||||
enhanced_gridmap.set_cell_item(Vector3i(current_position.x, 0, current_position.y),
|
||||
enhanced_gridmap.hover_item)
|
||||
|
||||
# Then check all adjacent cells for items
|
||||
var neighbors = enhanced_gridmap.get_neighbors(current_position, 0)
|
||||
for neighbor in neighbors:
|
||||
if neighbor.is_walkable:
|
||||
var cell_pos = neighbor.position
|
||||
var cell = Vector3i(cell_pos.x, 1, cell_pos.y)
|
||||
if enhanced_gridmap.get_cell_item(cell) != -1: # Only highlight cells with items
|
||||
highlighted_cells.append(cell_pos)
|
||||
enhanced_gridmap.set_cell_item(Vector3i(cell_pos.x, 0, cell_pos.y),
|
||||
enhanced_gridmap.hover_item)
|
||||
|
||||
func highlight_occupied_playerboard_slots():
|
||||
if is_bot == true or is_in_group("Bots") or not is_multiplayer_authority():
|
||||
@@ -1119,6 +1104,10 @@ func sync_playerboard(new_playerboard: Array):
|
||||
_after_action_completed()
|
||||
|
||||
func _after_action_completed():
|
||||
|
||||
# Clear the highlights after placing the tiles. ( Quickfix for Clientside )
|
||||
clear_highlights()
|
||||
|
||||
if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
if main:
|
||||
|
||||
Reference in New Issue
Block a user