You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HighGroundRoyaleNetcode/Assets/Scripts/Gameplay/CrowManager.cs

97 lines
2.2 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
using UnityEngine;
public class CrowManager : MonoBehaviour
{
public static CrowManager Instance { get; private set; }
private List<ServerCharacter> players = new List<ServerCharacter>();
private ServerCharacter currentCrow;
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(this);
return;
}
Instance = this;
}
private void Start()
{
// players = FindObjectsOfType<ServerCharacter>().ToList();
}
private void Update()
{
DetermineCrow();
}
private void DetermineCrow()
{
int unoccupiedPlayers = 0;
ServerCharacter potentialCrow = null;
foreach (var player in players)
{
if (!player.IsOnAPlatform)
{
unoccupiedPlayers++;
potentialCrow = player;
}
}
// If exactly one player is not on a platform, assign as crow
if (unoccupiedPlayers == 1)
{
AssignCrow(potentialCrow);
}
else if (unoccupiedPlayers == 0 && currentCrow != null)
{
// All players are on platforms, clear crow
ClearCrow();
}
}
private void AssignCrow(ServerCharacter player)
{
if (currentCrow == player) return; // Already the crow
if (currentCrow != null)
{
// Clear old crow
currentCrow.SetAsCrow(false);
}
currentCrow = player;
currentCrow.SetAsCrow(true);
Debug.Log($"{currentCrow.name} is now the Crow.");
}
private void ClearCrow()
{
if (currentCrow != null)
{
currentCrow.SetAsCrow(false);
Debug.Log($"{currentCrow.name} is no longer the Crow.");
currentCrow = null;
}
}
public void AddCharacterToList(ServerCharacter character)
{
players.Add(character);
}
public void RemoveCharacterFromList(ServerCharacter character)
{
players.Remove(character);
}
}