示例#1
0
        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));
        }
示例#2
0
        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));
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
 private bool PlayerCanPickDoubleSkill(SkillReadModel newSkill)
 {
     if (PlayerConfig.SkillsOnDefault.Contains(newSkill.SkillType))
     {
         return(true);
     }
     if (PlayerConfig.SkillsOnDouble.Contains(newSkill.SkillType))
     {
         return(true);
     }
     return(false);
 }
示例#5
0
 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);
 }
示例#6
0
 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);
 }
示例#7
0
 private bool PlayerCanPickNormalSkill(SkillReadModel newSkill)
 {
     return(PlayerConfig.SkillsOnDefault.Contains(newSkill.SkillType));
 }