コード例 #1
0
        public void EntityTestModifierAndHarm()
        {
            BaseEntity ent = new MockEntity(Engine)
            {
                Name = "MOCK_PLAYER", Key = "MOCK_KEY"
            };
            string expression = $"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.TargetKeyword},T,$0);{LConstants.ADD_MOD_F}(STR,$1)";

            MeNode[]       statuses = Engine.GetSanitizer().SplitAndConvert(expression);
            StatusTemplate test     = new StatusTemplate(statuses)
            {
                Interval = TreeConverter.Build("0", Engine)
            };

            test.Key = "TEST_STATUS_KEY3";
            double[] values     = { 20, 10 };
            double   expectedHp = ent.GetProperty(Entity.HP_KEY).Value - values[0];
            double   expected   = ent.GetProperty("STR").Value + values[1];

            ent.ApplyStatus(test, ent, 5, values);
            ent.Update();

            Assert.AreEqual(expectedHp, ent.GetProperty(Entity.HP_KEY).Value);
            Assert.AreEqual(expected, ent.GetProperty("STR").Value);
        }
コード例 #2
0
ファイル: StatusReader.cs プロジェクト: Bluegent/MeRpgBot
        public StatusTemplate FromJSON(JObject json)
        {
            MeNode[]       formulas = Engine.GetSanitizer().SplitAndConvert(json[GcConstants.General.FORMULA].ToString());
            StatusTemplate result   = new StatusTemplate(formulas);

            result.LoadBase(json);

            result.MaxStacks = json.ContainsKey(GcConstants.Statuses.MAX_STACK)
                ? TreeConverter.Build(json[GcConstants.Statuses.MAX_STACK].ToString(), Engine)
                : new MeNode(1);
            ;

            result.Interval = json.ContainsKey(GcConstants.Statuses.INTERVAL)
                ? TreeConverter.Build(json[GcConstants.Statuses.INTERVAL].ToString(), Engine)
                : new MeNode(1);
            ;

            result.Type = json.ContainsKey(GcConstants.Statuses.STACK_TYPE)
                ? StatusTemplate.FromString(json[GcConstants.Statuses.STACK_TYPE].ToString())
                : StackingType.Independent;



            return(result);
        }
コード例 #3
0
        public void EntityTestModifierMultipleStatusEffects()
        {
            BaseEntity ent = new MockEntity(Engine)
            {
                Name = "MOCK_PLAYER", Key = "MOCK_KEY"
            };
            string expression = $"{LConstants.ADD_MOD_F}(STR,$0);{LConstants.ADD_MOD_F}(AGI,$1)";

            MeNode[] statuses = Engine.GetSanitizer().SplitAndConvert(expression);

            StatusTemplate test = new StatusTemplate(statuses)
            {
                Interval = TreeConverter.Build("0", Engine)
            };

            test.Key = "TEST_STATUS_KEY5";
            double[] values = { 10, 5 };

            double expectedStr = ent.GetProperty("STR").Value + values[0];
            double expetedDex  = ent.GetProperty("AGI").Value + values[1];

            ent.ApplyStatus(test, ent, 5, values);
            MockTimer timer = (MockTimer)Engine.GetTimer();

            ent.Update();
            Assert.AreEqual(expectedStr, ent.GetProperty("STR").Value);
            Assert.AreEqual(expetedDex, ent.GetProperty("AGI").Value);
        }
コード例 #4
0
        public void EntityTestModifierHarmTickrate()
        {
            BaseEntity ent = new MockEntity(Engine)
            {
                Name = "MOCK_PLAYER", Key = "MOCK_KEY"
            };

            int[]  timeValues = { 10, 5 };
            string expression = $"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.TargetKeyword},T,$0)";

            MeNode[]       statuses = Engine.GetSanitizer().SplitAndConvert(expression);
            StatusTemplate test     = new StatusTemplate(statuses)
            {
                Interval = TreeConverter.Build(timeValues[0].ToString(), Engine)
            };

            test.Key = "TEST_STATUS_KEY4";
            double[] values = { 20 };
            ent.ApplyStatus(test, ent, timeValues[0], values);
            double    expectedHp = ent.GetProperty(Entity.HP_KEY).Value - values[0];
            MockTimer timer      = (MockTimer)Engine.GetTimer();

            ent.Update();
            Assert.AreEqual(expectedHp, ent.GetProperty(Entity.HP_KEY).Value);

            timer.ForceTick();
            timer.ForceTick();
            ent.Update();

            Assert.AreEqual(expectedHp, ent.GetProperty(Entity.HP_KEY).Value);
        }
