public void OnExpGained(ExpGainedEventArgs e) { ExpGained?.Invoke(this, e); }
private void _logExpGained(object sender, ExpGainedEventArgs e) { Logs.Add(new EventLog(EventType.ExpGained, sender, e)); }
public void GainExpMethod_AppropriatelyRaisesEvents_WhenFighterGainsMultipleLevels([Values(2, 3)] int numberOfLevelsToIncrease) { int currentLevel = _fighter.Level; int nextLevel = currentLevel + 1; int targetLevel = currentLevel + numberOfLevelsToIncrease; var expAmount = LevelUpManager.GetExpForLevel(targetLevel); int expectedLogsLength = numberOfLevelsToIncrease + 1; //expGained event, one for each level up int i = 0; for (int level = currentLevel; i < numberOfLevelsToIncrease; ++i, ++level) { var spellsLearned = SpellFactory.GetSpellsByLevel <HumanFighter>(level + 1, level + 1); if (spellsLearned.Count > 0) //SpellsLeaned event will fire { expectedLogsLength++; } } _fighter.GainExp(expAmount); var logs = _logger.Logs; Assert.AreEqual(expectedLogsLength, logs.Count); i = 0; var log = logs[i++]; Assert.AreEqual(EventType.ExpGained, log.Type); Assert.AreEqual(_fighter, log.Sender); ExpGainedEventArgs e1 = log.E as ExpGainedEventArgs; Assert.That(e1, Is.Not.Null); if (e1 != null) { Assert.AreEqual(expAmount, e1.AmountGained); } while (i < expectedLogsLength) { log = logs[i++]; Assert.AreEqual(EventType.LeveledUp, log.Type); Assert.AreEqual(_fighter, log.Sender); LeveledUpEventArgs e2 = log.E as LeveledUpEventArgs; Assert.That(e2, Is.Not.Null); if (e2 != null) { Assert.AreEqual(nextLevel, e2.NewLevel); Assert.AreEqual(LevelUpManager.HealthBoostByLevel(nextLevel), e2.HealthBoost); Assert.AreEqual(LevelUpManager.ManaBoostByLevel(nextLevel), e2.ManaBoost); Assert.AreEqual(LevelUpManager.StrengthBoostByLevel(nextLevel), e2.StrengthBoost); Assert.AreEqual(LevelUpManager.DefenseBoostByLevel(nextLevel), e2.DefenseBoost); Assert.AreEqual(LevelUpManager.SpeedBoostByLevel(nextLevel), e2.SpeedBoost); } List <Spell> spellsLearned = SpellFactory.GetSpellsByLevel <HumanFighter>(nextLevel, nextLevel++); if (spellsLearned.Count > 0) { log = logs[i++]; foreach (var spell in spellsLearned) { Assert.AreEqual(EventType.SpellLearned, log.Type); Assert.AreEqual(_fighter, log.Sender); var e3 = log.E as SpellsLearnedEventArgs; Assert.That(23, Is.Not.Null); if (e3 != null) { Assert.IsTrue(e3.SpellsLearned.Contains(spell)); } } } } }