public HumanFighter(string name, int level, List <Spell> spells = null, List <SpecialMove> specialMoves = null) : base(name , level , LevelUpManager.GetHealthByLevel(level) , LevelUpManager.GetManaByLevel(level) , LevelUpManager.GetStrengthByLevel(level) , LevelUpManager.GetDefenseByLevel(level) , LevelUpManager.GetSpeedByLevel(level) , LevelUpManager.GetEvadeByLevel(level) , LevelUpManager.GetLuckByLevel(level) , SpellFactory.GetSpellsByLevel <HumanFighter>(level) , MoveFactory.GetMovesByLevel <HumanFighter>(level) ) { if (spells != null) { Spells.AddRange(spells); } if (specialMoves != null) { SpecialMoves.AddRange(specialMoves); } _extraSpecialMoves = new List <BattleMove>(); CurrentExp = LevelUpManager.GetExpForLevel(level); _expToNextLevel = LevelUpManager.GetExpForLevel(level + 1); }
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); }
/// <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); }
public void LevelUp_DoesNotOverwriteNonLevelUpSpells() { const int maxLevel = LevelUpManager.MAX_LEVEL; var expAmount = LevelUpManager.GetExpForLevel(maxLevel); var fooSpell = new Spell("Foo", MagicType.None, SpellType.Attack, TargetType.SingleEnemy, 10, 40); _fighter.AddSpell(fooSpell); var barSpell = new Spell("Bar", MagicType.None, SpellType.Attack, TargetType.SingleEnemy, 5, 10); _fighter.AddSpell(barSpell); _fighter.GainExp(expAmount); Assert.AreEqual(expAmount, _fighter.CurrentExp); Assert.AreEqual(maxLevel, _fighter.Level); var spells = GetSpellsByLevel(maxLevel); Assert.AreEqual(spells.Count + 2, _fighter.Spells.Count); Assert.IsTrue(spells.TrueForAll(s => _fighter.Spells.SingleOrDefault(fs => fs.Description == s.Description) != null)); Assert.IsTrue(_fighter.Spells.SingleOrDefault(s => s.Description == fooSpell.Description) != null); Assert.IsTrue(_fighter.Spells.SingleOrDefault(s => s.Description == barSpell.Description) != null); }
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)); } } } } }
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)); } } }