Exemplo n.º 1
0
        //Features that need additional work; not functional yet
        #region WorkInProgress
        public IActionResult AddLand(string DeckName)
        {
            CombinedDeckViewModel combo = new CombinedDeckViewModel();

            List <DecksTable> landData = (from d in _context.DecksTable where d.AspUserId == FindUserId() && d.DeckName == DeckName && d.ColorIdentity == "L" select d).ToList();
            List <CardsTable> cards    = new List <CardsTable>();


            DecksTable passingDeckName = new DecksTable();

            passingDeckName.DeckName = DeckName;
            combo.deckObject         = landData;
            combo.Search             = cards;
            if (landData.Count == 0)
            {
                combo.deckObject = landData;
                combo.deckObject.Add(passingDeckName);
                return(View(combo));
            }
            else
            {
                for (int i = 0; i < landData.Count; i++)
                {
                    CardsTable index = new CardsTable();
                    cards.Add(index);
                    combo.Search[i].Name = (from c in _context.CardsTable where c.Id == landData[i].CardId select c.Name).ToString();
                }
                return(View(combo));
            }
        }
Exemplo n.º 2
0
 public void Setup()
 {
     mTable  = new CardsTable();
     mDealer = new Dealer()
     {
         Table = mTable
     };
 }
Exemplo n.º 3
0
 void Start()
 {
     mCards        = Pool.GenerateNewDeck();
     mDealer       = new Dealer();
     mTable        = new CardsTable();
     mDealer.Table = mTable;
     mDealer.DealNewGame(7);
     Layout();
 }
        public async void AddCardsToCardsTable(string assistedCardId)
        {
            Thread.Sleep(100);
            CardsTable cardTable = new CardsTable();

            if (_context.CardsTable.Where(x => x.CardId == assistedCardId).FirstOrDefault() == null)
            {
                Cardobject cardItem = await ScryfallDAL.GetApiResponse <Cardobject>("cards", assistedCardId, "https://api.scryfall.com/", "");

                if (cardItem.image_uris != null)
                {
                    cardTable.CardArtUrl = cardItem.image_uris.normal;
                }
                else
                {
                    cardTable.CardArtUrl = "https://img4.wikia.nocookie.net/__cb20140414012548/villains/images/8/86/Dennis_Nedry.png";
                }
                cardTable.CardId     = cardItem.id;
                cardTable.Cmc        = cardItem.cmc;
                cardTable.ManaCost   = cardItem.mana_cost;
                cardTable.Name       = cardItem.name;
                cardTable.OracleText = cardItem.oracle_text;
                cardTable.TypeLine   = cardItem.type_line;
                cardTable.EdhrecRank = cardItem.edhrec_rank;
                if (cardItem.prices.usd == null)
                {
                    cardItem.prices.usd = "0.00";
                }
                cardTable.CardPrice = decimal.Parse(cardItem.prices.usd);

                if (cardItem.color_identity.Contains("B"))
                {
                    cardTable.Black = "B";
                }
                if (cardItem.color_identity.Contains("U"))
                {
                    cardTable.Blue = "U";
                }
                if (cardItem.color_identity.Contains("W"))
                {
                    cardTable.White = "W";
                }
                if (cardItem.color_identity.Contains("G"))
                {
                    cardTable.Green = "G";
                }
                if (cardItem.color_identity.Contains("R"))
                {
                    cardTable.Red = "R";
                }
                _context.CardsTable.Add(cardTable);
                _context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public string FindColorId(CardsTable commanderId)
        {
            string deckIdentity = commanderId.ManaCost;

            string tempString = deckIdentity;

            tempString += "|";

            for (int i = 0; i < deckIdentity.Length; i++)
            {
                if (deckIdentity[i] == 'W' || deckIdentity[i] == 'U' || deckIdentity[i] == 'B' || deckIdentity[i] == 'R' || deckIdentity[i] == 'G')
                {
                    tempString += deckIdentity[i];
                }
            }

            deckIdentity = tempString.Substring(tempString.IndexOf('|') + 1);

            return(deckIdentity);
        }
Exemplo n.º 6
0
        public IActionResult SaveCommander(int cId)
        {
            //find the last deck this user made
            //save the chosen commanderid to the deck table

            string userName = FindUserId();

            //DecksTable lastEntry = _context.DecksTable.OrderByDescending(i => i.Id).FirstOrDefault();
            DecksTable lastEntry   = new DecksTable();
            CardsTable commanderId = _context.CardsTable.Where(c => c.Id == cId).FirstOrDefault();

            string colorId = FindColorId(commanderId);

            lastEntry.CardId        = commanderId.Id;
            lastEntry.ColorIdentity = colorId;
            lastEntry.AspUserId     = userName;
            lastEntry.Quantity      = 1;


            _context.DecksTable.Add(lastEntry);
            _context.SaveChanges();

            return(RedirectToAction("DeckName"));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> AddCard(CardsTable cId, DecksTable dName)
        {
            var userId = FindUserId();

            string id = cId.CardId;

            if (_context.CardsTable.Where(x => x.CardId == id).FirstOrDefault() == null)
            {
                Cardobject cardItem = await ScryfallDAL.GetApiResponse <Cardobject>("cards", id, "https://api.scryfall.com/", "" + RemoveDuplicatesFromEndpoint(dName.DeckName));

                cId.CardArtUrl = cardItem.image_uris.normal;
                cId.CardId     = cardItem.id;
                cId.Cmc        = cardItem.cmc;
                cId.ManaCost   = cardItem.mana_cost;
                cId.Name       = cardItem.name;
                cId.OracleText = cardItem.oracle_text;
                cId.TypeLine   = cardItem.type_line;
                cId.EdhrecRank = cardItem.edhrec_rank;
                if (cardItem.prices.usd == null)
                {
                    cardItem.prices.usd = "0.00";
                }
                cId.CardPrice = decimal.Parse(cardItem.prices.usd);
                if (cardItem.color_identity.Contains("B"))
                {
                    cId.Black = "B";
                }
                if (cardItem.color_identity.Contains("U"))
                {
                    cId.Blue = "U";
                }
                if (cardItem.color_identity.Contains("W"))
                {
                    cId.White = "W";
                }
                if (cardItem.color_identity.Contains("G"))
                {
                    cId.Green = "G";
                }
                if (cardItem.color_identity.Contains("R"))
                {
                    cId.Red = "R";
                }
                _context.CardsTable.Add(cId);
                _context.SaveChanges();
            }

            //if the card the user is adding exists in the decks table, return to deckview with an error
            //otherwise, add the card

            //find ID of the card in the cards table
            var idCollection = (from x in _context.CardsTable where id == x.CardId select x.Id).FirstOrDefault();
            //find if the card exists in the decks table for this user and this deck
            var cardExists = (from d in _context.DecksTable where idCollection == d.CardId && FindUserId() == d.AspUserId && dName.DeckName == d.DeckName select d).FirstOrDefault();

            //if the linq statement returns null, the card doesn't exist and needs to be added.
            if (cardExists == null || cardExists.CardId == 5633 || cardExists.CardId == 5634 || cardExists.CardId == 5635 || cardExists.CardId == 5636 || cardExists.CardId == 5637)
            {
                if (cId.ManaCost != null)
                {
                    string colorId = FindColorId(cId);
                    dName.ColorIdentity = colorId;
                }
                else
                {
                    dName.ColorIdentity = "L";
                }
                dName.CardId   = idCollection;
                dName.Quantity = 1;


                if (userId != null)
                {
                    dName.AspUserId = userId;
                }

                _context.DecksTable.Add(dName);
                _context.SaveChanges();

                return(RedirectToAction("DeckList", dName));
            }
            //else redirect to the decklist
            else
            {
                dName.errorMessage = "The card you've added already exists in your deck!";
                return(RedirectToAction("DeckList", dName));
            }
        }
Exemplo n.º 8
0
        public IActionResult DeckList(DecksTable dName)
        {
            CardsTable cd = new CardsTable();
            string     id = FindUserId();

            CombinedDeckViewModel combo = new CombinedDeckViewModel();

            List <DecksTable> deckList = (from d in _context.DecksTable
                                          where d.AspUserId == id && d.DeckName == dName.DeckName
                                          select d).ToList();

            List <CardsTable> cardlist = new List <CardsTable>();
            //List<DecksTable> userDecks = new List<DecksTable>();
            int cardCount = 0;

            for (int i = 0; i < deckList.Count; i++)
            {
                cardlist.Add(_context.CardsTable.Find(deckList[i].CardId));
            }

            float   cmc  = 0;
            decimal?cost = 0;

            foreach (CardsTable card in cardlist)
            {
                cmc  += card.Cmc;
                cost += card.CardPrice;


                if (card.TypeLine.Contains("Creature"))
                {
                    combo.creatureCount += 1;
                }
                if (card.TypeLine.Contains("Instant"))
                {
                    combo.instantCount += 1;
                }
                if (card.TypeLine.Contains("Sorcery"))
                {
                    combo.sorceryCount += 1;
                }
                if (card.TypeLine.Contains("Artifact") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Enchantment"))
                {
                    combo.artifactCount += 1;
                }
                if (card.TypeLine.Contains("Enchantment") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Artifact"))
                {
                    combo.enchantmentCount += 1;
                }
                if (card.TypeLine.Contains("Land") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Artifact") && !card.TypeLine.Contains("Enchantment"))
                {
                    combo.landCount += 1;
                }
            }
            combo.DeckCost = cost?.ToString("C2");

            deckList.Add(dName);

            combo.Search     = cardlist;
            combo.deckObject = deckList;

            return(View(combo));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> CardList(string cardName, DecksTable dName)
        {
            CardsTable            cardTable = new CardsTable();
            ScryfallDAL           dl        = new ScryfallDAL();
            List <CardsTable>     cardList  = new List <CardsTable>();
            CombinedDeckViewModel combo     = new CombinedDeckViewModel();

            var cardId = _context.CardsTable.Where(x => x.Name.Contains(cardName)).FirstOrDefault();

            if (cardId == null)
            {
                CardSearchObject cardItem = await dl.GetListOfCards($"{cardName}+{ RemoveDuplicatesFromEndpoint(dName.DeckName)}");

                if (cardItem.data != null)
                {
                    for (int i = 0; i < cardItem.data.Length; i++)
                    {
                        if (cardItem.data[i].image_uris == null)
                        {
                            cardTable.CardArtUrl = "https://img4.wikia.nocookie.net/__cb20140414012548/villains/images/8/86/Dennis_Nedry.png";
                        }
                        else
                        {
                            cardTable.CardArtUrl = cardItem.data[i].image_uris.normal;
                        }
                        cardTable.CardId     = cardItem.data[i].id;
                        cardTable.Cmc        = cardItem.data[i].cmc;
                        cardTable.ManaCost   = cardItem.data[i].mana_cost;
                        cardTable.Name       = cardItem.data[i].name;
                        cardTable.OracleText = cardItem.data[i].oracle_text;
                        cardTable.TypeLine   = cardItem.data[i].type_line;
                        cardTable.EdhrecRank = cardItem.data[i].edhrec_rank;
                        if (cardItem.data[i].prices == null)
                        {
                            cardItem.data[i].prices.usd      = "0.00";
                            cardItem.data[i].prices.eur      = "0.00";
                            cardItem.data[i].prices.usd_foil = "0.00";
                            cardItem.data[i].prices.tix      = "0.00";
                        }
                        else if (cardItem.data[i].prices.usd == null)
                        {
                            cardItem.data[i].prices.usd = "0.00";
                        }
                        cardTable.CardPrice = decimal.Parse(cardItem.data[i].prices.usd);

                        if (cardItem.data[i].color_identity.Contains("B"))
                        {
                            cardTable.Black = "B";
                        }
                        if (cardItem.data[i].color_identity.Contains("U"))
                        {
                            cardTable.Blue = "U";
                        }
                        if (cardItem.data[i].color_identity.Contains("W"))
                        {
                            cardTable.White = "W";
                        }
                        if (cardItem.data[i].color_identity.Contains("G"))
                        {
                            cardTable.Green = "G";
                        }
                        if (cardItem.data[i].color_identity.Contains("R"))
                        {
                            cardTable.Red = "R";
                        }

                        cardTable.Id = 0;

                        _context.CardsTable.Add(cardTable);
                        _context.SaveChanges();
                    }
                }
                else
                {
                    dName.errorMessage = "Unable to find the requested card";
                    return(RedirectToAction("DeckList", dName));
                }
            }

            //now that the card exists in the card table
            //we need to get the card from the cards table and save
            //first to the cardList then to the combo


            List <DecksTable> deckList = new List <DecksTable>();

            combo.Search     = cardList;
            combo.deckObject = deckList;

            cardList = (from c in _context.CardsTable where c.Name.Contains(cardName) select c).ToList();

            deckList.Add(dName);

            for (int i = 0; i < cardList.Count; i++)
            {
                combo.Search.Add(cardList[i]);
            }

            combo.deckObject = deckList;

            return(View(combo));
        }
        public IActionResult DeckList()
        {
            AssistedDeckViewModel assistedDeck = new AssistedDeckViewModel();
            var deckStatus = HttpContext.Session.GetString("AssistedDeck") ?? "EmptySession";

            if (deckStatus != "EmptySession")
            {
                assistedDeck = System.Text.Json.JsonSerializer.Deserialize <AssistedDeckViewModel>(deckStatus);
            }
            CardsTable cd = new CardsTable();
            string     id = FindUserId();

            List <DecksTable> deckList = (from d in _context.DecksTable
                                          where d.AspUserId == id && d.DeckName == assistedDeck.DeckName
                                          select d).ToList();
            List <CardsTable> cardlist = new List <CardsTable>();


            CombinedDeckViewModel combo = new CombinedDeckViewModel();

            for (int i = 0; i < deckList.Count; i++)
            {
                cardlist.Add(_context.CardsTable.Find(deckList[i].CardId));
            }

            float   cmc  = 0;
            decimal?cost = 0;

            foreach (CardsTable card in cardlist)
            {
                cmc  += card.Cmc;
                cost += card.CardPrice;


                if (card.TypeLine.Contains("Creature"))
                {
                    combo.creatureCount += 1;
                }
                if (card.TypeLine.Contains("Instant"))
                {
                    combo.instantCount += 1;
                }
                if (card.TypeLine.Contains("Sorcery"))
                {
                    combo.sorceryCount += 1;
                }
                if (card.TypeLine.Contains("Artifact") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Enchantment"))
                {
                    combo.artifactCount += 1;
                }
                if (card.TypeLine.Contains("Enchantment") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Artifact"))
                {
                    combo.enchantmentCount += 1;
                }
                if (card.TypeLine.Contains("Land") && !card.TypeLine.Contains("Creature") && !card.TypeLine.Contains("Artifact") && !card.TypeLine.Contains("Enchantment"))
                {
                    combo.landCount += 1;
                }
            }
            combo.DeckCost = cost?.ToString("C2");

            combo.Search     = cardlist;
            combo.deckObject = deckList;

            return(View(combo));
        }