Beispiel #1
0
 public static IQueryable <Card> GetLegalCards(this MtGDBContext context, string format, bool allowSilver = false) => context.Legalities
 .Where(l => l.Format == format.Replace("Penny Dreadful", "Penny").Replace(" ", string.Empty) &&
        (l.Legal || (allowSilver && l.Card.Printings.All(p => p.Set.SetType.Name == "funny"))) &&
        !l.Card.Supertypes.Any(t => t.Supertype.Name == "Basic") &&
        !(l.Card.Layout.Name == "meld" && l.Card.Side == "c"))
 .IncludeCardProperties()
 .Select(l => l.Card);
        protected async Task RefreshContext()
        {
            if (this.db != null)
            {
                await this.db.DisposeAsync();
            }

            this.db = new MtGDBContext();
            this.db.ChangeTracker.AutoDetectChangesEnabled = false;
        }
 public MtGController(MtGDBContext context)
 {
     this.context = context;
 }
        public DeckGenerator(MtGDBContext context, GenerateDeckDto settings)
        {
            this.context = context;
            int seed = settings.Seed ?? Guid.NewGuid().GetHashCode();

            RNG = new Random(seed);

            this.settings = settings;

            if (settings.DeckType == "Commander")
            {
                Card commander = context.GetCardById(settings.CommanderId.Value);
                Card partner   = null;
                if (settings.PartnerId.HasValue)
                {
                    partner = context.GetCardById(settings.PartnerId.Value);
                }

                commanderCreatureTypeIds = new List <int>();
                if (commander?.OracleText?.Contains("is every creature type") != true && partner?.OracleText?.Contains("is every creature type") != true)
                {
                    var creatureTypes = context.Subtypes
                                        .Include(st => st.Cards)
                                        .Where(st => st.Types.Any(t => t.CardType.Name == "Creature"));

                    if (partner != null)
                    {
                        creatureTypes = creatureTypes.Where(st => st.Cards.Any(c => c.CardID == commander.ID || c.CardID == partner.ID));
                    }
                    else
                    {
                        creatureTypes = creatureTypes.Where(st => st.Cards.Any(c => c.CardID == commander.ID));
                    }

                    commanderCreatureTypeIds.AddRange(creatureTypes.Select(st => st.ID));
                }

                deck = new EdhDeck()
                {
                    Commander = commander,
                    Partner   = partner,
                    Singleton = true,
                    Seed      = seed
                };
            }
            else if (settings.DeckType == "Oathbreaker")
            {
                deck = new OathbreakerDeck()
                {
                    Oathbreaker    = context.GetCardById(settings.CommanderId.Value),
                    SignatureSpell = context.GetCardById(settings.SignatureSpellId.Value),
                    Singleton      = true,
                    Seed           = seed
                };
            }
            else
            {
                deck = new Deck()
                {
                    Seed = seed
                };
            }

            format = settings.Format.Replace("Penny Dreadful", "Penny").Replace(" ", string.Empty);

            disabledColorIdentityIds = context.Colors.Where(c => c.Symbol != "C" && !settings.ColorIdentity.Contains(c.Symbol)).Select(t => t.ID).ToList();

            var disabledCardSupertypes = new List <string>();
            var disabledCardTypes      = new List <string>();
            var disabledCardSubtypes   = new List <string>();

            if (settings.BasicLands < 0)
            {
                disabledCardSupertypes.Add("Basic");
            }

            if (settings.NonbasicLands < 0)
            {
                disabledCardTypes.Add("land");
            }

            if (settings.Creatures < 0)
            {
                disabledCardTypes.Add("creature");
            }

            if (settings.Artifacts < 0)
            {
                disabledCardTypes.Add("artifact");
            }

            if (settings.Equipment < 0)
            {
                disabledCardSubtypes.Add("Equipment");
            }

            if (settings.Vehicles < 0)
            {
                disabledCardSubtypes.Add("Vehicle");
            }

            if (settings.Enchantments < 0)
            {
                disabledCardTypes.Add("enchantment");
            }

            if (settings.Auras < 0)
            {
                disabledCardSubtypes.Add("Aura");
            }

            if (settings.Planeswalkers < 0)
            {
                disabledCardTypes.Add("planeswalker");
            }

            if (settings.Spells < 0)
            {
                disabledCardTypes.Add("instant");
                disabledCardTypes.Add("sorcery");
            }

            if (settings.Legendary < 0)
            {
                disabledCardSupertypes.Add("Legendary");
            }

            disabledCardSupertypeIds = context.Supertypes.Where(t => disabledCardSupertypes.Contains(t.Name)).Select(t => t.ID).ToList();
            disabledCardTypeIds      = context.CardTypes.Where(t => disabledCardTypes.Contains(t.Name)).Select(t => t.ID).ToList();
            disabledCardSubtypeIds   = context.Subtypes.Where(t => disabledCardSubtypes.Contains(t.Name)).Select(t => t.ID).ToList();

            if (settings.SharesType < 0)
            {
                foreach (int id in commanderCreatureTypeIds)
                {
                    if (!disabledCardSubtypeIds.Contains(id))
                    {
                        disabledCardSubtypeIds.Add(id);
                    }
                }
            }
        }
Beispiel #5
0
 public static Card GetCardById(this MtGDBContext context, int id) => context.Cards
 .Where(c => c.ID == id)
 .IncludeCardProperties()
 .Single();