private void cboCardRarity_SelectedIndexChanged(object sender, EventArgs e) { Tags card = new Tags(); Tags.RarityType rarity; Affix.Modifier modifier; Affix.ModifierSpecific modifierSpecific; //Clear the list box so we can refill it with new data lstCards.Items.Clear(); //Show the item in the listbox using the name and description lstCards.DisplayMember = "listBoxDisplay"; //Query the Cards table for the base cards of the selected rarity using (OleDbConnection connection = new OleDbConnection(connectionString)) { //Query to run against the Cards table string cardsQuery = "SELECT * FROM Cards WHERE " + "Rarity = '" + cboCardRarity.SelectedItem + "'" + "ORDER BY CardName ASC;"; OleDbCommand command = new OleDbCommand(cardsQuery, connection); try { connection.Open(); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { //Refresh the card object card = new Tags(); //Fill card object of current row in the database card.name = reader[0].ToString(); card.imageURL = reader[12].ToString(); Enum.TryParse(cboCardRarity.SelectedItem.ToString(), out rarity); card.rarity = rarity; cardTags = new Tags.CardTags(); cardTags.points = (int)reader[5]; Enum.TryParse(reader[2].ToString(), out modifier); cardTags.prefix = new Affix("", modifier, (int)reader[3], reader[4].ToString().Replace("/r/n", Environment.NewLine)); Enum.TryParse(reader[6].ToString(), out modifier); try { cardTags.suffix = new Affix("", modifier, (int)reader[8], reader[9].ToString().Replace("/r/n", Environment.NewLine)); if (modifier == Affix.Modifier.Specific) { //We have a specific modifier (ie. +Destiny Card Points, Increased Rapier Charge damage, etc); capture that data if (Enum.TryParse(reader[7].ToString(), out modifierSpecific)) { cardTags.suffix.modifierSpecific = modifierSpecific; } else { MessageBox.Show("No Affix.ModifierSpecific enum found that matches '" + reader[7].ToString() + "'. Either add the enum or fix the value in the database."); } } } catch (Exception) { //No secondary mod for this card, let suffix = null and continue on } cardTags.unique = (bool)reader[10]; cardTags.conditional = (bool)reader[11]; card.cardTags = cardTags; //Update the description of the card by combining its base affixes (prefix and suffix) PopulateItemDescription(ref card, card.cardTags.prefix, card.cardTags.suffix, card.cardTags.thirdAffix); //Update the list box display value we'll use to show the card to the user card.listBoxDisplay = card.name + " | " + card.description.Replace("\r\n", " | "); //Store the card in the listbox of all available cards to create from lstCards.Items.Add(card); } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { connection.Close(); } Console.ReadLine(); } }
private void GetWeaponFromTable() { Tags.WeaponTags weaponTags; Tags.WeaponTags.AttackTags wpnAttack1 = null; Tags.WeaponTags.AttackTags wpnAttack2 = null; Tags.WeaponTags.AttackTags wpnAttack3 = null; //Generic data Tags.ItemType itemType = Tags.ItemType.Weapon; string wpnName; string wpnImage; //Weapon data Tags.WeaponTags.WeaponType wpnType; Tags.RarityType wpnRarity; int wpnDmgMin; int wpnDmgMax; int wpnArmorPenetration; int wpnCritChance; int wpnCritMulti; Tags.WeaponTags.WeaponDistance wpnDistance; Affix.Modifier modifier; string wpnDescription = string.Empty; //Attack data string attackSlot; string attackName; string attackImageURL; string attackImageHoverTextURL; using (OleDbConnection connection = new OleDbConnection(connectionString)) { #region GetAttacks //Query the Attacks table for the selected weapon's attacks string attackQuery = "SELECT * FROM Attacks WHERE " + "WeaponType = '" + cboType.SelectedItem + "';"; OleDbCommand command = new OleDbCommand(attackQuery, connection); try { connection.Open(); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { attackSlot = reader[1].ToString(); attackName = reader[2].ToString(); attackImageURL = reader[3].ToString(); attackImageHoverTextURL = reader[4].ToString(); switch (attackSlot) { case "Attack1": wpnAttack1 = new Tags.WeaponTags.AttackTags(attackName, attackImageURL, attackImageHoverTextURL); break; case "Attack2": wpnAttack2 = new Tags.WeaponTags.AttackTags(attackName, attackImageURL, attackImageHoverTextURL); break; case "Attack3": wpnAttack3 = new Tags.WeaponTags.AttackTags(attackName, attackImageURL, attackImageHoverTextURL); break; default: break; } } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { connection.Close(); } Console.ReadLine(); #endregion #region GetWeaponBase //Query the Weapons table for base values string weaponQuery = "SELECT * FROM Weapons WHERE " + "Type = '" + cboType.SelectedItem + "'" + "AND Rarity = '" + cboWeaponRarity.SelectedItem + "';"; command = new OleDbCommand(weaponQuery, connection); try { connection.Open(); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { Enum.TryParse(reader[0].ToString().Replace(" ", ""), out wpnType); Enum.TryParse(reader[1].ToString(), out wpnRarity); wpnDmgMin = (int)reader[2]; wpnDmgMax = (int)reader[3]; wpnArmorPenetration = (int)reader[4]; wpnCritChance = (int)reader[5]; wpnCritMulti = (int)reader[6]; wpnName = reader[7].ToString(); Enum.TryParse(reader[8].ToString(), out wpnDistance); wpnImage = reader[9].ToString(); weaponTags = new Tags.WeaponTags(wpnType, wpnDistance, wpnDmgMin, wpnDmgMax, wpnArmorPenetration, wpnCritChance, wpnCritMulti, wpnAttack1, wpnAttack2, wpnAttack3); newItemTags = new Tags(itemType, wpnRarity, wpnName, wpnDescription, wpnImage, weaponTags); } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { connection.Close(); } Console.ReadLine(); #endregion //If we are creating a Legendary item, grab/override additional data from the WeaponsLegendary table if (newItemTags.rarity == Tags.RarityType.Legendary) { #region SetLegendaryAffixesAndProperties //Substring the selection of lstLegendaries to just pull the Name (the list box is showing the Name and Special Stat description for the user to see) string weaponLegendaryQuery = "SELECT * FROM WeaponsLegendary WHERE " + "Type = '" + cboType.SelectedItem + "'" + "AND WeaponName = '" + lstLegendaries.SelectedItem.ToString().Substring(0, lstLegendaries.SelectedItem.ToString().IndexOf(" | ")) + "';"; command = new OleDbCommand(weaponLegendaryQuery, connection); try { connection.Open(); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { newItemTags.name = reader[1].ToString(); newItemTags.imageURL = reader[2].ToString(); Enum.TryParse(reader[4].ToString(), out modifier); newItemTags.weaponTags.prefix = new Affix("", modifier, (int)reader[3], reader[5].ToString().Replace("/r/n", Environment.NewLine)); Enum.TryParse(reader[7].ToString(), out modifier); newItemTags.weaponTags.suffix = new Affix("", modifier, (int)reader[6], reader[8].ToString().Replace("/r/n", Environment.NewLine)); newItemTags.weaponTags.specialStat = reader[9].ToString().Replace("/r/n", Environment.NewLine); } newItemTags.description = newItemTags.weaponTags.prefix.listBoxDisplay + Environment.NewLine + newItemTags.weaponTags.suffix.listBoxDisplay + Environment.NewLine + newItemTags.weaponTags.specialStat; reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { connection.Close(); } Console.ReadLine(); #endregion } else { #region SetRareAffixesAndProperties //Set the user-selected rare weapon affixes newItemTags.weaponTags.prefix = (Affix)lstPrefixes.SelectedItem; newItemTags.weaponTags.suffix = (Affix)lstSuffixes.SelectedItem; newItemTags.weaponTags.thirdAffix = (Affix)lstThirdAffix.SelectedItem; //Populate the hover text and update the weapon name PopulateItemDescription(ref newItemTags, newItemTags.weaponTags.prefix, newItemTags.weaponTags.suffix, newItemTags.weaponTags.thirdAffix); #endregion } } }