Exemplo n.º 1
0
        public void LoadTest()
        {
            int numPlayers = 7;
            RandomSource target = new RandomSource(numPlayers);
            Village village = new Village(target);

            // Every faction should have a win condition
            bool hasEvil = false;
            foreach(Faction faction in village.Factions) {
                Assert.AreNotEqual(0, faction.WinConditions.Count);
                foreach(IWinCondition condition in faction.WinConditions) {
                    Assert.AreEqual(false, condition.Check(faction));
                }

                if(faction.Alignment == Alignment.Evil) {
                    hasEvil = true;
                }
            }
            Assert.AreEqual(true, hasEvil);

            // Number of players should match
            Assert.AreEqual(numPlayers, village.Members.Count);

            // Power roles should have the appropriate powers
            foreach(VillageMember member in village.Members) {
                if(member.Name == "Cop") {
                    Assert.IsTrue(member.GetPower("investigate") != null);
                }
                if(member.Name == "Doc") {
                    Assert.IsTrue(member.GetPower("protect") != null);
                }
            }
        }
Exemplo n.º 2
0
        public void GameplayTestInitialize()
        {
            messages.Clear();

            IVariantLoader loader = new MafiaBotV2.MafiaLib.Sources.XmlSource(Assembly.GetExecutingAssembly().GetManifestResourceStream("MafiaBot.Test2.Old.Data.StaticC9.xml"));
            village = new Village(loader);
            village.Outside = new TestOutsideConnector();
        }
Exemplo n.º 3
0
        public void Init()
        {
            village = new Village(new MafiaBotV2.MafiaLib.Sources.BasicLayoutSource());
            town = village.Factions.First(v => v.Name == "Town");
            mafia = village.Factions.First(v => v.Name == "Mafia");

            NLog.Config.SimpleConfigurator.ConfigureForFileLogging("test.log", NLog.LogLevel.Debug);
        }
Exemplo n.º 4
0
        private void Init(int numTown, int numScum)
        {
            village = new Village(new TestVillageSource(numTown, numScum));
            town = village.Factions.First(v => v.Name == "Town");
            mafia = village.Factions.First(v => v.Name == "Mafia");

            village.Start();
            town.Members[0].ApplyEffect(new HeroEffect());
        }
Exemplo n.º 5
0
        public VillageMember(Village village, string name)
            : base(village, ActorType.Person)
        {
            this.RoleName = name;

            if (Village != null) {
                Village.Members.Add(this);
            }
        }
Exemplo n.º 6
0
        public Phase(Village village, PhaseType initialPhase)
        {
            this.village = village;
            this.type = initialPhase;
            village.ActionExecuted += new EventHandler<ActionEventArgs>(OnActionExecuted);

            votes = new MafiaVoteCounter(village.AliveMembers);
            votes.MajorityReached += new EventHandler<MajorityReachedEventArgs<VillageMember>>(OnMajorityReached);
        }
Exemplo n.º 7
0
 public void Init()
 {
     village = new Village();
     Faction f = village.CreateFaction("Faction");
     for (int i = 0; i < 5; i++) {
         f.CreateMember("Voter" + i);
     }
     counter = new MafiaVoteCounter(village.Members);
 }
Exemplo n.º 8
0
        public void Init()
        {
            village = new Village(new MafiaBotV2.MafiaLib.Sources.BasicLayoutSource());
            town = village.Factions.First(v => v.Name == "Town");
            mafia = village.Factions.First(v => v.Name == "Mafia");

            for(int i=0;i<2;i++) {
                town.CreateMember("Town" + i);
            }
            mafia.CreateMember("Mafia");
        }
