/// <summary>
        /// gets a list of spells that a given warlock pact may choose from
        /// </summary>
        /// <param name="pact">chosen warlock pact</param>
        public List <Spell> getPactSpells(WarlockPact pact)
        {
            List <Spell> pactSpells = 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 " +
                                          "FROM warlockPacts " +
                                          "INNER JOIN warlockPactGainedSpells ON warlockPactGainedSpells.pactId = warlockPacts.pactId " +
                                          "INNER JOIN spells ON spells.spellId = warlockPactGainedSpells.spellId " +
                                          "WHERE warlockPacts.name = @Pact";
                    command.Parameters.AddWithValue("@Pact", pact.Name);

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                pactSpells.Add(new Spell(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));
                            }
                        }
                    }
                }

            return(pactSpells);
        }
Ejemplo n.º 2
0
        private void togglePactSpellSelection()
        {
            WarlockPact currentPact = (WarlockPact)pactListBox.SelectedItem;

            if (currentPact.SpellAmount > 0)
            {
                pactLayout.Size         = new Size(425, pactLayout.Size.Height);
                pactSpellLayout.Visible = true;

                pactSpellIntroLabel.Text = $"Choose {currentPact.SpellAmount} spell(s):";
                if (currentPact.SpellAmount > 1)
                {
                    pactSpellListBox.SelectionMode = SelectionMode.MultiSimple;
                }
                else
                {
                    pactSpellListBox.SelectionMode = SelectionMode.One;
                }

                refreshPactSpellList(currentPact);
            }
            else
            {
                pactLayout.Size         = new Size(843, pactLayout.Size.Height);
                pactSpellLayout.Visible = false;
            }
        }
Ejemplo n.º 3
0
        private void pactSpellListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            syncPactSpellSelectionOrder();

            WarlockPact currentPact = (WarlockPact)pactListBox.SelectedItem;

            if (currentPact != null)
            {
                if (pactSpellListBox.SelectedIndices.Count > 0)
                {
                    if (pactSpellListBox.SelectedIndices.Count <= currentPact.SpellAmount)
                    {
                        int   lastSelectedIndex = pactSpellsOrderedSelection.ElementAt(pactSpellsOrderedSelection.Count - 1);
                        Spell currentSpell      = (Spell)pactSpellListBox.Items[lastSelectedIndex];
                        if (currentSpell != null)
                        {
                            pactSpellDescriptionLabel.Text = SpellFormatter.formatSpellDescription(currentSpell);
                        }
                    }
                    else
                    {
                        int lastSelectedIndex = pactSpellsOrderedSelection.ElementAt(pactSpellsOrderedSelection.Count - 1);
                        pactSpellListBox.SelectedIndices.Remove(lastSelectedIndex);
                    }

                    refreshInvocationList();
                    OnPactSpellChosen(null);
                }
            }
        }
Ejemplo n.º 4
0
        public string getInvalidElements()
        {
            string missingElements = "";

            //warlock pact
            if (wm.Choices.ClassChoice.HasWarlockPact)
            {
                if (!string.IsNullOrEmpty(missingElements))
                {
                    missingElements += ", ";
                }

                if (pactListBox.SelectedItems.Count > 0)
                {
                    WarlockPact currentPact = (WarlockPact)pactListBox.SelectedItem;
                    if (currentPact.SpellAmount > 0)
                    {
                        if (pactSpellListBox.SelectedItems.Count < currentPact.SpellAmount)
                        {
                            missingElements = $"select {currentPact.SpellAmount - pactSpellListBox.SelectedItems.Count} more pact spell(s)";
                        }
                    }
                }
                else
                {
                    missingElements = "select a pact";
                }
            }

            //warlock invocations
            if (wm.Choices.ClassChoice.HasEldritchInvocations)
            {
                if (!string.IsNullOrEmpty(missingElements))
                {
                    missingElements += ", ";
                }

                if (invocationListBox.SelectedItems.Count < invocationsKnown)
                {
                    missingElements += $"select {invocationsKnown - invocationListBox.SelectedItems.Count} more eldritch invocation(s)";
                }

                if (hasInvocationSelectionSpellChoice())
                {
                    if (invocationSpellListBox.SelectedItems.Count < invocationSpellsKnown)
                    {
                        if (!string.IsNullOrEmpty(missingElements))
                        {
                            missingElements += ", ";
                        }
                        missingElements += $"select {invocationSpellsKnown - invocationSpellListBox.SelectedItems.Count} more invocation spell(s)";
                    }
                }
            }

            return(missingElements);
        }
