public void FunctionalTreeConverterTestComplexFunctionWithAttributes() { string expression = $"{LConstants.GET_PROP_F}({MockPlayer.Key},STR)*100+{LConstants.MAX_F}({LConstants.GET_PROP_F}({MockPlayer.Key},AGI),3)"; double expected = MockPlayer.GetProperty("STR").Value * 100 + (MockPlayer.GetProperty("AGI").Value > 3? MockPlayer.GetProperty("AGI").Value : 3); Assert.AreEqual(expected, TreeResolver.Resolve(expression, Engine).Value.ToDouble()); }
public void FunctionalTreeConverterTestExecuteLater() { string expression = $"{LConstants.IF_F}(10>3,10,11)"; double actual = TreeResolver.Resolve(expression, Engine).Value.ToDouble(); Assert.AreEqual(10, actual); }
public void FunctionalTreeConverterTestBooleanAndUnaryOperator() { string expression = "!(10>3+8)"; bool actual = TreeResolver.Resolve(expression, Engine).Value.ToBoolean(); Assert.AreEqual(true, actual); }
public MeVariable ResolveStatus(MeNode tree, double[] values) { Dictionary <string, double> valueMap = GetNumericValueMap(values); ReplaceNumericPlaceholders(tree, valueMap); return(TreeResolver.Resolve(tree).Value); }
public void FunctionalTreeConverterTestPowerOperatorCombination() { string expression = "10+10^3+10"; double expected = 1020; double actual = TreeResolver.Resolve(expression, Engine).Value.ToDouble(); Assert.AreEqual(expected, actual); }
public void FunctionalTreeConverterTestNestedIf() { string expression = $"{LConstants.IF_F}({LConstants.MAX_F}(10,3)>3,{LConstants.IF_F}(10>3,10,20),30)"; double expected = 10; double actual = TreeResolver.Resolve(expression, Engine).Value.ToDouble(); Assert.AreEqual(expected, actual); }
public void FunctionalTreeConverterTestExecuteLaterFunctionThatChangesThings() { string expression = $"{LConstants.IF_F}(1>3,10,{LConstants.HARM_F}({MockPlayer.Key},{MockPlayer.Key},T,10))"; double expectedHp = MockPlayer.GetProperty(Entity.HP_KEY).Value - 10; TreeResolver.Resolve(expression, Engine); Assert.AreEqual(expectedHp, MockPlayer.GetProperty(Entity.HP_KEY).Value); }
public void EntityTestAlwaysDodge() { string expression = $"{LConstants.HARM_F}({BaseEntity.Key},{BaseEntity.Key},AD,20)"; double expected = BaseEntity.GetProperty(Entity.HP_KEY).Value; TreeResolver.Resolve(expression, Engine); Assert.AreEqual(expected, BaseEntity.GetProperty(Entity.HP_KEY).Value); }
public void FunctionalTreeConverterTestHarmEntity() { string expression = $"{LConstants.HARM_F}({MockPlayer.Key},{MockPlayer.Key},T,20)"; double expected = MockPlayer.GetProperty(Entity.HP_KEY).Value - 20; TreeResolver.Resolve(expression, Engine); Assert.AreEqual(expected, MockPlayer.GetProperty(Entity.HP_KEY).Value); }
public void FunctionalTreeConverterTestArrayAndFunction() { string expression = $"{LConstants.ARRAY_F}(10,{LConstants.MAX_F}(10,20),10)"; double[] expected = { 10, 20, 10 }; double[] actual = MeVariable.ToDoubleArray(TreeResolver.Resolve(expression, Engine).Value.ToArray()); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); }
public void FunctionalTreeConverterTestFunctionWithNoParameters() { string expression = $"{LConstants.GET_PLAYERS_F}()"; string expected = "MOCK_PLAYER"; Token[] tokens = Tokenizer.Tokenize(expression); MeVariable[] players = TreeResolver.Resolve(tokens, Engine).Value.ToArray(); Assert.AreEqual(1, players.Length); Assert.AreEqual(expected, players[0].ToEntity().Name); }
public void EntityTestAlwaysCrit() { double amt = 20; string expression = $"{LConstants.HARM_F}({BaseEntity.Key},{BaseEntity.Key},AC,{amt})"; double expected = BaseEntity.GetProperty(Entity.HP_KEY).Value - amt * 2; TreeResolver.Resolve(expression, Engine); Assert.AreEqual(expected, BaseEntity.GetProperty(Entity.HP_KEY).Value); }
public MeVariable SanitizeSkill(string skill, Entity caster, Entity target) { string[] lines = skill.Split(LConstants.FUNCTION_SEPARATOR); MeVariable var = null; foreach (string expr in lines) { Token[] tokens = Tokenizer.Tokenize(expr); Token[] sanitizedTokens = ReplaceEntities(tokens, caster, target); var = TreeResolver.Resolve(sanitizedTokens, _engine).Value; } return(var); }
public void FunctionalTreeConverterTestSimpleFunction() { string expression = $"{LConstants.MAX_F}(10,20)"; Assert.AreEqual(20, TreeResolver.Resolve(expression, Engine).Value.ToDouble()); }
public void FunctionalTreeConverterTestGetPropertyTest() { string expression = $"{LConstants.GET_PROP_F}({MockPlayer.Key},STR)"; Assert.AreEqual(5, TreeResolver.Resolve(expression, Engine).Value.ToDouble()); }
public void FunctionalTreeConverterTestSimpleOperationNegativeResult() { string expression = "10-13"; Assert.AreEqual(-3, TreeResolver.Resolve(expression, Engine).Value.ToDouble()); }
public double SanitizeCompoundStat(Entity entity, string expression) { Token[] tokens = Tokenizer.Tokenize(expression); Token[] sanitizedTokens = ReplaceProperties(tokens, entity); return(TreeResolver.Resolve(sanitizedTokens, _engine).Value.ToDouble()); }
public MeNode Resolve() { return(TreeResolver.Resolve(this)); }
public void FunctionalTreeConverterTestOperatorAndFunction() { string expression = $"{LConstants.ABS_F}(10-100)"; Assert.AreEqual(90, TreeResolver.Resolve(expression, Engine).Value.ToDouble()); }
public void FunctionalTreeConverterTestNestedFunctions() { string expression = $"{LConstants.MAX_F}(10,{LConstants.MAX_F}(3,4))"; Assert.AreEqual(10, TreeResolver.Resolve(expression, Engine).Value.ToDouble()); }
public void FunctionalTreeConverterTestNestedOperation() { string expression = "10*13+10"; Assert.AreEqual(140, TreeResolver.Resolve(expression, Engine).Value.ToDouble()); }