コード例 #5
0
        public void EntityTestHarmStatusIntervalIsFormula()
        {
            BaseEntity ent = new MockEntity(Engine)
            {
                Name = "MOCK_PLAYER", Key = "MOCK_KEY"
            };
            double damage     = 10;
            string expression = $"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.TargetKeyword},T,{damage})";

            MeNode[]       statuses           = Engine.GetSanitizer().SplitAndConvert(expression);
            string         intervalExpression = $"10-{LConstants.GET_PROP_F}({LConstants.SourceKeyword},INT)*2";
            MeNode         intervalNode       = TreeConverter.Build(intervalExpression, Engine);
            StatusTemplate test = new StatusTemplate(statuses)
            {
                Interval = intervalNode
            };

            test.Key = "TEST_STATUS_KEY2";
            ent.ApplyStatus(test, ent, 5, null);
            double    expectedHp  = ent.GetProperty(Entity.HP_KEY).Value - damage;
            double    expectedHp2 = ent.GetProperty(Entity.HP_KEY).Value - damage * 2;
            MockTimer timer       = (MockTimer)Engine.GetTimer();

            ent.Update();
            timer.ForceTick();
            Assert.AreEqual(expectedHp, ent.GetProperty(Entity.HP_KEY).Value);

            ent.Update();
            Assert.AreEqual(expectedHp2, ent.GetProperty(Entity.HP_KEY).Value);
        }
コード例 #6
0
        public void EntityTestPropertyTypeUpdatesWithFunction()
        {
            //initial test
            string strKey            = "STR";
            string expression        = $"{LConstants.GET_PROP_F}({BaseEntity.Key},{strKey})";
            double expected          = BaseEntity.GetProperty(strKey).Value;
            MeNode tree              = TreeConverter.Build(expression, Engine);
            MeNode partiallyResolved = TreeResolver.ResolveGivenOperations(tree, new string[1] {
                LConstants.GET_PROP_F
            });

            Assert.AreEqual(expected, partiallyResolved.Value.ToDouble());

            //apply a status that modifies the value
            string expression2 = $"{LConstants.ADD_MOD_F}(STR,$0)";

            MeNode[]       statuses = Engine.GetSanitizer().SplitAndConvert(expression2);
            StatusTemplate test     = new StatusTemplate(statuses)
            {
                Interval = TreeConverter.Build("0", Engine)
            };

            test.Key = "TEST_STATUS_KEY33";
            double[] values = { 10 };

            BaseEntity.ApplyStatus(test, BaseEntity, 10, values);
            BaseEntity.Update();

            //test again
            expected = BaseEntity.GetProperty(strKey).Value;
            Assert.AreEqual(expected, partiallyResolved.Value.ToDouble());

            BaseEntity.Cleanse();
        }
コード例 #7
0
ファイル: SkillReader.cs プロジェクト: Bluegent/MeRpgBot
        private SkillCost CostFromJson(JToken json, SkillTemplate skill)
        {
            string key;
            string amountFormula;

            if (json == null)
            {
                key           = Entity.HP_KEY;
                amountFormula = GcConstants.Skills.DEFAULT_COST_VALUE;
            }
            else
            {
                JObject costObj = json.ToObject <JObject>();

                key = JsonUtils.ValidateJsonEntry(GcConstants.General.KEY,
                                                  costObj,
                                                  JTokenType.String,
                                                  $"No cost key for skill {skill.Name}.")
                      .ToString();
                if (!Engine.GetPropertyManager().HasResource(key))
                {
                    throw new MeException($"Unknown resource {key} used by skill {skill.Name}.");
                }

                amountFormula = JsonUtils.ValidateJsonEntry(GcConstants.General.VALUE,
                                                            costObj,
                                                            JTokenType.Integer,
                                                            $"No cost amount for skill {skill.Name}.")
                                .ToString();
            }

            return(new SkillCost(Engine.GetPropertyManager().GetResource(key), TreeConverter.Build(amountFormula, Engine)));
        }