Ejemplo n.º 5
0
        public bool isValid()
        {
            bool isPactValid       = false;
            bool isInvocationValid = false;

            //warlock pact
            if (wm.Choices.ClassChoice.HasWarlockPact)
            {
                if (pactListBox.SelectedItems.Count > 0)
                {
                    WarlockPact currentPact = (WarlockPact)pactListBox.SelectedItem;
                    if (currentPact.SpellAmount > 0)
                    {
                        if (pactSpellListBox.SelectedItems.Count == currentPact.SpellAmount)
                        {
                            isPactValid = true;
                        }
                    }
                    else
                    {
                        isPactValid = true;
                    }
                }
            }
            else
            {
                isPactValid = true;
            }

            //warlock invocations
            if (wm.Choices.ClassChoice.HasEldritchInvocations)
            {
                if (hasInvocationSelectionSpellChoice())
                {
                    isInvocationValid = ((invocationListBox.SelectedItems.Count == invocationsKnown) && (invocationSpellListBox.SelectedItems.Count == invocationSpellsKnown));
                }
                else
                {
                    isInvocationValid = (invocationListBox.SelectedItems.Count == invocationsKnown);
                }
            }
            else
            {
                isInvocationValid = true;
            }

            return(isPactValid && isInvocationValid);
        }
Ejemplo n.º 6
0
        private void pactListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (pactListBox.SelectedItems.Count > 0)
            {
                WarlockPact currentPact = (WarlockPact)pactListBox.SelectedItem;
                if (currentPact != null)
                {
                    pactDescriptionLabel.Text = currentPact.Description.Replace("<br>", Environment.NewLine);

                    togglePactSpellSelection();

                    refreshInvocationList();

                    OnPactChosen(null);
                }
            }
        }
Ejemplo n.º 7
0
        public void refreshInvocationList()
        {
            //compile list of all known spells
            List <Spell> knownSpells = new List <Spell>();

            knownSpells.AddRange(wm.Choices.Spells);
            foreach (Spell spell in wm.Choices.RaceSpells)
            {
                if (!string.IsNullOrEmpty(spell.Name))
                {
                    knownSpells.Add(spell);
                }
            }
            if (wm.Choices.ClassChoice.HasWarlockPact)
            {
                foreach (Spell spell in pactSpellListBox.SelectedItems)
                {
                    if (spell != null)
                    {
                        knownSpells.Add(spell);
                    }
                }
            }

            //refresh list
            WarlockPact currentPact = (WarlockPact)pactListBox.SelectedItem;

            if ((currentPact != null) && (wm.Choices.ClassChoice.HasWarlockPact))
            {
                invocationSource = wm.DBManager.ExtraClassChoiceData.WarlockChoiceData.getEldritchInvocations(knownSpells, currentPact, wm.Choices.Level);
            }
            else
            {
                invocationSource = wm.DBManager.ExtraClassChoiceData.WarlockChoiceData.getEldritchInvocations(knownSpells, new WarlockPact(), wm.Choices.Level);
            }

            invocationListBox.BeginUpdate();
            invocationListBox.DataSource    = null;
            invocationListBox.DataSource    = invocationSource;
            invocationListBox.DisplayMember = "Name";
            invocationListBox.EndUpdate();
        }
