public Preferences(string directory, PpPlugin plugin)
        {
            this.directory = directory;
            this.plugin    = plugin;
            records        = new Dictionary <string, PlayerRecord>();

            Read();
        }
Example #2
0
        public void OnRoundStart(RoundStartEvent ev)
        {
            Player[] players = ev.Server.GetPlayers().Where(x => x.SteamId != "0").ToArray();
            new Thread(() =>
            {
                PpPlugin.Shuffle(players);

                Dictionary <Player, Role> playerRoles = players.ToDictionary(x => x, x => x.TeamRole.Role);

                plugin.Info("Calculating optimal starting player roles...");
                AssignRoles(playerRoles, Role.CLASSD);
                lock (actions)
                {
                    actions.Enqueue(() =>
                    {
                        int changes = 0;
                        foreach (KeyValuePair <Player, Role> playerRole in playerRoles)
                        {
                            Player player = playerRole.Key;
                            Role role     = playerRole.Value;
                            plugin.Debug($"{player.Name} is {player.TeamRole.Role} and should be {role}");
                            if (player.TeamRole.Role != role && role != Role.UNASSIGNED)
                            {
                                changes++;
                                player.ChangeRole(role);
                                plugin.Debug($"Setting {player.Name} to {role}");
                            }

                            lock (last_roles_count)
                            {
                                if (last_roles_count.ContainsKey(player.IpAddress))
                                {
                                    if (last_roles_count[player.IpAddress].lastRole == role)
                                    {
                                        last_roles_count[player.IpAddress].count++;
                                    }
                                    else
                                    {
                                        last_roles_count[player.IpAddress].count    = 0;
                                        last_roles_count[player.IpAddress].lastRole = role;
                                    }
                                }
                            }
                        }
                        plugin.Info($"Changed {changes} roles");
                    });
                }
            }).Start();
        }
        public static PlayerRecord Load(string path, string steamId, PpPlugin plugin)
        {
            PlayerRecord player = new PlayerRecord(path, steamId, plugin);

            try
            {
                player.Read();
                return(player);
            }
            catch (Exception e)
            {
                plugin.Error($"Preference record {steamId} threw an exception while loading:\n{e}");
                return(null);
            }
        }
Example #4
0
 public EventHandlers(PpPlugin plugin)
 {
     this.plugin = plugin;
 }
Example #5
0
 public PlayerPrefCommand(PpPlugin plugin)
 {
     this.plugin = plugin;
 }
 public PlayerRecord(string path, string steamId, PpPlugin plugin)
 {
     SteamId     = steamId;
     this.path   = path;
     this.plugin = plugin;
 }