public void AddSpells(Spells Input, int Level) { if (this.Spells[Level] == null) { this.Spells[Level] = new Spells[1] { Input }; } else { Spells[] temp = new Spells[this.Spells[Level].Length + 1]; bool dup = false; for (int x = 0; x < this.Spells[Level].Length; x++) { if (this.Spells[Level][x].Equals(Input)) { dup = true; } temp[x] = this.Spells[Level][x]; } if (!dup) { temp[this.Spells[Level].Length] = Input; } this.Spells[Level] = temp; } this.Contains = true; }
private void SpellChange(object sender, System.EventArgs e) { if (this.FirstLetter.Text.Length > 0) { int letter = char.ToUpper(this.FirstLetter.Text[0]) - 64; this.newSpell = newData.FindSpell(this.SpellName.Text); } }
public SpellDisplayForm(Spells input) { InitializeComponent(); this.SpellName.Text = input.Name + " (pg " + input.PageNum + ")"; if (input.Level>4) { this.School.Text = input.Level + "th-Level " + input.School; } else if (input.Level == 1) { this.School.Text = input.Level + "st-Level " + input.School; } else if (input.Level == 2) { this.School.Text = input.Level + "nd-Level " + input.School; } else if (input.Level == 3) { this.School.Text = input.Level + "rd-Level " + input.School; } else { this.School.Text = input.School + " Cantrip"; } this.Cast.Text = "Cast Time: " + input.CastTime; this.Range.Text = "Range: " + input.Range; if (input.Verbal) { this.Component.Text = "V"; } if (input.Somatic) { if (this.Component.Text=="") { this.Component.Text = "S"; } else { this.Component.Text += ", S"; } } if (input.Material.Length != 0) { if (this.Component.Text == "") { this.Component.Text = "M (" + input.Material + ")"; } else { this.Component.Text += ", M (" + input.Material + ")"; } } this.Duration.Text = "Duration: " + input.Duration; this.Info.Text = input.Info; }
public void LoadSpell(object sender, System.EventArgs e) { Spells newSpell = null; if (this.NameInput.Text.Length>0) { newSpell = newData.FindSpell(this.NameInput.Text); } if (newSpell != null) { this.LevelInput.Text = newSpell.Level.ToString(); this.PageNum.Text = newSpell.PageNum.ToString(); this.School.Text = newSpell.School; this.CastInput.Text = newSpell.CastTime; this.RangeInput.Text = newSpell.Range; this.DurationInput.Text = newSpell.Duration; this.RitualInput.Checked = newSpell.Ritual; this.Concentration.Checked = newSpell.Concentration; this.VerbalInput.Checked = newSpell.Verbal; this.SomaticInput.Checked = newSpell.Somatic; if (newSpell.Material != null) { this.MaterialCheck.Checked = true; this.MaterialInput.Text = newSpell.Material; } this.InfoInput.Text = newSpell.Info; Loaded = true; LoadedSpell = newSpell; } }
private void DoneClick(object sender, System.EventArgs e) { if (!Loaded) { if ((this.PageNum.Text != "" && this.NameInput.Text != "" && this.CastInput.Text != "" && this.RangeInput.Text != "" && this.DurationInput.Text != "" && this.School.Text != "" && this.InfoInput.Text != "") && (this.VerbalInput.Checked || this.SomaticInput.Checked || this.MaterialCheck.Checked)) { Spells newSpell = new Spells(int.Parse(this.PageNum.Text), this.NameInput.Text, this.SpellLevel, this.CastInput.Text, this.RangeInput.Text, this.MaterialInput.Text, this.VerbalInput.Checked, this.SomaticInput.Checked, this.RitualInput.Checked, this.Concentration.Checked, this.DurationInput.Text, this.School.Text, this.InfoInput.Text); if (this.LevelList.Text == "Cantrip") { Slots[0] = -1; } AllActions.AddSpells(newSpell, this.SpellLevel); AllActions.AddSlots(this.Slots); if (this.ModInput.Text != "" && this.DCInput.Text != "") { AllActions.AddSpellMod(int.Parse(this.ModInput.Text), int.Parse(this.DCInput.Text)); } newData.AddSpell(newSpell, true); this.Close(); } else { if (this.PageNum.Text == "") { err = new ErrorForm(new Exception("Page number not filled"), "Please enter a number"); } else if (this.NameInput.Text == "") { err = new ErrorForm(new Exception("Name not filled"), "Please enter a name"); } else if (this.CastInput.Text == "") { err = new ErrorForm(new Exception("Cast time not filled"), "Please enter a cast time"); } else if (this.RangeInput.Text == "") { err = new ErrorForm(new Exception("Range not filled"), "Please enter a range"); } else if (this.DurationInput.Text == "") { err = new ErrorForm(new Exception("Duration not filled"), "Please enter a duration"); } else if (this.School.Text == "") { err = new ErrorForm(new Exception("School not filled"), "Please enter a school"); } else if (this.InfoInput.Text == "") { err = new ErrorForm(new Exception("Info not filled"), "Please enter additional info"); } else if (!this.VerbalInput.Checked && !this.SomaticInput.Checked && !this.MaterialCheck.Checked) { err = new ErrorForm(new Exception("Component not filled"), "Please check either verbal, somatic or material"); } err.Show(); } //SpellDisplayForm test = new SpellDisplayForm(newSpell); //test.Show(); } }
private void AddClick(object sender, System.EventArgs e) { if (!Loaded) { Spells newSpell = new Spells(int.Parse(this.PageNum.Text), this.NameInput.Text, this.SpellLevel, this.CastInput.Text, this.RangeInput.Text, this.MaterialInput.Text, this.VerbalInput.Checked, this.SomaticInput.Checked, this.RitualInput.Checked, this.Concentration.Checked, this.DurationInput.Text, this.School.Text, this.InfoInput.Text); if (this.LevelList.Text == "Cantrip") { Slots[0] = -1; } AllActions.AddSpells(newSpell, this.SpellLevel); AllActions.AddSlots(this.Slots); if (this.ModInput.Text != "" && this.DCInput.Text != "") { AllActions.AddSpellMod(int.Parse(this.ModInput.Text), int.Parse(this.DCInput.Text)); } newData.AddSpell(newSpell, true); //SpellDisplayForm test = new SpellDisplayForm(newSpell); //test.Show(); } this.NameInput.Text = ""; this.PageNum.Text = ""; this.School.Text = ""; this.CastInput.Text = ""; this.RangeInput.Text = ""; this.DurationInput.Text = ""; this.RitualInput.Checked = false; this.Concentration.Checked = false; this.VerbalInput.Checked = false; this.SomaticInput.Checked = false; this.MaterialCheck.Checked = false; this.MaterialInput.Visible = false; this.MaterialInput.Text = ""; this.InfoInput.Text = ""; }
public void AddSpellToDatabase(Spells newSpell) { StreamWriter file = new StreamWriter("Spells.txt", true); file.WriteLine("New Spell\r\n" + newSpell.ToString()); file.Close(); }
public void AddSpell(Spells newSpell, bool load) { int letter = char.ToUpper(newSpell.Name[0]) -64; if (!this.SpellLoad) { this.LoadDatabaseSpells(); } if (this.FindSpell(newSpell.Name)==null) { if (this.AllSpells[letter] == null) { Spells[] temp = new Spells[1] { newSpell }; this.AllSpells[letter] = temp; } else { Spells[] temp = new Spells[AllSpells[letter].Length + 1]; for (int x = 0; x < AllSpells[letter].Length; x++) { temp[x] = AllSpells[letter][x]; } temp[AllSpells[letter].Length] = newSpell; this.AllSpells[letter] = temp; } if (load) { AddSpellToDatabase(newSpell); } } }
public void LoadDatabaseSpells() { StreamReader file = new StreamReader("Spells.txt"); SpellLoad = true; int location = 1; string line = file.ReadLine(); while (line!=null) { int PageNum = 0; string Name = ""; int Level = 0; string CastTime = ""; string Range = ""; string Material = ""; bool Verbal = false; bool Somatic = false; bool Ritual = false; bool Concentration = false; string Duration = ""; string School = ""; string Info = ""; if (line == "New Spell") { location++; line = file.ReadLine(); Name = line; location++; line = file.ReadLine(); } else { err = new ErrorForm(new Exception("Error in line " + location), "Expected New Spell line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Page Number")) { PageNum = int.Parse(line.Substring(13)); location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Page Number line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } line = line.ToLower(); if (line.Contains("level") || line.Contains("cantrip")) { if (line.Contains("ritual")) { Level = int.Parse(line.Substring(0, 1)); School = line.Substring(8); } else { if (line.Contains("cantrip")) { Level = 0; School = line.Substring(0, line.IndexOf("cantrip")); } else { int schoolLength = line.Length - 16; Level = int.Parse(line.Substring(0, 1)); School = line.Substring(8, schoolLength); Ritual = true; } } location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Level and School."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Cast Time")) { CastTime = line.Substring(11); location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Cast Time line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Range")) { Range = line.Substring(7); location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location), "Expected Range line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Components")) { if (line.Substring(10).Contains(" V")) { Verbal = true; } if(line.Substring(10).Contains(" S")) { Somatic = true; } if(line.Contains(", M")) { Material = line.Substring(line.IndexOf("(") + 3); Material = Material.Substring(0, Material.Length - 1); } location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Components line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Duration")) { if (line.Contains("Concentration")) { Concentration = true; Duration = line.Substring(25); } else { Duration = line.Substring(10); } location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Duration line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } Spells newSpell = new Spells(PageNum, Name, Level, CastTime, Range, Material, Verbal, Somatic, Ritual, Concentration, Duration, School, Info); AddSpell(newSpell, false); } file.Close(); }
public void LoadDatabaseSpells() { StreamReader file = new StreamReader("Spells.txt"); SpellLoad = true; int location = 1; string line = file.ReadLine(); while (line != null) { int PageNum = 0; string Name = ""; int Level = 0; string CastTime = ""; string Range = ""; string Material = ""; bool Verbal = false; bool Somatic = false; bool Ritual = false; bool Concentration = false; string Duration = ""; string School = ""; string Info = ""; if (line == "New Spell") { location++; line = file.ReadLine(); Name = line; location++; line = file.ReadLine(); } else { err = new ErrorForm(new Exception("Error in line " + location), "Expected New Spell line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Page Number")) { PageNum = int.Parse(line.Substring(13)); location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Page Number line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } line = line.ToLower(); if (line.Contains("level") || line.Contains("cantrip")) { if (line.Contains("ritual")) { Level = int.Parse(line.Substring(0, 1)); School = line.Substring(8); } else { if (line.Contains("cantrip")) { Level = 0; School = line.Substring(0, line.IndexOf("cantrip")); } else { int schoolLength = line.Length - 16; Level = int.Parse(line.Substring(0, 1)); School = line.Substring(8, schoolLength); Ritual = true; } } location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Level and School."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Cast Time")) { CastTime = line.Substring(11); location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Cast Time line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Range")) { Range = line.Substring(7); location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location), "Expected Range line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Components")) { if (line.Substring(10).Contains(" V")) { Verbal = true; } if (line.Substring(10).Contains(" S")) { Somatic = true; } if (line.Contains(", M")) { Material = line.Substring(line.IndexOf("(") + 3); Material = Material.Substring(0, Material.Length - 1); } location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Components line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } if (line.Contains("Duration")) { if (line.Contains("Concentration")) { Concentration = true; Duration = line.Substring(25); } else { Duration = line.Substring(10); } location++; line = file.ReadLine(); } else if (line != "New Spell") { err = new ErrorForm(new Exception("Error in line " + location + "\nAt spell: " + Name), "Expected Duration line."); err.Show(); while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } } while (line != null) { if (line == "New Spell") { break; } Info += line + " "; location++; line = file.ReadLine(); } Spells newSpell = new Spells(PageNum, Name, Level, CastTime, Range, Material, Verbal, Somatic, Ritual, Concentration, Duration, School, Info); AddSpell(newSpell, false); } file.Close(); }