update with bot system, but bot visually hosted on host side, doesn't visually appear on client side
This commit is contained in:
@@ -72,6 +72,25 @@ func find_valid_starting_position() -> Vector2i: # Find a valid starting positi
|
||||
|
||||
return Vector2i(0, 0) # Default position if no valid position found
|
||||
|
||||
func find_random_valid_position() -> Vector2i:
|
||||
var rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
|
||||
var max_attempts = 100
|
||||
var attempts = 0
|
||||
|
||||
while attempts < max_attempts:
|
||||
var random_position = Vector2i(rng.randi_range(0, enhanced_gridmap.columns - 1),
|
||||
rng.randi_range(0, enhanced_gridmap.rows - 1))
|
||||
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(random_position.x, 0, random_position.y))
|
||||
|
||||
if cell_item not in enhanced_gridmap.non_walkable_items and random_position != current_position:
|
||||
return random_position # Return valid position
|
||||
|
||||
attempts += 1
|
||||
|
||||
return current_position # Return current position if no new valid position found
|
||||
|
||||
func _physics_process(_delta): # Called every physics frame
|
||||
if is_multiplayer_authority():
|
||||
rpc("remote_set_position", global_position) # RPC call to sync position
|
||||
@@ -139,6 +158,24 @@ func move_player_along_path(path: Array): # Move player along calculated path
|
||||
end_turn()
|
||||
)
|
||||
|
||||
func move_bot_along_path(path: Array):
|
||||
is_player_moving = true
|
||||
var tween = create_tween()
|
||||
tween.set_trans(Tween.TRANS_CUBIC)
|
||||
tween.set_ease(Tween.EASE_IN_OUT)
|
||||
|
||||
for point in path:
|
||||
var target_position = grid_to_world(Vector2i(point.x, point.y))
|
||||
tween.tween_property(self, "position", target_position, 0.5)
|
||||
|
||||
tween.tween_callback(func():
|
||||
current_position = Vector2i(path[-1].x, path[-1].y)
|
||||
is_player_moving = false
|
||||
enhanced_gridmap.clear_path_visualization()
|
||||
has_moved_this_turn = true
|
||||
end_turn()
|
||||
)
|
||||
|
||||
func update_player_position(grid_position: Vector2i): # Update player's position
|
||||
position = grid_to_world(grid_position)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user