示例#1
0
        public ChoicesCollection CreateChoiceCollection(List <Feature> ClassFeatures, Character character)
        {
            ChoicesCollection returnChoiceCollection = new ChoicesCollection();

            returnChoiceCollection.Choices = new List <ChoiceViewModel>();

            foreach (var classFeature in ClassFeatures)
            {
                bool choicePresent = false;

                choicePresent = IsChoiceInFeature(classFeature);

                if (choicePresent)
                {
                    returnChoiceCollection.Choices.Add(CreateChoiceViewModelFromDB(

                                                           _context.FeatureChoices
                                                           .Where(fc => fc.FK_Feature == classFeature.Id)
                                                           .Select(c => c.Choice).Include(c => c.AvailableOptions).FirstOrDefault()
                                                           ));
                }
            }

            returnChoiceCollection.Character = character;

            returnChoiceCollection.FK_Class = _context.ClassFeatures.Where(cf => cf.FK_Feature == ClassFeatures[0].Id).FirstOrDefault().FK_Class;

            return(returnChoiceCollection);
        }
示例#2
0
        //Creates the universal choice collection that all choices will become. 2 versions, one for race features and one for classfeatures. Can be extended for feats.
        //Can this become one with the implementation of an interface?
        public ChoicesCollection CreateChoiceCollection(List <RaceFeature> raceFeatures, Character character)
        {
            ChoicesCollection returnChoiceCollection = new ChoicesCollection();

            returnChoiceCollection.Choices = new List <ChoiceViewModel>();

            foreach (var raceFeature in raceFeatures)
            {
                bool choicePresent = false;

                choicePresent = IsChoiceInFeature(raceFeature);

                if (choicePresent)
                {
                    returnChoiceCollection.Choices.Add(CreateChoiceViewModelFromDB(

                                                           _context.RaceFeatureChoices
                                                           .Where(c => c.FK_RaceFeature == raceFeature.Id)
                                                           .Select(c => c.Choice).Include(c => c.AvailableOptions).FirstOrDefault()
                                                           ));
                }
            }

            returnChoiceCollection.Character = character;

            return(returnChoiceCollection);
        }
        //For both leveling and applying classes.
        public async Task <IActionResult> ChooseClass(int Id, int ClassId)
        {
            Character character = _characterServices.GetCharacterFromId(Id);

            Class _class = _context.Classes.Where(c => c.Id == ClassId).FirstOrDefault();

            int levelGained = _characterServices.GetClassLevel(character, _class);

            bool hasChoice = _choiceServices.IsChoicesInClass(_class, (levelGained + 1));

            _characterServices.AddCharacterClass(ClassId, character);

            //If a choice is present, reconstruct the different features needed for the choicecollection.
            if (hasChoice)
            {
                List <Feature> classFeatures = _context.ClassFeatures
                                               .Where(f => f.FK_Class == ClassId && f.Level == (levelGained + 1))
                                               .Select(f => f.Feature)
                                               .ToList();

                classFeatures.AddRange(_context.SubClassFeatures.Where(f => f.SubClass.FK_Class == ClassId && f.Level == (levelGained + 1))
                                       .Select(f => f.Feature)
                                       .ToList());

                ChoicesCollection choicesCollection = _choiceServices.CreateChoiceCollection(classFeatures, character);

                return(View("ChoiceView", choicesCollection));
            }

            return(View("Details", character));
        }
        public IActionResult ChooseRace(int Id, int FK_Race)
        {
            Character character = _characterServices.GetCharacterFromId(Id);

            _characterServices.SetCharacterRace(FK_Race, character);

            bool hasChoices = _choiceServices.IsChoiceInRace(character.Race);

            if (hasChoices)
            {
                List <RaceFeature> raceFeatures = _context.RaceRacefeatures.Where(r => r.FK_Race == FK_Race).Select(r => r.RaceFeature).ToList();

                ChoicesCollection choicesCollection = _choiceServices.CreateChoiceCollection(raceFeatures, character);

                return(View("ChoiceView", choicesCollection));
            }

            return(View("Details", character));
        }
        //Generic controller for all choices actions. Takes several objects right now; can this be combined in a single class? ASP.NET doesn't seem to like sending larger objects between classes; study this.
        public IActionResult Choice(int Id, ChoicesCollection choicesCollection, List <List <bool> > optionsChosen, List <List <string> > optionsNames, List <List <string> > optionsDescriptions, List <List <int> > OptionIds)
        {
            //Restored the choicecollection from all the loose lists that were send here.
            for (int i = 0; i < choicesCollection.Choices.Count; i++)
            {
                choicesCollection.Choices[i].OptionNames = optionsNames[i];
                if (optionsDescriptions.Count - 1 > i)
                {
                    choicesCollection.Choices[i].OptionDescriptions = optionsDescriptions[i];
                }
                choicesCollection.Choices[i].OptionsChosen = optionsChosen[i];
                choicesCollection.Choices[i].OptionIds     = OptionIds[i];
            }

            _choiceServices.ResolveChoice(Id, choicesCollection);

            //Is this needed? The character get's reconstructed a lot, which might be redundant.
            Character character = _characterServices.GetCharacterFromId(Id);

            return(View("Details", character));
        }
