public Voting(Arena arena, int time, ref ArenaManager arenaManager) { Arena = arena; EndTime = time; ArenaManager = arenaManager; TimeStart = DateTime.Now; Maps = new List <Map> { Arena.Map }; Votes = new List <Vote>(); arenaManager.GetPlayersInArena(arena).ForEach(plr => plr.SendInfoMessage("Map vote started! Use /vote for map vote or add new in vote.")); }
public void RegistVote(TSPlayer tSPlayer, Map map) { var players = ArenaManager.GetPlayersInArena(Arena); var vote = Votes.Find(v => v.Player == tSPlayer); if (vote != null) { Votes.Remove(vote); } if (!Maps.Contains(map)) { Maps.Add(map); players.ForEach(plr => plr.SendInfoMessage($"{tSPlayer.Name} add map {map.Name} in vote!")); } Votes.Add(new Vote(tSPlayer, Maps.IndexOf(map))); }
public void OnUpdate() { for (int i = 0; i < ArenaManager.Arenas.Count; i++) { var arena = ArenaManager.Arenas[i]; if (ParamContains(arena, "autochange")) { if (arena.NextChange < DateTime.Now) { string[] param = arena.Parameters.Find(s => s.StartsWith("autochange")).Split(':'); int nextVoteSec = int.Parse(param[1]); string tag = param[2]; var maps = MapManager.GetMapsByTag(tag); maps.RemoveAll(mp => mp.Size.X > arena.Size.X || mp.Size.Y > arena.Size.Y); maps.Remove(arena.Map); if (maps.Count > 0) { int id = new Random().Next() % maps.Count; ArenaManager.SetMap(arena, maps[id]); } arena.NextChange = DateTime.Now.AddSeconds(nextVoteSec); } } } for (int i = 0; i < Votings.Count; i++) { if (Votings[i].CheckEnd()) { var arena = Votings[i].Arena; var map = Votings[i].GetWinner(); string[] param = arena.Parameters.Find(s => s.StartsWith("vote")).Split(':'); ArenaManager.SetMap(arena, map); arena.NextChange = DateTime.Now; var nextVote = DateTime.Now.AddSeconds(int.Parse(param[2])); arena.NextChange = nextVote; ArenaManager.GetPlayersInArena(arena).ForEach(plr => plr.SendInfoMessage($"Next vote will be available in {GenerateTimeString(TimeSpan.FromSeconds(int.Parse(param[1])))}")); Votings.RemoveAt(i); } } }