public void CastTestNonInterrupt() { BaseEntity mob = new MockEntity(Engine); double expectedMobHealth = mob.GetProperty(Entity.HP_KEY).Value - 10; _testPlayer.Cast(mob, _unpushable.Key); _testPlayer.InterruptCasting(); MockTimer timer = (MockTimer)Engine.GetTimer(); MeNode duration = _unpushable.ByLevel[0].Duration; duration = Sanitizer.ReplaceTargetAndSource(duration, _testPlayer, _testPlayer); long skillDuration = duration.Resolve().Value.ToLong(); for (int i = 0; i < skillDuration; ++i) { timer.ForceTick(); } timer.ForceTick(); _testPlayer.Update(); Assert.AreEqual(expectedMobHealth, mob.GetProperty(Entity.HP_KEY).Value); }
public void CastTestPushbackChannelSkill() { long delay = 10; BaseEntity mob = new MockEntity(Engine); double expectedMobHealth = mob.GetProperty(Entity.HP_KEY).Value - 50; _testPlayer.Cast(mob, _testChannelSkill.Key); _testPlayer.AddPushback(delay); MockTimer timer = (MockTimer)Engine.GetTimer(); MeNode duration = _testChannelSkill.ByLevel[0].Duration; duration = Sanitizer.ReplaceTargetAndSource(duration, _testPlayer, _testPlayer); long skillDuration = duration.Resolve().Value.ToLong(); for (int i = 0; i < skillDuration; ++i) { timer.ForceTick(); _testPlayer.Update(); mob.Update(); } timer.ForceTick(); _testPlayer.Update(); mob.Update(); Assert.AreEqual(expectedMobHealth, mob.GetProperty(Entity.HP_KEY).Value); }
private void AddStatusFromTemplate(StatusTemplate status, Entity source, double duration, double[] values) { long removeTime = GetRemoveTime(duration); AppliedStatus newStatus = new AppliedStatus() { Source = source, LastTick = 0, RemovalTime = removeTime, Template = status, NumericValues = values }; MeNode intervalTree = Sanitizer.ReplaceTargetAndSource(status.Interval, source, this); newStatus.Interval = intervalTree.Resolve().Value.ToLong(); Statuses.Add(newStatus); foreach (MeNode tree in newStatus.Template.Modifiers) { StatModifier mod = Engine.GetSanitizer().ResolveStatus(tree, newStatus.NumericValues).ToModifier(); newStatus.MyMods.Add(mod); Attributes[mod.StatKey].Modifiers.Add(mod); } RefreshProperties(); int stackCount = 0; foreach (AppliedStatus sts in Statuses) { if (sts.Template.Key.Equals(newStatus.Template.Key)) { ++stackCount; } } Engine.Log().Log($"[{Name}] Affected by {status.Name}[{stackCount}]."); }
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()); }
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()); }
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()); }
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); } }
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()); }
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()); } }
private void TickCurrentCast() { if (CurrentlyCasting == null) { return; } long now = Engine.GetTimer().GetNow(); if (CurrentlyCasting.Skill.Skill.Type == SkillType.Cast) { if (CurrentlyCasting.CastFinishTime <= now) { string castedFinish = Key.Equals(CurrentlyCasting.Target.Key) ? "" : $" on {CurrentlyCasting.Target.Name}"; Engine.Log().Log($"[{Name}] Casted {CurrentlyCasting.Skill.Skill.Name}{castedFinish}."); //casting has finished so resolve the formula MeNode[] toResolve = CurrentlyCasting.Skill.Formulas; foreach (MeNode node in toResolve) { MeNode sanitized = Sanitizer.ReplaceTargetAndSource(node, this, CurrentlyCasting.Target); sanitized.Resolve(); } FinishCasting(); } } else if (CurrentlyCasting.Skill.Skill.Type == SkillType.Channel) { if (CurrentlyCasting.CastFinishTime <= now) { Engine.Log().Log($"[{Name}] Finished channeling {CurrentlyCasting.Skill.Skill.Name}."); FinishCasting(); } else { //apply the formulas if it's the case if (CurrentlyCasting.NextInterval == 0 || CurrentlyCasting.NextInterval < now) { MeNode[] toResolve = CurrentlyCasting.Skill.Formulas; foreach (MeNode node in toResolve) { Sanitizer.ReplaceTargetAndSource(node, this, CurrentlyCasting.Target).Resolve(); } CurrentlyCasting.NextInterval = now + CurrentlyCasting.Interval * 1000; } } } }
public long GetMaxExp(int level) { if (ExpFormula == null) { return(0); } if (ExpValues.Count <= level) { ExpValues.Capacity = level + 1; for (int i = ExpValues.Count - 1; i <= level; ++i) { double prev = ExpValues[i]; MeNode sanitized = Sanitizer.ReplaceExpValues(ExpFormula, (long)prev, i + 1); ExpValues.Add((long)Math.Floor(sanitized.Resolve().Value.ToDouble())); } } return(ExpValues[level]); }
public static MeNode ResolveGivenOperations(MeNode node, string[] operationNames, int index = 0) { for (int i = 0; i < node.Leaves.Count; ++i) { node.Leaves[i] = ResolveGivenOperations(node.Leaves[i], operationNames, i); } if (node.Value.Type == VariableType.Function || node.Value.Type == VariableType.Operator) { foreach (string key in operationNames) { if (node.Value.GetString().Equals(key)) { return(node.Resolve()); } } } return(node); }
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()); }
public void CastTestChannelSkill() { BaseEntity mob = new MockEntity(Engine); double expected = mob.GetProperty(Entity.HP_KEY).Value - 60; _testPlayer.Cast(mob, _testChannelSkill.Key); MockTimer timer = (MockTimer)Engine.GetTimer(); MeNode duration = _testChannelSkill.ByLevel[0].Duration; duration = Sanitizer.ReplaceTargetAndSource(duration, _testPlayer, _testPlayer); long skillDuration = duration.Resolve().Value.ToLong(); for (int i = 0; i <= skillDuration; ++i) { timer.ForceTick(); _testPlayer.Update(); } double actual = mob.GetProperty(Entity.HP_KEY).Value; Assert.AreEqual(expected, actual); }
private void ApplyHealAndHarm() { foreach (AppliedStatus status in Statuses) { if (IsTime(status)) { foreach (MeNode tree in status.Template.HpMods) { MeNode newTree = Sanitizer.ReplaceTargetAndSource(tree, status.Source, this); Engine.GetSanitizer().ReplaceNumericPlaceholders(newTree, status.NumericValues); newTree = newTree.Resolve(); if (tree.Value.GetString() == LConstants.HEAL_F) { status.TotalHeal += newTree.Value.ToDouble(); } else { status.TotalDamamge += newTree.Value.ToDouble(); } } status.LastTick = Engine.GetTimer().GetNow(); } } }
public void CastTestFormulaIsExecutedWithTime() { double expected = _testPlayer.GetProperty(Entity.HP_KEY).Value - 10; double before = _testPlayer.GetProperty(Entity.HP_KEY).Value; _testPlayer.Cast(_testPlayer, _testSkill.Key); MockTimer timer = (MockTimer)Engine.GetTimer(); MeNode duration = _testSkill.ByLevel[0].Duration; duration = Sanitizer.ReplaceTargetAndSource(duration, _testPlayer, _testPlayer); double actual; long skillDuration = duration.Resolve().Value.ToLong();; for (int i = 0; i < skillDuration; ++i) { timer.ForceTick(); actual = _testPlayer.GetProperty(Entity.HP_KEY).Value; Assert.AreEqual(before, actual); _testPlayer.Update(); } actual = _testPlayer.GetProperty(Entity.HP_KEY).Value; Assert.AreEqual(expected, actual); }
public long ResolveInterval(Entity target) { MeNode entityNode = Sanitizer.ReplacePropeties(RegenInterval, target); return(entityNode.Resolve().Value.ToLong()); }
public double ResolveModifier(Entity target) { MeNode entityNode = Sanitizer.ReplacePropeties(StartMod, target); return(entityNode.Resolve().Value.ToDouble()); }
private void SetCurrentCD() { //set skill's cooldown] if (CurrentlyCasting == null) { return; } MeNode cd = CurrentlyCasting.Skill.Values().Cooldown; cd = Sanitizer.ReplaceTargetAndSource(cd, this, CurrentlyCasting.Target); CurrentlyCasting.Skill.CooldownFinishTime = Engine.GetTimer().GetFuture((long)cd.Resolve().Value.ToDouble()); }
public double ResolveMaxAmount(Entity target) { MeNode entityNode = Sanitizer.ReplacePropeties(Formula, target); return(entityNode.Resolve().Value.ToDouble()); }