public void Clean_WithAllReportsFilteringOutEvents_RemovesAllEvents() { ResetCleaner(); const string context = ""; var registry = new DefaultMetricsRegistry(); EventMetricsCleaner.ContextRegistries.Add(context, registry); var timer = new MockTimer(); EventMetricsCleaner.EnableTestTimer(timer); var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60)); var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60)); var metric = new EventMetric(); registry.Event(MetricName, () => { return(metric); }, MetricTags.None); metric.Record(); metric.Record(); metric.Record(); EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, new List <EventValueSource>()); EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex2, new List <EventValueSource>()); GetReportsReportedEventDetailCount(reportIndex1, MetricNameType).Should().Be(0); GetReportsReportedEventDetailCount(reportIndex2, MetricNameType).Should().Be(0); var registryCounts = GetRegistryEventDetailCounts(MetricNameType); registryCounts[context].Should().Be(3); timer.OnTimerCallback(); registryCounts = GetRegistryEventDetailCounts(MetricNameType); registryCounts[context].Should().Be(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); }
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); }
public ITimer GetTimer() { var timer = new MockTimer(); LastTimer = timer; return(timer); }
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); }
public void Clean_IgnoresReportsThatHaveNotReportedAnyEvents() { ResetCleaner(); const string context = ""; var registry = new DefaultMetricsRegistry(); EventMetricsCleaner.ContextRegistries.Add(context, registry); var timer = new MockTimer(); EventMetricsCleaner.EnableTestTimer(timer); var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60)); var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60)); var metric = new EventMetric(); registry.Event(MetricName, () => { return(metric); }, MetricTags.None); metric.Record(); EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, registry.DataProvider.Events); GetReportsReportedEventDetailCount(reportIndex1, metricNameTypeTags).Should().Be(1); GetReportsReportedEventDetailCount(reportIndex2, metricNameTypeTags).Should().Be(0); timer.OnTimerCallback(); var registryCounts = GetRegistryEventDetailCounts(MetricNameType); registryCounts[context].Should().Be(0); }
public void Clean_WithNoReportsRegistered_RemovesAllEvents() { ResetCleaner(); const string context = ""; var registry = new DefaultMetricsRegistry(); EventMetricsCleaner.ContextRegistries.Add(context, registry); var timer = new MockTimer(); EventMetricsCleaner.EnableTestTimer(timer); var metric = new EventMetric(); registry.Event(MetricName, () => { return(metric); }, MetricTags.None); metric.Record(); metric.Record(); metric.Record(); var registryCounts = GetRegistryEventDetailCounts(MetricNameType); registryCounts[context].Should().Be(3); timer.OnTimerCallback(); registryCounts = GetRegistryEventDetailCounts(MetricNameType); registryCounts[context].Should().Be(0); }
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 DeathTestReviveLater() { BaseEntity player = new MockEntity(Engine) { Name = "MOCK_PLAYER", Key = "MOCK_KEY" }; long reviveDuration = 10; player.ReviveDuration = new MeNode(reviveDuration); player.RefreshProperties(); player.Kill(); MockTimer timer = (MockTimer)Engine.GetTimer(); for (int i = 0; i < reviveDuration; ++i) { player.Update(); timer.ForceTick(); Assert.AreEqual(true, player.IsDead); } player.Update(); Assert.AreEqual(false, player.IsDead); ResourceInstance hp = player.GetResource(Entity.HP_KEY); Assert.AreEqual(hp.MaxAmount * hp.Modifier, hp.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); }
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); }
public void Clean_WithMultipleRegistriesInSeparateContexts_RemovesEvents() { ResetCleaner(); const string ctx1 = "ctx1"; var registry1 = new DefaultMetricsRegistry(); EventMetricsCleaner.ContextRegistries.Add(ctx1, registry1); const string ctx2 = "ctx2"; var registry2 = new DefaultMetricsRegistry(); EventMetricsCleaner.ContextRegistries.Add(ctx2, registry2); var timer = new MockTimer(); EventMetricsCleaner.EnableTestTimer(timer); var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60)); var metric1 = new EventMetric(); registry1.Event("test1", () => { return(metric1); }, MetricTags.None); metric1.Record(); metric1.Record(); metric1.Record(); EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, registry1.DataProvider.Events); var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60)); var metric2 = new EventMetric(); registry2.Event("test2", () => { return(metric2); }, MetricTags.None); metric2.Record(); metric2.Record(); EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex2, registry2.DataProvider.Events); var registryCounts = GetRegistryEventDetailCounts("test1.event"); registryCounts[ctx1].Should().Be(3); registryCounts[ctx2].Should().Be(0); registryCounts = GetRegistryEventDetailCounts("test2.event"); registryCounts[ctx1].Should().Be(0); registryCounts[ctx2].Should().Be(2); timer.OnTimerCallback(); registryCounts = GetRegistryEventDetailCounts("test1.event"); registryCounts[ctx1].Should().Be(0); registryCounts[ctx2].Should().Be(0); registryCounts = GetRegistryEventDetailCounts("test2.event"); registryCounts[ctx1].Should().Be(0); registryCounts[ctx2].Should().Be(0); }
public void CastTestResourceEnoughMana() { BaseEntity mob = new MockEntity(Engine); double expectedMobHealth = mob.GetProperty(Entity.HP_KEY).Value - 10; _testPlayer.Cast(mob, _costly.Key); Assert.AreEqual(0, _testPlayer.ResourceMap["MP"].Value); MockTimer timer = (MockTimer)Engine.GetTimer(); timer.ForceTick(); _testPlayer.Update(); Assert.AreEqual(expectedMobHealth, mob.GetProperty(Entity.HP_KEY).Value); }
public void Delayed_actions_should_be_scheduled_correctly() { var timer = new MockTimer(); var i = 0; var action = new DelayedAction(0, () => ++ i); timer.DoThings(new[] { action, action }); Assert.AreEqual(0, i); timer.OnTick(); Assert.AreEqual(1, i); timer.OnTick(); Assert.AreEqual(2, i); timer.OnTick(); Assert.AreEqual(2, i); }
public void CastTestSkillUsingStats() { BaseEntity mob = new MockEntity(Engine); double expectedMobHealth = mob.GetProperty(Entity.HP_KEY).Value - _testPlayer.GetProperty("STR").Value *10 - _testPlayer.GetProperty(BASE_VALUE).Value; _testPlayer.Cast(mob, _skillUsingStat.Key); foreach (MeNode node in _skillUsingStat.ByLevel[0].Formulas) { Console.WriteLine(node.ToString()); } MockTimer timer = (MockTimer)Engine.GetTimer(); timer.ForceTick(); _testPlayer.Update(); Assert.AreEqual(expectedMobHealth, mob.GetProperty(Entity.HP_KEY).Value); }
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); }
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 void startTimer(int seconds) { timer = new MockTimer(seconds); }
public void Should_have_had_the_internal_timer_started() { MockTimer.Verify(v => v.Start(), Times.Exactly(1)); }
protected virtual void PublishTimerFiredEvent() { MockTimer.Raise(t => t.Elapsed += null, new TimerWrapperElapsedEventArgs(DateTime.Now.AddSeconds(2))); }
protected override void PublishTimerFiredEvent() { MockTimer.Raise(t => t.Elapsed += null, new TimerWrapperElapsedEventArgs(DateTime.Now)); }
static void Main(string[] args) { const int SLEEP_TIME = 1000; GameEngine engine = new GameEngine(new DiscordLogHelper(new ConsoleLogger())); engine.LoadConfigFromFiles(); MockTimer timer = (MockTimer)engine.GetTimer(); CommandManager.Instance.Engine = engine; Command cmd = new Command() { UserId = 1, Name = "create", Args = new string[] { "John", "edge" } }; Command cmd2 = new Command() { UserId = 2, Name = "create", Args = new string[] { "Putza", "shonen" } }; Command cmd3 = new Command() { UserId = 1, Name = "duel", Args = new string[] { "challenge", "Putza" } }; Command cmd4 = new Command() { UserId = 2, Name = "duel", Args = new string[] { "accept" } }; Command cmd5 = new Command() { UserId = 2, Name = "autoattack", Args = new string[] {} }; Command cmd6 = new Command() { UserId = 1, Name = "cast", Args = new string[] { "strike" } }; Command meCmd = new Command() { UserId = 2, Name = "me", Args = new string[] {} }; Command meSkills = new Command() { UserId = 2, Name = "me", Args = new string[] { "skills" } }; engine.EnqueueCommand(cmd); engine.EnqueueCommand(cmd2); engine.Update(); timer.ForceTick(); engine.GetPlayerManager().FindPlayerById(1).Entity.AddToResource("RP", 100); engine.EnqueueCommand(cmd3); engine.EnqueueCommand(cmd4); engine.EnqueueCommand(cmd5); engine.EnqueueCommand(meCmd); engine.EnqueueCommand(cmd6); engine.EnqueueCommand(meSkills); while (true) { engine.Update(); timer.ForceTick(); Thread.Sleep(SLEEP_TIME); } }
public ProjectTrackerViewModelTests() { timer = new MockTimer(); }