Exemplo n.º 1
0
        private int CompareType(ICardAllDbInfo x, ICardAllDbInfo y)
        {
            CardType xCardType = MultiPartCardManager.Instance.GetCardType(x);
            CardType yCardType = MultiPartCardManager.Instance.GetCardType(y);


            //  a) By Type for all no Artifact: Instant, Sorcery, Enchantment, Creature, Planeswalker, others

            foreach (CardType cardType in new[] { CardType.Instant, CardType.Sorcery, CardType.Enchantment, CardType.Creature, CardType.Planeswalker })
            {
                int?comp = CompareHasValue(xCardType, yCardType, cardType, true);
                if (comp.HasValue)
                {
                    //  b) In Enchantement: Aura then No Aura
                    if (comp.Value == 0 && cardType == CardType.Enchantment)
                    {
                        CardSubType xCardSubType = MultiPartCardManager.Instance.GetCardSubType(x);
                        CardSubType yCardSubType = MultiPartCardManager.Instance.GetCardSubType(y);

                        comp = CompareHasValue(xCardSubType, yCardSubType, CardSubType.Aura, true);
                        if (comp.HasValue)
                        {
                            return(comp.Value);
                        }
                        return(0);
                    }

                    return(comp.Value);
                }
            }

            return(0);
        }
Exemplo n.º 2
0
 public Card(Texture2D texture = null, CardType cardType = CardType.Minion, CardSubType cardSubType = CardSubType.None)
 {
     Texture         = texture;
     _CardType       = cardType;
     _CardSubType    = cardSubType;
     Pos             = __default_start_pos__;
     Collider.Width  = (int)(Texture.Width * Scale.X);
     Collider.Height = (int)(Texture.Height * Scale.Y);
     Origin          = new Vector2((Texture.Width) / 2, (Texture.Height) / 2);
 }
Exemplo n.º 3
0
        public CardSubType GetCardSubType(ICardAllDbInfo cai)
        {
            CardSubType subType = MagicRules.GetCardSubType(cai.Card.Type);

            if (IsSplitted(cai.Card))
            {
                subType |= MagicRules.GetCardSubType(cai.CardPart2.Type);
            }

            return(subType);
        }
Exemplo n.º 4
0
        private int CompareArtifact(ICardAllDbInfo x, ICardAllDbInfo y)
        {
            CardSubType xCardSubType = MultiPartCardManager.Instance.GetCardSubType(x);
            CardSubType yCardSubType = MultiPartCardManager.Instance.GetCardSubType(y);

            //for artifact
            //Rule 1:
            //  a) Vehicule last
            int?comp = CompareHasValue(xCardSubType, yCardSubType, CardSubType.Vehicle, false);

            if (comp.HasValue && comp.Value != 0)
            {
                return(comp.Value);
            }
            //  a) creature before
            CardType xCardType = MultiPartCardManager.Instance.GetCardType(x);
            CardType yCardType = MultiPartCardManager.Instance.GetCardType(y);

            comp = CompareHasValue(xCardType, yCardType, CardType.Creature, false);
            if (comp.HasValue && comp.Value != 0)
            {
                return(comp.Value);
            }
            //  c) equipement before, others first
            comp = CompareHasValue(xCardSubType, yCardSubType, CardSubType.Equipment, false);
            if (comp.HasValue && comp.Value != 0)
            {
                return(comp.Value);
            }
            //  d) others first

            //Rule 2: By Color
            comp = CompareColor(x, y, true);
            if (comp.HasValue && comp.Value != 0)
            {
                return(comp.Value);
            }

            //Rule 3: By weighted CCM (Number of colored mana increasing), then by generic mana (X is biggest)
            comp = CompareCCM(x, y);
            if (comp.HasValue && comp.Value != 0)
            {
                return(comp.Value);
            }

            //Rule 4: for Creature and Vehicule: by force increasing, then endurance increasing
            comp = ComparePTLoyalty(x, y);
            if (comp.HasValue && comp.Value != 0)
            {
                return(comp.Value);
            }

            return(0);
        }
