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() var bot_character = player_scene.instantiate()
bot_character.set_multiplayer_authority(1) bot_character.set_multiplayer_authority(1)
bot_character.name = str(bot_id) bot_character.name = str(bot_id)
bot_character.is_bot = true # Set bot flag
add_child(bot_character) add_child(bot_character)
bot_character.add_to_group("Players", true) bot_character.add_to_group("Players", true)
bot_character.add_to_group("Bots", true) bot_character.add_to_group("Bots", true)
# The BehaviorTree will auto-activate for bots # Get behavior tree reference
var behavior_tree = bot_character.get_node_or_null("BotBehavior") var behavior_tree = bot_character.get_node_or_null("BehaviorTree")
if behavior_tree: if behavior_tree:
behavior_tree.enabled = true behavior_tree.enabled = true
behavior_tree.actor = bot_character behavior_tree.actor = bot_character
+1
View File
@@ -17,6 +17,7 @@
[node name="Main" type="Node3D"] [node name="Main" type="Node3D"]
script = ExtResource("1_xcpe3") script = ExtResource("1_xcpe3")
turn_based_mode = false
[node name="EnhancedGridMap" type="GridMap" parent="."] [node name="EnhancedGridMap" type="GridMap" parent="."]
mesh_library = ExtResource("1_110wo") mesh_library = ExtResource("1_110wo")
+15 -2
View File
@@ -1,5 +1,7 @@
extends Node3D extends Node3D
@export var is_bot: bool = false
@export var enhanced_gridmap_path: NodePath = "/root/Main/EnhancedGridMap" @export var enhanced_gridmap_path: NodePath = "/root/Main/EnhancedGridMap"
var enhanced_gridmap: EnhancedGridMap var enhanced_gridmap: EnhancedGridMap
@export var current_position: Vector2i @export var current_position: Vector2i
@@ -59,13 +61,24 @@ func _ready():
current_position = find_valid_starting_position() current_position = find_valid_starting_position()
update_player_position(current_position) update_player_position(current_position)
if not is_in_group("Bots"): # Set bot flag if in Bots group
set_process_unhandled_input(is_multiplayer_authority()) 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() append_random_goals()
playerboard.resize(25) playerboard.resize(25)
playerboard.fill(-1) 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): func _physics_process(_delta):
if is_multiplayer_authority(): if is_multiplayer_authority():
rpc("remote_set_position", global_position) rpc("remote_set_position", global_position)
+3 -1
View File
@@ -87,5 +87,7 @@ autowrap_mode = 3
justification_flags = 171 justification_flags = 171
width = 700.0 width = 700.0
[node name="Node" type="Node" parent="."] [node name="BehaviorTree" type="Node" parent="."]
script = ExtResource("8_1o2fn") script = ExtResource("8_1o2fn")
tick_rate = 60
actor_node_path = NodePath("\"..\"")
+5
View File
@@ -7,8 +7,13 @@ func _ready():
# Only setup for bots # Only setup for bots
if not get_parent().is_in_group("Bots"): if not get_parent().is_in_group("Bots"):
queue_free() # Remove tree if not a bot
return return
# Set this tree's actor
actor = get_parent()
enabled = true
# Create root selector # Create root selector
var selector = SelectorComposite.new() var selector = SelectorComposite.new()
add_child(selector) add_child(selector)