public void BoolBag2() { var player = new { health = 10, flags = new BagBoolElement[] { new BagBoolElement() { name = "a.part", value = true } }.ToList() }; var rules = new DialogRule[] { new DialogRule() { Name = "I have full health!", Conditions = new DialogRule.DialogCondition[] { new DialogRule.DialogCondition() { Left = "player.flags.a.part", Op = "=", Right = "true" }, new DialogRule.DialogCondition() { Left = "player.flags.b", Op = "=", Right = "false" } } }, }; var engine = new DialogEngine() .AddHandler(new BagBoolHandler()); var attributes = new DialogAttribute[] { new ObjectDialogAttribute(player, "player", "health"), DialogAttribute.New("player.flags", false, player.flags).UpdateElements(engine) //new BagDialogAttribute<bool>("player.flags", player.flags).UpdateElements(engine) }; attributes.ToList().ForEach(a => engine.AddAttribute(a)); rules.ToList().ForEach(r => engine.AddRule(r)); var best = engine.GetBestValidDialog(); Assert.IsNotNull(best); Assert.AreEqual("I have full health!", best.Name); }
public void IntBag() { var player = new { health = 10, ints = new BagIntElement[] { }.ToList() }; var rules = new DialogRule[] { new DialogRule() { Name = "I have full health!", Conditions = new DialogRule.DialogCondition[] { new DialogRule.DialogCondition() { Left = "player.ints.a", Op = "=", Right = "10" }, new DialogRule.DialogCondition() { Left = "player.ints.hidaldo.rep", Op = ">", Right = "6" } } }, }; var engine = new DialogEngine() .AddHandler(new BagIntHandler()); var attributes = new DialogAttribute[] { new ObjectDialogAttribute(player, "player", "health"), DialogAttribute.New("player.ints", 10, player.ints).UpdateElements(engine) //new BagDialogAttribute<bool>("player.flags", player.flags).UpdateElements(engine) }; attributes.ToList().ForEach(a => engine.AddAttribute(a)); rules.ToList().ForEach(r => engine.AddRule(r)); var best = engine.GetBestValidDialog(); Assert.IsNotNull(best); Assert.AreEqual("I have full health!", best.Name); }
public void SimpleEngineOutcomeRunner() { 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 = "run", Target = "player.sampleFunc", Arguments = new Dictionary <string, string>() { { "h", "(/ player.maxHealth 2)" }, { "ammo", "55" } } } } } }; // new OFDA(player, "setAll", new Dictionary<string, string>(){ var attributes = new DialogAttribute[] { new ObjectDialogAttribute(player, "player", "health"), new ObjectDialogAttribute(player, "player", "maxHealth"), new ObjectDialogAttribute(player, "player", "ammo"), new ObjectFunctionDialogAttribute("player.sampleFunc", new Action <Dictionary <string, object> >(vars => { var health = (int)vars["h"]; var maxHealth = (int)vars["mx"]; var ammo = (int)vars["ammo"]; player.SetAll(health, maxHealth, ammo); }), new Dictionary <string, object> { { "mx", 200 } }) }; 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); Assert.AreEqual(200, player.MaxHealth); Assert.AreEqual(55, player.Ammo); }
public void StringAndIntBags() { var player = new { health = 10, nums = new BagIntElement[] { new BagIntElement() { name = "a", value = 5 } }.ToList(), strs = new BagStringElement[] { new BagStringElement() { name = "a", value = "tuna" } }.ToList() }; var rules = new DialogRule[] { new DialogRule() { Name = "I have full health!", Conditions = new DialogRule.DialogCondition[] { new DialogRule.DialogCondition() { Left = "player.nums.a", Op = "=", Right = "5" }, new DialogRule.DialogCondition() { Left = "player.nums.b", Op = ">", Right = "6" }, new DialogRule.DialogCondition() { Left = "player.strs.a", Op = "=!", Right = "player.strs.b" } } }, }; var engine = new DialogEngine() .AddHandler(new BagIntHandler()) .AddHandler(new BagStringHandler()); var attributes = new DialogAttribute[] { new ObjectDialogAttribute(player, "player", "health"), DialogAttribute.New("player.nums", 10, player.nums).UpdateElements(engine), DialogAttribute.New("player.strs", "eggs", player.strs).UpdateElements(engine) //new BagDialogAttribute<bool>("player.flags", player.flags).UpdateElements(engine) }; attributes.ToList().ForEach(a => engine.AddAttribute(a)); rules.ToList().ForEach(r => engine.AddRule(r)); var best = engine.GetBestValidDialog(); Assert.IsNotNull(best); Assert.AreEqual("I have full health!", best.Name); }