Exemplo n.º 1
0
    public bool CheckWinCondition(WerewolfGameInfo gameInfo, WerewolfPlayer[] players)
    {
        if (players.Count(p => p.Role.Alignment.GetType() == typeof(WerewolfRoleAlignment)) == 0)
        {
            return(true);
        }

        return(false);
    }
Exemplo n.º 2
0
    public override WerewolfPlayer[] DoNightEvent(WerewolfGameInfo gameNfo)
    {
        if (TargetPlayers[0] == null)
        {
            return(new WerewolfPlayer[0]);
        }

        TargetPlayers[0].Status = PlayerStatus.Dead;
        return(TargetPlayers);
    }
Exemplo n.º 3
0
 public static bool InitializeServerInstance()
 {
     gameInfo = new WerewolfGameInfo(LoadedRoleTypes);
     players  = new List <NetWerewolfPlayer>();
     udpSv    = new UdpServer(SharedSecret);
     udpSv.AddNetEventsFromAssembly(Assembly.GetExecutingAssembly(), ServerEventGroup);
     udpSv.ClientConnected    += ServerNetEvents.ClientConnectedEventHandler;
     udpSv.ClientDisconnected += ServerNetEvents.ClientDisconnectedEventHandler;
     return(udpSv.StartServer(7235));
 }
Exemplo n.º 4
0
    public bool CheckWinCondition(WerewolfGameInfo gameInfo, WerewolfPlayer[] players)
    {
        int werewolves  = players.Count(p => p.Role.Alignment.GetType() == typeof(WerewolfRoleAlignment));
        int halfPlayers = Mathf.CeilToInt(players.Count() / 2.0f);

        if (werewolves >= halfPlayers)
        {
            return(true);
        }

        return(false);
    }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Random           rand         = new Random();
            Assembly         roleAssembly = Assembly.LoadFrom(@".\TestWerewolfRoles.dll");
            WerewolfGameInfo gameNfo      = new WerewolfGameInfo(roleAssembly);

            List <Type> roleList = Enumerable.Repeat(gameNfo.RoleTypeFromName("Villager"), 24).ToList();

            roleList.AddRange(Enumerable.Repeat(gameNfo.RoleTypeFromName("Werewolf"), 6));

            List <WerewolfPlayer> playerList = new List <WerewolfPlayer>();

            for (int i = 0; i < 30; ++i)
            {
                gameNfo.AddPlayerAndAssignId();
            }

            gameNfo.AssignRolesAndSpectators(30, roleList);

            foreach (WerewolfPlayer p in gameNfo.Players)
            {
                Console.WriteLine($"[{p.PlayerID}] {p.Role?.RoleName} ({p.Status})");
            }

            Console.ReadKey();

            List <NightEvent> nightEvents = new List <NightEvent>();

            foreach (WerewolfPlayer p in gameNfo.Players)
            {
                if (p.Role.NightEvent != null)
                {
                    WerewolfPlayer[] targets = gameNfo.Players.Where(p => p.Status == PlayerStatus.Alive && p.Role.RoleName != "Werewolf").ToArray();

                    p.Role.NightEvent.SourcePlayer  = p;
                    p.Role.NightEvent.TargetPlayers = new WerewolfPlayer[] { targets[rand.Next(targets.Length)] };

                    Console.WriteLine($"{p.PlayerID} attacks {p.Role.NightEvent.TargetPlayers[0].PlayerID}");

                    nightEvents.Add(p.Role.NightEvent);
                }
            }

            gameNfo.ResolveNightEvents(nightEvents);

            foreach (WerewolfPlayer p in gameNfo.Players)
            {
                Console.WriteLine($"[{p.PlayerID}] {p.Role?.RoleName} ({p.Status})");
            }

            Console.ReadKey();
        }
Exemplo n.º 6
0
    public static void LoadAllRoles()
    {
        List <Assembly> roleAsms = new List <Assembly>();

        roleAsms.Add(Assembly.GetExecutingAssembly()); // This assembly to load the internal roles.

        if (Directory.Exists(modsDirectory))
        {
            foreach (string dll in Directory.EnumerateFiles(modsDirectory, "*.dll"))
            {
                Assembly modAsm = Assembly.LoadFrom(dll);
                roleAsms.Add(modAsm);
                modAsms.Add(modAsm);
            }
        }
        else
        {
            Directory.CreateDirectory(modsDirectory);
        }

        LoadedRoleTypes  = WerewolfGameInfo.LoadRolesFromAssemblies(roleAsms.ToArray());
        LoadedRoleHashes = WerewolfGameInfo.GenerateRoleHashes(LoadedRoleTypes.Values.ToArray());
    }
Exemplo n.º 7
0
 public bool CheckWinCondition(WerewolfGameInfo gameInfo, WerewolfPlayer[] players)
 {
     return(true);
 }
Exemplo n.º 8
0
 public abstract WerewolfPlayer[] DoNightEvent(WerewolfGameInfo gameNfo);