<commit_before>﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using ARKBreedingStats.species;
using System.Threading;
using System.Threading.Tasks;

namespace ARKBreedingStats
{
    public partial class BreedingPlan : UserControl
    {
        public event PedigreeCreature.CreatureEditEventHandler EditCreature;
        public event PedigreeCreature.CreaturePartnerEventHandler BestBreedingPartners;
        public event PedigreeCreature.ExportToClipboardEventHandler exportToClipboard;
        public event Raising.createIncubationEventHandler createIncubationTimer;
        public event Form1.setMessageLabelTextEventHandler setMessageLabelText;
        private List<Creature> females = new List<Creature>();
        private List<Creature> males = new List<Creature>();
        private List<BreedingPair> breedingPairs;
        private string currentSpecies;
        private int speciesIndex;
        public double[] statWeights = new double[8]; // how much are the stats weighted when looking for the best
        private List<int> bestLevels = new List<int>();
        private List<PedigreeCreature> pcs = new List<PedigreeCreature>();
        private List<PictureBox> pbs = new List<PictureBox>();
        private bool[] enabledColorRegions;
        private TimeSpan incubationTime = TimeSpan.Zero;
        private Creature chosenCreature;
        private BreedingMode breedingMode;
        public StatWeighting statWeighting;
        public bool breedingPlanNeedsUpdate;
        public CreatureCollection creatureCollection;
        private CancellationTokenSource cancelSource;
        private ToolTip tt = new ToolTip();
        private double probHigherLvl = 0.55, probLowerLvl = 0.45; // probability of inheriting the higher level-stat

        public BreedingPlan()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
            for (int i = 0; i < 8; i++)
                statWeights[i] = 1;

            breedingPairs = new List<BreedingPair>();
            pedigreeCreatureBest.IsVirtual = true;
            pedigreeCreatureWorst.IsVirtual = true;
            pedigreeCreatureBestPossibleInSpecies.IsVirtual = true;
            pedigreeCreatureBest.onlyLevels = true;
            pedigreeCreatureWorst.onlyLevels = true;
            pedigreeCreatureBestPossibleInSpecies.onlyLevels = true;
            pedigreeCreatureBest.Clear();
            pedigreeCreatureWorst.Clear();
            pedigreeCreatureBestPossibleInSpecies.Clear();
            pedigreeCreatureBest.HandCursor = false;
            pedigreeCreatureWorst.HandCursor = false;
            pedigreeCreatureBestPossibleInSpecies.HandCursor = false;

            statWeighting = statWeighting1;
            breedingPlanNeedsUpdate = false;

            tagSelectorList1.OnTagChanged += TagSelectorList1_OnTagChanged;
        }

        private void TagSelectorList1_OnTagChanged()
        {
            calculateBreedingScoresAndDisplayPairs();
        }

        public void bindEvents()
        {
            // has to be done after the BreedingPlan-class got the binding
            pedigreeCreatureBest.CreatureEdit += new PedigreeCreature.CreatureEditEventHandler(EditCreature);
            pedigreeCreatureWorst.CreatureEdit += new PedigreeCreature.CreatureEditEventHandler(EditCreature);
            pedigreeCreatureBest.exportToClipboard += new PedigreeCreature.ExportToClipboardEventHandler(exportToClipboard);
            pedigreeCreatureWorst.exportToClipboard += new PedigreeCreature.ExportToClipboardEventHandler(exportToClipboard);
            pedigreeCreatureBestPossibleInSpecies.exportToClipboard += new PedigreeCreature.ExportToClipboardEventHandler(exportToClipboard);
            pedigreeCreatureBest.CreatureClicked += new PedigreeCreature.CreatureChangedEventHandler(CreatureClicked);
            pedigreeCreatureWorst.CreatureClicked += new PedigreeCreature.CreatureChangedEventHandler(CreatureClicked);
        }

