示例#1
0
        public void Test_FightingMakesYouEnemies()
        {
            var you  = YouInARoom(out IWorld world);
            var room = you.CurrentLocation;

            var bob = new Npc("Bob", room);

            //don't do anything bob like wander off!
            bob.BaseActions.Clear();

            Assert.IsEmpty(world.Relationships.Where(r => r.AppliesTo(bob, you) && r.Attitude < 0), "bob should not have a negative opinion of you starting out");

            var ui = new FixedChoiceUI(bob, bob);

            //fight each other
            world.RunRound(ui, new FightAction(you));

            var youAndBob = world.Relationships.OfType <PersonalRelationship>()
                            .SingleOrDefault(r => r.AppliesTo(bob, you) && r.Attitude < 0);

            Assert.IsNotNull(youAndBob, "bob should now be angry at you");

            var attitudeBefore = youAndBob.Attitude;

            //fight again
            world.RunRound(ui, new FightAction(you));

            Assert.Greater(attitudeBefore, youAndBob.Attitude, "Expected continuing to fight to make matters worse");
        }
示例#2
0
        public void TestFactionRelationships_BetweenFactions()
        {
            TwoInARoom(out You you, out IActor them, out IWorld world);

            var f1 = new Faction("F1", FactionRole.Civilian);
            var f2 = new Faction("F2", FactionRole.Civilian);

            you.FactionMembership.Add(f1);
            them.FactionMembership.Add(f2);
            them.BaseActions.Clear();

            Assert.IsEmpty(world.Relationships.OfType <FactionRelationship>().ToArray());

            var ui = new FixedChoiceUI(them);

            //fight each other
            world.RunRound(ui, new FightAction(you));

            //not only do you hate each other now but your factions should also hate each other
            var newRelationship = world.Relationships.OfType <FactionRelationship>().Single();

            Assert.IsInstanceOf <InterFactionRelationship>(newRelationship);

            Assert.Less(newRelationship.Attitude, 0);

            // relationship should be from the fight victim towards the evil attacker!
            Assert.AreEqual(f2, newRelationship.HostFaction);
            Assert.AreEqual(f1, ((InterFactionRelationship)newRelationship).ObservedFaction);
        }
示例#3
0
        public void FightingIsFrownedUponByOthers(bool areFriends)
        {
            //when I'm in a room with 2 people
            var you  = YouInARoom(out IWorld world);
            var room = you.CurrentLocation;

            var bob        = new Npc("Bob", room);
            var bobsFriend = new Npc("Bobs Friend", room);

            //don't do anything bob like wander off!
            bob.BaseActions.Clear();
            bobsFriend.BaseActions.Clear();

            Assert.IsEmpty(world.Relationships.Where(r => r.AppliesTo(bob, you) && r.Attitude < 0), "bob should not have a negative opinion of you starting out");

            //if bobs friend likes him create a relationship
            if (areFriends)
            {
                world.Relationships.Add(new PersonalRelationship(bobsFriend, bob)
                {
                    Attitude = 10
                });
            }

            var ui = new FixedChoiceUI(bob);

            //fight each other
            world.RunRound(ui, new FightAction(you));

            var youAndBob = world.Relationships.OfType <PersonalRelationship>()
                            .SingleOrDefault(r => r.AppliesTo(bob, you) && r.Attitude < 0);
            var youAndBobsFriend = world.Relationships.OfType <PersonalRelationship>()
                                   .SingleOrDefault(r => r.AppliesTo(bobsFriend, you) && r.Attitude < 0);

            Assert.IsNotNull(youAndBob, "bob should now be angry at you");

            if (areFriends)
            {
                Assert.IsNotNull(youAndBobsFriend, "bobs friend should also be angry at you");
            }
            else
            {
                Assert.IsNull(youAndBobsFriend, "bobs friend should not care that you hit bob because they aren't really friends");
            }
        }
示例#4
0
        public void Test_SevereInjuriesAreHarderToHeal()
        {
            var you = YouInARoom(out IWorld world);

            //you are a medic
            var medic = new Adjective(Mock.Of <IActor>())
            {
                Name = "Medic"
            };

            medic.BaseActions.Add(new HealAction(you));
            you.Adjectives.Add(medic);

            you.BaseStats["Savvy"] = 20;

            //give them an injury
            var injury = new Injured("Cut Lip", you, 2, InjuryRegion.Leg, world.InjurySystems.First(i => i.IsDefault));

            you.Adjectives.Add(injury);

            var stack = new ActionStack();

            Assert.Contains(injury, you.Adjectives.ToArray());
            Assert.IsTrue(stack.RunStack(world, new FixedChoiceUI(you, injury), you.GetFinalActions().OfType <HealAction>().Single(), you, you.GetFinalBehaviours()));

            var badInjury = new Injured("Cut Lip", you, 80, InjuryRegion.Leg, world.InjurySystems.First(i => i.IsDefault));

            you.Adjectives.Add(badInjury);

            stack = new ActionStack();

            var ui = new FixedChoiceUI(you, badInjury);

            Assert.IsFalse(stack.RunStack(world, ui,
                                          you.GetFinalActions().OfType <HealAction>().Single(), you, you.GetFinalBehaviours()));

            Assert.Contains("Test Wanderer was unable to heal Test Wanderer's Cut Lip because Savvy was too low (required 40)",
                            ui.Log.RoundResults.Select(l => l.ToString()).ToArray());

            you.BaseStats["Savvy"] = 100;

            Assert.IsTrue(stack.RunStack(world, new FixedChoiceUI(you, badInjury),
                                         you.GetFinalActions().OfType <HealAction>().Single(), you, you.GetFinalBehaviours()));
        }
