Esempio n. 1
0
        public ExecutionResult Handle(SetPCSkillsCommand command)
        {
            var result = new ExecutionResult();

            var pc = _context.PlayerCharacter.Where(n => n.Id == command.PcId)
                     .Include(n => n.PcSkill)
                     .Include(n => n.Class.ClassSkill)
                     .ThenInclude(n => n.Skill)
                     .Include(n => n.Background.BgSkill)
                     .ThenInclude(n => n.Skill)
                     .SingleOrDefault();

            if (pc != null)
            {
                var numberOfSkills = Math.Max(pc.PcSkill.Count(), (pc.Class?.NumberOfStartingSkills ?? 0) +
                                              (pc.Background?.BgSkill.Count() ?? 0));

                foreach (var skill in pc.Background.BgSkill)
                {
                    if (!command.Skills.Contains(skill.Skill.Id))
                    {
                        result.ErrorMessages.Add($"{skill.Skill.Name} is a mandatory skill but was not selected");
                        return(result);
                    }
                }

                foreach (var skillId in command.Skills)
                {
                    if (!pc.Class.ClassSkill.Any(n => n.SkillId == skillId) && !pc.Background.BgSkill.Any(n => n.SkillId == skillId))
                    {
                        result.ErrorMessages.Add($"{_context.Skill.SingleOrDefault(n => n.Id == skillId)?.Name} is a not a valid skill for your character");
                        return(result);
                    }
                }

                if (command.Skills.Count != numberOfSkills)
                {
                    result.ErrorMessages.Add($"Invalid number of skills selected");
                    return(result);
                }

                _context.PcSkill.RemoveRange(_context.PcSkill.Where(n => n.PcId == pc.Id));

                _context.SaveChanges();

                foreach (var skillId in command.Skills)
                {
                    pc.PcSkill.Add(new PcSkill
                    {
                        SkillId = skillId
                    });
                }

                _context.SaveChanges();

                result.Success = true;
            }

            return(result);
        }
Esempio n. 2
0
        public ExecutionResult Handle(SetPCLanguagesCommand command)
        {
            var result = new ExecutionResult();

            var pc = _context.PlayerCharacter.Where(n => n.Id == command.PcId)
                     .Include(n => n.PcLanguage)
                     .Include(n => n.Race.RaceLanguage)
                     .ThenInclude(n => n.Language)
                     .Include(n => n.SubRace)
                     .Include(n => n.Background)
                     .SingleOrDefault();

            if (pc != null)
            {
                var numberOfLanguages = Math.Max(pc.PcLanguage.Count(), pc.Race.RaceLanguage.Count() +
                                                 (pc.Race?.AdditionalLanguages ?? 0) +
                                                 (pc.SubRace?.AdditionalLanguages ?? 0) +
                                                 (pc.Background?.AdditionalLanguages ?? 0));

                foreach (var language in pc.Race.RaceLanguage)
                {
                    if (!command.Languages.Contains(language.Language.Id))
                    {
                        result.ErrorMessages.Add($"{language.Language.Name} is a mandatory language but was not selected");
                        return(result);
                    }
                }

                if (command.Languages.Count != numberOfLanguages)
                {
                    result.ErrorMessages.Add($"Invalid number of languages selected");
                    return(result);
                }

                _context.PcLanguage.RemoveRange(_context.PcLanguage.Where(n => n.PcId == pc.Id));

                _context.SaveChanges();

                foreach (var languageId in command.Languages)
                {
                    pc.PcLanguage.Add(new PcLanguage
                    {
                        LanguageId = languageId
                    });
                }

                _context.SaveChanges();

                result.Success = true;
            }

            return(result);
        }
Esempio n. 3
0
        public ExecutionResult Handle(SetPCSpellSlotsCommand command)
        {
            var result = new ExecutionResult();

            var pc = _context.PlayerCharacter.Include(n => n.PcSpellLevel).SingleOrDefault(n => n.Id == command.PcId);

            if (pc != null)
            {
                foreach (var spellSlot in command.SpellSlots)
                {
                    var pcSpellLevel = pc.PcSpellLevel.Single(n => n.SpellLevel == spellSlot.Key);

                    if (spellSlot.Value >= 0)
                    {
                        pcSpellLevel.SlotsMaximum = spellSlot.Value;
                    }
                }

                _context.SaveChanges();

                result.Success = true;
            }

            return(result);
        }
Esempio n. 4
0
        public ExecutionResult Handle(SetPCSpellsCommand command)
        {
            var result = new ExecutionResult();

            var pc = _context.PlayerCharacter.Where(n => n.Id == command.PcId)
                     .Include(n => n.PcSpell)
                     .SingleOrDefault();

            if (pc != null)
            {
                if (command.SpellToRemove.HasValue)
                {
                    var spellToRemove = pc.PcSpell.Single(n => n.SpellId == command.SpellToRemove.Value);

                    pc.PcSpell.Remove(spellToRemove);
                }

                foreach (var spellId in command.Spells)
                {
                    pc.PcSpell.Add(new PcSpell
                    {
                        SpellId = spellId
                    });
                }

                _context.SaveChanges();

                result.Success = true;
            }

            return(result);
        }
Esempio n. 5
0
        public ExecutionResult Handle(SetPCRaceCommand command)
        {
            var result = new ExecutionResult();

            var pc = _context.PlayerCharacter.Find(command.PcId);

            pc.RaceId = command.RaceId;
            _context.SaveChanges();

            result.Success = true;

            return(result);
        }