コード例 #8
0
        public void EntityTestModifierStatusEffectsRemoved()
        {
            BaseEntity ent = new MockEntity(Engine)
            {
                Name = "MOCK_PLAYER", Key = "MOCK_KEY"
            };
            string expression = $"{LConstants.ADD_MOD_F}(STR,$0)";

            MeNode[]       statuses = Engine.GetSanitizer().SplitAndConvert(expression);
            StatusTemplate test     = new StatusTemplate(statuses)
            {
                Interval = TreeConverter.Build("0", Engine)
            };

            test.Key = "TEST_STATUS_KEY10";
            double[] values   = { 10 };
            int      duration = 5;
            double   expected = ent.GetProperty("STR").Value + 10;

            double removedExpected = ent.GetProperty("STR").Value;

            ent.ApplyStatus(test, ent, duration, values);
            MockTimer timer = (MockTimer)Engine.GetTimer();

            Assert.AreEqual(expected, ent.GetProperty("STR").Value);
            for (int i = 0; i <= duration; ++i)
            {
                timer.ForceTick();
            }
            ent.Update();
            Assert.AreEqual(removedExpected, ent.GetProperty("STR").Value);
        }
コード例 #9
0
ファイル: SkillReader.cs プロジェクト: Bluegent/MeRpgBot
        private SkillLevelTemplate LevelFromJson(JObject levelValue, SkillTemplate skill)
        {
            SkillLevelTemplate levelTemplate = new SkillLevelTemplate();

            //get cost
            levelTemplate.Cost = CostFromJson(levelValue[GcConstants.Skills.COST], skill);

            //get needed level, push-back and interrupt because they have default values
            levelTemplate.NeededLevel   = JsonUtils.GetValueOrDefault <long>(levelValue, GcConstants.Skills.NEEDED_LEVEL, GcConstants.Skills.DEFAULT_NEEDED_LEVEL);
            levelTemplate.PushBack      = new MeNode(JsonUtils.GetValueOrDefault(levelValue, GcConstants.Skills.PUSH_BACK, GcConstants.Skills.DEFAULT_PUSHBACK));
            levelTemplate.Interruptible = new MeNode(JsonUtils.GetValueOrDefault(levelValue, GcConstants.Skills.INTERRUPT, GcConstants.Skills.DEFAULT_INTERRUPT));

            //get cast duration
            string durationFormula = JsonUtils.GetValueOrDefault(levelValue,
                                                                 GcConstants.Skills.CAST_DURATION,
                                                                 GcConstants.Skills.DEFAULT_CAST_DURATION);

            levelTemplate.Duration = TreeConverter.Build(durationFormula, Engine);

            //get cooldown
            string cdFormula = JsonUtils.GetValueOrDefault(
                levelValue,
                GcConstants.Skills.COOLDOWN,
                GcConstants.Skills.DEFAULT_COOLDOWN);

            levelTemplate.Cooldown = TreeConverter.Build(cdFormula, Engine);

            //get skill threat
            string threatFormula = JsonUtils.GetValueOrDefault <string>(levelValue, GcConstants.Skills.THREAT, null);

            if (threatFormula == null)
            {
                threatFormula = Engine.GetCoreManager().DefaultSkillThreat.ToString();
            }
            levelTemplate.SkillThreat = TreeConverter.Build(threatFormula, Engine);

            //get formulas
            string formulas = JsonUtils.ValidateJsonEntry(GcConstants.General.FORMULA,
                                                          levelValue,
                                                          JTokenType.String,
                                                          $"Missing formula for skill {skill.Name}.").ToString();

            levelTemplate.Formulas.AddRange(Engine.GetSanitizer().SplitAndConvert(formulas));


            //get interval
            if (skill.Type == SkillType.Channel)
            {
                string intervalFormula = JsonUtils.GetValueOrDefault(
                    levelValue,
                    GcConstants.Skills.INTERVAL,
                    GcConstants.Skills.DEFAULT_INTERVAL_VALUE);
                levelTemplate.Interval = TreeConverter.Build(intervalFormula, Engine);
            }

            return(levelTemplate);
        }
コード例 #10
0
        public void TreeResolverTestArrayProperty()
        {
            string expression = $"{LConstants.ARRAY_F}(10,11,12){LConstants.PROP_OP}{LConstants.ARR_LENGTH}";
            double expected   = 3;
            MeNode tree       = TreeConverter.Build(expression, Engine);
            MeNode result     = tree.Resolve();

            Assert.AreEqual(expected, result.Value.ToDouble());
        }
