public DomainResult ChooseSkill(SkillReadModel newSkill) { if (!FreeSkillPoints.Any()) { return(DomainResult.Error(new NoLevelUpsAvailable())); } if (CurrentSkills.Any(s => s.SkillId == newSkill.SkillId)) { return(DomainResult.Error( new CanNotPickSkillTwice(CurrentSkills.Select(s => s.SkillId)))); } foreach (var freeSkillPoint in FreeSkillPoints) { if (!HasPlayerFreeSkillForChosenSkill(newSkill, freeSkillPoint)) { return(DomainResult.Error(new SkillNotPickable(freeSkillPoint))); } } var newFreeSkills = GetMinimalSkillToRemove(FreeSkillPoints, newSkill); var domainEvent = new SkillChosen(PlayerId, newSkill, newFreeSkills); Apply(domainEvent); return(DomainResult.Ok(domainEvent)); }
private IEnumerable <FreeSkillPoint> GetMinimalSkillToRemove( IEnumerable <FreeSkillPoint> freeSkillPoints, SkillReadModel newSkill) { var skillPoints = freeSkillPoints.ToList(); if (PlayerConfig.SkillsOnDefault.Contains(newSkill.SkillType)) { return(RemoveBiggerThan(skillPoints, FreeSkillPoint.Normal)); } if (PlayerConfig.SkillsOnDouble.Contains(newSkill.SkillType)) { return(RemoveBiggerThan(skillPoints, FreeSkillPoint.Double)); } switch (newSkill.SkillType) { case SkillType.PlusOneArmorOrMovement: return(RemoveBiggerThan(skillPoints, FreeSkillPoint.PlusOneArmorOrMovement)); case SkillType.PlusOneAgility: return(RemoveBiggerThan(skillPoints, FreeSkillPoint.PlusOneAgility)); default: return(RemoveBiggerThan(skillPoints, FreeSkillPoint.PlusOneStrength)); } }
private bool HasPlayerFreeSkillForChosenSkill( SkillReadModel newSkill, FreeSkillPoint freeSkillType) { switch (freeSkillType) { case FreeSkillPoint.Normal: return(PlayerCanPickNormalSkill(newSkill)); case FreeSkillPoint.Double: return(PlayerCanPickDoubleSkill(newSkill)); case FreeSkillPoint.PlusOneArmorOrMovement: return(PlayerCanPickArmorOrMovement(newSkill)); case FreeSkillPoint.PlusOneAgility: return(PlayerCanPickAgility(newSkill)); case FreeSkillPoint.PlusOneStrength: return(PlayerCanPickPlusOneStrength(newSkill)); default: return(false); } }
private bool PlayerCanPickDoubleSkill(SkillReadModel newSkill) { if (PlayerConfig.SkillsOnDefault.Contains(newSkill.SkillType)) { return(true); } if (PlayerConfig.SkillsOnDouble.Contains(newSkill.SkillType)) { return(true); } return(false); }
private bool PlayerCanPickPlusOneStrength(SkillReadModel newSkill) { if (PlayerConfig.SkillsOnDefault.Contains(newSkill.SkillType)) { return(true); } if (PlayerConfig.SkillsOnDouble.Contains(newSkill.SkillType)) { return(true); } if (newSkill.SkillType == SkillType.PlusOneStrength) { return(true); } return(false); }
private bool PlayerCanPickArmorOrMovement(SkillReadModel newSkill) { if (PlayerConfig.SkillsOnDefault.Contains(newSkill.SkillType)) { return(true); } if (PlayerConfig.SkillsOnDouble.Contains(newSkill.SkillType)) { return(true); } if (newSkill.SkillType == SkillType.PlusOneArmorOrMovement) { return(true); } return(false); }
private bool PlayerCanPickNormalSkill(SkillReadModel newSkill) { return(PlayerConfig.SkillsOnDefault.Contains(newSkill.SkillType)); }