Пример #1
0
    static void TryStartGame(UdpClient sender)
    {
        if (GameInfo.Players.Count < MIN_PLAYERS)
        {
            sender.Send(5, 0u, $"There must be at least {MIN_PLAYERS} players to start the round.");
            return;
        }
        if (ActiveRoleHashes.Count < MIN_PLAYERS)
        {
            sender.Send(5, 0u, $"There must be enough roles in the active list for at least {MIN_PLAYERS} players.");
            return;
        }
        if (ActiveRoleHashes.Count > GameInfo.Players.Count)
        {
            sender.Send(5, 0u, $"There are more active roles than there are players! ({ActiveRoleHashes.Count}/{GameInfo.Players.Count})");
            return;
        }

        List <Type> roleTypes = (from h in ActiveRoleHashes
                                 from t in LoadedRoleTypes.Values
                                 let th = GetRoleHashFromType(t)
                                          where h == th
                                          select t).ToList();

        GameInfo.AssignRolesAndSpectators(ActiveRoleHashes.Count, roleTypes);

        foreach (NetWerewolfPlayer p in ConnectedPlayers)
        {
            p.PlayerClient.Send(191, GetRoleHashFromType(p.Role.GetType()));
        }

        GameLoopCT = new CancellationToken(false);
        _          = Task.Run(NetGameLoop, GameLoopCT);
    }