fix the overlapping input
This commit is contained in:
@@ -1,27 +1,32 @@
|
||||
extends ActionLeaf
|
||||
|
||||
func tick(actor: Node, blackboard: Blackboard) -> int:
|
||||
var grab_position = blackboard.get_value("grab_position")
|
||||
if not grab_position:
|
||||
return FAILURE
|
||||
|
||||
# Find empty slot in playerboard
|
||||
var empty_slot = actor.playerboard.find(-1)
|
||||
if empty_slot == -1:
|
||||
# Early validation for bots only
|
||||
if not actor.is_bot or actor.action_points <= 0:
|
||||
return FAILURE
|
||||
|
||||
# Get item at position
|
||||
var grab_position = blackboard.get_value("grab_position")
|
||||
if not grab_position:
|
||||
grab_position = actor.current_position # Default to current position if no target
|
||||
|
||||
# Check if there's an item at the position first
|
||||
var cell = Vector3i(grab_position.x, 1, grab_position.y)
|
||||
var item = actor.enhanced_gridmap.get_cell_item(cell)
|
||||
if item == -1 or actor.action_points <= 0:
|
||||
if item == -1:
|
||||
return FAILURE
|
||||
|
||||
# Find empty slot in playerboard
|
||||
var empty_slot_idx = actor.playerboard.find(-1)
|
||||
if empty_slot_idx == -1:
|
||||
return FAILURE
|
||||
|
||||
# Grab the item
|
||||
# For bots, we bypass the usual visual feedback system
|
||||
if actor.is_multiplayer_authority():
|
||||
actor.playerboard[empty_slot] = item
|
||||
actor.playerboard[empty_slot_idx] = item
|
||||
actor.rpc("sync_grid_item", cell.x, cell.y, cell.z, -1)
|
||||
actor.rpc("sync_playerboard", actor.playerboard)
|
||||
actor.has_performed_action = true
|
||||
actor.action_points -= 1
|
||||
blackboard.set_value("current_action", "idle")
|
||||
|
||||
return SUCCESS
|
||||
|
||||
@@ -18,7 +18,11 @@ func _ready():
|
||||
# Set this tree's actor
|
||||
actor = parent
|
||||
|
||||
# Wait a frame to ensure all nodes are ready
|
||||
await get_tree().process_frame
|
||||
|
||||
enabled = parent.is_multiplayer_authority() and parent.is_bot
|
||||
|
||||
# Set up blackboard with initial values
|
||||
if blackboard:
|
||||
blackboard.set_value("action_points", parent.action_points)
|
||||
blackboard.set_value("current_action", "idle")
|
||||
blackboard.set_value("grab_position", parent.current_position) # Default grab position
|
||||
blackboard.set_value("move_target", null)
|
||||
|
||||
Reference in New Issue
Block a user