Added Crow functionality. Not server authenticated yet
parent
955e59bf04
commit
0bd0070054
@ -0,0 +1,96 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 501460ae984b4e44d991e4b43e36afee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue