using UnityEngine; using System.Collections.Generic; using NeonTea.Quakeball.Networking.Instances; using NeonTea.Quakeball.Networking; using NeonTea.Quakeball.Interface; namespace NeonTea.Quakeball.Game { public class GameMaster { private NetInstance Instance; public GameMode GameMode; public Dictionary> Players = new Dictionary>(); public GameMaster() { Instance = Net.Singleton.Instance; GameMode = GameMode.TeamPlay; Players[Team.FreeForAll] = new List(); Players[Team.Sun] = new List(); Players[Team.Moon] = new List(); } public void PlayerJoined(NetPlayer player) { Team team = Team.FreeForAll; if (GameMode == GameMode.TeamPlay) { if (Players[Team.Sun].Count > Players[Team.Moon].Count) { team = Team.Moon; } else { team = Team.Sun; } } player.Team = team; Players[player.Team].Add(player.Id); Terminal.Singleton.Println($"Put {player.Nick} to Team {player.Team}"); } public void PlayerLeft(NetPlayer player) { Players[player.Team].Remove(player.Id); } public Vector3 GetSpawn(NetPlayer player) { string Tag = "Respawn"; switch (player.Team) { case Team.Sun: Tag = "SunRespawn"; break; case Team.Moon: Tag = "MoonRespawn"; break; } GameObject[] spawnPoints = GameObject.FindGameObjectsWithTag(Tag); return spawnPoints[Random.Range(0, spawnPoints.Length)].transform.position; } } public enum GameMode { TeamPlay = 0, FreeForAll = 1, } public enum Team { FreeForAll = 0, Sun = 1, Moon = 2, } }