Exemple #1
0
        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());
        }
Exemple #2
0
        public void FunctionalTreeConverterTestExecuteLater()
        {
            string expression = $"{LConstants.IF_F}(10>3,10,11)";
            double actual     = TreeResolver.Resolve(expression, Engine).Value.ToDouble();

            Assert.AreEqual(10, actual);
        }
Exemple #3
0
        public void FunctionalTreeConverterTestBooleanAndUnaryOperator()
        {
            string expression = "!(10>3+8)";
            bool   actual     = TreeResolver.Resolve(expression, Engine).Value.ToBoolean();

            Assert.AreEqual(true, actual);
        }
Exemple #4
0
        public MeVariable ResolveStatus(MeNode tree, double[] values)
        {
            Dictionary <string, double> valueMap = GetNumericValueMap(values);

            ReplaceNumericPlaceholders(tree, valueMap);
            return(TreeResolver.Resolve(tree).Value);
        }
Exemple #5
0
        public void FunctionalTreeConverterTestPowerOperatorCombination()
        {
            string expression = "10+10^3+10";
            double expected   = 1020;
            double actual     = TreeResolver.Resolve(expression, Engine).Value.ToDouble();

            Assert.AreEqual(expected, actual);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        public void FunctionalTreeConverterTestSimpleFunction()
        {
            string expression = $"{LConstants.MAX_F}(10,20)";

            Assert.AreEqual(20, TreeResolver.Resolve(expression, Engine).Value.ToDouble());
        }
Exemple #15
0
        public void FunctionalTreeConverterTestGetPropertyTest()
        {
            string expression = $"{LConstants.GET_PROP_F}({MockPlayer.Key},STR)";

            Assert.AreEqual(5, TreeResolver.Resolve(expression, Engine).Value.ToDouble());
        }
Exemple #16
0
        public void FunctionalTreeConverterTestSimpleOperationNegativeResult()
        {
            string expression = "10-13";

            Assert.AreEqual(-3, TreeResolver.Resolve(expression, Engine).Value.ToDouble());
        }
Exemple #17
0
 public double SanitizeCompoundStat(Entity entity, string expression)
 {
     Token[] tokens          = Tokenizer.Tokenize(expression);
     Token[] sanitizedTokens = ReplaceProperties(tokens, entity);
     return(TreeResolver.Resolve(sanitizedTokens, _engine).Value.ToDouble());
 }
Exemple #18
0
 public MeNode Resolve()
 {
     return(TreeResolver.Resolve(this));
 }
Exemple #19
0
        public void FunctionalTreeConverterTestOperatorAndFunction()
        {
            string expression = $"{LConstants.ABS_F}(10-100)";

            Assert.AreEqual(90, TreeResolver.Resolve(expression, Engine).Value.ToDouble());
        }
Exemple #20
0
        public void FunctionalTreeConverterTestNestedFunctions()
        {
            string expression = $"{LConstants.MAX_F}(10,{LConstants.MAX_F}(3,4))";

            Assert.AreEqual(10, TreeResolver.Resolve(expression, Engine).Value.ToDouble());
        }
Exemple #21
0
        public void FunctionalTreeConverterTestNestedOperation()
        {
            string expression = "10*13+10";

            Assert.AreEqual(140, TreeResolver.Resolve(expression, Engine).Value.ToDouble());
        }