Ejemplo n.º 8
0
        private void refreshPactSpellList(WarlockPact currentPact)
        {
            pactSpellSource = wm.DBManager.ExtraClassChoiceData.WarlockChoiceData.getPactSpells(currentPact);

            //remove already chosen spells
            foreach (Spell spell in wm.Choices.Spells)
            {
                pactSpellSource.Remove(spell);
            }

            foreach (Spell spell in wm.Choices.RaceSpells)
            {
                if (!string.IsNullOrEmpty(spell.Name))
                {
                    pactSpellSource.Remove(spell);
                }
            }

            pactSpellListBox.BeginUpdate();
            pactSpellListBox.DataSource    = null;
            pactSpellListBox.DataSource    = pactSpellSource;
            pactSpellListBox.DisplayMember = "Name";
            pactSpellListBox.EndUpdate();
        }
        ///// <summary>
        ///// gets a list of eldritch invocations the warlock may choose with the current level and pact choice
        ///// </summary>
        ///// <param name="warlockPact">chosen warlock pact</param>
        ///// <param name="level">current level</param>
        //public List<EldritchInvocation> getEldritchInvocations(WarlockPact warlockPact, int level)
        //{
        //    List<EldritchInvocation> invocations = new List<EldritchInvocation>();

        //    using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
        //    using (SQLiteCommand command = new SQLiteCommand(connection))
        //    {
        //        connection.Open();
        //        command.CommandText = "SELECT eldritchInvocations.name, eldritchInvocations.description, eldritchInvocations.level, " +
        //                              "eldritchInvocations.pactRestriction, eldritchInvocations.hasSpellChoice, RequiredSpells.name, RequiredSpells.ritual, RequiredSpells.level, " +
        //                              "RequiredSpells.school, RequiredSpells.castTime, RequiredSpells.range, RequiredSpells.duration, " +
        //                              "RequiredSpells.components, RequiredSpells.materials, RequiredSpells.description, GainedSpells.name, " +
        //                              "GainedSpells.ritual, GainedSpells.level, GainedSpells.school, GainedSpells.castTime, GainedSpells.range, " +
        //                              "GainedSpells.duration, GainedSpells.components, GainedSpells.materials, GainedSpells.description " +
        //                              "FROM eldritchInvocations " +
        //                              "LEFT JOIN eldritchInvocationRequiredSpells ON eldritchInvocationRequiredSpells.invocationId = eldritchInvocations.invocationId " +
        //                              "LEFT JOIN eldritchInvocationGainedSpells ON eldritchInvocationGainedSpells.invocationId = eldritchInvocations.invocationId " +
        //                              "LEFT JOIN spells as RequiredSpells ON RequiredSpells.spellId = eldritchInvocationRequiredSpells.spellId " +
        //                              "LEFT JOIN spells as GainedSpells ON GainedSpells.spellId = eldritchInvocationGainedSpells.spellId " +
        //                              "WHERE (eldritchInvocations.pactRestriction = @NonPact OR eldritchInvocations.pactRestriction LIKE @Pact) " +
        //                              "AND eldritchInvocations.level BETWEEN 1 AND @Level";
        //        command.Parameters.AddWithValue("@NonPact", string.Empty);
        //        command.Parameters.AddWithValue("@Pact", warlockPact.Name);
        //        command.Parameters.AddWithValue("@Level", level.ToString());

        //        using (SQLiteDataReader dbReader = command.ExecuteReader())
        //        {
        //            while (dbReader.Read())
        //            {
        //                if (!dbReader.IsDBNull(0))
        //                {
        //                    Spell gainedSpell = new Spell();
        //                    if (!dbReader.IsDBNull(5))
        //                    {
        //                        gainedSpell = new Spell(dbReader.GetString(5), dbReader.GetBoolean(6), dbReader.GetInt32(7), dbReader.GetString(8), dbReader.GetString(9), dbReader.GetString(10), dbReader.GetString(11), dbReader.GetString(12), dbReader.GetString(13), dbReader.GetString(14), false);
        //                    }

        //                    Spell requiredSpell = new Spell();
        //                    if (!dbReader.IsDBNull(15))
        //                    {
        //                        requiredSpell = new Spell(dbReader.GetString(15), dbReader.GetBoolean(16), dbReader.GetInt32(17), dbReader.GetString(18), dbReader.GetString(19), dbReader.GetString(20), dbReader.GetString(21), dbReader.GetString(22), dbReader.GetString(23), dbReader.GetString(24), false);
        //                    }

        //                    invocations.Add(new EldritchInvocation(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetInt32(2), requiredSpell, dbReader.GetString(3), gainedSpell, dbReader.GetBoolean(4)));
        //                }
        //            }
        //        }
        //    }

        //    return invocations;
        //}



        /// <summary>
        /// gets a list of eldritch invocations the warlock may choose with the current level and pact choice
        /// </summary>
        /// <param name="knownSpells">list of known spells</param>
        /// <param name="warlockPact">chosen warlock pact</param>
        /// <param name="level">current level</param>
        public List <EldritchInvocation> getEldritchInvocations(List <Spell> knownSpells, WarlockPact warlockPact, int level)
        {
            List <EldritchInvocation> invocations = new List <EldritchInvocation>();

            using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    connection.Open();
                    command.CommandText = "SELECT eldritchInvocations.name, eldritchInvocations.description, eldritchInvocations.level, " +
                                          "eldritchInvocations.pactRestriction, eldritchInvocations.hasSpellChoice, RequiredSpells.name, RequiredSpells.ritual, RequiredSpells.level, " +
                                          "RequiredSpells.school, RequiredSpells.castTime, RequiredSpells.range, RequiredSpells.duration, " +
                                          "RequiredSpells.components, RequiredSpells.materials, RequiredSpells.description, GainedSpells.name, " +
                                          "GainedSpells.ritual, GainedSpells.level, GainedSpells.school, GainedSpells.castTime, GainedSpells.range, " +
                                          "GainedSpells.duration, GainedSpells.components, GainedSpells.materials, GainedSpells.description " +
                                          "FROM eldritchInvocations " +
                                          "LEFT JOIN eldritchInvocationRequiredSpells ON eldritchInvocationRequiredSpells.invocationId = eldritchInvocations.invocationId " +
                                          "LEFT JOIN eldritchInvocationGainedSpells ON eldritchInvocationGainedSpells.invocationId = eldritchInvocations.invocationId " +
                                          "LEFT JOIN spells as RequiredSpells ON RequiredSpells.spellId = eldritchInvocationRequiredSpells.spellId " +
                                          "LEFT JOIN spells as GainedSpells ON GainedSpells.spellId = eldritchInvocationGainedSpells.spellId " +
                                          "WHERE (eldritchInvocations.pactRestriction = @NonPact OR eldritchInvocations.pactRestriction LIKE @Pact) " +
                                          "AND eldritchInvocations.level BETWEEN 1 AND @Level " +
                                          "AND (RequiredSpells.name IS NULL OR RequiredSpells.name IN (@KnownSpells))";
                    command.Parameters.AddWithValue("@NonPact", string.Empty);
                    command.Parameters.AddWithValue("@Pact", warlockPact.Name);
                    command.Parameters.AddWithValue("@Level", level.ToString());
                    SQLiteCommandExtensions.AddParametersWithValues(command, "@KnownSpells", knownSpells.Select(spell => spell.Name).ToList());

                    using (SQLiteDataReader dbReader = command.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            if (!dbReader.IsDBNull(0))
                            {
                                Spell gainedSpell = new Spell();
                                if (!dbReader.IsDBNull(5))
                                {
                                    gainedSpell = new Spell(dbReader.GetString(5),
                                                            dbReader.GetBoolean(6),
                                                            dbReader.GetInt32(7),
                                                            dbReader.GetString(8),
                                                            dbReader.GetString(9),
                                                            dbReader.GetString(10),
                                                            dbReader.GetString(11),
                                                            dbReader.GetString(12),
                                                            dbReader.GetString(13),
                                                            dbReader.GetString(14),
                                                            false);
                                }

                                Spell requiredSpell = new Spell();
                                if (!dbReader.IsDBNull(15))
                                {
                                    requiredSpell = new Spell(dbReader.GetString(15),
                                                              dbReader.GetBoolean(16),
                                                              dbReader.GetInt32(17),
                                                              dbReader.GetString(18),
                                                              dbReader.GetString(19),
                                                              dbReader.GetString(20),
                                                              dbReader.GetString(21),
                                                              dbReader.GetString(22),
                                                              dbReader.GetString(23),
                                                              dbReader.GetString(24),
                                                              false);
                                }

                                invocations.Add(new EldritchInvocation(dbReader.GetString(0),
                                                                       dbReader.GetString(1),
                                                                       dbReader.GetInt32(2),
                                                                       requiredSpell,
                                                                       dbReader.GetString(3),
                                                                       gainedSpell,
                                                                       dbReader.GetBoolean(4),
                                                                       hasInvocationSkillGain(dbReader.GetString(0))));
                            }
                        }
                    }
                }

            return(invocations);
        }