示例#6
0
        public void ResolveChoice(int Id, ChoicesCollection choicesCollection)
        {
            choicesCollection.Character = _characterServices.GetCharacterFromId(Id);

            foreach (var choice in choicesCollection.Choices)
            {
                List <Option> options = new List <Option>();

                for (int i = 0; i < choice.OptionsChosen.Count; i++)
                {
                    if (choice.OptionsChosen[i])
                    {
                        options.Add(new Option {
                            Name = choice.OptionNames[i], Id = choice.OptionIds[i]
                        });
                    }
                    if (choice.OptionDescriptions.Count - 1 > i)
                    {
                        options[i].Description = choice.OptionDescriptions[i];
                    }
                }


                //This one is becoming WAY too large. Adress this.
                switch (choice.Descriminator)
                {
                case ChoiceType.RacialLanguage:
                    foreach (var option in options)
                    {
                        _context.CharacterProficiencies.Add(new CharacterProficiency
                        {
                            FK_Character   = Id,
                            FK_Proficiency = _context.Proficiencies.Where(p => p.Name == option.Name).Select(p => p.Id).FirstOrDefault()
                        });;
                    }
                    break;

                case ChoiceType.RacialProficiency:
                    foreach (var option in options)
                    {
                        _context.CharacterProficiencies.Add(new CharacterProficiency
                        {
                            FK_Character   = Id,
                            FK_Proficiency = _context.Proficiencies.Where(p => p.Name == option.Name).Select(p => p.Id).FirstOrDefault()
                        });;
                    }
                    break;

                case ChoiceType.ClassSkillChoice:
                    foreach (var option in options)
                    {
                        _context.CharacterSkills.Add(new CharacterSkill
                        {
                            FK_Character = Id,
                            FK_Skill     = _context.Skills.Where(s => s.Name == option.Name).Select(p => p.Id).FirstOrDefault(),
                        });;
                    }
                    break;

                case ChoiceType.ClassFeature:

                    _context.Decisions.Add(new Decision
                    {
                        FK_Character = Id,
                        Description  = choice.Description,
                        Name         = choice.Name,
                        FK_Class     = choicesCollection.FK_Class
                    });

                    //Is this really needed? Investigate this.
                    _context.SaveChanges();

                    foreach (var option in options)
                    {
                        _context.DecisionOptions.Add(new DecisionOption
                        {
                            //FK_Decision = _context.Decisions.Count() +1,
                            FK_Decision = _context.Decisions.Where(d => d.FK_Character == Id && d.Description == choice.Description && d.Name == choice.Name).FirstOrDefault().Id,
                            FK_Option   = option.Id
                        });;
                    }
                    break;

                case ChoiceType.SubClass:
                    SubClass subClass = _context.SubClasses.Where(sc => sc.Id == options[0].Id).FirstOrDefault();

                    choicesCollection.Character.SubClasses.Add(subClass);

                    _context.characterSubClasses.Add(new CharacterSubClass {
                        FK_Character = choicesCollection.Character.Id, FK_SubClass = subClass.Id
                    });

                    _context.Log.Add(new LogItem {
                        DateLogged = DateTime.Now, Message = $"Added subclass {subClass.Name} to {choicesCollection.Character.Name}, id {choicesCollection.Character.Id}."
                    });
                    break;

                case ChoiceType.AbilityScoreImprovement:
                    foreach (var option in options)
                    {
                        _context.Log.Add(new LogItem {
                            DateLogged = DateTime.Now, Message = $"Ability Score {option.Name} improved for character {choicesCollection.Character.Name}, id {choicesCollection.Character.Id}."
                        });

                        switch (option.Name)
                        {
                        case "Strenght":
                            choicesCollection.Character.Strenght += 1;
                            break;

                        case "Dexterity":
                            choicesCollection.Character.Dexterity += 1;
                            break;

                        case "Constitution":
                            choicesCollection.Character.Constitution += 1;
                            break;

                        case "Wisdom":
                            choicesCollection.Character.Wisdom += 1;
                            break;

                        case "Intelligence":
                            choicesCollection.Character.Intelligence += 1;
                            break;

                        case "Charisma":
                            choicesCollection.Character.Charisma += 1;
                            break;

                        default:
                            break;
                        }
                    }


                    break;

                default:
                    break;
                }
            }

            _context.Log.Add(new LogItem {
                DateLogged = DateTime.Now, Message = $"resolved {choicesCollection.Character.Name} choice, id {choicesCollection.Character.Id}."
            });

            _context.SaveChanges();
        }