コード例 #11
0
        public void TreeResolverTestEntityProperty()
        {
            string strKey     = "STR";
            string expression = $"{MockPlayer.Key}{LConstants.PROP_OP}{strKey}";
            double expected   = MockPlayer.GetProperty(strKey).Value;
            MeNode tree       = TreeConverter.Build(expression, Engine);
            MeNode result     = tree.Resolve();

            Assert.AreEqual(expected, result.Value.ToDouble());
        }
コード例 #12
0
        public void TreeResolverTestResolveOnlyFunctionsNamed()
        {
            string expression        = $"{LConstants.HARM_F}({MockPlayer.Key},{MockPlayer.Key},P,{LConstants.GET_PROP_F}({MockPlayer.Key},{LConstants.IF_F}({LConstants.GET_PROP_F}({MockPlayer.Key},STR) > {LConstants.GET_PROP_F}({MockPlayer.Key},AGI),STR,AGI)))";
            MeNode tree              = TreeConverter.Build(expression, Engine);
            MeNode partiallyResolved = TreeResolver.ResolveGivenOperations(tree, new string[1] {
                LConstants.GET_PROP_F
            });

            Assert.AreEqual(tree.Value.Type, partiallyResolved.Value.Type);
        }
コード例 #13
0
        public DamageTypeTemplate(IGameEngine engine, string mitigation, string dodge, string crit, string critmod)
        {
            Mitigation = mitigation != null?TreeConverter.Build(mitigation, engine) : null;

            Dodge = dodge != null?TreeConverter.Build(dodge, engine) : null;

            CriticalChance = crit != null?TreeConverter.Build(crit, engine) : null;

            CriticalModifier = critmod != null?TreeConverter.Build(critmod, engine) : null;
        }
コード例 #14
0
ファイル: MockEntity.cs プロジェクト: Bluegent/MeRpgBot
        public static ResourceTemplate getMockHP(IGameEngine engine)
        {
            MeNode           max   = TreeConverter.Build("VIT*20", engine);;
            MeNode           regen = TreeConverter.Build("0", engine);
            ResourceTemplate hp    = new ResourceTemplate();

            hp.Formula       = max;
            hp.RegenFormula  = regen;
            hp.Key           = Entity.HP_KEY;
            hp.RegenInterval = new MeNode(GcConstants.Resources.DEFAULT_INTERVAL);
            return(hp);
        }
コード例 #15
0
ファイル: VariableTest.cs プロジェクト: Bluegent/MeRpgBot
        public void VariableTestAssignOperatorWorks()
        {
            string varName    = "testVar";
            double number     = 3.14;
            string expression = $"{varName} {LConstants.ASSIGN_OP} {number}";
            MeNode tree       = TreeConverter.Build(expression, Engine);

            tree.Resolve();
            MeVariable result = Engine.GetVariable(varName);

            Assert.IsNotNull(result);
            Assert.AreEqual(number, result.ToDouble());
        }
コード例 #16
0
ファイル: StatReader.cs プロジェクト: Bluegent/MeRpgBot
        public StatTemplate FromJson(JObject json)
        {
            StatTemplate result = new StatTemplate();

            result.LoadBase(json);

            string formulaString =
                JsonUtils.ValidateJsonEntry(GcConstants.General.FORMULA, json, JTokenType.String, $"Missing formula for stat {result.Name}.").ToString();

            result.Formula = TreeConverter.Build(formulaString, _engine);

            return(result);
        }
コード例 #17
0
        public void LevelingTestPowerOperator()
        {
            double prev = 500;

            for (int i = 0; i < 20; ++i)
            {
                MeNode ExpFormula = TreeConverter.Build($"{prev}+50*2^{LConstants.FLOOR_F}({i}/5.0)",
                                                        Engine);
                double res = ExpFormula.Resolve().Value.ToDouble();
                double exp = prev + 50 * Math.Pow(2, Math.Floor(i / 5.0));
                prev = exp;
                Assert.AreEqual(exp, res);
            }
        }
コード例 #18
0
ファイル: SanitizerTest.cs プロジェクト: Bluegent/MeRpgBot
        public void SanitizerTestReplacePropetyOperators()
        {
            string expected      = "AGI";
            string expression    = $"1 + {expected}";
            double expectedValue = MockPlayer.GetProperty(expected).Value + 1;

            MeNode result = Sanitizer.ReplacePropeties(TreeConverter.Build(expression, Engine), MockPlayer);

            Assert.AreEqual(LConstants.PROP_OP, result.Leaves[1].Value.GetString());
            Assert.AreEqual(expected, result.Leaves[1].Leaves[1].Value.ToMeString());

            MeNode resolved = result.Resolve();

            Assert.AreEqual(expectedValue, resolved.Value.ToDouble());
        }
