33 lines
1.0 KiB
GDScript
33 lines
1.0 KiB
GDScript
extends ActionLeaf
|
|
|
|
func tick(actor: Node, blackboard: Blackboard) -> int:
|
|
# Early validation for bots only
|
|
if not actor.is_bot or actor.action_points <= 0:
|
|
return FAILURE
|
|
|
|
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:
|
|
return FAILURE
|
|
|
|
# Find empty slot in playerboard
|
|
var empty_slot_idx = actor.playerboard.find(-1)
|
|
if empty_slot_idx == -1:
|
|
return FAILURE
|
|
|
|
# For bots, we bypass the usual visual feedback system
|
|
if actor.is_multiplayer_authority():
|
|
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
|