/// <summary> /// The constructor for creating a new Card object. This is called internally by the public static CreateCard method. /// </summary> /// <param name="arenaId">The Unique Identifier of the card on Arena.</param> /// <param name="name">The card's Name.</param> /// <param name="set">The Set that contains the card.</param> /// <param name="collectorNumber">The card's collector number.</param> /// <param name="rarity">The card's Rarity.</param> /// <param name="colors">The card's Color definition.</param> /// <param name="fullName">The string used to identify the specfic card/printing when exporting from or importing to Arena.</param> /// <param name="rank">The card's power ranking used when generating replacement suggestions.</param> /// <param name="type">A string containing the card's types.</param> /// <param name="cost">The card's casting cost.</param> /// <param name="cmc">The card's converted mana cost.</param> /// <param name="scryfallId">The card's unique identifier on Scryfall.</param> private Card(int arenaId, string name, Set set, string collectorNumber, CardRarity rarity, string colors, string fullName, int rank, string type, string cost, int cmc, string scryfallId) { ArenaId = arenaId; Name = name; Set = set; CollectorNumber = collectorNumber; Rarity = rarity; Colors = CardColors.CardColorFromString(colors); FullName = fullName; Rank = rank; Type = type; Cost = cost; Cmc = cmc; ScryfallId = scryfallId; PrintedName = name; if (Rarity == CardRarity.BasicLand || Rarity == CardRarity.Token) { BoosterCost = 0; } else { double cardFreq = WildcardFreq[Rarity]; if (!Set.NotInBooster.Contains(Name)) { cardFreq += BoosterFreq(); } BoosterCost = 1.0 / cardFreq; } }
/// <summary> /// Static Method to create new card object and add it to the database. /// </summary> /// <param name="arenaId">The Unique Identifier of the card on Arena.</param> /// <param name="name">The card's Name.</param> /// <param name="setName">The name of the Set that contains the card.</param> /// <param name="collectorNumber">The card's collector number.</param> /// <param name="rarity">A string representing the card's Rarity.</param> /// <param name="colors">A string representing the card's Colors.</param> /// <param name="rank">The card's power ranking used when generating replacement suggestions.</param> /// <param name="type">A string containing the card's types.</param> /// <param name="cost">The card's casting cost</param> /// <param name="cmc">The card's converted mana cost.</param> /// <param name="scryfallId">The card's unique identifier on Scryfall.</param> /// <returns>The new Card object that was added to the database.</returns> public static Card CreateCard(int arenaId, string name, string setName, string collectorNumber, string rarity, string colors, int rank, string type, string cost, int cmc, string scryfallId) { int step = 0; try { if (setName == "Aether Revolt" || setName == "Hour of Devastation") { // fixing a bug in the downloaded database setName = "Historic Anthology 4"; } Set set = Set.GetSet(setName); CardRarity cardRarity = CardRarity.CardRarityFromString(rarity); if (cardRarity == CardRarity.BasicLand && !IsBasicLandName(name)) { IEnumerable <string> typenames = type.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)); name = typenames.Last(); } string fullName = $"{name} ({set.ArenaCode}) {collectorNumber}"; if (_cardsById.ContainsKey(arenaId)) { Card card = _cardsById[arenaId]; step = 1; if (card.FullName != fullName) { throw new ArgumentException($"Card with ArenaId {arenaId} exists with full name {card.FullName}, but {fullName} was passed."); } else if (_cardsByFullName.ContainsKey(fullName)) { int existingId = _cardsByFullName[fullName].ArenaId; throw new ArgumentException($"Card with full name {fullName} exists with ArenaId {existingId}, but {arenaId} was passed."); } return(card); } step = 2; Card newCard = new Card(arenaId, name, set, collectorNumber, cardRarity, colors, fullName, rank, type, cost, cmc, scryfallId); _cardsById.Add(arenaId, newCard); if (!_cardsByFullName.ContainsKey(fullName)) { // there are a few cards with art variants that aren't distinguishable by full name, // in those cases, we just keep the first, so _cardsByFullName will be a slightly smaller // set of cards than _cardsById _cardsByFullName.Add(fullName, newCard); } if (!_cardsByName.ContainsKey(name)) { _cardsByName.Add(name, new List <Card>()); } _cardsByName[name].Add(newCard); return(newCard); } catch (KeyNotFoundException e) { throw new KeyNotFoundException($"Key not found exception in Card.CreateCard(): step={step}, arenaId={arenaId}, name={name}, setName={setName}, collectorNumber={collectorNumber}, rarity={rarity}, colors={colors}, rank={rank}, type={type}, cost={cost}, cmc={cmc}, scryfallId={scryfallId}", e); } catch (InvalidOperationException e) { throw new InvalidOperationException($"Invaid operation exception in Card.CreateCard(): step={step}, arenaId={arenaId}, name={name}, setName={setName}, collectorNumber={collectorNumber}, rarity={rarity}, colors={colors}, rank={rank}, type={type}, cost={cost}, cmc={cmc}, scryfallId={scryfallId}", e); } }