online fix

This commit is contained in:
2025-10-27 12:37:18 +01:00
parent 96d50bfad5
commit e6759d6610
281 changed files with 7337 additions and 136 deletions

View File

@@ -6,6 +6,7 @@ using Game.Scripts.Runtime.Data;
using Game.Scripts.Runtime.Pooling;
using Game.Scripts.Runtime.Navigation;
using MegaKoop.Game;
using MegaKoop.Game.Networking;
using UnityEngine;
using UnityEngine.AI;
@@ -68,6 +69,8 @@ namespace Game.Scripts.Runtime.Spawning
private IEnemyFactory _factory;
private bool _warnedMissingPlayer;
private bool _warnedMissingNavMesh;
private bool _authorityOverrideSet;
private bool _authorityOverrideValue = true;
private void OnValidate()
{
@@ -170,8 +173,16 @@ namespace Game.Scripts.Runtime.Spawning
_spawnedThisWave.Clear();
_localElapsed = 0f;
_nextSpawnTimestamp = 0f;
_spawnLoop = StartCoroutine(SpawnLoop());
LogLifecycle($"Begin wave {CurrentWaveIndex}, pool prewarm complete, maxConcurrent={_runtimeConfig.MaxConcurrent}");
if (HasAuthority())
{
_spawnLoop = StartCoroutine(SpawnLoop());
LogLifecycle($"Begin wave {CurrentWaveIndex}, pool prewarm complete, maxConcurrent={_runtimeConfig.MaxConcurrent}");
}
else
{
_spawnLoop = null;
LogLifecycle($"Begin follower mode (no spawn loop), wave {CurrentWaveIndex}, maxConcurrent={_runtimeConfig?.MaxConcurrent}");
}
}
public void End()
@@ -226,6 +237,12 @@ namespace Game.Scripts.Runtime.Spawning
_localElapsed = _clock.Elapsed;
}
if (!HasAuthority())
{
yield return null;
continue;
}
if (_localElapsed >= _nextSpawnTimestamp)
{
ExecuteSpawnTick();
@@ -640,6 +657,22 @@ namespace Game.Scripts.Runtime.Spawning
}
}
internal void SetAuthorityOverride(bool hasAuthority)
{
_authorityOverrideSet = true;
_authorityOverrideValue = hasAuthority;
if (!HasAuthority() && _spawnLoop != null)
{
StopCoroutine(_spawnLoop);
_spawnLoop = null;
}
else if (HasAuthority() && _spawnLoop == null && _runtimeConfig != null && _runtimeTable != null)
{
_spawnLoop = StartCoroutine(SpawnLoop());
}
}
private bool RequirePlayerReference()
{
if (EnsurePlayerReference())
@@ -706,5 +739,26 @@ namespace Game.Scripts.Runtime.Spawning
return null;
}
}
private bool HasAuthority()
{
if (_authorityOverrideSet)
{
return _authorityOverrideValue;
}
var manager = SteamCoopNetworkManager.Instance;
if (manager == null)
{
return true;
}
if (!manager.IsConnected)
{
return true;
}
return manager.IsHost;
}
}
}