ARKBreedingStats.Form1.extractLevels C# (CSharp) Method

extractLevels() private method

private extractLevels ( ) : bool
return bool
        private bool extractLevels()
        {
            SuspendLayout();
            int activeStatKeeper = activeStat;
            clearAll();

            Extraction.E.extractLevels(sE, (int)numericUpDownLevel.Value, statIOs,
                (double)numericUpDownLowerTEffBound.Value / 100, (double)numericUpDownUpperTEffBound.Value / 100,
                checkBoxWildTamedAuto.Checked, radioButtonTamed.Checked, checkBoxJustTamed.Checked, checkBoxAlreadyBred.Checked,
                (double)numericUpDownImprintingBonusExtractor.Value / 100, creatureCollection.imprintingMultiplier);

            checkBoxJustTamed.Checked = Extraction.E.justTamed;

            // remove all results that require a total wild-level higher than the max
            if (!checkBoxAlreadyBred.Checked
                && creatureCollection.maxWildLevel > 0
                && Extraction.E.levelWildFromTorporRange[0] > creatureCollection.maxWildLevel
                )
            {
                double minTECheck = 2d * (Extraction.E.levelWildFromTorporRange[0] - creatureCollection.maxWildLevel) / creatureCollection.maxWildLevel;

                if (minTECheck < 1)
                {
                    // if min TE is equal or greater than 1, that indicates it can't possibly be anything but bred, and there cannot be any results that should be sorted out

                    for (int s = 0; s < 8; s++)
                    {
                        if (Extraction.E.results[s].Count == 0 || Extraction.E.results[s][0].TE < 0)
                            continue;
                        for (int r = 0; r < Extraction.E.results[s].Count; r++)
                        {
                            if (Extraction.E.results[s][r].TE < minTECheck)
                                Extraction.E.results[s].RemoveAt(r--);
                        }
                    }
                }
            }

            if (!Extraction.E.setStatLevelBounds())
            {
                this.numericUpDownLevel.BackColor = Color.LightSalmon;
                if (!checkBoxAlreadyBred.Checked && this.numericUpDownLowerTEffBound.Value > 0)
                    this.numericUpDownLowerTEffBound.BackColor = Color.LightSalmon;
                if (!checkBoxAlreadyBred.Checked && this.numericUpDownUpperTEffBound.Value < 100)
                    this.numericUpDownUpperTEffBound.BackColor = Color.LightSalmon;
                this.checkBoxAlreadyBred.BackColor = Color.LightSalmon;
                this.checkBoxJustTamed.BackColor = Color.LightSalmon;
                panelWildTamedAuto.BackColor = Color.LightSalmon;
                extractionFailed();
                return false;
            }

            int removeOOBResult = Extraction.E.removeOutOfBoundsResults();
            if (removeOOBResult >= 0)
            {
                this.numericUpDownLevel.BackColor = Color.LightSalmon;
                statIOs[removeOOBResult].Status = StatIOStatus.Error;
                statIOs[7].Status = StatIOStatus.Error;
            }

            // get mean-level (most probable for the wild levels)
            double meanWildLevel = Math.Round((double)Extraction.E.levelWildFromTorporRange[1] / 7, 1);
            bool nonUniqueStats = false;

            for (int s = 0; s < 8; s++)
            {
                if (Extraction.E.results[s].Count > 0)
                {
                    // choose the most probable wild-level, aka the level nearest to the mean of the wild levels.
                    int r = 0;
                    for (int b = 1; b < Extraction.E.results[s].Count; b++)
                    {
                        if (Math.Abs(meanWildLevel - Extraction.E.results[s][b].levelWild) < Math.Abs(meanWildLevel - Extraction.E.results[s][r].levelWild)) r = b;
                    }

                    setPossibility(s, r);
                    if (Extraction.E.results[s].Count > 1)
                    {
                        statIOs[s].Status = StatIOStatus.Nonunique;
                        nonUniqueStats = true;
                    }
                    else { statIOs[s].Status = StatIOStatus.Unique; }
                }
                else
                {
                    // no results for this stat
                    statIOs[s].Status = StatIOStatus.Error;
                    Extraction.E.validResults = false;
                    if (!checkBoxAlreadyBred.Checked && Extraction.E.statsWithEff.IndexOf(s) >= 0 && this.numericUpDownLowerTEffBound.Value > 0)
                    {
                        this.numericUpDownLowerTEffBound.BackColor = Color.LightSalmon;
                    }
                    if (!checkBoxAlreadyBred.Checked && Extraction.E.statsWithEff.IndexOf(s) >= 0 && this.numericUpDownUpperTEffBound.Value < 100)
                    {
                        this.numericUpDownUpperTEffBound.BackColor = Color.LightSalmon;
                    }
                    this.checkBoxAlreadyBred.BackColor = Color.LightSalmon;
                    this.checkBoxJustTamed.BackColor = Color.LightSalmon;
                    panelWildTamedAuto.BackColor = Color.LightSalmon;
                }
            }
            if (!Extraction.E.validResults)
            {
                extractionFailed();
                return false;
            }
            if (nonUniqueStats)
            {
                groupBoxPossibilities.Visible = true;
                labelDoc.Visible = true;
            }

            // if damage (s==5) has a possibility for the dom-levels to make it a valid sum, take this
            int domLevelsChosenSum = 0;
            for (int s = 0; s < 7; s++)
            {
                domLevelsChosenSum += Extraction.E.results[s][Extraction.E.chosenResults[s]].levelDom;
            }
            if (domLevelsChosenSum < Extraction.E.levelDomFromTorporAndTotalRange[0] || domLevelsChosenSum > Extraction.E.levelDomFromTorporAndTotalRange[1])
            {
                // sum of domlevels is not correct. Try to find another combination
                domLevelsChosenSum -= Extraction.E.results[5][Extraction.E.chosenResults[5]].levelDom;
                bool changeChosenResult = false;
                int cR = 0;
                for (int r = 0; r < Extraction.E.results[5].Count; r++)
                {
                    if (domLevelsChosenSum + Extraction.E.results[5][r].levelDom >= Extraction.E.levelDomFromTorporAndTotalRange[0] && domLevelsChosenSum + Extraction.E.results[5][r].levelDom <= Extraction.E.levelDomFromTorporAndTotalRange[1])
                    {
                        cR = r;
                        changeChosenResult = true;
                        break;
                    }
                }
                if (changeChosenResult)
                    setPossibility(5, cR);
            }

            if (Extraction.E.postTamed) { setUniqueTE(); }
            else
            {
                labelTE.Text = "not yet tamed";
                labelTE.BackColor = System.Drawing.Color.Transparent;
            }

            setWildSpeedLevelAccordingToOthers();

            labelSumWildSB.Text = "≤" + Extraction.E.levelWildFromTorporRange[1].ToString();
            labelSumDomSB.Text = (Extraction.E.levelDomFromTorporAndTotalRange[0] != Extraction.E.levelDomFromTorporAndTotalRange[1] ? Extraction.E.levelDomFromTorporAndTotalRange[0].ToString() + "-" : "") + Extraction.E.levelDomFromTorporAndTotalRange[1].ToString();
            showSumOfChosenLevels();
            showStatsInOverlay();

            setActiveStat(activeStatKeeper);

            if (!Extraction.E.postTamed)
            {
                labelFootnote.Text = "*Creature is not yet tamed and may get better values then.";
                button2TamingCalc.Visible = true;
                // display taming info

                if (checkBoxQuickWildCheck.Checked)
                    tamingControl1.level = statIOs[7].LevelWild + 1;
                else
                    tamingControl1.level = (int)numericUpDownLevel.Value;
                tamingControl1.selectedSpeciesIndex = comboBoxSpeciesExtractor.SelectedIndex;
                labelTamingInfo.Text = tamingControl1.tamingInfo;
                groupBoxTamingInfo.Visible = true;
            }
            ResumeLayout();
            return true;
        }
Form1