Ejemplo n.º 10
0
        public void saveContent()
        {
            if (wm.Choices.ClassChoice.HasWarlockPact)
            {
                //save chosen pact
                WarlockPact currentPact = (WarlockPact)pactListBox.SelectedItem;
                wm.Choices.ClassChoice.WarlockPactChoice = currentPact;

                //save pact spells, if applicable
                wm.Choices.ClassChoice.WarlockPactSpells.Clear();
                if (currentPact.SpellAmount > 0)
                {
                    foreach (Spell spell in pactSpellListBox.SelectedItems)
                    {
                        if (spell != null)
                        {
                            wm.Choices.ClassChoice.WarlockPactSpells.Add(spell);
                        }
                    }
                }
            }
            else
            {
                wm.Choices.ClassChoice.WarlockPactChoice = new WarlockPact();
                wm.Choices.ClassChoice.WarlockPactSpells.Clear();
            }

            if (wm.Choices.ClassChoice.HasEldritchInvocations)
            {
                wm.Choices.ClassChoice.WarlockInvocations.Clear();
                wm.Choices.ClassChoice.WarlockInvocationSkills.Clear();
                wm.Choices.ClassChoice.WarlockInvocationSpells.Clear();

                //save chosen invocations and possibly gained skills
                foreach (EldritchInvocation invocation in invocationListBox.SelectedItems)
                {
                    if (invocation != null)
                    {
                        wm.Choices.ClassChoice.WarlockInvocations.Add(invocation);

                        if (invocation.HasSkillGain)
                        {
                            wm.Choices.ClassChoice.WarlockInvocationSkills.AddRange(wm.DBManager.ExtraClassChoiceData.WarlockChoiceData.getInvocationGainedSkills(invocation));
                        }
                    }
                }

                //save invocation spells, if applicable
                if (hasInvocationSelectionSpellChoice())
                {
                    foreach (Spell spell in invocationSpellListBox.SelectedItems)
                    {
                        if (spell != null)
                        {
                            wm.Choices.ClassChoice.WarlockInvocationSpells.Add(spell);
                        }
                    }
                }
            }
            else
            {
                wm.Choices.ClassChoice.WarlockInvocations.Clear();
                wm.Choices.ClassChoice.WarlockInvocationSpells.Clear();
                wm.Choices.ClassChoice.WarlockInvocationSkills.Clear();
            }
        }