コード例 #19
0
        public void FunctionalTreeConverterTestCopy()
        {
            string expression = "11+10";

            double[] expected = { 11, 10 };
            MeNode   tree     = TreeConverter.Build(expression, Engine);
            MeNode   copy     = tree.Resolve();

            Assert.AreEqual(tree.Value.ToOperator().Key, "+");
            Assert.AreEqual(2, tree.Leaves.Count);
            for (int i = 0; i < expected.Length; ++i)
            {
                Assert.AreEqual(expected[i], tree.Leaves[i].Value.ToDouble());
            }
        }
コード例 #20
0
ファイル: Sanitizer.cs プロジェクト: Bluegent/MeRpgBot
        public MeNode[] SplitAndConvert(string expression)
        {
            string[]      lines  = expression.Split(LConstants.FUNCTION_SEPARATOR);
            List <MeNode> result = new List <MeNode>();

            foreach (string expr in lines)
            {
                if (expr.Length != 0)
                {
                    Token[] tokens = Tokenizer.Tokenize(expr);
                    result.Add(TreeConverter.Build(tokens, _engine));
                }
            }

            return(result.ToArray());
        }
コード例 #21
0
        public static void StartUp(TestContext ctx)
        {
            Definer.Instance().Engine     = Engine;
            DamageTypeTemplate trueDamage = new DamageTypeTemplate(Engine, null, null, null, null);

            trueDamage.Name = "true";
            trueDamage.Key  = "T";
            Engine.AddDamageType(trueDamage);
            ResourceTemplate res = new ResourceTemplate()
            {
                Key = "MP"
            };
            SkillCost nullCost = new SkillCost(res, TreeConverter.Build("0", Engine));

            _testSkill      = new SkillTemplate();
            _testSkill.Type = SkillType.Cast;
            _testSkill.Key  = "TEST_CAST";
            SkillLevelTemplate testLevelTemplate = new SkillLevelTemplate();

            testLevelTemplate.Cooldown      = TreeConverter.Build("3", Engine);
            testLevelTemplate.Duration      = TreeConverter.Build($"{LConstants.SourceKeyword}{LConstants.PROP_OP}INT", Engine);
            testLevelTemplate.Interruptible = TreeConverter.Build("true", Engine);
            testLevelTemplate.Formulas.Add(TreeConverter.Build($"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.SourceKeyword},{trueDamage.Key},10)", Engine));
            testLevelTemplate.PushBack = TreeConverter.Build("true", Engine);
            testLevelTemplate.Cost     = nullCost;
            _testSkill.ByLevel.Add(testLevelTemplate);

            Engine.GetSkillManager().AddSkill(_testSkill);

            BaseObject bDmg = new BaseObject()
            {
                Description = "", Key = "BASE_DMG", Name = "Base damage"
            };

            Engine.GetPropertyManager().BaseValues.Add("BASE_DMG", bDmg);

            BaseObject intellect = new BaseObject()
            {
                Description = "", Key = "INT", Name = "Intellect"
            };

            Engine.GetPropertyManager().Attributes.Add("INT", intellect);
        }
コード例 #22
0
ファイル: MockEntity.cs プロジェクト: Bluegent/MeRpgBot
        public MockEntity(IGameEngine engine)
            : base(engine)
        {
            AddAttribute("VIT", 5);
            AddAttribute("STR", 5);
            AddAttribute("INT", 5);
            AddAttribute("AGI", 10);
            AddAttribute("DEF", 10);
            AddAttribute("MDEF", 10);
            AddResource(getMockHP(engine));
            MeNode           mpNode  = TreeConverter.Build("INT*10", engine);
            MeNode           mpRegen = TreeConverter.Build("INT/100", engine);
            ResourceTemplate resTemp = new ResourceTemplate();

            resTemp.Formula       = mpNode;
            resTemp.RegenFormula  = mpRegen;
            resTemp.Key           = "MP";
            resTemp.RegenInterval = new MeNode(GcConstants.Resources.DEFAULT_INTERVAL);
            AddResource(resTemp);
        }
