update
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
extends ActionLeaf
|
||||
|
||||
func tick(actor: Node, blackboard: Blackboard) -> int:
|
||||
var target_pos = blackboard.get_value("move_target")
|
||||
if not target_pos:
|
||||
return FAILURE
|
||||
|
||||
if actor.action_points <= 0:
|
||||
return FAILURE
|
||||
|
||||
# Verify target is still valid
|
||||
if not actor.is_within_movement_range(target_pos):
|
||||
return FAILURE
|
||||
|
||||
if actor.is_position_occupied(target_pos):
|
||||
return FAILURE
|
||||
|
||||
var cell_item = actor.enhanced_gridmap.get_cell_item(Vector3i(target_pos.x, 0, target_pos.y))
|
||||
if cell_item == -1 or cell_item in actor.enhanced_gridmap.non_walkable_items:
|
||||
return FAILURE
|
||||
|
||||
# Move to position
|
||||
actor.rotate_towards_target(target_pos)
|
||||
var path = actor.enhanced_gridmap.find_path(Vector2(actor.current_position), Vector2(target_pos))
|
||||
|
||||
if path.size() <= 1:
|
||||
return FAILURE
|
||||
|
||||
# Verify path is clear
|
||||
var valid_path = true
|
||||
for point in path.slice(1):
|
||||
if actor.is_position_occupied(Vector2i(point.x, point.y)):
|
||||
valid_path = false
|
||||
break
|
||||
|
||||
if valid_path:
|
||||
if actor.is_multiplayer_authority():
|
||||
path.pop_front()
|
||||
actor.rpc("start_movement_along_path", path)
|
||||
actor.action_points -= 1
|
||||
actor.clear_highlights()
|
||||
return SUCCESS
|
||||
|
||||
return FAILURE
|
||||
Reference in New Issue
Block a user