// Adds attacks to both the Monster._Attacks and TraitList private void addAction(object sender, EventArgs e) { AddActionForm addAttack = new AddActionForm(ChallengeRatingDropDown.Text); addAttack.Show(); addAttack.FormClosing += (senders, es) => { if (addAttack.NewAttack != null) { Console.WriteLine("1"); if (TraitsList.Items.Contains(addAttack.NewAttack.Title)) { addAttack.NewAttack.Title += "_"; } Monster.AddAction(addAttack.NewAttack); TraitsList.Items.Add("Action: " + addAttack.NewAttack.Title); } if (addAttack.NewAbility != null) { Console.WriteLine("2"); if (TraitsList.Items.Contains(addAttack.NewAbility.Title)) { addAttack.NewAbility.Title += "_"; } Monster.AddAction(addAttack.NewAbility); TraitsList.Items.Add("Action: " + addAttack.NewAbility.Title); } if (addAttack.NewReaction != null) { Console.WriteLine("3"); if (TraitsList.Items.Contains(addAttack.NewReaction.Title)) { addAttack.NewReaction.Title += "_"; } Monster.AddReaction(addAttack.NewReaction); TraitsList.Items.Add("Reaction: " + addAttack.NewReaction.Title); } }; }
/* Edits selected item in the TraitList. If it's an Ability/Attack, Open the appropriate window and load that data. */ private void editTrait(object sender, MouseEventArgs e) { if (TraitsList.SelectedItem == null) return; if (TraitsList.SelectedItem.ToString().Split(':')[0].Trim() == "Legendary") { AddLegendaryForm loadLegendary = new AddLegendaryForm(); foreach (Legendary legendary in Monster._Legendaries) { if (legendary.Title == TraitsList.SelectedItem.ToString().Split(':')[1].Trim()) { loadLegendary.LoadLegendary(legendary); loadLegendary.Show(); loadLegendary.FormClosing += (senderx, ex) => { loadLegendary.SerializeTraits(); int index = Monster._Legendaries.IndexOf(legendary); Monster._Legendaries.RemoveAt(index); Monster._Legendaries.Insert(index, loadLegendary.LegendaryAbility); index = TraitsList.Items.IndexOf(TraitsList.SelectedItem); TraitsList.Items.RemoveAt(index); TraitsList.Items.Insert(index, "Legendary: " + loadLegendary.LegendaryAbility.Title); }; return; } } } if (TraitsList.SelectedItem.ToString().Split(':')[0].Trim() == "Action") { AddActionForm loadAttack = new AddActionForm(); foreach (Ability attack in Monster._Actions) { if (attack.isDamage) { if (attack.Title == TraitsList.SelectedItem.ToString().Split(':')[1].Trim()) { loadAttack.LoadAttack(attack); loadAttack.Show(); loadAttack.FormClosing += (senderx, ex) => { int index = Monster._Actions.IndexOf(attack); Monster._Actions.RemoveAt(index); Monster._Actions.Insert(index, loadAttack.NewAttack); index = TraitsList.Items.IndexOf(TraitsList.SelectedItem); TraitsList.Items.RemoveAt(index); TraitsList.Items.Insert(index, "Action: " + loadAttack.NewAttack.Title); }; return; } } if (!attack.isDamage) { if (attack.Title == TraitsList.SelectedItem.ToString().Split(':')[1].Trim()) { loadAttack.LoadAction((Ability)attack); loadAttack.Show(); loadAttack.FormClosing += (senderx, ex) => { int index = Monster._Actions.IndexOf(attack); Monster._Actions.RemoveAt(index); Monster._Actions.Insert(index, loadAttack.NewAbility); index = TraitsList.Items.IndexOf(TraitsList.SelectedItem); TraitsList.Items.RemoveAt(index); TraitsList.Items.Insert(index, "Action: " + loadAttack.NewAbility.Title); }; return; } } } } if (TraitsList.SelectedItem.ToString().Split(':')[0].Trim() == "Reaction") { AddActionForm loadReaction = new AddActionForm(); foreach (Ability reaction in Monster._Reactions) { if (reaction.Title == TraitsList.SelectedItem.ToString().Split(':')[1].Trim()) { loadReaction.LoadReaction(reaction); loadReaction.Show(); loadReaction.FormClosing += (senderx, ex) => { int index = Monster._Reactions.IndexOf(reaction); Monster._Reactions.RemoveAt(index); Monster._Reactions.Insert(index, loadReaction.NewReaction); index = TraitsList.Items.IndexOf(TraitsList.SelectedItem); TraitsList.Items.RemoveAt(index); TraitsList.Items.Insert(index, "Reaction: " + loadReaction.NewReaction.Title); }; return; } } } if (TraitsList.SelectedItem.ToString().Split(':')[0].Trim() == "Ability") { AddAbilityForm loadAbility = new AddAbilityForm(); foreach (Ability ability in Monster._Abilities) { if (ability.Title == TraitsList.SelectedItem.ToString().Split(':')[1].Trim()) { if (ability.isSpell) { loadAbility.LoadSpell(ability); } else { loadAbility.LoadAbility(ability); } loadAbility.Show(); loadAbility.FormClosing += (senderx, ex) => { int index = Monster._Abilities.IndexOf(ability); Monster._Abilities.RemoveAt(index); Monster._Abilities.Insert(index, loadAbility.NewAbility); index = TraitsList.Items.IndexOf(TraitsList.SelectedItem); TraitsList.Items.RemoveAt(index); TraitsList.Items.Insert(index, "Ability: " + loadAbility.NewAbility.Title); }; return; } } } }
// Adds attacks to both the Monster._Attacks and TraitList private void addAction(object sender, EventArgs e) { AddActionForm addAttack = new AddActionForm(ChallengeRatingDropDown.Text); addAttack.Show(); addAttack.FormClosing += (senders, es) => { int increment = 0; if (addAttack.NewAttack != null) { foreach (string item in TraitsList.Items) { if (item.Contains(addAttack.NewAttack.Title)) { increment++; } } if (increment > 0) { addAttack.NewAttack.Title += " " + increment; } Monster.AddAction(addAttack.NewAttack); TraitsList.Items.Add("Action: " + addAttack.NewAttack.Title); } if (addAttack.NewAbility != null) { foreach (string item in TraitsList.Items) { if (item.Contains(addAttack.NewAbility.Title)) { increment++; } } if (increment > 0) { addAttack.NewAbility.Title += " " + increment; } Monster.AddAction(addAttack.NewAbility); TraitsList.Items.Add("Action: " + addAttack.NewAbility.Title); } if (addAttack.NewReaction != null) { foreach (string item in TraitsList.Items) { if (item.Contains(addAttack.NewReaction.Title)) { increment++; } } if (increment > 0) { addAttack.NewReaction.Title += " " + increment; } Monster.AddReaction(addAttack.NewReaction); TraitsList.Items.Add("Reaction: " + addAttack.NewReaction.Title); } }; }