update feature & bugfix
This commit is contained in:
+23
-11
@@ -367,15 +367,17 @@ func _setup_client_game():
|
||||
add_player_character(p_id)
|
||||
print("Client: Pre-spawned player ", p_id)
|
||||
|
||||
# Pre-spawn potential bots (IDs 2 to MaxPlayers) to prevent RPC "Node not found" errors
|
||||
# Bots use small integer IDs (2, 3, 4...) while clients use large unique IDs
|
||||
# Pre-spawn potential bots (IDs from count+1 to MaxPlayers) to prevent RPC "Node not found" errors
|
||||
# Bots use small integer IDs (e.g. 2, 3, 4...) while clients use large unique IDs
|
||||
if GameStateManager.enable_bots:
|
||||
for i in range(2, GameStateManager.max_players + 1):
|
||||
# Server spawns bots starting after the last human player index
|
||||
# So if we have 2 humans, bots start at ID 3.
|
||||
var start_bot_id = lobby_players.size() + 1
|
||||
for i in range(start_bot_id, GameStateManager.max_players + 1):
|
||||
# Only spawn if not already existing (e.g. if a human somehow got this ID, though unlikely)
|
||||
if not has_node(str(i)):
|
||||
add_player_character(i)
|
||||
get_node(str(i)).is_bot = true # Assume bot initially
|
||||
get_node(str(i)).add_to_group("Bots", true)
|
||||
# Spawning as BOT
|
||||
add_player_character(i, true)
|
||||
print("Client: Pre-spawned potential bot ", i)
|
||||
|
||||
# Ensure local player setup (UI, controls) is verified
|
||||
@@ -488,18 +490,28 @@ func create_bot(bot_id: int):
|
||||
|
||||
var goal_index = bot_id - 1
|
||||
if goal_index < GoalManager.preset_goals.size():
|
||||
# Wait for bot managers to be ready
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
# Wait for bot managers to be ready (race_manager is created at T=0.5)
|
||||
await get_tree().create_timer(0.75).timeout
|
||||
bot_character.goals = GoalManager.preset_goals[goal_index].duplicate()
|
||||
# Use deferred goals sync to avoid timing issues
|
||||
call_deferred("_deferred_set_player_goals", bot_id, bot_character.goals)
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func add_player_character(peer_id: int):
|
||||
func add_player_character(peer_id: int, is_bot: bool = false):
|
||||
if has_node(str(peer_id)):
|
||||
return
|
||||
|
||||
var player_character = PlayerManager.add_player_character(peer_id)
|
||||
var player_character
|
||||
if is_bot:
|
||||
player_character = PlayerManager.create_bot(peer_id)
|
||||
player_character.add_to_group("Bots", true)
|
||||
else:
|
||||
player_character = PlayerManager.add_player_character(peer_id)
|
||||
|
||||
# Set properties BEFORE adding to tree (ensure _ready sees correct state)
|
||||
# create_bot already sets is_bot=true, but we ensure consistency
|
||||
player_character.is_bot = is_bot
|
||||
|
||||
add_child(player_character)
|
||||
player_character.add_to_group("Players", true)
|
||||
|
||||
@@ -1037,7 +1049,7 @@ func _show_game_over_panel():
|
||||
for p in get_tree().get_nodes_in_group("Players"):
|
||||
player_scores.append({
|
||||
"name": p.display_name if not p.display_name.is_empty() else str(p.name),
|
||||
"score": goals_cycle_manager.get_player_score(p.get_multiplayer_authority()) if goals_cycle_manager else 0
|
||||
"score": goals_cycle_manager.get_player_score(p.name.to_int()) if goals_cycle_manager else 0
|
||||
})
|
||||
player_scores.sort_custom(func(a, b): return a.score > b.score)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user