/// <summary> /// Draws a card. /// </summary> /// <param name="type"></param> /// <param name="traitString"></param> /// <param name="cost"></param> /// <param name="blacklist">Will not draw cards from this list.</param> /// <returns>Null if none available.</returns> private InvestigatorCard Draw(InvestigatorCardType type, string traitString, int?cost, List <InvestigatorCard> blacklist) { IEnumerable <InvestigatorCard> potentialDraws = cards.InDeck.Except(blacklist); Dictionary <int, InvestigatorCard> pool = new Dictionary <int, InvestigatorCard>(); int poolIndex = 0; TraitPredicate tp = new TraitPredicate(traitString); foreach (InvestigatorCard card in potentialDraws) { bool checkForCost = (type == InvestigatorCardType.Asset && cost.HasValue); if (card.CardType == type && tp.IsValid(card) && (!checkForCost || ((AssetCard)card).Cost == cost.Value)) { for (int i = 0; i < cards.GetQuantityInCollectionDeck(card); i++) { pool.Add(poolIndex, card); poolIndex++; } } } if (pool.Count > 0) { Random rand = new Random(); int i = rand.Next(0, pool.Count); return(pool[i]); } else { //No possible cards return(null); } }
/// <summary> /// Loads and displays all cards of a given type from file / stored manual input. /// </summary> /// <param name="type"></param> private void LoadAndDisplay(InvestigatorCardType type) { try { IEnumerable <InvestigatorCard> cards; switch (type) { case InvestigatorCardType.Artifact: cards = HTMLReader.GetArtifacts(); break; case InvestigatorCardType.Asset: cards = HTMLReader.GetAssets(); break; case InvestigatorCardType.Spell: cards = HTMLReader.GetSpells(); break; case InvestigatorCardType.Condition: cards = HTMLReader.GetConditions(); break; case InvestigatorCardType.UniqueAsset: cards = UniqueAssetsManual.GetAllUniqueAssets(); break; default: throw new Exception("Type not handled: " + type); } MessageBox.Show(string.Format("{0} cards loaded.", cards.Count())); DataTable table = new DataTable("cardsTable"); table.Columns.Add(new DataColumn("Name")); table.Columns.Add(new DataColumn("Traits")); table.Columns.Add(new DataColumn("Expansion")); foreach (InvestigatorCard card in cards) { DataRow row = table.NewRow(); row.SetField("Name", card.Name); row.SetField("Traits", string.Join(", ", card.Traits)); row.SetField("Expansion", card.Expansion.ToString()); table.Rows.Add(row); } CardDataGrid.DataSource = table; CardDataGrid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n---\n" + ex.StackTrace); } }
/// <summary> /// Shuffles discarded cards of the given type back into the deck. /// </summary> /// <param name="type"></param> public void ClearDiscard(InvestigatorCardType type) { foreach (InvestigatorCard card in InDeck) { if (card.CardType.Equals(type)) { Discards[card] = 0; } } }
/// <summary> /// Constructor. /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <param name="expansion"></param> /// <param name="traits"></param> public InvestigatorCard(string name, InvestigatorCardType type, Expansion expansion, IEnumerable <string> traits) { Name = name; CardType = type; Expansion = expansion; Traits = new List <string>(traits); Quantities = new Dictionary <Expansion, int> { { expansion, 1 } }; }
/// <summary> /// Parses a HTML table in file to get all the card data listed within. /// </summary> /// <param name="filepath"></param> /// <param name="type"></param> /// <returns></returns> private static IEnumerable <InvestigatorCard> Parse(string filepath, InvestigatorCardType type) { List <InvestigatorCard> cards = new List <InvestigatorCard>(); HtmlDocument doc = new HtmlDocument(); doc.Load(filepath); foreach (HtmlNode rowNode in doc.DocumentNode.Descendants("tr")) { IEnumerable <HtmlNode> cardNodes = rowNode.Descendants("td"); string name = cardNodes.ElementAt(0).InnerText.Trim(); string traitsString = cardNodes.ElementAt(1).InnerText.Replace('-', ',').Replace('—', ','); HtmlNode expNode = cardNodes.ElementAt(2); HtmlNode expLinkNode = expNode.SelectSingleNode(".//a"); string expString = "Core"; if (expLinkNode != null) { expString = expLinkNode.GetAttributeValue("title", "Core"); } List <string> traits = new List <string>(); foreach (string traitRaw in traitsString.Split(',')) { traits.Add(traitRaw.ToUpper().Trim()); } Expansion exp = ExpansionExtensions.FromString(expString); InvestigatorCard card; if (type == InvestigatorCardType.Asset) { int cost = int.Parse(cardNodes.ElementAt(3).InnerText); card = new AssetCard(name, type, exp, traits, cost); } else { card = new InvestigatorCard(name, type, exp, traits); } cards.Add(card); } return(cards); }
/// <summary> /// Constructor. /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <param name="expansion"></param> /// <param name="traits"></param> /// <param name="cost"></param> public AssetCard(string name, InvestigatorCardType type, Expansion expansion, IEnumerable <string> traits, int cost) : base(name, type, expansion, traits) { Cost = cost; }