public void GainExpMethod_AppropriatelyRaisesCurrentExp()
        {
            var amount = _expToLevel2 - 1;

            Assert.AreEqual(0, _fighter.CurrentExp);

            _fighter.GainExp(amount);

            Assert.AreEqual(amount, _fighter.CurrentExp);
            Assert.AreEqual(1, _fighter.Level);
        }
Beispiel #2
0
        public void GainExpMethod_AppropriatelyRaisesEvents_WhenFighterDoesNotLevelUp()
        {
            var expAmount = LevelUpManager.GetExpForLevel(_fighter.Level + 1) - 1;

            _fighter.GainExp(expAmount);

            var logs = _logger.Logs;

            Assert.AreEqual(1, logs.Count);
            Assert.AreEqual(EventType.ExpGained, logs[0].Type);
            Assert.AreEqual(_fighter, logs[0].Sender);
            var e = logs[0].E as ExpGainedEventArgs;

            Assert.That(e, Is.Not.Null);
            Assert.AreEqual(expAmount, e.AmountGained);
        }
Beispiel #3
0
        public void GainExpMethod_AppropriatelyRaisesEvents_WhenFighterGainsOneLevel([Range(1, 4)] int initialLevel)
        {
            int nextLevel = initialLevel + 1;

            _fighter = (HumanFighter)TestFighterFactory.GetFighter(TestFighterType.HumanControlledPlayer, initialLevel, "Ted");
            _logger.SubscribeAll(_fighter);

            var expAmount     = LevelUpManager.GetExpForLevel(nextLevel);
            var spellsLearned = SpellFactory.GetSpellsByLevel <HumanFighter>(nextLevel, nextLevel);

            _fighter.GainExp(expAmount);

            var logs = _logger.Logs;

            int expectedLogCount = 2 + (spellsLearned.Count > 0 ? 1 : 0);

            Assert.AreEqual(expectedLogCount, logs.Count); //exp gained, level up, potentially spells learned

            var i   = 0;
            var log = logs[i++];

            Assert.AreEqual(EventType.ExpGained, log.Type);
            Assert.AreEqual(_fighter, log.Sender);
            var e1 = log.E as ExpGainedEventArgs;

            Assert.That(e1, Is.Not.Null);
            if (e1 != null)
            {
                Assert.AreEqual(expAmount, e1.AmountGained);
            }

            log = logs[i++];
            Assert.AreEqual(EventType.LeveledUp, log.Type);
            Assert.AreEqual(_fighter, log.Sender);
            var 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);
            }

            if (spellsLearned.Count > 0)
            {
                log = logs[i];

                Assert.AreEqual(EventType.SpellLearned, log.Type);
                Assert.AreEqual(_fighter, log.Sender);
                var e3 = log.E as SpellsLearnedEventArgs;
                Assert.That(e3, Is.Not.Null);
                if (e3 == null)
                {
                    return;
                }

                foreach (var spell in spellsLearned)
                {
                    Assert.IsTrue(e3.SpellsLearned.Contains(spell));
                }
            }
        }