Exemplo n.º 1
0
 public override void HandleNewConditionSet(DialogEngine engine, DialogConditionSet condition, List <string> extractedRefs)
 {
     _nameToSet.Add("__.conditions." + condition.Name.ToLower(),
                    condition.Conditions.Select(c => new DialogRule.DialogCondition()
     {
         Left = c.Left, Op = c.Op, Right = c.Right
     }).ToList());
     base.HandleNewConditionSet(engine, condition, extractedRefs);
 }
Exemplo n.º 2
0
        public DialogEngine AddConditionSet(DialogConditionSet condition)
        {
            var refs = ExtractReferencesFromCondition(condition);

            for (var i = 0; i < _onAdditionHandlers.Count; i++)
            {
                _onAdditionHandlers[i].HandleNewConditionSet(this, condition, refs);
            }
            _conditionSets.Add(condition);
            return(this);
        }
Exemplo n.º 3
0
        public List <string> ExtractReferencesFromCondition(DialogConditionSet condition)
        {
            var references = new List <string>();

            for (var i = 0; i < condition.Conditions?.Length; i++)
            {
                references.AddRange(condition.Conditions[i].Left.ExtractReferences());
                references.AddRange(condition.Conditions[i].Right.ExtractReferences());
            }

            return(references.Distinct().ToList());
        }
Exemplo n.º 4
0
        public void SimpleEngineWithConditionSetLoopDetected()
        {
            var player = new Actor();

            player.Health = player.MaxHealth;
            var sets = new DialogConditionSet[]
            {
                new DialogConditionSet()
                {
                    Name       = "test",
                    Conditions = new DialogConditionSet.DialogCondition[]
                    {
                        new DialogConditionSet.DialogCondition()
                        {
                            Left  = "player.health",
                            Op    = ">",
                            Right = "1"
                        },
                        new DialogConditionSet.DialogCondition()
                        {
                            Left  = "__.conditions.egg",
                            Op    = "=",
                            Right = "true"
                        }
                    }
                },
                new DialogConditionSet()
                {
                    Name       = "egg",
                    Conditions = new DialogConditionSet.DialogCondition[]
                    {
                        new DialogConditionSet.DialogCondition()
                        {
                            Left  = "__.conditions.test",
                            Op    = "=",
                            Right = "true"
                        },
                        new DialogConditionSet.DialogCondition()
                        {
                            Left  = "player.ammo",
                            Op    = ">",
                            Right = "5"
                        }
                    }
                }
            };

            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"
                        },
                        new DialogRule.DialogCondition()
                        {
                            Left  = "__.conditions.egg",
                            Op    = "=",
                            Right = "true"
                        }
                    }
                },
                new DialogRule()
                {
                    Name       = "I am less specific",
                    Conditions = new DialogRule.DialogCondition[]
                    {
                        new DialogRule.DialogCondition()
                        {
                            Left  = "player.health",
                            Op    = "=",
                            Right = "player.maxHealth"
                        },
                        new DialogRule.DialogCondition()
                        {
                            Left  = "player.health",
                            Op    = "=",
                            Right = "player.maxHealth"
                        }
                    }
                },
            };

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

            var engine = new DialogEngine().AddHandler(new ConditionSetEvalHandler());

            sets.ToList().ForEach(r => engine.AddConditionSet(r));
            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);
        }
Exemplo n.º 5
0
 public virtual void HandleNewConditionSet(DialogEngine engine, DialogConditionSet condition, List <string> extractedRefs)
 {
 }
Exemplo n.º 6
0
 public override void HandleNewConditionSet(DialogEngine engine, DialogConditionSet condition, List <string> extractedRefs)
 {
     HandleRefs(engine, extractedRefs);
     base.HandleNewConditionSet(engine, condition, extractedRefs);
 }