コード例 #23
0
ファイル: CoreReader.cs プロジェクト: Bluegent/MeRpgBot
        public CoreManager FromJson(JObject json)
        {
            CoreManager manager = new CoreManager();

            //get max level
            manager.MaxLevel = JsonUtils.GetValueOrDefault <long>(json, GcConstants.Core.MAX_LEVEL, GcConstants.Core.DEFAULT_MAX_LEVEL);

            //get attributes per level
            manager.AttributePointsPerLevel = JsonUtils.GetValueOrDefault <long>(json, GcConstants.Core.ATTRIBUTES_PER_LEVEL, GcConstants.Core.DEFAULT_ATTRIBUTE_POINTS);

            //get default skill threat
            manager.DefaultSkillThreat = JsonUtils.GetValueOrDefault <long>(json, GcConstants.Core.DEFAULT_SKILL_THREAT, GcConstants.Core.DEFAULT_THREAT);

            //get start experience
            manager.StartExp = JsonUtils.ValidateJsonEntry(
                GcConstants.Core.LEVEL_ONE_EXP,
                json,
                JTokenType.Integer,
                "Core config is missing experience amount necessary for the first level up.").ToObject <long>();

            //get revive time
            string reviveString = JsonUtils.ValidateJsonEntry(GcConstants.Core.REVIVE_TIME,
                                                              json,
                                                              JTokenType.String,
                                                              "Core config is missing revive time.").ToString();

            manager.ReviveTime = TreeConverter.Build(reviveString, _engine);

            //get exp formula
            string expFormulaString = JsonUtils.ValidateJsonEntry(GcConstants.Core.EXP_FORMULA,
                                                                  json,
                                                                  JTokenType.String,
                                                                  "Core config is missing experience calculation formula.").ToString();

            manager.ExpFormula = TreeConverter.Build(expFormulaString, _engine);



            return(manager);
        }
コード例 #24
0
        public void EntityTestHarmStatusEffect()
        {
            BaseEntity ent = new MockEntity(Engine)
            {
                Name = "MOCK_PLAYER", Key = "MOCK_KEY"
            };
            double damage     = 10;
            string expression = $"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.TargetKeyword},T,{damage})";

            MeNode[]       statuses = Engine.GetSanitizer().SplitAndConvert(expression);
            StatusTemplate test     = new StatusTemplate(statuses)
            {
                Interval = TreeConverter.Build("0", Engine)
            };

            test.Key = "TEST_STATUS_KEY";
            ent.ApplyStatus(test, ent, 5, null);
            double expectedHp = ent.GetProperty(Entity.HP_KEY).Value - damage;

            ent.Update();
            Assert.AreEqual(expectedHp, ent.GetProperty(Entity.HP_KEY).Value);
        }
コード例 #25
0
        public ResourceTemplate FromJson(JObject json)
        {
            ResourceTemplate result = new ResourceTemplate();

            result.LoadBase(json);

            //get formula for calculating max amount
            string maxValue = JsonUtils.ValidateJsonEntry(
                GcConstants.General.FORMULA,
                json,
                JTokenType.String,
                $"Unknown formula for resource {result.Name}").ToString();

            result.Formula = TreeConverter.Build(maxValue, Engine);

            //get formula for calculating regen
            string regenValue = JsonUtils.GetValueOrDefault(
                json,
                GcConstants.Resources.REGEN,
                GcConstants.Resources.DEFAULT_REGEN.ToString(CultureInfo.InvariantCulture));

            result.RegenFormula = TreeConverter.Build(regenValue, Engine);

            //get interval
            string intervalValue = JsonUtils.GetValueOrDefault <string>(json, GcConstants.Resources.INTERVAL, GcConstants.Resources.DEFAULT_INTERVAL.ToString());

            result.RegenInterval = TreeConverter.Build(intervalValue, Engine);

            //get modifier
            string modifierValue = JsonUtils.GetValueOrDefault <string>(
                json,
                GcConstants.Resources.MODIFIER,
                GcConstants.Resources.DEFAULT_MODIFIER.ToString());

            result.StartMod = TreeConverter.Build(modifierValue, Engine);

            return(result);
        }
コード例 #26
0
        public void EntityTestModifierStatusEffect()
        {
            BaseEntity ent = new MockEntity(Engine)
            {
                Name = "MOCK_PLAYER", Key = "MOCK_KEY"
            };
            string expression = $"{LConstants.ADD_MOD_F}(STR,$0)";

            MeNode[]       statuses = Engine.GetSanitizer().SplitAndConvert(expression);
            StatusTemplate test     = new StatusTemplate(statuses)
            {
                Interval = TreeConverter.Build("0", Engine)
            };

            test.Key = "TEST_STATUS_KEY6";
            double[] values = { 10 };

            double expected = ent.GetProperty("STR").Value + 10;

            ent.ApplyStatus(test, ent, 5, values);
            ent.Update();
            Assert.AreEqual(expected, ent.GetProperty("STR").Value);
        }