Exemplo n.º 5
0
    public bool isCardSubTypeInStack(CardSubType subType)
    {
        foreach (BaseCard card in theStack)
        {
            if (card.details.subTypes.Contains(subType))
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 6
0
 public static CardSubTypeModel GetCardSubTypeModel(CardSubType cardSubType, SubType subType)
 {
     return(new CardSubTypeModel()
     {
         CardSubTypeId = cardSubType.CardSubTypeId,
         CardId = cardSubType.CardId,
         SubType = SubTypeService.GetSubTypeModel(subType),
         CreatedById = cardSubType.CreatedById,
         CreatedDate = cardSubType.CreatedDate,
         UpdatedById = cardSubType.UpdatedById,
         UpdatedDate = cardSubType.UpdatedDate,
         Deleted = cardSubType.Deleted,
     });
 }
Exemplo n.º 7
0
        public void PersistCardSubType(Guid cardId, Guid subTypeId)
        {
            var cardSubType = new CardSubType()
            {
                CardSubTypeId = Guid.NewGuid(),
                CardId        = cardId,
                SubTypeId     = subTypeId,
                CreatedById   = Guid.Empty,
                CreatedDate   = DateTime.UtcNow,
                UpdatedById   = Guid.Empty,
                UpdatedDate   = DateTime.UtcNow,
                Deleted       = false,
            };

            _context.CardSubType.Add(cardSubType);
            _context.SaveChanges();
        }
Exemplo n.º 8
0
        private bool CheckSubType(ICardAllDbInfo cai)
        {
            if (SubTypesSelected.Count == 0)
            {
                return(true);
            }

            CardSubType subType = MultiPartCardManager.Instance.GetCardSubType(cai);

            CardSubType wantedSubType = SubTypesSelected.Aggregate(CardSubType.None, (current, newsubtype) => current | newsubtype);

            if (SubTypeAggregation == MultiSelectedAggregation.And)
            {
                return(Matcher <CardSubType> .IncludeValue(subType, wantedSubType));
            }
            //SubTypeAggregation == MultiSelectedAggregation.Or
            return(Matcher <CardSubType> .HasValue(subType, wantedSubType));
        }
Exemplo n.º 9
0
        private int ComparePTLoyalty(ICardAllDbInfo x, ICardAllDbInfo y)
        {
            CardType    xCardType    = MultiPartCardManager.Instance.GetCardType(x);
            CardType    yCardType    = MultiPartCardManager.Instance.GetCardType(y);
            CardSubType xCardSubType = MultiPartCardManager.Instance.GetCardSubType(x);
            CardSubType yCardSubType = MultiPartCardManager.Instance.GetCardSubType(y);

            if ((Matcher <CardType> .HasValue(xCardType, CardType.Creature) && Matcher <CardType> .HasValue(yCardType, CardType.Creature)) ||
                (Matcher <CardSubType> .HasValue(xCardSubType, CardSubType.Vehicle) && Matcher <CardSubType> .HasValue(yCardSubType, CardSubType.Vehicle)))
            {
                int xPower = GetPower(x);
                int yPower = GetPower(y);

                int comp = xPower.CompareTo(yPower);
                if (comp != 0)
                {
                    return(comp);
                }
                int xToughness = GetToughness(x);
                int yToughness = GetToughness(y);

                comp = xToughness.CompareTo(yToughness);
                if (comp != 0)
                {
                    return(comp);
                }
            }

            if (Matcher <CardType> .HasValue(xCardType, CardType.Planeswalker) && Matcher <CardType> .HasValue(yCardType, CardType.Planeswalker))
            {
                int xLoyalty = GetLoyalty(x);
                int yLoyalty = GetLoyalty(y);

                int comp = xLoyalty.CompareTo(yLoyalty);
                if (comp != 0)
                {
                    return(comp);
                }
            }

            return(0);
        }
Exemplo n.º 10
0
        public Bitmap DrawTextASBitmap(CardStructure structure, string?name, CardSubType subType, bool twoHanded, Condition condition,
                                       string?modifiers, string?center, string?text, string?flavorText, string?scrapped,
                                       string?lvl, string?winText, string?loseText, Race race)
        {
            var placeholder = new Bitmap(700, 1000);

            switch (structure)
            {
            case CardStructure.Normal:
                return(_drawNormalCards.DrawTextForNormalCards(name, subType, twoHanded, condition,
                                                               modifiers, center, text, flavorText, scrapped));

            case CardStructure.Monster:
                return(_drawMonsterCards.DrawTextForMonsterCards(name, lvl, race, winText, loseText, text, flavorText));

            default:
                break;
            }

            return(placeholder);
        }
Exemplo n.º 11
0
        public async Task <ActionResult> SyncCards(string syncKey)
        {
            try
            {
                if (ValidateSyncKey(syncKey) == false)
                {
                    return(Json("Unauthorized"));
                }

                var cardRarities      = context.Select <CardRarity>();
                var localColors       = new Dictionary <string, Color>();
                var localCardSets     = new Dictionary <string, CardSet>();
                var localCardRarities = new Dictionary <string, CardRarity>();
                var localCardTypes    = new Dictionary <string, CardType>();
                var localCardSubTypes = new Dictionary <string, CardSubType>();

                // Fetch first page of cards
                var url           = Paths.GetScryCardsURL(1);
                var cardsPageTask = Common.HttpGet <Cards>(url);
                for (var i = 2; /*i < 200*/; i += 1)
                {
                    var cardsPage = await cardsPageTask;
                    // Check for next page and setup task to grab next page
                    if (cardsPage.HasMore)
                    {
                        url           = Paths.GetScryCardsURL(i);
                        cardsPageTask = Common.HttpGet <Cards>(url);
                    }
                    var cardInfos            = new List <CardInfo>();
                    var colorRelations       = new List <CardColorRelation>();
                    var cardSetRelations     = new List <CardSetRelation>();
                    var cardRarityRelations  = new List <CardRarityRelation>();
                    var cardTypeRelations    = new List <CardTypeRelation>();
                    var cardSubTypeRelations = new List <CardSubTypeRelation>();
                    foreach (var card in cardsPage.CardList)
                    {
                        // Check if card is english
                        if (card.Language != "en")
                        {
                            continue;
                        }
                        // Check if card image is null (ignore it)
                        if (card.ImageURIs == null)
                        {
                            continue;
                        }

                        // Check if card is already in Db using CardId
                        var cardFound = context.Select <CardInfo>()
                                        .Any(c => c.CardId == card.Id);
                        //.FirstOrDefault(c => c.CardId == card.Id);
                        if (cardFound == true)
                        {
                            continue;
                        }

                        // Restrict some outliers cards
                        if (card.Name.Length > 60)
                        {
                            continue;
                        }

                        // Create card index
                        var cardInfo = CardInfoFactory.GetCardInfo(card);
                        // Add colors of card
                        foreach (var cardColor in card.Colors)
                        {
                            // Check local
                            Color color = null;
                            if (localColors.ContainsKey(cardColor))
                            {
                                color = localColors[cardColor];
                            }
                            // Check in Db
                            if (color == null)
                            {
                                color = context.Select <Color>().FirstOrDefault(c => c.Abbv == cardColor);
                            }
                            // Create new color
                            if (color == null)
                            {
                                color = new Color()
                                {
                                    Name = GetColorName(cardColor), Abbv = cardColor
                                };
                                context.Select <Color>().Add(color);
                                localColors.Add(cardColor, color);
                            }
                            colorRelations.Add(new CardColorRelation()
                            {
                                Card = cardInfo, Color = color
                            });
                        }

                        // Parse type and subtypes
                        var splitResult = card.Type.Split('—');

                        // Add types of card
                        if (splitResult.Length > 0)
                        {
                            var cardTypeSplit = splitResult[0].Trim().Split(typeDelimiters, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var cardType in cardTypeSplit)
                            {
                                // Check local
                                CardType cardTypeObject = null;
                                if (localCardTypes.ContainsKey(cardType))
                                {
                                    cardTypeObject = localCardTypes[cardType];
                                }
                                // Check in Db
                                if (cardTypeObject == null)
                                {
                                    cardTypeObject = context.Select <CardType>().FirstOrDefault(ct => ct.Name == cardType);
                                }
                                // Create new type
                                if (cardTypeObject == null)
                                {
                                    cardTypeObject = new CardType()
                                    {
                                        Name = cardType
                                    };
                                    context.Select <CardType>().Add(cardTypeObject);
                                    localCardTypes.Add(cardType, cardTypeObject);
                                }
                                cardTypeRelations.Add(new CardTypeRelation()
                                {
                                    Card = cardInfo, Type = cardTypeObject
                                });
                            }
                        }

                        // Add sub-types of card
                        if (splitResult.Length > 1)
                        {
                            var cardSubTypesSplit = splitResult[1].Trim().Split(typeDelimiters, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var cardSubType in cardSubTypesSplit)
                            {
                                // Check local
                                CardSubType cardSubTypeObject = null;
                                if (localCardSubTypes.ContainsKey(cardSubType))
                                {
                                    cardSubTypeObject = localCardSubTypes[cardSubType];
                                }
                                // Check in Db
                                if (cardSubTypeObject == null)
                                {
                                    cardSubTypeObject = context.Select <CardSubType>().FirstOrDefault(cst => cst.Name == cardSubType);
                                }
                                // Create new sub type
                                if (cardSubTypeObject == null)
                                {
                                    cardSubTypeObject = new CardSubType()
                                    {
                                        Name = cardSubType
                                    };
                                    context.Select <CardSubType>().Add(cardSubTypeObject);
                                    localCardSubTypes.Add(cardSubType, cardSubTypeObject);
                                }
                                cardSubTypeRelations.Add(new CardSubTypeRelation()
                                {
                                    Card = cardInfo, SubType = cardSubTypeObject
                                });
                            }
                        }

                        // Add card set
                        // Check local
                        CardSet cardSetObject = null;
                        if (localCardSets.ContainsKey(card.Set))
                        {
                            cardSetObject = localCardSets[card.Set];
                        }
                        // Check in Db
                        if (cardSetObject == null)
                        {
                            cardSetObject = context.Select <CardSet>().FirstOrDefault(ct => ct.Abbv == card.Set);
                        }
                        // Create new set
                        if (cardSetObject == null)
                        {
                            cardSetObject = new CardSet()
                            {
                                Name = card.SetName, Abbv = card.Set
                            };
                            context.Select <CardSet>().Add(cardSetObject);
                            localCardSets.Add(card.Set, cardSetObject);
                        }
                        cardSetRelations.Add(new CardSetRelation()
                        {
                            Card = cardInfo, CardSet = cardSetObject
                        });

                        // Add card rarity
                        // Check local
                        CardRarity cardRarityObject = null;
                        if (localCardRarities.ContainsKey(card.Rarity))
                        {
                            cardRarityObject = localCardRarities[card.Rarity];
                        }
                        // Check in Db
                        if (cardRarityObject == null)
                        {
                            cardRarityObject = context.Select <CardRarity>().FirstOrDefault(cr => cr.Name == card.Rarity);
                        }
                        // Create new set
                        if (cardRarityObject == null)
                        {
                            cardRarityObject = new CardRarity()
                            {
                                Name = card.Rarity
                            };
                            context.Select <CardRarity>().Add(cardRarityObject);
                            localCardRarities.Add(card.Rarity, cardRarityObject);
                        }
                        cardRarityRelations.Add(new CardRarityRelation()
                        {
                            Card = cardInfo, CardRarity = cardRarityObject
                        });

                        // Add card info
                        cardInfos.Add(cardInfo);
                    }
                    // Add cards to Db
                    context.Select <CardInfo>().AddRange(cardInfos);
                    context.Select <CardColorRelation>().AddRange(colorRelations);
                    context.Select <CardTypeRelation>().AddRange(cardTypeRelations);
                    context.Select <CardSubTypeRelation>().AddRange(cardSubTypeRelations);
                    context.Select <CardSetRelation>().AddRange(cardSetRelations);
                    context.Select <CardRarityRelation>().AddRange(cardRarityRelations);
                    // Commit page
                    context.Commit();
                    Thread.Sleep(100);

                    // Check if all done
                    if (cardsPage.HasMore == false)
                    {
                        break;
                    }
                }

                context.Dispose();
                return(Json("success"));
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                return(Json(ex.Message));
            }
        }
Exemplo n.º 12
0
        public static CardSubType GetCardSubType(string type)
        {
            CardSubType cardSubType = CardSubType.None;

            if (IsVehicle(type))
            {
                cardSubType |= CardSubType.Vehicle;
            }

            if (IsHost(type))
            {
                cardSubType |= CardSubType.Host;
            }

            if (IsAura(type))
            {
                cardSubType |= CardSubType.Aura;
            }

            if (IsSnow(type))
            {
                cardSubType |= CardSubType.Snow;
            }

            if (IsLegendary(type))
            {
                cardSubType |= CardSubType.Legendary;
            }

            if (IsCurse(type))
            {
                cardSubType |= CardSubType.Curse;
            }

            if (IsTrap(type))
            {
                cardSubType |= CardSubType.Trap;
            }

            if (IsArcane(type))
            {
                cardSubType |= CardSubType.Arcane;
            }

            if (IsTribal(type))
            {
                cardSubType |= CardSubType.Tribal;
            }

            if (IsSaga(type))
            {
                cardSubType |= CardSubType.Saga;
            }

            if (IsAdventure(type))
            {
                cardSubType |= CardSubType.Adventure;
            }

            if (IsEquipment(type))
            {
                cardSubType |= CardSubType.Equipment;
            }
            return(cardSubType);
        }
        public bool MeassureTextForNormalCards(string?name, CardSubType subType, bool twoHanded, Condition condition, string?modifiers, string?center, string?text, string?flavorText, string?scrapped,
                                               int nameFontsize, int cardSubTypeFontsize, int twoHandedFontsize, int conditionFontsize, int modifiersFontsize, int centerFontsize,
                                               int textFontsize, int flavorTextFontsize, int scrappedFontsize)
        {
            const int TextOffset          = 30;
            var       textHigth           = 20;
            var       textHigthFromButtom = 1000 - textHigth;

            using var textBitmap = new Bitmap(700, 1000);
            textBitmap.SetResolution(120, 120);
            var textRectangle = new RectangleF();

            //Graphic
            using (var g = Graphics.FromImage(textBitmap))
            {
                g.SmoothingMode      = SmoothingMode.AntiAlias;
                g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                g.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
                g.PageUnit           = GraphicsUnit.Pixel;
                g.CompositingMode    = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.HighQuality;

                using var formatCentert = new StringFormat()
                      {
                          Alignment = StringAlignment.Center,
                          Trimming  = StringTrimming.EllipsisWord
                      };

                using var formatInlined = new StringFormat()
                      {
                          Trimming = StringTrimming.EllipsisWord
                      };

                //Headline
                using (var useFont = new Font("Segoe Print", nameFontsize, FontStyle.Bold))
                {
                    if ((int)g.MeasureString(name, useFont, 640, formatCentert).Width > (640 - TextOffset))
                    {
                        return(false);
                    }

                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(name, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                }

                //Dividingline
                using var dividingline = _picturesFromArchive.Dividingline();
                textHigth += dividingline.Height;

                //CardSubType

                if (subType != CardSubType.Empty)
                {
                    var subTypeDescription = subType.GetDescription();

                    using var useFont      = new Font("Segoe Print", cardSubTypeFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(subTypeDescription, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                }

                if (twoHanded)
                {
                    using var useFont      = new Font("Segoe Print", twoHandedFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString("Zweihändig", useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                }

                if (condition != Condition.Empty)
                {
                    var conditionDescription = condition.GetDescription();

                    using var useFont      = new Font("Segoe Print", conditionFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(conditionDescription, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                }

                if (modifiers != "")
                {
                    using var useFont      = new Font("Segoe Print", modifiersFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(modifiers, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                }

                if (center != "")
                {
                    using var useFont      = new Font("Segoe Print", centerFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(center, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                }

                if (text != "")
                {
                    if (text == null)
                    {
                        text = "";
                    }
                    textHigth += (int)Math.Round(_meassureStringWithTopograpy.MeassureStringOnBitmapWithTopograpy(text, g, textHigth, textFontsize,
                                                                                                                  (TextOffset, textBitmap.Width), "Segoe Print"));
                }

                if (scrapped != "")
                {
                    if (scrapped == null)
                    {
                        scrapped = "";
                    }
                    textHigthFromButtom -= (int)Math.Round(_meassureStringWithTopograpy.MeassureStringOnBitmapWithTopograpy(scrapped, g, textHigth, scrappedFontsize,
                                                                                                                            (TextOffset, textBitmap.Width), "Segoe Print"));

                    //ScappedLine
                    using var scappedLine = _picturesFromArchive.Scrapped();
                    textHigthFromButtom  -= scappedLine.Height;
                }

                if (flavorText != "")
                {
                    using var useFont  = new Font("Segoe Print", flavorTextFontsize, FontStyle.Italic);
                    textRectangle.Size = new Size(640, (int)g.MeasureString(flavorText, useFont, 640, formatInlined).Height);
                    var textBoxHigth = (int)textRectangle.Bottom - (int)textRectangle.Top;
                    textHigthFromButtom   -= textBoxHigth;
                    textRectangle.Location = new Point(TextOffset, textHigthFromButtom);
                }
            }

            return(textHigth < textHigthFromButtom);
        }
Exemplo n.º 14
0
        public static Set ConvertToModel(string json)
        {
            //deserialize json into import model
            var importSet = JsonConvert.DeserializeObject <ImportSet>(json);

            //use automapper to map into correct model
            var convertedModel = Mapper.Map <Set>(importSet);

            //TODO beautify
            //Manual mapping that I couldn't do in automapper
            #region manual mapping
            foreach (ImportCard card in importSet.Cards)
            {
                //verify that the card has a number
                if (card.MciNumber != null)
                {
                    //first to allow for duplicates in data
                    var newCard = convertedModel.Cards.First(x => x.Number == card.MciNumber);

                    if (card.Supertypes != null)
                    {
                        foreach (string supertype in card.Supertypes)
                        {
                            var super = new CardSuperType();
                            super.Name = supertype;
                            newCard.CardSuperType.Add(super);
                        }
                    }

                    if (card.Types != null)
                    {
                        foreach (string type in card.Types)
                        {
                            var newType = new CardType();
                            newType.Name = type;
                            newCard.CardType.Add(newType);
                        }
                    }

                    if (card.Subtypes != null)
                    {
                        foreach (string subtype in card.Subtypes)
                        {
                            var sub = new CardSubType();
                            sub.Name = subtype;
                            newCard.CardSubType.Add(sub);
                        }
                    }

                    if (card.ColorIdentity != null)
                    {
                        foreach (string coloridentity in card.ColorIdentity)
                        {
                            var identity = new ColorIdentity();
                            Enum.TryParse(coloridentity, out EColorIdentity ciEnum);
                            identity.Name = ciEnum;
                            newCard.ColorIdentity.Add(identity);
                        }
                    }

                    if (card.Colors != null)
                    {
                        foreach (string color in card.Colors)
                        {
                            var c = new Color();
                            Enum.TryParse(color, out EColor cEnum);
                            c.Name = cEnum;
                            newCard.Color.Add(c);
                        }
                    }

                    if (card.Rarity != null)
                    {
                        var r = new Rarity();
                        Enum.TryParse(card.Rarity, out ERarity rEnum);
                        r.Name         = rEnum;
                        newCard.Rarity = r;
                    }

                    if (card.Legalities != null)
                    {
                        var legal = new Legality();

                        foreach (ImportLegality legality in card.Legalities)
                        {
                            switch (legality.Format)
                            {
                            case "Vintage":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Vintage = true;
                                }
                                break;

                            case "Legacy":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Legacy = true;
                                }
                                break;

                            case "Commander":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Commander = true;
                                }
                                break;

                            case "Modern":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Modern = true;
                                }
                                break;

                            case "Standard":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Standard = true;
                                }
                                break;

                            case "Arena":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Arena = true;
                                }
                                break;

                            default:
                                break;
                            }
                        }

                        if (newCard.Rarity.Name == 0)
                        {
                            legal.Pauper = true;
                        }

                        newCard.Legality = legal;
                    }

                    if (card.Power == null)
                    {
                        newCard.Power = " ";
                    }

                    if (card.Toughness == null)
                    {
                        newCard.Toughness = " ";
                    }
                }
            }
            #endregion

            return(convertedModel);
        }
Exemplo n.º 15
0
        public DisposableList <Bitmap> CardTemplate(CardStructure structure, CardType type, Race race, bool extra,
                                                    string?name, CardSubType subType, bool twoHanded, Condition condition, string?modifiers, string?center, string?text, string?flavorText, string?scrapped,
                                                    string?lvl, string?winText, string?loseText)
        {
            var bitmaplist = new DisposableList <Bitmap>();

            switch (structure)
            {
            case CardStructure.Normal:
                switch (type)
                {
                case CardType.Action:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Action()));
                    break;

                case CardType.Monster1:

                case CardType.Monster2:

                case CardType.Monster3:

                case CardType.Monster4:

                case CardType.Monster5:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Spell()));
                    break;

                case CardType.Equipment1:

                case CardType.Equipment2:

                case CardType.Equipment3:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Equipment()));
                    break;

                case CardType.Companion:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Soilder()));
                    break;

                case CardType.Library:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Spell()));
                    break;

                case CardType.Bar:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Class()));
                    break;

                case CardType.Duell:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Duell()));
                    break;

                case CardType.Curse:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Desaster()));
                    break;

                case CardType.Blessing:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Animal()));
                    break;

                case CardType.Disaster:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Desaster()));
                    break;

                case CardType.Class:

                case CardType.Tavern:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Class()));
                    break;

                case CardType.Spell:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Spell()));
                    break;

                case CardType.Empty:
                    break;
                }
                bitmaplist.Add(() => _picturesFromArchive.Boarder());
                break;

            case CardStructure.Monster:
                switch (race)
                {
                case Race.Human:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Spell()));
                    break;

                case Race.Soldier:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Soilder()));
                    break;

                case Race.Vampire:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Action()));
                    break;

                case Race.Animal:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Animal()));
                    break;

                case Race.God:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.God()));
                    break;

                case Race.Monster:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Equipment()));
                    break;

                case Race.All:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Class()));
                    break;

                case Race.Rock:
                    bitmaplist.Add(() => _createPicture.BlendingMultiply(() => _picturesFromArchive.Filter(), () => _picturesFromArchive.Rock()));
                    break;

                case Race.Empty:
                    break;
                }
                bitmaplist.Add(() => _picturesFromArchive.Boarder());
                bitmaplist.Add(() => _picturesFromArchive.Win());
                break;
            }

            bitmaplist.Add(() => _drawText.DrawTextASBitmap(structure, name, subType, twoHanded, condition, modifiers, center, text, flavorText, scrapped,
                                                            lvl, winText, loseText, race));

            if (extra)
            {
                bitmaplist.Add(() => _picturesFromArchive.Extra());
            }

            return(bitmaplist);
        }
        public Bitmap DrawTextForNormalCards(string?name, CardSubType subType, bool twoHanded, Condition condition, string?modifiers, string?center, string?text, string?flavorText, string?scrapped)
        {
            const int TextOffset          = 30;
            var       textHigth           = 20;
            var       textHigthFromButtom = 1000 - textHigth;
            var       textBitmap          = new Bitmap(700, 1000);

            textBitmap.SetResolution(120, 120);
            var textRectangle = new RectangleF();

            //FontSize
            var nameFontsize        = 36;
            var cardSubTypeFontsize = 28;
            var twoHandedFontsize   = 28;
            var conditionFontsize   = 28;
            var modifiersFontsize   = 36;
            var centerFontsize      = 28;
            var textFontsize        = 24;
            var flavorTextFontsize  = 18;
            var scrappedFontsize    = 22;

            var fontsizeIsCorrect = false;

            for (var run = 0; !fontsizeIsCorrect; run++)
            {
                var resizedFontsizes = _resizeFont.NewFontSize(run, nameFontsize, cardSubTypeFontsize, twoHandedFontsize, conditionFontsize,
                                                               modifiersFontsize, centerFontsize, textFontsize, flavorTextFontsize, scrappedFontsize);

                fontsizeIsCorrect = _meassureDrawNormalCards.MeassureTextForNormalCards(name, subType, twoHanded, condition, modifiers, center, text, flavorText, scrapped,
                                                                                        resizedFontsizes.nameFontsize, resizedFontsizes.cardSubTypeFontsize, resizedFontsizes.twoHandedFontsize,
                                                                                        resizedFontsizes.conditionFontsize, resizedFontsizes.modifiersFontsize, resizedFontsizes.centerFontsize, resizedFontsizes.textFontsize,
                                                                                        resizedFontsizes.flavorTextFontsize, resizedFontsizes.scrappedFontsize);

                if (fontsizeIsCorrect)
                {
                    nameFontsize        = resizedFontsizes.nameFontsize;
                    cardSubTypeFontsize = resizedFontsizes.cardSubTypeFontsize;
                    twoHandedFontsize   = resizedFontsizes.twoHandedFontsize;
                    conditionFontsize   = resizedFontsizes.conditionFontsize;
                    modifiersFontsize   = resizedFontsizes.modifiersFontsize;
                    centerFontsize      = resizedFontsizes.centerFontsize;
                    textFontsize        = resizedFontsizes.textFontsize;
                    flavorTextFontsize  = resizedFontsizes.flavorTextFontsize;
                    scrappedFontsize    = resizedFontsizes.scrappedFontsize;
                }
            }

            //Graphic
            using (var g = Graphics.FromImage(textBitmap))
            {
                g.SmoothingMode      = SmoothingMode.AntiAlias;
                g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                g.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
                g.PageUnit           = GraphicsUnit.Pixel;
                g.CompositingMode    = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.HighQuality;

                using var formatCentert = new StringFormat()
                      {
                          Alignment = StringAlignment.Center,
                          Trimming  = StringTrimming.EllipsisWord
                      };

                using var formatInlined = new StringFormat()
                      {
                          Trimming = StringTrimming.EllipsisWord
                      };

                //Headline
                using (var useFont = new Font("Segoe Print", nameFontsize, FontStyle.Bold))
                {
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(name, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                    g.DrawString(name, useFont, Brushes.Black, textRectangle, formatCentert);
                }

                //Dividingline
                using var dividingline = _picturesFromArchive.Dividingline();
                g.DrawImage(dividingline, new Point(0, textHigth));
                textHigth += dividingline.Height;

                //CardSubType
                if (subType != CardSubType.Empty)
                {
                    var subTypeDescription = subType.GetDescription();

                    using var useFont      = new Font("Segoe Print", cardSubTypeFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(subTypeDescription, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                    g.DrawString(subTypeDescription, useFont, Brushes.Black, textRectangle, formatCentert);
                }

                if (twoHanded)
                {
                    using var useFont      = new Font("Segoe Print", twoHandedFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString("Zweihändig", useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                    g.DrawString("Zweihändig", useFont, Brushes.Black, textRectangle, formatCentert);
                }

                if (condition != Condition.Empty)
                {
                    var conditionDescription = condition.GetDescription();

                    using var useFont      = new Font("Segoe Print", conditionFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(conditionDescription, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                    g.DrawString(conditionDescription, useFont, Brushes.Black, textRectangle, formatCentert);
                }

                if (modifiers != "")
                {
                    using var useFont      = new Font("Segoe Print", modifiersFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(modifiers, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                    g.DrawString(modifiers, useFont, Brushes.Black, textRectangle, formatCentert);
                }

                if (center != "")
                {
                    using var useFont      = new Font("Segoe Print", centerFontsize, FontStyle.Bold);
                    textRectangle.Location = new Point(TextOffset, textHigth);
                    textRectangle.Size     = new Size(640, (int)g.MeasureString(center, useFont, 640, formatCentert).Height);
                    textHigth = (int)textRectangle.Bottom;
                    g.DrawString(center, useFont, Brushes.Black, textRectangle, formatCentert);
                }

                if (text != "")
                {
                    if (text == null)
                    {
                        text = "";
                    }
                    _drawStringWithTopograpy.DrawStringOnBitmapWithTopograpy(text, g, textHigth, textFontsize,
                                                                             (TextOffset, textBitmap.Width), "Segoe Print");

                    textHigth += (int)Math.Round(_meassureStringWithTopograpy.MeassureStringOnBitmapWithTopograpy(text, g, textHigth, textFontsize,
                                                                                                                  (TextOffset, textBitmap.Width), "Segoe Print"));
                }

                if (scrapped != "")
                {
                    if (scrapped == null)
                    {
                        scrapped = "";
                    }
                    textHigthFromButtom -= (int)Math.Round(_meassureStringWithTopograpy.MeassureStringOnBitmapWithTopograpy(scrapped, g, textHigth, textFontsize,
                                                                                                                            (TextOffset, textBitmap.Width), "Segoe Print"));

                    _drawStringWithTopograpy.DrawStringOnBitmapWithTopograpy(scrapped, g, textHigthFromButtom, scrappedFontsize,
                                                                             (TextOffset, textBitmap.Width), "Segoe Print");

                    //ScappedLine
                    using var scappedLine = _picturesFromArchive.Scrapped();
                    textHigthFromButtom  -= scappedLine.Height;
                    g.DrawImage(scappedLine, new Point(0, textHigthFromButtom));
                }

                if (flavorText != "")
                {
                    using var useFont  = new Font("Segoe Print", flavorTextFontsize, FontStyle.Italic);
                    textRectangle.Size = new Size(640, (int)g.MeasureString(flavorText, useFont, 640, formatInlined).Height);
                    var textBoxHigth = (int)textRectangle.Bottom - (int)textRectangle.Top;
                    textHigthFromButtom   -= textBoxHigth;
                    textRectangle.Location = new Point(TextOffset, textHigthFromButtom);
                    g.DrawString(flavorText, useFont, Brushes.Black, textRectangle, formatInlined);
                }
            }

            return(textBitmap);
        }