示例#5
0
        public void Test_GiantsAreHarderToHeal(bool withGiantItem)
        {
            var you = YouInARoom(out IWorld world);

            //you are a medic
            var medic = new Adjective(you)
            {
                Name = "Medic"
            };

            medic.BaseActions.Add(new HealAction(medic));
            you.Adjectives.Add(medic);

            you.BaseStats["Savvy"] = 50;
            you.With(world, world.AdjectiveFactory, "Giant");


            if (withGiantItem)
            {
                var hammer = new Item("Hammer").With(world, world.AdjectiveFactory, "Giant");
                you.Items.Add(hammer);
            }

            var badInjury = new Injured("Cut Lip", you, 80, InjuryRegion.Leg, world.InjurySystems.First(i => i.IsDefault));

            you.Adjectives.Add(badInjury);

            var stack = new ActionStack();

            var ui = new FixedChoiceUI(you, badInjury);

            Assert.IsFalse(stack.RunStack(world, ui,
                                          you.GetFinalActions().OfType <HealAction>().Single(), you, you.GetFinalBehaviours()));

            Assert.Contains("Test Wanderer was unable to heal Test Wanderer's Cut Lip because Savvy was too low (required 80)",
                            ui.Log.RoundResults.Select(l => l.ToString()).ToArray());

            //shrink you back down again and presto you are healed!
            you.Adjectives.Remove(you.Adjectives.Single(a => a.Name.Equals("Giant")));

            Assert.IsTrue(stack.RunStack(world, new FixedChoiceUI(you, badInjury),
                                         you.GetFinalActions().OfType <HealAction>().Single(), you, you.GetFinalBehaviours()));
        }
示例#6
0
        public void TestCreatingItem_FromBlueprint()
        {
            var yaml = @"
- Name: Crumpled Pamphlet
  Dialogue: 
    Verb: read
    Next: e088ff6e-60de-4a59-a9d8-b9406a2aed7c
- Name: Torn Pamphlet
  Dialogue: 
    Verb: read
    Next: f1909b20-80c3-4af4-b098-b6bf22bf5ca8
";

            var factory = new ItemFactory {
                Blueprints = Compiler.Instance.Deserializer.Deserialize <List <ItemBlueprint> >(yaml)
            };

            Assert.AreEqual(2, factory.Blueprints.Count);

            var you  = YouInARoom(out IWorld w);
            var item = factory.Create(w, factory.Blueprints[1]);

            Assert.AreEqual("Torn Pamphlet", item.Name);
            Assert.AreEqual(new Guid("f1909b20-80c3-4af4-b098-b6bf22bf5ca8"), item.Dialogue.Next);

            w.Dialogue.AllDialogues.Add(new DialogueNode()
            {
                Identifier = new Guid("f1909b20-80c3-4af4-b098-b6bf22bf5ca8"),
                Body       = new List <TextBlock>
                {
                    new TextBlock("Welcome to the ship")
                }
            });

            you.Items.Add(item);

            var ui = new FixedChoiceUI("read:Torn Pamphlet");

            w.RunRound(ui, you.GetFinalActions().OfType <DialogueAction>().First());

            Assert.Contains("Welcome to the ship", ui.MessagesShown);
        }
        public void TestMainDialogueCondition_AreFriends(bool friends)
        {
            TwoInARoomWithRelationship(friends ? 10 : -10, false, out You you, out IActor them, out IWorld w);
            them.BaseActions.Clear();

            //so you don't starve
            you.BaseBehaviours.Clear();
            them.BaseBehaviours.Clear();

            var g1 = new Guid("93d68a59-d0ef-4df7-97af-fa3db0840bad");
            var n1 = new DialogueNode()
            {
                Identifier = g1,
                Body       = new List <TextBlock> {
                    new TextBlock("Hey I want to give you all the space bucks!")
                },
                Condition = new List <ICondition>()
                {
                    new ConditionCode("return Recipient:AttitudeTo(AggressorIfAny) > 5")
                }
            };

            w.Dialogue.AllDialogues = new List <DialogueNode>(new [] { n1 });
            them.Dialogue.Next      = g1;
            them.Dialogue.Verb      = "talk";

            for (int i = 0; i < 10; i++)
            {
                var ui = new FixedChoiceUI("talk:Chaos Sam");
                w.RunRound(ui, you.GetFinalActions().OfType <DialogueAction>().Single());

                if (friends)
                {
                    Assert.Contains("Hey I want to give you all the space bucks!", ui.MessagesShown);
                }
                else
                {
                    Assert.Contains("Chaos Sam had nothing interesting to say", ui.MessagesShown);
                }
            }
        }
示例#8
0
 protected void GoEast(IWorld world, out FixedChoiceUI ui)
 {
     world.RunRound(ui = GetUI(Direction.East), new LeaveAction(world.Player));
 }