public IActionResult OnPostAddToCollection(string cardName, string lang, string setName, int amount, bool isSigned = false, bool isFoil = false) { MTGCard searchedCard = cardData.SearchForCard(cardName, lang, setName); if (searchedCard != null) { MTGUserCard c = new MTGUserCard(); c.CardId = searchedCard.Id; c.UserId = httpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); c.Amount = amount; c.Signed = isSigned; c.Foil = isFoil; if (cardData.AddToCollection(c)) { return(StatusCode(201, "Successfully added " + cardName + " to collection")); } else { return(StatusCode(500, "Internal Server error, try again later")); } } return(StatusCode(500, "Internal Server error, try again later")); }
private void button1_Click(object sender, EventArgs e) { MTGCard card = null; Cursor.Current = Cursors.WaitCursor; try { if (Search.FindCard(368970, out card)) { using (var bitmap = Downloader.DownloadCardImage(card)) { Guid guid = Guid.Parse(card.Id.Substring(0, 32)); string fileName = string.Format(@"c:\temp\cards\{0}.bmp", guid); bitmap.Save(fileName); using (Mat image = new Mat(fileName, LoadImageType.AnyColor)) { CardImage.ImageEvent += CardImage_ImageEvent; CardField cardField = new CardField(image); var cards = cardField.FindCards(guid).ToArray(); CardImage.ImageEvent -= CardImage_ImageEvent; } } } } finally { Cursor.Current = Cursors.Default; } }
private static bool Process(MTGCard card, string dir) { bool hashName = false; Guid cardId = Guid.Parse(card.Id.Substring(0, 32)); string fileName = string.Format(@"c:\temp\cards\{0}.bmp", cardId); using (Mat image = new Mat(fileName, LoadImageType.Color)) { Console.WriteLine(string.Format("Processing: {0}", fileName)); CardImage cardImage = new CardImage(cardId, image, angle: 0, cardFrame: card.Set.CardFrame); using (Mat setIcon = cardImage.FindSetIcons().FirstOrDefault()) { if (setIcon != null) { string fullName; if (hashName == true) { string hash; using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider()) { ImageConverter converter = new ImageConverter(); var byteArray = (byte[])converter.ConvertTo(setIcon.Bitmap, typeof(byte[])); hash = Convert.ToBase64String(sha1.ComputeHash(byteArray)); hash = hash.Replace("=", "").Replace("-", "").Replace("+", "").Replace("\\", "").Replace("/", "").ToUpper().Substring(0, 8); } fullName = string.Format(@"{0}{1}-{2}.bmp", dir, card.Set.Code, hash); } else { fullName = string.Format(@"{0}{1}-{2}.bmp", dir, cardId, card.Set.CardFrame); } setIcon.Bitmap.Save(fullName); return(true); } else { var savedColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Format("Unable To Process: {0}", fileName)); Console.ForegroundColor = savedColor; } } } return(false); }
/// <summary> /// /// </summary> /// <param name="NewCards"></param> private void AddToCollection(MTGCollection NewCards) { try { ArrayList Display = new ArrayList(); // update the collection data grid Collection.Add(NewCards); foreach (Int32 cardnumber in Collection.Cards) { MTGCard card = new MTGCard(); foreach (MTGCard cardInfo in ((MTGCardSet)CardSets[0]).CardSet) { if (cardInfo.ID == cardnumber) { card = cardInfo; if (Display.Contains(card)) { // increment the quantity Int32 index = Display.IndexOf(card); ((MTGCard)Display[index]).Quantity += 1; } else { Display.Add(card); } break; } } } UpdateCollection(Display); Display = new ArrayList(); UpdateCombo("Create New"); // now update the combobox foreach (String DeckName in Collection.Decks.Keys) { UpdateCombo(DeckName); UpdateCombo2(DeckName); } } catch (Exception ex) { LogError("AddToCollection: Unable to add cards to collection. [" + ex.Message + "]"); } }
/// <summary> /// Download Card Image As Bitmap /// </summary> /// <param name="card"></param> /// <returns></returns> public static Bitmap DownloadCardImage(MTGCard card) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(card.MagicCardsImageUri); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { return(new Bitmap(stream)); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonGameSolitare_Click(object sender, EventArgs e) { // enable the game tab Gaming = true; EnableTabPages(false); EnableTabPages(true); // move tab focus to the game tab tabControl1.SelectTab(4); // start the game! String DeckName = comboBoxDecks2.SelectedItem.ToString(); ArrayList Cards = new ArrayList(); MTGDeck Deck = new MTGDeck(); Deck.Name = DeckName; foreach (Int32 cardnumber in Collection.Decks[DeckName]) { MTGCard card = new MTGCard(); foreach (MTGCard cardInfo in ((MTGCardSet)CardSets[0]).CardSet) { if (cardInfo.ID == cardnumber) { card = cardInfo; if (Cards.Contains(card)) { // increment the quantity Int32 index = Cards.IndexOf(card); ((MTGCard)Cards[index]).Quantity += 1; } else { Cards.Add(card); } break; } } } Deck.Cards = Cards; CurrentGame = new Game(this); CurrentGame.AddPlayerDeck(Deck); CurrentGame.StartSolitareGame(); Update(); }
public MTGCardList GetAllMagicCardsByTerm(string q) { MTGCardList model = new MTGCardList(); using (var db = new TCGEntities()) { var query = db.MTG_Card.Select(x => x); var query2 = db.MTG_Card.Select(x => x).Where(x => x.card_artist.Contains(q) || x.flavor_text.Contains(q) || x.card_name.Contains(q) || x.card_subtype.Contains(q) || x.card_text.Contains(q) || x.card_type.Contains(q)); var cardList = query2.ToList(); foreach (var card in cardList) { MTGCard newMTGCard = new MTGCard(); newMTGCard.Name = card.card_name; newMTGCard.CMC = (double)card.cmc; newMTGCard.MCINumber = card.mci_number; newMTGCard.ManaCost = card.mana_cost; newMTGCard.Id = card.card_id; newMTGCard.Flavor = card.flavor_text; newMTGCard.Power = card.power; newMTGCard.Toughness = card.toughness; newMTGCard.Rarity = card.card_rarity; newMTGCard.Layout = card.card_layout; newMTGCard.Types = card.card_type.Split(' ').ToList(); newMTGCard.Subtypes = card.card_subtype.Split(' ').ToList(); newMTGCard.Text = card.card_text; newMTGCard.MultiverseId = (int)card.multiverse_id; newMTGCard.Colors = card.card_colors.Split(' ').ToList(); newMTGCard.ColorIdentity = card.card_color_identity.Split(' ').ToList(); newMTGCard.Artist = card.card_artist; newMTGCard.Printings = card.sets.Split(' ').ToList(); newMTGCard.Image = ""; if (newMTGCard.Flavor == null) { newMTGCard.Flavor = ""; } if (newMTGCard.Subtypes == null) { newMTGCard.Subtypes[0] = ""; } if (newMTGCard.Text == null) { newMTGCard.Text = ""; } model.Cards.Add(newMTGCard); } } return(model); }
public async Task <MTGCard> GetCard(string id) { var response = await httpClient.GetAsync(API_URL + "/cards/" + id); string json = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; Console.WriteLine(json); MTGCard card = Newtonsoft.Json.JsonConvert.DeserializeObject <MTGCard>(json); return(card);// .JsonSerializer.Deserialize<MTGCard>(json, options); }
public void TestCard() { // Arrange var set = new MTGSet(1, "abc123", "conflux", new DateTime(2020, 01, 01), 300); // Act MTGCard mtgcard = new MTGCard(1, "path to exile", false, false, false, false, true, false, "W", "1", TypeRarity.Uncommon, "instant", "", "", "", "Exile target creature. " + "Its controller may search their library for a basic land card, put that card onto the " + "battlefield tapped, then shuffle their library.", "", "", 0, 0, 15, set); //Assert Assert.Equal(1, mtgcard.MTGSet.Id); Assert.Equal(300, mtgcard.MTGSet.SetLenght); Assert.Equal(1, mtgcard.Id); Assert.Equal(TypeRarity.Uncommon, mtgcard.Rarity); }
public static bool FindCard(int multiverseId, out MTGCard result) { result = default(MTGCard); foreach (MTGSet set in _sets.GetSets()) { foreach (MTGCard card in set.Cards) { if (card.MultiverseId == multiverseId) { result = card; return(true); } } } return(false); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comboBoxDecks_SelectedIndexChanged(object sender, EventArgs e) { ArrayList Display = new ArrayList(); String DeckName = comboBoxDecks.SelectedItem.ToString(); try { if (Collection.Decks.ContainsKey(DeckName)) { // update the decks data grid ArrayList Deck = Collection.Decks[DeckName]; foreach (Int32 cardnumber in Deck) { MTGCard card = new MTGCard(); foreach (MTGCard cardInfo in ((MTGCardSet)CardSets[0]).CardSet) { if (cardInfo.ID == cardnumber) { card = cardInfo; if (Display.Contains(card)) { // increment the quantity Int32 index = Display.IndexOf(card); ((MTGCard)Display[index]).Quantity += 1; } else { Display.Add(card); } } } } } UpdateDecks(Display); } catch (Exception ex) { LogError("comboBoxDecks_SelectedIndexChanged: Problem with combobox switch. [" + ex.Message + "]"); } }
private void button2_Click(object sender, EventArgs e) { for (int i = 0; i < 100; i++) { MTGCard card = Search.RandomCard(); try { using (var bitmap = Downloader.DownloadCardImage(card)) { Guid guid = Guid.Parse(card.Id.Substring(0, 32)); string fileName = string.Format(@"c:\temp\cards\{0}.bmp", guid); bitmap.Save(fileName); } } catch (Exception) { } } }
private static void DownloadAndProcess(string dir) { for (int i = 0; i < 1000; i++) { MTGCard card = Search.RandomCard(); try { using (var bitmap = Downloader.DownloadCardImage(card)) { Guid cardId = Guid.Parse(card.Id.Substring(0, 32)); string fileName = string.Format(@"c:\temp\cards\{0}.bmp", cardId); bitmap.Save(fileName); Process(card, dir); } } catch (Exception) { } } }
public static bool TryFindCard(Guid cardGuid, out MTGCard result) { result = default(MTGCard); foreach (MTGSet set in _sets.GetSets()) { foreach (MTGCard card in set.Cards) { if (Guid.Parse(card.Id.Substring(0, 32)) == cardGuid) { result = card; return(true); } } } return(false); throw new NotImplementedException(); }
public void UpdateCard(MTGCard card) { _context.MTGCard.Add(card).State = Microsoft.EntityFrameworkCore.EntityState.Modified; }
public void AddCard(MTGCard card) { _context.MTGCard.Add(card); }
public MemoryStream GetImage(MTGCard card) { throw new NotImplementedException(); }