Esempio n. 6
0
        public ExecutionResult Handle(CreatePCCommand command)
        {
            var result = new ExecutionResult();

            var player = _context.Player.SingleOrDefault(n => n.UserId == _sessionInformation.UserId && n.IsEnabled);

            if (player != null)
            {
                var pc = new PlayerCharacter
                {
                    CampaignId = command.CampaignId,
                    PlayerId   = player.Id,
                    Level      = 1
                };

                _context.PlayerCharacter.Add(pc);

                foreach (var abilityId in _context.Ability.ToList().Select(n => n.Id))
                {
                    pc.PcAbilityScore.Add(new PcAbilityScore
                    {
                        AbilityId = abilityId,
                        Score     = 0
                    });
                }

                for (int i = 1; i <= 9; i++)
                {
                    pc.PcSpellLevel.Add(new PcSpellLevel
                    {
                        SpellLevel = i
                    });
                }

                _context.SaveChanges();

                result.Success     = true;
                result.NewRecordId = pc.Id;
            }

            return(result);
        }
Esempio n. 7
0
        public ExecutionResult Handle(CreateCampaignCommand command)
        {
            var result = new ExecutionResult();

            if (_sessionInformation.IsDM)
            {
                var dm = _context.Player.SingleOrDefault(n => n.UserId == _sessionInformation.UserId && n.IsEnabled);

                if (dm != null)
                {
                    var campaign = new Campaign
                    {
                        Name        = command.Name,
                        Description = command.Description,
                        OwningDmId  = dm.Id,
                        CharacterGenerationMethodId = command.CharacterGenerationMethodId,
                        NewCharacterStartingLevel   = command.NewCharacterStartingLevel
                    };

                    _context.Campaign.Add(campaign);

                    campaign.PlayerCampaign.Add(new PlayerCampaign
                    {
                        PlayerId = dm.Id
                    });

                    foreach (var source in command.Sources)
                    {
                        campaign.CampaignSource.Add(new CampaignSource
                        {
                            SourceId = source
                        });
                    }

                    _context.SaveChanges();

                    result.NewRecordId = campaign.Id;
                }
            }

            return(result);
        }
        public ExecutionResult Handle(SetPCAbilityScoresCommand command)
        {
            var result = new ExecutionResult();

            var pc = _context.PlayerCharacter.Where(n => n.Id == command.PcId)
                     .Include(n => n.PcAbilityScore)
                     .SingleOrDefault();

            if (pc != null)
            {
                foreach (var abilityScore in command.AbilityScores)
                {
                    var pcAbility = pc.PcAbilityScore.Single(n => n.AbilityId == abilityScore.Key);

                    pcAbility.Score = abilityScore.Value;
                }

                _context.SaveChanges();

                result.Success = true;
            }

            return(result);
        }
Esempio n. 9
0
        public ExecutionResult Handle(LevelUpPCCommand command)
        {
            var result = new ExecutionResult();

            var pc = _context.PlayerCharacter.Include(n => n.PcFeature)
                     .Include(n => n.Class)
                     .Include(n => n.PcAbilityScore)
                     .SingleOrDefault(n => n.Id == command.PcId);

            if (pc != null)
            {
                var classFeatures = _context.ClassFeature.Include(n => n.Feature)
                                    .Where(n => n.ClassId == pc.ClassId && n.Level == (pc.Level + 1) ||
                                           (pc.ArchetypeId != null && n.ArchetypeId == pc.ArchetypeId && n.Level == (pc.Level + 1)));

                foreach (var classFeature in classFeatures)
                {
                    pc.PcFeature.Add(new PcFeature
                    {
                        ClassFeatureId  = classFeature.Id,
                        QuantityMaximum = classFeature.Feature.Quantity
                    });
                }

                var conModifier = Math.Floor((pc.PcAbilityScore.SingleOrDefault(n => n.AbilityId == 3).Score - 10m) / 2m);

                if (command.HitPointMaxIncrease < Math.Max(1, (1 + conModifier)) || command.HitPointMaxIncrease > Math.Max(1, (pc.Class.HitDie + conModifier)))
                {
                    result.ErrorMessages.Add($"Invalid Hit Point increase: {command.HitPointMaxIncrease}");
                    return(result);
                }

                if (command.AbilityIncrease.Any() && command.AbilityIncrease.Count != 2)
                {
                    result.ErrorMessages.Add($"Invalid number of Ability Score increases: {command.AbilityIncrease.Count}");
                    return(result);
                }
                foreach (var abilityId in command.AbilityIncrease)
                {
                    var pcAbilityScore = pc.PcAbilityScore.SingleOrDefault(n => n.AbilityId == abilityId);
                    if (pcAbilityScore.Score >= 20)
                    {
                        result.ErrorMessages.Add($"Cannot increase Ability Score past 20.");
                        return(result);
                    }
                    pcAbilityScore.Score++;
                }

                if (command.ProficiencyBonusIncrease)
                {
                    pc.ProficiencyBonus++;
                }

                pc.HitPointMaximum += command.HitPointMaxIncrease;
                pc.HitDiceMaximum++;
                pc.Level++;

                _context.SaveChanges();

                result.Success = true;
            }

            return(result);
        }