quakeball/Assets/Scripts/Game/GameMaster.cs

69 lines
2.0 KiB
C#
Raw Permalink Normal View History

using UnityEngine;
using System.Collections.Generic;
using NeonTea.Quakeball.Networking.Instances;
using NeonTea.Quakeball.Networking;
2020-08-10 02:08:09 +02:00
using NeonTea.Quakeball.Interface;
namespace NeonTea.Quakeball.Game {
public class GameMaster {
private NetInstance Instance;
public GameMode GameMode;
public Dictionary<Team, List<ulong>> Players = new Dictionary<Team, List<ulong>>();
public GameMaster() {
Instance = Net.Singleton.Instance;
GameMode = GameMode.TeamPlay;
Players[Team.FreeForAll] = new List<ulong>();
Players[Team.Sun] = new List<ulong>();
Players[Team.Moon] = new List<ulong>();
}
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);
2020-08-10 02:08:09 +02:00
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,
}
}