コード例 #27
0
ファイル: VariableTest.cs プロジェクト: Bluegent/MeRpgBot
        public void VariableTestAssignFromFunction()
        {
            string varName = "testVar";

            double[]      numbers = { 10, 11, 12 };
            StringBuilder sb      = new StringBuilder();

            foreach (double num in numbers)
            {
                sb.Append(num);
                sb.Append(",");
            }
            sb.Remove(sb.Length - 1, 1);

            string expression = $"{varName} {LConstants.ASSIGN_OP} {LConstants.MAX_F}({sb.ToString()})";
            MeNode tree       = TreeConverter.Build(expression, Engine);

            tree.Resolve();
            MeVariable result = Engine.GetVariable(varName);

            Assert.IsNotNull(result);
            Assert.AreEqual(numbers.Max(), result.ToDouble());
        }
コード例 #28
0
        public void EntityTestAddResource()
        {
            MockEntity       ent     = new MockEntity(Engine);
            ResourceTemplate resTemp = new ResourceTemplate();

            resTemp.Formula       = new MeNode(100);
            resTemp.RegenFormula  = new MeNode(0);
            resTemp.RegenInterval = new MeNode(0);
            resTemp.StartMod      = new MeNode(0);
            resTemp.Key           = "TEST_RES";
            resTemp.Name          = "Test Resource";
            resTemp.Description   = "";

            ent.AddResource(resTemp);
            ent.Key = "TEST_KEY";
            Assert.AreEqual(0, ent.GetProperty(resTemp.Key).Value);
            long amount = 50;

            Engine.AddPlayer(ent);
            string fromula = $"{LConstants.ADD_TO_RESOURCE_F}({ent.Key},{resTemp.Key},{amount})";

            TreeConverter.Build(fromula, Engine).Resolve();
            Assert.AreEqual(amount, ent.GetProperty(resTemp.Key).Value);
        }
