diff --git a/Assets/Scripts/FogOfWarSystem.cs b/Assets/Scripts/FogOfWarSystem.cs index fd27d62..37c1c6f 100644 --- a/Assets/Scripts/FogOfWarSystem.cs +++ b/Assets/Scripts/FogOfWarSystem.cs @@ -342,12 +342,14 @@ namespace Northbound fogData.ClearCurrentVision(); } - // 모든 시야 제공자의 시야 범위 계산 + // 모든 시야 제공자의 시야 범위 계산 (팀 시야 공유) foreach (var provider in _visionProviders) { if (provider == null || !provider.IsActive()) continue; ulong ownerId = provider.GetOwnerId(); + TeamType providerTeam = provider.GetTeam(); + if (!_serverFogData.ContainsKey(ownerId)) { _serverFogData[ownerId] = new FogOfWarData(gridWidth, gridHeight); @@ -356,7 +358,8 @@ namespace Northbound Vector3 position = provider.GetTransform().position; float visionRange = provider.GetVisionRange(); - RevealArea(ownerId, position, visionRange); + // 같은 팀의 모든 멤버에게 시야 공유 + RevealAreaForTeam(providerTeam, position, visionRange); } // 각 클라이언트에게 시야 데이터 전송 @@ -387,6 +390,47 @@ namespace Northbound } } + /// + /// 같은 팀의 모든 멤버에게 시야 공개 + /// + private void RevealAreaForTeam(TeamType team, Vector3 worldPosition, float radius) + { + // 해당 팀의 모든 멤버 찾기 + foreach (var kvp in _serverFogData) + { + ulong clientId = kvp.Key; + + // 클라이언트의 팀 확인 + if (GetClientTeam(clientId) == team) + { + RevealArea(clientId, worldPosition, radius); + } + } + } + + /// + /// 클라이언트의 팀 가져오기 + /// + private TeamType GetClientTeam(ulong clientId) + { + if (NetworkManager.Singleton == null) return TeamType.Neutral; + + // 연결된 클라이언트에서 플레이어 오브젝트 찾기 + if (NetworkManager.Singleton.SpawnManager.SpawnedObjects != null) + { + foreach (var netObj in NetworkManager.Singleton.SpawnManager.SpawnedObjects.Values) + { + var playerController = netObj.GetComponent(); + if (playerController != null && playerController.OwnerPlayerId == clientId) + { + return playerController.GetTeam(); + } + } + } + + return TeamType.Neutral; + } + /// /// 클라이언트에게 안개 데이터 전송 /// diff --git a/Assets/Scripts/IVisionProvider.cs b/Assets/Scripts/IVisionProvider.cs index a9ac83c..933624d 100644 --- a/Assets/Scripts/IVisionProvider.cs +++ b/Assets/Scripts/IVisionProvider.cs @@ -26,5 +26,10 @@ namespace Northbound /// 현재 활성화 상태인지 /// bool IsActive(); + + /// + /// 소속 팀 (팀 시야 공유용) + /// + TeamType GetTeam(); } } \ No newline at end of file diff --git a/Assets/Scripts/PlayerVisionProvider.cs b/Assets/Scripts/PlayerVisionProvider.cs index 17c8c88..459a6b1 100644 --- a/Assets/Scripts/PlayerVisionProvider.cs +++ b/Assets/Scripts/PlayerVisionProvider.cs @@ -35,6 +35,7 @@ namespace Northbound public float GetVisionRange() => _playerStats?.GetSight() ?? 10f; public Transform GetTransform() => transform; public bool IsActive() => IsSpawned; + public TeamType GetTeam() => _playerController?.GetTeam() ?? TeamType.Player; private void OnDrawGizmosSelected() {