fixed
This commit is contained in:
+33
-23
@@ -239,24 +239,24 @@ func _on_host_pressed():
|
||||
multiplayer.multiplayer_peer = multiplayer_peer
|
||||
$NetworkInfo/UniquePeerID.text = str(multiplayer.get_unique_id())
|
||||
|
||||
# Generate all goals first
|
||||
preset_goals.clear()
|
||||
for i in range(max_players):
|
||||
var goals = initialize_random_goals(9, 7, 10, 1.0)
|
||||
# Convert to int array explicitly
|
||||
var int_goals: Array[int] = []
|
||||
for g in goals:
|
||||
int_goals.append(g)
|
||||
preset_goals.append(int_goals)
|
||||
|
||||
# Sync goals to all clients
|
||||
rpc("sync_preset_goals", preset_goals)
|
||||
|
||||
# Now add host with first set of goals
|
||||
add_player_character(1)
|
||||
players.append(1)
|
||||
|
||||
# Generate goals for host first
|
||||
var host_player = get_node_or_null("1")
|
||||
if host_player:
|
||||
host_player.append_random_goals()
|
||||
rpc("sync_player_goals", 1, host_player.goals)
|
||||
|
||||
# Generate and store goals for future bots/players
|
||||
var preset_goals = []
|
||||
for i in range(2, max_players + 1):
|
||||
var goals = initialize_random_goals(9, 7, 10, 1.0)
|
||||
preset_goals.append(goals)
|
||||
|
||||
# Store preset goals in network state
|
||||
rpc("sync_preset_goals", preset_goals)
|
||||
|
||||
# Add bots with their own goals
|
||||
for i in range(2, max_players + 1):
|
||||
add_bot(i)
|
||||
|
||||
@@ -315,6 +315,18 @@ func add_player_character(peer_id):
|
||||
add_child(player_character)
|
||||
player_character.add_to_group("Players", true)
|
||||
|
||||
# Set goals based on player ID if server
|
||||
if multiplayer.is_server():
|
||||
var goal_index = peer_id - 1
|
||||
# Verify index is valid
|
||||
if goal_index >= 0 and goal_index < preset_goals.size():
|
||||
# Convert to int array before assigning
|
||||
var goals: Array[int] = []
|
||||
for g in preset_goals[goal_index]:
|
||||
goals.append(g)
|
||||
player_character.goals = goals
|
||||
rpc("sync_player_goals", peer_id, goals)
|
||||
|
||||
if peer_id == multiplayer.get_unique_id():
|
||||
local_player_character = player_character
|
||||
update_button_states()
|
||||
@@ -338,9 +350,6 @@ func add_player_character(peer_id):
|
||||
var bot_to_replace = get_node_or_null(str(bots[0])) if bots.size() > 0 else null
|
||||
if bot_to_replace:
|
||||
player_character.goals = bot_to_replace.goals.duplicate()
|
||||
else:
|
||||
# Only generate new goals if not inheriting from a bot
|
||||
player_character.append_random_goals()
|
||||
|
||||
func add_bot(bot_id):
|
||||
rpc("create_bot", bot_id)
|
||||
@@ -372,10 +381,11 @@ func create_bot(bot_id):
|
||||
bots.append(bot_id)
|
||||
players.append(bot_id)
|
||||
|
||||
# Assign preset goals
|
||||
var goal_index = bot_id - 2
|
||||
# Assign goals from preset array
|
||||
var goal_index = bot_id - 1
|
||||
if goal_index < preset_goals.size():
|
||||
bot_character.goals = preset_goals[goal_index]
|
||||
bot_character.goals = preset_goals[goal_index].duplicate()
|
||||
rpc("sync_player_goals", bot_id, bot_character.goals)
|
||||
|
||||
# Sync bot status after a short delay to ensure node is ready
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
@@ -384,8 +394,8 @@ func create_bot(bot_id):
|
||||
rpc("sync_player_goals", bot_id, bot_character.goals)
|
||||
|
||||
# Only generate goals for new bots, not replacement bots
|
||||
if not (players.size() > max_players):
|
||||
bot_character.append_random_goals()
|
||||
#if not (players.size() > max_players):
|
||||
#bot_character.append_random_goals()
|
||||
|
||||
# Always sync the bot's goals
|
||||
rpc("sync_player_goals", bot_id, bot_character.goals)
|
||||
|
||||
Reference in New Issue
Block a user