public void SimpleEngineConMath() { var player = new Actor(); player.Ammo = 3; var rules = new DialogRule[] { new DialogRule() { Name = "I have more than half health", Conditions = new DialogRule.DialogCondition[] { new DialogRule.DialogCondition() { Left = "player.health", Op = ">", Right = "(/ player.maxHealth 2)" } } }, new DialogRule() { Name = "I am the king of health and ammo", Conditions = new DialogRule.DialogCondition[] { new DialogRule.DialogCondition() { Left = "player.health", Op = "=", Right = "player.maxHealth" }, new DialogRule.DialogCondition() { Left = "player.ammo", Op = ">", Right = "25" } } } }; 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 more than half health", best.Name); }
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]); }
public void SimpleEngineOutcomeSetter() { var player = new Actor(); player.MaxHealth = 100; player.Health = 100; 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" } }, Outcomes = new DialogRule.DialogOutcome[] { new DialogRule.DialogOutcome() { Command = "set", Target = "player.health", Arguments = new Dictionary <string, string>() { { "", "(/ player.maxHealth 2)" } } } } } }; 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); engine.ExecuteRuleOutcomes(best); Assert.AreEqual(50, player.Health); }
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]); }
public void SimpleEngineTransform() { var player = new Actor(); var rules = new DialogRule[] { new DialogRule() { Name = "I have full health!", Conditions = new DialogRule.DialogCondition[] { new DialogRule.DialogCondition() { Left = "dialog.target.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() .AddTransform("dialog.target", () => "player"); 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 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); }