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); }
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); }
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()); }
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); }
public virtual void HandleNewConditionSet(DialogEngine engine, DialogConditionSet condition, List <string> extractedRefs) { }
public override void HandleNewConditionSet(DialogEngine engine, DialogConditionSet condition, List <string> extractedRefs) { HandleRefs(engine, extractedRefs); base.HandleNewConditionSet(engine, condition, extractedRefs); }