コード例 #1
0
        public void TestEffect_StatBoost()
        {
            var you = YouInARoom(out IWorld world);

            string yaml =
                @"
Body: 
    - Text: Would you like a stat bonus?
Options:   
    - Text: Yes Please!
      Effect: 
        - Lua: AggressorIfAny.BaseStats:Increase(Fight , 20)
";
            var blue    = Compiler.Instance.Deserializer.Deserialize <DialogueNodeBlueprint>(yaml);
            var factory = new DialogueNodeFactory();
            var n       = factory.Create(blue);

            var d = new DialogueSystem();

            d.AllDialogues.Add(n);

            //pick the first option
            var ui = GetUI(n.Options.First());

            double before = you.BaseStats[Stat.Fight];

            d.Run(new SystemArgs(world, ui, 0, you, Mock.Of <IHasStats>(), Guid.NewGuid()), n);
            Assert.AreEqual(before + 20, you.BaseStats[Stat.Fight]);
        }
コード例 #2
0
ファイル: HasGuidTest.cs プロジェクト: tznind/Wanderer
        public void TestHasGuid_Deserialization(bool useNot)
        {
            string yaml = @$ "
Text: You have a jolly glo globe.
Condition:
  - Lua: return AggressorIfAny.CurrentLocation:Has(Guid('6fa349e4-aefe-4ebc-9922-e3476ea1dba7')) {(useNot?" == false ":" ")}";

            var blockBlueprint = Compiler.Instance.Deserializer.Deserialize <TextBlockBlueprint>(yaml);

            var f     = new DialogueNodeFactory();
            var block = f.Create(blockBlueprint);

            var you = YouInARoom(out IWorld world);

            you.Identifier = new Guid("6fa349e4-aefe-4ebc-9922-e3476ea1dba7");

            Assert.AreEqual(!useNot,
                            block.Condition.Single().IsMet(world, new SystemArgs(world, null, 0, you, null, Guid.Empty)));
        }
コード例 #3
0
ファイル: DialogueTests.cs プロジェクト: tznind/Wanderer
        public void TestConditionalDialogue_RoomHasLight()
        {
            string yaml = @"
- Identifier: ce16ae16-4de8-4e33-8d52-ace4543ada20
  Body: 
    - Text: This room is
    - Text: Pitch Black
      Condition: 
        - Lua: return Room:Has('Light') == false
    - Text: Dimly Illuminated
      Condition: 
        - Lua: return Room:Has('Light')";

            var nodes   = Compiler.Instance.Deserializer.Deserialize <List <DialogueNodeBlueprint> >(yaml);
            var factory = new DialogueNodeFactory();

            var system = new DialogueSystem {
                AllDialogues = nodes.Select(factory.Create).ToList()
            };

            Assert.IsNotNull(system);

            var ui = GetUI();

            var room = InARoom(out IWorld world);

            system.Run(new SystemArgs(world, ui, 0,
                                      Mock.Of <IActor>(a => a.CurrentLocation == room), room,
                                      Guid.NewGuid()), system.AllDialogues.Single());

            Assert.Contains("This room is Pitch Black", ui.MessagesShown);

            room.Adjectives.Add(world.AdjectiveFactory.Create(world, room, "Light"));

            system.Run(new SystemArgs(world, ui, 0,
                                      Mock.Of <IActor>(a => a.CurrentLocation == room), room,
                                      Guid.NewGuid()), system.AllDialogues.Single());

            Assert.Contains("This room is Dimly Illuminated", ui.MessagesShown);
        }
コード例 #4
0
ファイル: DialogueTests.cs プロジェクト: tznind/Wanderer
        public void TestConditionalDialogue_ActorHasStat()
        {
            string yaml = @"
- Identifier: ce16ae16-4de8-4e33-8d52-ace4543ada20
  Body: 
    - Text: The denizens of this degenerate bar 
    - Text: make you nervous
      Condition: 
        - Lua: return AggressorIfAny:GetFinalStats()[Corruption] <= 5
    - Text: seem like your kind of people
      Condition: 
        - Lua: return AggressorIfAny:GetFinalStats()[Corruption] > 5";

            var blueprints = Compiler.Instance.Deserializer.Deserialize <List <DialogueNodeBlueprint> >(yaml);
            var f          = new DialogueNodeFactory();

            var system = new DialogueSystem {
                AllDialogues = blueprints.Select(b => f.Create(b)).ToList()
            };

            Assert.IsNotNull(system);

            var ui = GetUI();

            var you        = YouInARoom(out IWorld world);
            var corruption = world.AllStats.GetOrAdd("Corruption");

            you.BaseStats[corruption] = 0;

            system.Run(new SystemArgs(world, ui, 0, you, you.CurrentLocation, Guid.NewGuid()), system.AllDialogues.Single());

            Assert.Contains("The denizens of this degenerate bar make you nervous", ui.MessagesShown);

            you.BaseStats[corruption] = 10;

            system.Run(new SystemArgs(world, ui, 0, you, you.CurrentLocation, Guid.NewGuid()), system.AllDialogues.Single());

            Assert.Contains("The denizens of this degenerate bar seem like your kind of people", ui.MessagesShown);
        }
コード例 #5
0
ファイル: DialogueTests.cs プロジェクト: tznind/Wanderer
        public void Test_Substitutions(bool areFriends)
        {
            TwoInARoomWithRelationship(areFriends ? 10:-10, false, out You you, out IActor them, out IWorld world);

            them.Name          = "Space Crab";
            them.Dialogue.Next = new Guid("339271e0-7b11-4aba-a9e2-2776f6c5a197");

            var yaml = @"- Identifier: 339271e0-7b11-4aba-a9e2-2776f6c5a197
  Body: 
    - Text: Screeeee (this creature seems friendly)
      Condition: 
        - Lua: return Recipient:AttitudeTo(AggressorIfAny) > 0
    - Text: Screeeee (this creature seems hostile)
      Condition: 
        - Lua: return Recipient:AttitudeTo(AggressorIfAny)  < 0
    - Text: Screeeee (this creature seems indifferent)
      Condition: 
        - Lua: return Recipient:AttitudeTo(AggressorIfAny) == 0";

            var blueprints      = Compiler.Instance.Deserializer.Deserialize <List <DialogueNodeBlueprint> >(yaml);
            var dialogueFactory = new DialogueNodeFactory();
            var dlg             = new DialogueSystem {
                AllDialogues = blueprints.Select(b => dialogueFactory.Create(b)).ToList()
            };

            var ui = GetUI();

            dlg.Apply(new SystemArgs(world, ui, 0, you, them, Guid.Empty));

            if (areFriends)
            {
                Assert.Contains("Screeeee (this creature seems friendly)", ui.MessagesShown);
            }
            else
            {
                Assert.Contains("Screeeee (this creature seems hostile)", ui.MessagesShown);
            }
        }