This commit is contained in:
2025-01-28 14:35:32 +08:00
parent 9640283964
commit 5a9092adfc
5 changed files with 29 additions and 7 deletions
+3 -2
View File
@@ -273,12 +273,13 @@ func create_bot(bot_id):
var bot_character = player_scene.instantiate()
bot_character.set_multiplayer_authority(1)
bot_character.name = str(bot_id)
bot_character.is_bot = true # Set bot flag
add_child(bot_character)
bot_character.add_to_group("Players", true)
bot_character.add_to_group("Bots", true)
# The BehaviorTree will auto-activate for bots
var behavior_tree = bot_character.get_node_or_null("BotBehavior")
# Get behavior tree reference
var behavior_tree = bot_character.get_node_or_null("BehaviorTree")
if behavior_tree:
behavior_tree.enabled = true
behavior_tree.actor = bot_character
+1
View File
@@ -17,6 +17,7 @@
[node name="Main" type="Node3D"]
script = ExtResource("1_xcpe3")
turn_based_mode = false
[node name="EnhancedGridMap" type="GridMap" parent="."]
mesh_library = ExtResource("1_110wo")
+16 -3
View File
@@ -1,5 +1,7 @@
extends Node3D
@export var is_bot: bool = false
@export var enhanced_gridmap_path: NodePath = "/root/Main/EnhancedGridMap"
var enhanced_gridmap: EnhancedGridMap
@export var current_position: Vector2i
@@ -52,19 +54,30 @@ func _ready():
if not enhanced_gridmap:
push_error("EnhancedGridMap node not found")
return
enhanced_gridmap.initialize_astar()
enhanced_gridmap.set_diagonal_movement(use_diagonal_movement)
current_position = find_valid_starting_position()
update_player_position(current_position)
if not is_in_group("Bots"):
set_process_unhandled_input(is_multiplayer_authority())
# Set bot flag if in Bots group
if is_in_group("Bots"):
is_bot = true
# Only process input if not a bot and is authority
set_process_unhandled_input(not is_bot and is_multiplayer_authority())
append_random_goals()
playerboard.resize(25)
playerboard.fill(-1)
# Enable behavior tree if bot
if is_bot:
var behavior_tree = $BehaviorTree
if behavior_tree:
behavior_tree.enabled = true
behavior_tree.actor = self
func _physics_process(_delta):
if is_multiplayer_authority():
+3 -1
View File
@@ -87,5 +87,7 @@ autowrap_mode = 3
justification_flags = 171
width = 700.0
[node name="Node" type="Node" parent="."]
[node name="BehaviorTree" type="Node" parent="."]
script = ExtResource("8_1o2fn")
tick_rate = 60
actor_node_path = NodePath("\"..\"")
+6 -1
View File
@@ -7,8 +7,13 @@ func _ready():
# Only setup for bots
if not get_parent().is_in_group("Bots"):
queue_free() # Remove tree if not a bot
return
# Set this tree's actor
actor = get_parent()
enabled = true
# Create root selector
var selector = SelectorComposite.new()
add_child(selector)