コード例 #29
0
        public static void StartUp(TestContext context)
        {
            DamageTypeTemplate trueDamage = new DamageTypeTemplate(Engine, null, null, null, null);

            trueDamage.Key  = "T";
            trueDamage.Name = "true";
            Engine.AddDamageType(trueDamage);
            ResourceTemplate res = new ResourceTemplate()
            {
                Key = "MP"
            };

            SkillCost nullCost = new SkillCost(res, TreeConverter.Build("0", Engine));
            SkillCost notFree  = new SkillCost(res, TreeConverter.Build("50", Engine));

            _testSkill      = new SkillTemplate();
            _testSkill.Type = SkillType.Cast;
            _testSkill.Key  = "TEST_CAST";
            SkillLevelTemplate testLevelTemplate = new SkillLevelTemplate();

            testLevelTemplate.Cooldown      = TreeConverter.Build("3", Engine);
            testLevelTemplate.Duration      = TreeConverter.Build($"{LConstants.SourceKeyword}{LConstants.PROP_OP}INT", Engine);
            testLevelTemplate.Interruptible = TreeConverter.Build("true", Engine);
            testLevelTemplate.Formulas.Add(TreeConverter.Build($"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.SourceKeyword},{trueDamage.Key},10)", Engine));
            testLevelTemplate.PushBack = TreeConverter.Build("true", Engine);
            testLevelTemplate.Cost     = nullCost;
            _testSkill.ByLevel.Add(testLevelTemplate);

            _testChannelSkill      = new SkillTemplate();
            _testChannelSkill.Type = SkillType.Channel;
            _testChannelSkill.Key  = "TEST_CHANNEL";
            SkillLevelTemplate testLevelTemplate2 = new SkillLevelTemplate();

            testLevelTemplate2.Cooldown      = TreeConverter.Build("120", Engine);
            testLevelTemplate2.Duration      = TreeConverter.Build("60", Engine);
            testLevelTemplate2.Interval      = TreeConverter.Build("10", Engine);
            testLevelTemplate2.PushBack      = TreeConverter.Build("true", Engine);
            testLevelTemplate2.Interruptible = TreeConverter.Build("true", Engine);
            testLevelTemplate2.Cost          = nullCost;
            MeNode channelFormula = TreeConverter.Build(
                $"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.SourceKeyword},{trueDamage.Key},10)",
                Engine);

            Engine.GetSanitizer().SetHarmsToPeriodic(channelFormula);

            testLevelTemplate2.Formulas.Add(channelFormula);
            _testChannelSkill.ByLevel.Add(testLevelTemplate2);

            _instantHarm      = new SkillTemplate();
            _instantHarm.Type = SkillType.Cast;
            _instantHarm.Key  = "HURT";
            SkillLevelTemplate hurtLevelTemplate = new SkillLevelTemplate();

            hurtLevelTemplate.Cooldown      = TreeConverter.Build("0", Engine);
            hurtLevelTemplate.Duration      = TreeConverter.Build("0", Engine);
            hurtLevelTemplate.PushBack      = TreeConverter.Build("false", Engine);
            hurtLevelTemplate.Interruptible = TreeConverter.Build("true", Engine);
            hurtLevelTemplate.Formulas.Add(TreeConverter.Build($"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.SourceKeyword},{trueDamage.Key},10)", Engine));
            hurtLevelTemplate.Cost = nullCost;
            _instantHarm.ByLevel.Add(hurtLevelTemplate);



            _unpushable      = new SkillTemplate();
            _unpushable.Type = SkillType.Cast;
            _unpushable.Key  = "NOPUSH";
            SkillLevelTemplate unpushTemplate = new SkillLevelTemplate();

            unpushTemplate.Cooldown      = TreeConverter.Build("0", Engine);
            unpushTemplate.Duration      = TreeConverter.Build("5", Engine);
            unpushTemplate.Interruptible = TreeConverter.Build("false", Engine);
            unpushTemplate.PushBack      = TreeConverter.Build("false", Engine);
            unpushTemplate.Formulas.Add(TreeConverter.Build($"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.SourceKeyword},{trueDamage.Key},10)", Engine));
            unpushTemplate.Cost = nullCost;
            _unpushable.ByLevel.Add(unpushTemplate);


            _costly      = new SkillTemplate();
            _costly.Type = SkillType.Cast;
            _costly.Key  = "COSTLY";
            SkillLevelTemplate costlyTemplate = new SkillLevelTemplate();

            costlyTemplate.Cooldown      = TreeConverter.Build("0", Engine);
            costlyTemplate.Duration      = TreeConverter.Build("0", Engine);
            costlyTemplate.Interruptible = TreeConverter.Build("true", Engine);
            costlyTemplate.Formulas.Add(TreeConverter.Build($"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.SourceKeyword},{trueDamage.Key},10)", Engine));
            costlyTemplate.PushBack = TreeConverter.Build("true", Engine);
            costlyTemplate.Cost     = notFree;
            _costly.ByLevel.Add(costlyTemplate);


            _skillUsingStat      = new SkillTemplate();
            _skillUsingStat.Type = SkillType.Cast;
            _skillUsingStat.Key  = "WITH_STAT";
            SkillLevelTemplate withStaTemplate = new SkillLevelTemplate();

            withStaTemplate.Cooldown      = TreeConverter.Build("0", Engine);
            withStaTemplate.Duration      = TreeConverter.Build("0", Engine);
            withStaTemplate.Interruptible = TreeConverter.Build("true", Engine);
            withStaTemplate.Formulas.Add(TreeConverter.Build($"{LConstants.HARM_F}({LConstants.TargetKeyword},{LConstants.SourceKeyword},{trueDamage.Key},10*{LConstants.SourceKeyword}{LConstants.PROP_OP}STR+{LConstants.GET_PROP_F}({LConstants.SourceKeyword},{BASE_VALUE}))", Engine));
            withStaTemplate.PushBack = TreeConverter.Build("true", Engine);
            withStaTemplate.Cost     = nullCost;

            _skillUsingStat.ByLevel.Add(withStaTemplate);
        }
コード例 #30
0
 public static void StartUp(TestContext ctx)
 {
     Definer.Instance().Engine          = Engine;
     Engine.GetCoreManager().ExpFormula = TreeConverter.Build($"{LConstants.ExpPrevKeyword}*1.1+50*2^{LConstants.FLOOR_F}({LConstants.LevelKeyword}/5.0)", Engine);
     Engine.SetStartExp(StartExp);
 }