        public void determineBestBreeding(Creature chosenCreature = null, bool forceUpdate = false)
        {
            if (creatureCollection == null) return;

            string selectedSpecies = (chosenCreature != null ? chosenCreature.species : "");
            bool newSpecies = false;
            if (selectedSpecies.Length == 0 && listViewSpeciesBP.SelectedIndices.Count > 0)
                selectedSpecies = listViewSpeciesBP.SelectedItems[0].Text;
            if (selectedSpecies.Length > 0 && CurrentSpecies != selectedSpecies)
            {
                CurrentSpecies = selectedSpecies;
                newSpecies = true;

                int s = Values.V.speciesNames.IndexOf(selectedSpecies);
                EnabledColorRegions = (s >= 0 ? Values.V.species[s].colors.Select(n => n.name != "").ToArray() : new bool[6] { true, true, true, true, true, true });

                breedingPlanNeedsUpdate = true;
            }
            if (forceUpdate || breedingPlanNeedsUpdate)
                Creatures = creatureCollection.creatures.Where(
                    c => c.species == selectedSpecies && c.status == CreatureStatus.Available && !c.neutered
                    && (cnBPIncludeCooldowneds.Checked || (c.cooldownUntil < DateTime.Now && c.growingUntil < DateTime.Now))<commit_msg>missing event handler for best possible levels (#759) (#760)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using ARKBreedingStats.species;
using System.Threading;
using System.Threading.Tasks;

namespace ARKBreedingStats
{
    public partial class BreedingPlan : UserControl
    {
        public event PedigreeCreature.CreatureEditEventHandler EditCreature;
        public event PedigreeCreature.CreaturePartnerEventHandler BestBreedingPartners;
        public event PedigreeCreature.ExportToClipboardEventHandler exportToClipboard;
        public event Raising.createIncubationEventHandler createIncubationTimer;
        public event Form1.setMessageLabelTextEventHandler setMessageLabelText;
        private List<Creature> females = new List<Creature>();
        private List<Creature> males = new List<Creature>();
        private List<BreedingPair> breedingPairs;
        private string currentSpecies;
        private int speciesIndex;
        public double[] statWeights = new double[8]; // how much are the stats weighted when looking for the best
        private List<int> bestLevels = new List<int>();
        private List<PedigreeCreature> pcs = new List<PedigreeCreature>();
        private List<PictureBox> pbs = new List<PictureBox>();
        private bool[] enabledColorRegions;
        private TimeSpan incubationTime = TimeSpan.Zero;
        private Creature chosenCreature;
        private BreedingMode breedingMode;
        public StatWeighting statWeighting;
        public bool breedingPlanNeedsUpdate;
        public CreatureCollection creatureCollection;
        private CancellationTokenSource cancelSource;
        private ToolTip tt = new ToolTip();
        private double probHigherLvl = 0.55, probLowerLvl = 0.45; // probability of inheriting the higher level-stat

        public BreedingPlan()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
            for (int i = 0; i < 8; i++)
                statWeights[i] = 1;

            breedingPairs = new List<BreedingPair>();
            pedigreeCreatureBest.IsVirtual = true;
            pedigreeCreatureWorst.IsVirtual = true;
            pedigreeCreatureBestPossibleInSpecies.IsVirtual = true;
            pedigreeCreatureBest.onlyLevels = true;
            pedigreeCreatureWorst.onlyLevels = true;
            pedigreeCreatureBestPossibleInSpecies.onlyLevels = true;
            pedigreeCreatureBest.Clear();
            pedigreeCreatureWorst.Clear();
            pedigreeCreatureBestPossibleInSpecies.Clear();
            pedigreeCreatureBest.HandCursor = false;
            pedigreeCreatureWorst.HandCursor = false;
            pedigreeCreatureBestPossibleInSpecies.HandCursor = false;

            statWeighting = statWeighting1;
            breedingPlanNeedsUpdate = false;

            tagSelectorList1.OnTagChanged += TagSelectorList1_OnTagChanged;
        }

        private void TagSelectorList1_OnTagChanged()
        {
            calculateBreedingScoresAndDisplayPairs();
        }

        public void bindEvents()
        {
            // has to be done after the BreedingPlan-class got the binding
            pedigreeCreatureBest.CreatureEdit += new PedigreeCreature.CreatureEditEventHandler(EditCreature);
            pedigreeCreatureWorst.CreatureEdit += new PedigreeCreature.CreatureEditEventHandler(EditCreature);
            pedigreeCreatureBestPossibleInSpecies.CreatureEdit += new PedigreeCreature.CreatureEditEventHandler(EditCreature);
            pedigreeCreatureBest.exportToClipboard += new PedigreeCreature.ExportToClipboardEventHandler(exportToClipboard);
            pedigreeCreatureWorst.exportToClipboard += new PedigreeCreature.ExportToClipboardEventHandler(exportToClipboard);
            pedigreeCreatureBestPossibleInSpecies.exportToClipboard += new PedigreeCreature.ExportToClipboardEventHandler(exportToClipboard);
            pedigreeCreatureBest.CreatureClicked += new PedigreeCreature.CreatureChangedEventHandler(CreatureClicked);
            pedigreeCreatureWorst.CreatureClicked += new PedigreeCreature.CreatureChangedEventHandler(CreatureClicked);
        }

        public void determineBestBreeding(Creature chosenCreature = null, bool forceUpdate = false)
        {
            if (creatureCollection == null) return;

            string selectedSpecies = (chosenCreature != null ? chosenCreature.species : "");
            bool newSpecies = false;
            if (selectedSpecies.Length == 0 && listViewSpeciesBP.SelectedIndices.Count > 0)
                selectedSpecies = listViewSpeciesBP.SelectedItems[0].Text;
            if (selectedSpecies.Length > 0 && CurrentSpecies != selectedSpecies)
            {
                CurrentSpecies = selectedSpecies;
                newSpecies = true;

                int s = Values.V.speciesNames.IndexOf(selectedSpecies);
                EnabledColorRegions = (s >= 0 ? Values.V.species[s].colors.Select(n => n.name != "").ToArray() : new bool[6] { true, true, true, true, true, true });

                breedingPlanNeedsUpdate = true;
            }
            if (forceUpdate || breedingPlanNeedsUpdate)
                Creatures = creatureCollection.creatures.Where(
                    c => c.species == selectedSpecies && c.status == CreatureStatus.Available && !c.neutered
                    && (cnBPIncludeCooldowneds.Checked || (c.cooldownUntil < DateTime.Now && c.growingUntil < DateTime.Now))
{'fraction_non_alphanumeric': 0.07321266968325792, 'fraction_numerical': 0.0043438914027149325, 'mean_word_length': 3.008342401160682, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246823', 'n_tokens_mistral': 2998, 'n_tokens_neox': 2882, 'n_words': 594}