/// <summary> /// This Method updates the Equipment and Items Grids /// </summary> private void UpdateGrids() { Item_Grid.Rows.Clear(); Equipment_Grid.Rows.Clear(); LIB.m_MainCharacterInfo.CarryingWeight = 0; foreach (var key in LIB.m_MainCharacterInfo.Items.Keys) { CLIB.Item_Class item = LIB.m_MainCharacterInfo.Items[key]; object[] param = { item.Style, key, item.Quantity, item.Cost, item.Weight + " lb.", item.Description }; Item_Grid.Rows.Add(param); } foreach (var key in LIB.m_MainCharacterInfo.Weapons.Keys) { CLIB.Weapon_Class weapon = LIB.m_MainCharacterInfo.Weapons[key]; string properties = string.Join(", ", weapon.Properties.ToArray()); object[] param = { weapon.Equipped, weapon.Style, key, weapon.Quantity, weapon.Cost, weapon.Damage, string.Empty, weapon.Weight + " lb.", properties }; Equipment_Grid.Rows.Add(param); } foreach (var key in LIB.m_MainCharacterInfo.Armor.Keys) { CLIB.Armor_Class armor = LIB.m_MainCharacterInfo.Armor[key]; string properties = string.Format(LC.ArmorProperties, armor.StrengthReq, armor.Disadvantage); object[] param = { armor.Equipped, armor.Style, key, armor.Quantity, armor.Cost, string.Empty, armor.ArmorClass, armor.Weight + " lb.", properties }; Equipment_Grid.Rows.Add(param); } CALC.CarryWeight(); Carry_TextBox.Text = LIB.m_MainCharacterInfo.CarryingWeight + " / " + LIB.m_MainCharacterInfo.CarryingCapacity + " lb."; }
/// <summary> /// This method handles whenever a user changes the quantity of items in their Equipment or Items grid /// </summary> /// <param name="grid">Equipment/Item Grid</param> /// <param name="index">Quantity Column Index</param> private void EqupimentGrid_ValueChanged(DataGridView grid, int index) { string itemName = grid.CurrentRow.Cells[index].Value.ToString(); bool isArmor = LIB.m_MainCharacterInfo.Armor.ContainsKey(itemName); bool isWeapon = LIB.m_MainCharacterInfo.Weapons.ContainsKey(itemName); bool isItem = LIB.m_MainCharacterInfo.Items.ContainsKey(itemName); DataGridViewCell currentCell = grid.CurrentCell; if (currentCell.Value == null) { if (isArmor) { currentCell.Value = LIB.m_MainCharacterInfo.Armor[itemName].Quantity; } else if (isWeapon) { currentCell.Value = LIB.m_MainCharacterInfo.Weapons[itemName].Quantity; } else if (isItem) { currentCell.Value = LIB.m_MainCharacterInfo.Items[itemName].Quantity; } return; } if (int.TryParse(currentCell.Value.ToString(), out int newValue)) { if (newValue <= 0) { if (isArmor) { LIB.m_MainCharacterInfo.Armor.Remove(itemName); } else if (isWeapon) { LIB.m_MainCharacterInfo.Weapons.Remove(itemName); } else if (isItem) { LIB.m_MainCharacterInfo.Items.Remove(itemName); } else { MessageBox.Show("Error: This item was not correctly added into the Equipment Library for this character"); } grid.Rows.RemoveAt(grid.CurrentRow.Index); } else { if (isArmor) { LIB.m_MainCharacterInfo.Armor[itemName].Quantity = newValue; } else if (isWeapon) { LIB.m_MainCharacterInfo.Weapons[itemName].Quantity = newValue; } else if (isItem) { LIB.m_MainCharacterInfo.Items[itemName].Quantity = newValue; } else { MessageBox.Show("Error: This item was not correctly added into the Equipment Library for this character"); } } } else { if (isArmor) { currentCell.Value = LIB.m_MainCharacterInfo.Armor[itemName].Quantity; } else if (isWeapon) { currentCell.Value = LIB.m_MainCharacterInfo.Weapons[itemName].Quantity; } else if (isItem) { currentCell.Value = LIB.m_MainCharacterInfo.Items[itemName].Quantity; } else { MessageBox.Show("Error: This item was not correctly added into the Equipment Library for this character"); } } CALC.CarryWeight(); Carry_TextBox.Text = LIB.m_MainCharacterInfo.CarryingWeight + " / " + LIB.m_MainCharacterInfo.CarryingCapacity + " lb."; }
/// <summary> /// This method sets the level based on the xp the user inputs into the spin control /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void XP_ValueChanged(NumericUpDown xpSpin) { if (LIB.m_CharacterLoaded) { int oldXP = LIB.m_MainCharacterInfo.ExperiencePoints; int oldLevel1 = LIB.m_MainCharacterInfo.Level1; int oldLevel2 = LIB.m_MainCharacterInfo.Level2; int oldTotalLevel = LIB.m_MainCharacterInfo.TotalLevel; int oldHitDice1 = LIB.m_MainCharacterInfo.HitDiceTotal1; int oldHitDice2 = LIB.m_MainCharacterInfo.HitDiceTotal2; LIB.m_MainCharacterInfo.ExperiencePoints = (int)xpSpin.Value; int newTotalLevel = CALC.Level(); if (oldTotalLevel > newTotalLevel) { XP_Spin.Value = oldXP; LIB.m_MainCharacterInfo.ExperiencePoints = oldXP; return; } if (oldTotalLevel != newTotalLevel) { for (; oldTotalLevel < newTotalLevel; oldTotalLevel++) { if (LIB.m_MainCharacterInfo.Multiclass) { MulticlassLevelUpForm multiclassLevelUpForm = new MulticlassLevelUpForm( LIB.m_MainCharacterInfo.Class1, LIB.m_MainCharacterInfo.Class2, LIB.m_MainCharacterInfo.Level1, LIB.m_MainCharacterInfo.Level2); var result = multiclassLevelUpForm.ShowDialog(); if (result == DialogResult.OK) { string value = multiclassLevelUpForm.ClassSelection; if (value == "Class1") { LIB.m_MainCharacterInfo.Level1 += 1; LIB.m_MainCharacterInfo.HitDiceTotal1 = LIB.m_MainCharacterInfo.Level1; MessageBox.Show("Will soon add a new form for level up.", "Future Implimentation", MessageBoxButtons.OK); // Need to show level up for Class 1 } else { LIB.m_MainCharacterInfo.Level2 += 1; LIB.m_MainCharacterInfo.HitDiceTotal2 = LIB.m_MainCharacterInfo.Level2; MessageBox.Show("Will soon add a new form for level up.", "Future Implimentation", MessageBoxButtons.OK); // Need to show level up for Class 2 } } else { // User has canceled the level up, therefore need to reset to previous levels LIB.m_MainCharacterInfo.ExperiencePoints = oldXP; LIB.m_MainCharacterInfo.Level1 = oldLevel1; LIB.m_MainCharacterInfo.Level2 = oldLevel2; LIB.m_MainCharacterInfo.HitDiceTotal1 = oldHitDice1; LIB.m_MainCharacterInfo.HitDiceTotal2 = oldHitDice2; break; } } else { // Need to show level up for Class 1 var result = MessageBox.Show("Congrats on level: " + (oldTotalLevel + 1), "Level UP", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result == DialogResult.Cancel) { LIB.m_MainCharacterInfo.ExperiencePoints = oldXP; LIB.m_MainCharacterInfo.Level1 = oldLevel1; LIB.m_MainCharacterInfo.HitDiceTotal1 = oldHitDice1; break; } MessageBox.Show("Will soon add a new form for level up instead of the previous message box.", "Future Implimentation", MessageBoxButtons.OK); LIB.m_MainCharacterInfo.HitDiceTotal1 += 1; LIB.m_MainCharacterInfo.Level1 += 1; } } LIB.m_MainCharacterInfo.Calculate(); PopulateCharacterUI(); } } }