Exemple #1
0
        /// <summary>
        /// Assumes CurrentExp has already been updated
        /// </summary>
        private void LevelUp()
        {
            var continuer = true;

            for (var i = Level + 1; i <= LevelUpManager.MAX_LEVEL && continuer; ++i)
            {
                if (CurrentExp >= LevelUpManager.GetExpForLevel(i))
                {
                    ++Level;

                    CurrentHealth = LevelUpManager.GetHealthByLevel(Level);
                    MaxHealth     = LevelUpManager.GetHealthByLevel(Level);
                    CurrentMana   = LevelUpManager.GetManaByLevel(Level);
                    MaxMana       = LevelUpManager.GetManaByLevel(Level);
                    Strength      = LevelUpManager.GetStrengthByLevel(Level);
                    Defense       = LevelUpManager.GetDefenseByLevel(Level);
                    Speed         = LevelUpManager.GetSpeedByLevel(Level);
                    Evade         = LevelUpManager.GetEvadeByLevel(Level);
                    Luck          = LevelUpManager.GetLuckByLevel(Level);

                    OnLeveledUp(new LeveledUpEventArgs(
                                    Level
                                    , LevelUpManager.HealthBoostByLevel(Level)
                                    , LevelUpManager.ManaBoostByLevel(Level)
                                    , LevelUpManager.StrengthBoostByLevel(Level)
                                    , LevelUpManager.DefenseBoostByLevel(Level)
                                    , LevelUpManager.SpeedBoostByLevel(Level)));

                    var spells = SpellFactory.GetSpellsByLevel <HumanFighter>(Level, Level);

                    if (spells.Count > 0)
                    {
                        AddSpells(spells);
                    }
                }
                else
                {
                    continuer = false;
                }
            }

            _expToNextLevel = LevelUpManager.GetExpForLevel(Level + 1);
        }
Exemple #2
0
        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));
                        }
                    }
                }
            }
        }
Exemple #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));
                }
            }
        }