/// <summary> /// Learn skill /// </summary> /// <param name="ganger">The ganger</param> /// <param name="advancementId">The advancement ID. Used to verify that the /// ganger is able to learn a new skill.</param> /// <param name="type">Skill type</param> /// <returns>Ganger skill</returns> public GangerSkill LearnSkill(Ganger ganger, string advancementId, SkillType type) { if (!_gangerProvider.CanLearnSkill(ganger.GangerId, advancementId)) { throw new HivemindException("Invalid advancement ID."); } // TODO: If the ganger knows all the skills of that category, we return for now. if (ganger.Skills.Where(s => s.SkillType == type).Count() >= 6) { return(null); } var skill = _skillManager.GetRandomSkillByType(type); while (ganger.Skills.Contains(skill)) { skill = _skillManager.GetRandomSkillByType(type); } _gangerProvider.AddGangerSkill(ganger.GangerId, skill.SkillId); _gangerProvider.RemoveGangerAdvancement(ganger.GangerId, advancementId); var skills = ganger.Skills.ToList(); skills.Add(skill); ganger.Skills = skills; return(new GangerSkill { SkillId = skill.SkillId, GangerId = ganger.GangerId, }); }
public void GetRandomSkillByTypeTest(SkillType skillType) { _mockSkillProvider.Setup(m => m.GetSkillsByType(It.IsAny <SkillType>())) .Returns((SkillType type) => _skills.Where(s => s.SkillType == type)); _mockDiceRoller.Setup(m => m.RollDie()).Returns(1); var skill = _skillManager.GetRandomSkillByType(skillType); Assert.AreEqual(skillType, skill.SkillType); }