コード例 #1
0
        public void SimpleTemplateInterp()
        {
            var player = new Actor();

            var rules = new DialogRule[]
            {
                new DialogRule()
                {
                    Name       = "I have full health!",
                    Conditions = new DialogRule.DialogCondition[]
                    {
                        new DialogRule.DialogCondition()
                        {
                            Left  = "player.health",
                            Op    = "=",
                            Right = "player.maxHealth"
                        }
                    },
                    Dialog = new DialogRule.DialogPart[]
                    {
                        new DialogRule.DialogPart()
                        {
                            Speaker      = "player",
                            Content      = "I have health of {player health} which and {player maxHealth + player health}",
                            ContentParts = new string[]
                            {
                                "'I have health of '",
                                "player.health",
                                "' which and '",
                                "(+ player.maxHealth player.health)"
                            }
                        }
                    }
                },
            };

            var attributes = new ObjectDialogAttribute[]
            {
                new ObjectDialogAttribute(player, "player", "health"),
                new ObjectDialogAttribute(player, "player", "maxHealth"),
                new ObjectDialogAttribute(player, "player", "ammo"),
            };

            var engine = new DialogEngine();

            rules.ToList().ForEach(r => engine.AddRule(r));
            attributes.ToList().ForEach(a => engine.AddAttribute(a));

            var best = engine.GetBestValidDialog();

            Assert.IsNotNull(best);
            Assert.AreEqual("I have full health!", best.Name);

            var dialogs = engine.ExecuteRuleDialogs(best);

            Assert.AreEqual(1, dialogs.Length);
            Assert.AreEqual("I have health of 50 which and 100", dialogs[0]);
        }
コード例 #2
0
        public void TemplateInterpStrings()
        {
            var player = new Actor();

            var rules = new DialogRule[]
            {
                new DialogRule()
                {
                    Name       = "I have full health!",
                    Conditions = new DialogRule.DialogCondition[]
                    {
                        new DialogRule.DialogCondition()
                        {
                            Left  = "player.health",
                            Op    = "=",
                            Right = "player.maxHealth"
                        }
                    },
                    Dialog = new DialogRule.DialogPart[]
                    {
                        new DialogRule.DialogPart()
                        {
                            Speaker      = "player",
                            Content      = "my health is <color='red'> great </color>",
                            ContentParts = new string[]
                            {
                                "'my health is <color='red'> great </color>'",
                            }
                        }
                    }
                },
            };

            var attributes = new ObjectDialogAttribute[]
            {
                new ObjectDialogAttribute(player, "player", "health"),
                new ObjectDialogAttribute(player, "player", "maxHealth"),
                new ObjectDialogAttribute(player, "player", "ammo"),
            };

            var engine = new DialogEngine();

            rules.ToList().ForEach(r => engine.AddRule(r));
            attributes.ToList().ForEach(a => engine.AddAttribute(a));

            var best = engine.GetBestValidDialog();

            Assert.IsNotNull(best);
            Assert.AreEqual("I have full health!", best.Name);

            var dialogs = engine.ExecuteRuleDialogs(best);

            Assert.AreEqual(1, dialogs.Length);
            Assert.AreEqual("my health is <color='red'> great </color>", dialogs[0]);
        }