Exemplo n.º 9
0
        public void C9Test()
        {
            IVariantLoader loader = new MafiaBotV2.MafiaLib.Sources.XmlSource(Assembly.GetExecutingAssembly().GetManifestResourceStream("MafiaBot.Test2.Old.Data.C9.xml"));
            Village target = new Village(loader);

            Assert.AreEqual(2, target.Factions.Count);
            Assert.AreEqual(target.Rules.MaximumPopulation, target.Members.Count);

            int count = 0;
            foreach (Faction f in target.Factions) {
                count += f.Members.Count;
            }
            Assert.AreEqual(target.Rules.MaximumPopulation, count);
        }
Exemplo n.º 10
0
 public void Init()
 {
     village = new Village(new MafiaBotV2.MafiaLib.Sources.BasicLayoutSource());
     town = village.Factions.First(v => v.Name == "Town");
     mafia = village.Factions.First(v => v.Name == "Mafia");
 }
Exemplo n.º 11
0
        public override void Start()
        {
            if (Players.Any(p => p.Name.ToLower() == "nolynch")) {
                this.RemoveUser(Players.Find(p => p.Name.ToLower() == "nolynch"));
                throw new Exception("Users may not have the name NoLynch. The game has not been started.");
            }

            if (variantName == null) {
                throw new UnknownVariantException("You need to set a variant before starting the game.");
            }
            else if (variantName == "random" && http == null) {
                village = new Village(new MafiaLib.Sources.RandomSource(Players.Count));
                this.MaxPlayers = Players.Count;
                Channel.SendMessage("Generated random variant for " + Players.Count + " players.");
            }

            village.GameOver += new EventHandler<GameOverEventArgs>(OnGameOver);
            village.PhaseOver += new EventHandler<PhaseOverEventArgs>(OnPhaseOver);

            village.Outside = new VillageConnector(this);

            if (MaxPlayers == -1) {
                MaxPlayers = Village.Rules.MaximumPopulation;
            }
            Players.RemoveRange(MaxPlayers, Players.Count - MaxPlayers);
            //HACK
            if (!(Creator is MafiaBotV2.Network.File.FileUser)) {
                Players = Players.Shuffle();
            }

            // Give players their roles
            int index = 0;
            foreach (VillageMember member in village.Members) {
                NetUser player = Players[index];
                member.Name = player.Name;
                mapper.Add(player, member);
                member.Outside = new MafiaUser(this, player, member);
                member.Killed += new EventHandler<VillageMemberEventArgs>(OnKilled);
                index++;
            }

            foreach (VillageMember member in village.Members) {
                (member.Outside as MafiaUser).SendRoleInfo();
            }

            base.Start();
            village.Start();

            Channel.Commands.Add(new Commands.VoteCountCommand(this));

            if (http != null && Players.Contains(Creator)) {
                Bot.MainChannel.SendMessage("Keep in mind " + Creator.Name + " knows the setup.");
            }
            Bot.MainChannel.SendMessage("A game has started in " + Channel.Name + ". You can join the channel to watch it!");
        }
Exemplo n.º 12
0
        public void SetVariant(string variant, List<string> args)
        {
            variantName = variant;
            if (variantName.ToLower() == "random") {
                if (args.Count > 0) {
                    village = new Village(new MafiaLib.Sources.RandomSource(Math.Max(3, Players.Count), args[0]));
                }
                else {
                    village = new Village(new MafiaLib.Sources.RandomSource(Math.Max(3, Players.Count)));
                }
                this.MaxPlayers = -1;
            }
            else {
                village = VariantManager.Instance.CreateVillage(variant);
                this.MaxPlayers = village.Members.Count;
            }

            if (village == null) {
                variantName = null;
                throw new UnknownVariantException("Variant " + variant + " not found.");
            }

            Channel.SendMessage("Variant set to " + village.Name + ". Players: " + Players.Count + "/" + village.Members.Count);
        }
Exemplo n.º 13
0
 internal Faction(Village village, string name)
     : base(village, ActorType.Faction)
 {
     this.Name = name;
     this.Outside = new DefaultFactionConnector(this);
 }
Exemplo n.º 14
0
 public Actor(Village village, ActorType type)
 {
     this.village = village;
     this.type = type;
 }