예제 #1
0
파일: Form1.cs 프로젝트: Lynthias/PF2EZ
 public Dupes(Dupes d)
 {
     NAME  = d.NAME;
     COUNT = d.COUNT;
     INDEX = d.INDEX;
     URL   = d.URL;
 }
예제 #2
0
파일: Form1.cs 프로젝트: Lynthias/PF2EZ
        private void RemoveCreature()
        {
            int      selectedItemIndex = listBox_Encounter.SelectedIndex;
            int      index             = 0;
            Creature remove;

            try
            {
                for (int i = 0; i < dupes.Count; i++)
                {
                    if (listBox_Encounter.SelectedItem.ToString().Contains(dupes[i].NAME))
                    {
                        index = listBox_Encounter.SelectedIndex;
                        break;
                    }
                }
                Dupes temp = new Dupes(dupes[index]);
                if (temp.COUNT > 1)
                {
                    temp.COUNT--;
                    dupes[index] = temp;
                    remove       = encounter[dupes[index].INDEX[dupes[index].INDEX.Count - 1] - 1];
                    encounter.RemoveAt(dupes[index].INDEX[dupes[index].INDEX.Count - 1] - 1);
                    dupes[index].INDEX.RemoveAt(dupes[index].INDEX.Count - 1);
                    for (int i = 0; i < dupes.Count; i++)
                    {
                        for (int j = 0; j < dupes[i].INDEX.Count; j++)
                        {
                            if (dupes[index].INDEX.Count > 0)
                            {
                                if (dupes[i].INDEX[j] > dupes[index].INDEX[dupes[index].INDEX.Count - 1])
                                {
                                    Dupes copy = new Dupes(dupes[i]);
                                    //copy.INDEX[j]--;
                                    copy.INDEX[j]--;
                                    dupes[i] = copy;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (dupes.Count > 1)
                    {
                        remove = encounter[dupes[index].INDEX[dupes[index].INDEX.Count - 1]];
                        encounter.RemoveAt(dupes[index].INDEX[dupes[index].INDEX.Count - 1]);
                    }
                    else
                    {
                        remove = encounter[0];
                        encounter.RemoveAt(0);
                    }
                    //encounter.RemoveAt(dupes[index].INDEX[dupes[index].INDEX.Count - 1]-1);

                    dupes.RemoveAt(index);
                    if (index > 0)
                    {
                        index--;
                    }
                    for (int i = 0; i < dupes.Count; i++)
                    {
                        for (int j = 0; j < dupes[i].INDEX.Count; j++)
                        {
                            if (dupes[index].INDEX.Count > 0)
                            {
                                if (dupes[i].INDEX[j] > dupes[index].INDEX[dupes[index].INDEX.Count - 1])
                                {
                                    Dupes copy = new Dupes(dupes[i]);
                                    //copy.INDEX[j]--;
                                    copy.INDEX[j]--;
                                    dupes[i] = copy;
                                }
                            }
                        }
                    }
                }

                listBox_Encounter.Items.Clear();
                foreach (Dupes dupe in dupes)
                {
                    listBox_Encounter.Items.Add(dupe.NAME + " x" + dupe.COUNT);
                }
                if (listBox_Encounter.Items.Count > selectedItemIndex)
                {
                    listBox_Encounter.SelectedIndex = selectedItemIndex;
                }
                else
                {
                    listBox_Encounter.SelectedIndex = selectedItemIndex - 1;
                }

                //refund
                Refund(remove);
                CheckSearchParameters();
                dataGridViewCreatures.Sort(dataGridViewCreatures.Columns[sortCol], ascending);
            }
            catch (Exception e2)
            {
            }
        }
예제 #3
0
파일: Form1.cs 프로젝트: Lynthias/PF2EZ
        private void AddCreature()
        {
            try
            {
                Creature creature = new Creature();
                creature.NAME      = dataGridViewCreatures.Rows[dataGridViewCreatures.SelectedCells[0].RowIndex].Cells[0].Value.ToString();
                creature.FAMILY    = dataGridViewCreatures.Rows[dataGridViewCreatures.SelectedCells[0].RowIndex].Cells[1].Value.ToString();
                creature.LEVEL     = Int32.Parse(dataGridViewCreatures.Rows[dataGridViewCreatures.SelectedCells[0].RowIndex].Cells[2].Value.ToString());
                creature.ALIGNMENT = dataGridViewCreatures.Rows[dataGridViewCreatures.SelectedCells[0].RowIndex].Cells[3].Value.ToString();
                creature.TYPE      = dataGridViewCreatures.Rows[dataGridViewCreatures.SelectedCells[0].RowIndex].Cells[4].Value.ToString();
                creature.SIZE      = dataGridViewCreatures.Rows[dataGridViewCreatures.SelectedCells[0].RowIndex].Cells[5].Value.ToString();
                creature.URL       = dataGridViewCreatures.Rows[dataGridViewCreatures.SelectedCells[0].RowIndex].Cells[6].Value.ToString();
                if (CalculateDifficulty(creature, false))
                {
                    encounter.Add(creature);


                    listBox_Encounter.Items.Clear();

                    dupes = new List <Dupes>();

                    for (int i = 0; i < encounter.Count; i++)
                    {
                        if (dupes.Count == 0)
                        {
                            Dupes dupe = new Dupes();
                            dupe.INDEX = new List <int>();
                            dupe.NAME  = encounter[i].NAME;
                            dupe.COUNT = 0;
                            //dupe.INDEX.Add(i);
                            dupe.URL = encounter[i].URL;
                            dupes.Add(dupe);
                        }

                        bool d     = false;
                        int  index = 0;
                        for (int j = 0; j < dupes.Count; j++)
                        {
                            if (dupes[j].NAME == encounter[i].NAME)
                            {
                                d     = true;
                                index = j;
                                break;
                            }
                        }

                        if (!d)
                        {
                            Dupes temp = new Dupes();
                            temp.INDEX = new List <int>();
                            temp.NAME  = encounter[i].NAME;
                            temp.COUNT = 1;
                            temp.INDEX.Add(i);
                            temp.URL = encounter[i].URL;
                            dupes.Add(temp);
                        }
                        else
                        {
                            Dupes temp = new Dupes(dupes[index]);
                            temp.COUNT++;
                            temp.INDEX.Add(i);
                            dupes[index] = temp;
                        }
                    }

                    //write encounter to listBox_Encounter
                    foreach (Dupes dupe in dupes)
                    {
                        listBox_Encounter.Items.Add(dupe.NAME + " x" + dupe.COUNT);
                    }
                    if (threat != -1)
                    {
                        textBoxBudget.Text = budget.ToString();
                        textBoxValue.Text  = spent.ToString();
                    }
                    else
                    {
                        textBoxBudget.Text = "infinite";
                        textBoxValue.Text  = spent.ToString();
                    }
                    CheckSearchParameters();
                    dataGridViewCreatures.Sort(dataGridViewCreatures.Columns[sortCol], ascending);
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #4
0
파일: Form1.cs 프로젝트: Lynthias/PF2EZ
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog encFile = new OpenFileDialog();

            encFile.Title            = "Open Text File";
            encFile.Filter           = "PF2E Encounter|*.PFSE";
            encFile.InitialDirectory = @"C:\";
            if (encFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (File.Exists(encFile.FileName))
                    {
                        InitializeStuff();
                        toolStripStatusLabel1.Text = "Loaded Encounter: " + Path.GetFileName(encFile.FileName);

                        List <Creature> loadEnc         = new List <Creature>();
                        List <Dupes>    loadDupes       = new List <Dupes>();
                        List <int>      dupesIndexSizes = new List <int>();
                        using (BinaryReader reader = new BinaryReader(File.Open(encFile.FileName, FileMode.Open)))
                        {
                            int numEncounterCreatures = reader.ReadInt32();
                            int numDupesCreatures     = reader.ReadInt32();
                            for (int i = 0; i < numDupesCreatures; i++)
                            {
                                dupesIndexSizes.Add(reader.ReadInt32());
                            }
                            for (int i = 0; i < numEncounterCreatures; i++)
                            {
                                Creature c = new Creature();
                                c.ALIGNMENT = reader.ReadString();
                                c.FAMILY    = reader.ReadString();
                                c.LEVEL     = reader.ReadInt32();
                                c.NAME      = reader.ReadString();
                                c.SIZE      = reader.ReadString();
                                c.TYPE      = reader.ReadString();
                                c.URL       = reader.ReadString();
                                loadEnc.Add(c);
                            }
                            for (int i = 0; i < numDupesCreatures; i++)
                            {
                                Dupes d = new Dupes();
                                d.COUNT = reader.ReadInt32();
                                d.INDEX = new List <int>();
                                for (int j = 0; j < dupesIndexSizes[i]; j++)
                                {
                                    d.INDEX.Add(reader.ReadInt32());
                                }
                                d.NAME = reader.ReadString();
                                d.URL  = reader.ReadString();
                                loadDupes.Add(d);
                            }
                            budget          = reader.ReadInt32();
                            spent           = reader.ReadInt32();
                            difficultyIndex = reader.ReadInt32();
                            threat          = reader.ReadInt32();
                            avglevel        = reader.ReadInt32();
                            limiter         = reader.ReadString();
                            party           = reader.ReadInt32();
                            reader.Close();
                        }
                        textBoxBudget.Text = budget.ToString();
                        textBoxValue.Text  = spent.ToString();

                        comboBox1.SelectedIndex = difficultyIndex;
                        numericUpDown2.Value    = avglevel;
                        numericUpDown3.Value    = party;

                        encounter = loadEnc;
                        dupes     = loadDupes;
                        CheckSearchParameters();
                        foreach (Dupes dupe in dupes)
                        {
                            listBox_Encounter.Items.Add(dupe.NAME + " x" + dupe.COUNT);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to load file :(");
                }
            }
        }