Esempio n. 1
0
        /// <summary>
        /// gets all available backgrounds
        /// </summary>
        public List <Background> getBackgrounds()
        {
            List <Background> backgroundList = new List <Background>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT name, description, equipment, gp, extraToolProficiencies, extraFeatureChoice FROM backgrounds " +
                                          "INNER JOIN backgroundEquipment ON backgroundEquipment.backgroundId = backgrounds.backgroundId " +
                                          "INNER JOIN books ON backgrounds.book=books.bookid " +
                                          "WHERE books.title IN (@UsedBooks)";
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                backgroundList.Add(new Background(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetInt32(3), dbReader.GetBoolean(4), dbReader.GetBoolean(5)));
                            }
                        }
                    }
                }

            return(backgroundList);
        }
        /// <summary>
        /// gets a list of all playable classes
        /// </summary>
        public List <CharacterClass> getClasses(int level)
        {
            List <CharacterClass> classList = new List <CharacterClass>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT name, description, dieType, extraToolProficiencies FROM classes " +
                                          "INNER JOIN hitDice ON hitDice.classId=classes.classid " +
                                          "INNER JOIN books ON classes.book=books.bookid " +
                                          "WHERE books.title IN (@UsedBooks)";
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                CharacterClass newClass = new CharacterClass(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetBoolean(3), getProficiencyChoiceAmount(dbReader.GetString(0)));
                                newClass.Subclasses = SubclassData.getSubclasses(newClass.Name, level);
                                classList.Add(newClass);
                            }
                        }
                    }
                }

            return(classList);
        }
        /// <summary>
        /// gets a list of armors with the specified name or of of the specified type
        /// </summary>
        /// <param name="name">chosen name or wildcard *</param>
        /// <param name="type">chosen type or wildcard *</param>
        public List <Armor> getArmorList(string name, string type)
        {
            List <Armor> armor = new List <Armor>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT * FROM armor " +
                                          "INNER JOIN books ON armor.book = books.bookid " +
                                          "WHERE name LIKE @Armor AND type LIKE @Type " +
                                          "AND books.title IN (@UsedBooks)";
                    //replace * with % for sqlite wildcard
                    command.Parameters.AddWithValue("@Armor", name.Replace('*', '%'));
                    command.Parameters.AddWithValue("@Type", type.Replace('*', '%'));
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                bool hasStealthDisadvantage = (dbReader.GetString(8) != "-");
                                armor.Add(new Armor(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetInt32(3), dbReader.GetInt32(4), dbReader.GetString(5), dbReader.GetInt32(6), dbReader.GetInt32(7), hasStealthDisadvantage));
                            }
                        }
                    }
                }

            return(armor);
        }
        /// <summary>
        /// gets a list of weapons with the specified name
        /// </summary>
        /// <param name="name">name of weapon to get</param>
        public List <Weapon> getWeaponList(string name)
        {
            List <Weapon> weapons = new List <Weapon>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT name, type, range, damage, damageType, properties FROM weapons " +
                                          "INNER JOIN books ON weapons.book = books.bookid " +
                                          "WHERE name LIKE @Weapon " +
                                          "AND books.title IN (@UsedBooks)";
                    //replace * with % for sqlite wildcard
                    command.Parameters.AddWithValue("@Weapon", name.Replace('*', '%'));
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                weapons.Add(new Weapon(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4), dbReader.GetString(5)));
                            }
                        }
                    }
                }

            return(weapons);
        }
        /// <summary>
        /// gets a list of the additional cantrips the given subrace may choose from
        /// </summary>
        /// <param name="subrace">chosen subrace</param>
        public List <Spell> getExtraRaceCantripChoiceOptions(string subrace)
        {
            List <Spell> cantripList = new List <Spell>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT spells.name, spells.ritual, spells.level, spells.school, spells.castTime, spells.range, spells.duration, " +
                                          "spells.components, spells.materials, spells.description, (SELECT abilities.name FROM extraRaceCantrips " +
                                          "INNER JOIN races ON races.raceid = extraRaceCantrips.raceId INNER JOIN classes ON classes.classid = extraRaceCantrips.classId " +
                                          "INNER JOIN abilities ON abilities.abilityId = extraRaceCantrips.spellcastingAbility " +
                                          "WHERE races.subrace = @Subrace) as spellcastingAbility " +
                                          "FROM spells " +
                                          "INNER JOIN books ON spells.book = books.bookid " +
                                          "WHERE spells.level = 0 " +
                                          "AND spells.classes LIKE \"%\" || " +
                                          "(SELECT classes.name FROM extraRaceCantrips " +
                                          "INNER JOIN races ON races.raceid = extraRaceCantrips.raceId " +
                                          "INNER JOIN classes ON classes.classid = extraRaceCantrips.classId " +
                                          "WHERE races.subrace=@Subrace) || \"%\" " +
                                          "AND books.title IN(@UsedBooks)";
                    command.Parameters.AddWithValue("@Subrace", subrace);
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                cantripList.Add(new ExtraRaceSpell(dbReader.GetString(0),
                                                                   dbReader.GetBoolean(1),
                                                                   dbReader.GetInt32(2),
                                                                   dbReader.GetString(3),
                                                                   dbReader.GetString(4),
                                                                   dbReader.GetString(5),
                                                                   dbReader.GetString(6),
                                                                   dbReader.GetString(7),
                                                                   dbReader.GetString(8),
                                                                   dbReader.GetString(9),
                                                                   false, 0,
                                                                   dbReader.GetString(10)));
                            }
                        }
                    }
                }

            return(cantripList);
        }
        /// <summary>
        /// gets a list of spells the character can choose from
        /// </summary>
        /// <param name="className">chosen class</param>
        /// <param name="subclass">chosen subclass</param>
        /// <param name="level">current level</param>
        public List <Spell> getSpellOptions(string className, string subclass, int level)
        {
            List <Spell> spellList = new List <Spell>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT * FROM spells " +
                                          "INNER JOIN books ON books.bookid=spells.book " +
                                          "WHERE spells.level = " +
                                          "(SELECT maxSpellLevel FROM maxSpellLevel " +
                                          "INNER JOIN classes ON maxSpellLevel.classId = classes.classid " +
                                          "WHERE classes.name=@Class AND maxSpellLevel.level BETWEEN 1 AND @Level " +
                                          "UNION " +
                                          "SELECT maxSpellLevel FROM maxSpellLevelSubclass " +
                                          "INNER JOIN subclasses ON maxSpellLevelSubclass.subclassId = subclasses.subclassId " +
                                          "WHERE subclasses.name=@Subclass AND maxSpellLevelSubclass.level BETWEEN 1 AND @Level " +
                                          "ORDER BY maxSpellLevel DESC LIMIT 1) " +
                                          "AND(spells.classes LIKE @LikeClass " +
                                          "OR spells.classes LIKE @LikeSubclass) " +
                                          "AND books.title IN (@UsedBooks)";
                    command.Parameters.AddWithValue("@Class", className);
                    command.Parameters.AddWithValue("@LikeClass", "%" + className + "%");
                    command.Parameters.AddWithValue("@Subclass", subclass);
                    command.Parameters.AddWithValue("@LikeSubclass", "%" + subclass + "%");
                    command.Parameters.AddWithValue("@Level", level.ToString());
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                spellList.Add(new Spell(dbReader.GetString(1), dbReader.GetBoolean(2), dbReader.GetInt32(3), dbReader.GetString(4), dbReader.GetString(5), dbReader.GetString(6), dbReader.GetString(7), dbReader.GetString(8), dbReader.GetString(9), dbReader.GetString(10), false));
                            }
                        }
                    }
                }

            return(spellList);
        }
        /// <summary>
        /// gets a list of all playable races
        /// </summary>
        public List <Race> getRaces()
        {
            List <Race> raceList    = new List <Race>();
            Race        currentRace = new Race();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT race, subrace, description, alignmentDescription, speed FROM races " +
                                          "INNER JOIN books ON races.book=books.bookid " +
                                          "WHERE books.title IN (@UsedBooks)";
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                if (dbReader.GetString(0) != currentRace.Name)
                                {
                                    if (!string.IsNullOrEmpty(currentRace.Name))
                                    {
                                        raceList.Add(currentRace);
                                    }
                                    currentRace = new Race(dbReader.GetString(0));
                                }
                                currentRace.addSubrace(new Subrace(dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetInt32(4), subraceHasProficiencyChoice(dbReader.GetString(1))));
                            }
                        }

                        if (!raceList.Contains(currentRace) && !string.IsNullOrEmpty(currentRace.Name))
                        {
                            raceList.Add(currentRace);
                        }
                    }
                }

            return(raceList);
        }
        /// <summary>
        /// gets a list of cantrips the character can choose from
        /// </summary>
        /// <param name="className">chosen class</param>
        /// <param name="subclass">chosen subclass</param>
        public List <Spell> getCantripOptions(string className, string subclass)
        {
            List <Spell> cantripList = new List <Spell>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT * FROM spells " +
                                          "INNER JOIN books ON books.bookid=spells.book " +
                                          "WHERE spells.level=0 " +
                                          "AND spells.classes LIKE @Class " +
                                          "AND books.title IN (@UsedBooks)";
                    if ((subclass == "Arcane Trickster") || (subclass == "Eldritch Knight"))
                    {
                        command.Parameters.AddWithValue("@Class", "%" + subclass + "%");
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@Class", "%" + className + "%");
                    }
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                cantripList.Add(new Spell(dbReader.GetString(1), dbReader.GetBoolean(2), dbReader.GetInt32(3), dbReader.GetString(4), dbReader.GetString(5), dbReader.GetString(6), dbReader.GetString(7), dbReader.GetString(8), dbReader.GetString(9), dbReader.GetString(10), false));
                            }
                        }
                    }
                }

            return(cantripList);
        }
        /// <summary>
        /// gets a list of all subclass options for the chosen class
        /// </summary>
        /// <param name="className">class for which to get subclasses</param>
        /// <param name="level">player level</param>
        public List <Subclass> getSubclasses(string className, int level)
        {
            List <Subclass> subclassList = new List <Subclass>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT subclasses.name, subclasses.description FROM subclasses " +
                                          "INNER JOIN books ON subclasses.book=books.bookid " +
                                          "INNER JOIN classes ON subclasses.parentclass=classes.classid " +
                                          "WHERE books.title IN (@UsedBooks) AND classes.name=@Class " +
                                          "AND classes.subclasslevel<=@Level";
                    command.Parameters.AddWithValue("@Class", className);
                    command.Parameters.AddWithValue("@Level", level.ToString());
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@UsedBooks", UsedBooks);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                subclassList.Add(new Subclass(dbReader.GetString(0), dbReader.GetString(1)));
                            }
                        }
                    }
                }

            if (subclassList.Count == 0)
            {
                subclassList.Add(new Subclass("---", string.Empty));
            }

            return(subclassList);
        }