Пример #1
0
        private static async Task <PreviewResult> GenerateOrFetchPreview(PreviewResult result, string skinId, int?version, DragonCache dragon, bool isDressingRoom, bool swapSilhouette, bool force)
        {
            var azureImageService = new AzureImageService();

            using (var ctx = new DataContext())
            {
                Skin skin;
                var  skins = ctx.Skins.Where(x => x.GeneratedId == skinId);
                if (version == null)
                {
                    skin    = skins.OrderByDescending(x => x.Version).FirstOrDefault();
                    version = skin.Version;
                }
                else
                {
                    skin = skins.FirstOrDefault(x => x.Version == version);
                }

                if (skin == null)
                {
                    return(result.WithErrorMessage("Skin not found."));
                }

                result.Skin = skin;

                if (dragon == null)
                {
                    dragon = FRHelpers.ParseUrlForDragon(string.Format(FRHelpers.DressingRoomDummyUrl, skin.DragonType, skin.GenderType), skinId, version);
                }

                result.Dragon = dragon;

                if (dragon.Age == Age.Hatchling)
                {
                    return(result.WithErrorMessage("Skins can only be previewed on adult dragons."));
                }

                if (swapSilhouette)
                {
                    var swappedDragon = FRHelpers.ParseUrlForDragon(GeneratedFRHelpers.GenerateDragonImageUrl(dragon, swapSilhouette));
                    swappedDragon.FRDragonId = dragon.FRDragonId;
                    dragon = swappedDragon;
                }

                if (skin.DragonType != (int)dragon.DragonType)
                {
                    return(result.WithErrorMessage("This skin is meant for a {0} {1}, the dragon you provided is a {2} {3}.", (DragonType)skin.DragonType, (Gender)skin.GenderType, dragon.DragonType, dragon.Gender));
                }

                if (skin.GenderType != (int)dragon.Gender)
                {
                    return(result.WithErrorMessage("This skin is meant for a {0}, the dragon you provided is a {1}.", (Gender)skin.GenderType, dragon.Gender));
                }
            }

            Bitmap dragonImage = null;

            var azureImagePreviewPath = $@"previews\{skinId}\{(version == 1 ? "" : $@"{version}\")}{dragon.GetFileName()}.png";
Пример #2
0
        public static async Task <PreviewResult> GenerateOrFetchPreview(string skinId, int dragonId, bool swapSilhouette = false, bool force = false, int?version = null)
        {
            var result = new PreviewResult(PreviewSource.DragonId)
            {
                Forced = force
            };
            var dragonUrl = FRHelpers.GetDragonImageUrlFromDragonId(dragonId);

            if (dragonUrl.StartsWith(".."))
            {
                return(result.WithErrorMessage("{0} appears to be an invalid dragon id", dragonId));
            }

            var dragon = FRHelpers.ParseUrlForDragon(dragonUrl);

            dragon.FRDragonId = dragonId;
            return(await GenerateOrFetchPreview(result, skinId, version, dragon, false, swapSilhouette, force));
        }
Пример #3
0
        public static async Task <PreviewResult> GenerateOrFetchPreview(string skinId, string dragonUrl, bool force = false, int?version = null)
        {
            PreviewResult result = null;

            if (dragonUrl.Contains("/dgen/dressing-room"))
            {
                // Dressing room link
                result = new PreviewResult(PreviewSource.DressingRoom)
                {
                    Forced = force
                };

                var         apparelDragon = FRHelpers.ParseUrlForDragon(dragonUrl);
                DragonCache dragon;
                if (dragonUrl.Contains("/dgen/dressing-room/dummy"))
                {
                    dragon = FRHelpers.ParseUrlForDragon(dragonUrl);
                }
                else if (dragonUrl.Contains("dgen/dressing-room/scry"))
                {
                    var scryId  = int.Parse(Regex.Match(dragonUrl, @"sdid=([\d]*)").Groups[1].Value);
                    var scryUrl = FRHelpers.GetDragonImageUrlFromScryId(scryId);
                    dragon = FRHelpers.ParseUrlForDragon(scryUrl);
                }
                else
                {
                    var dragonId = int.Parse(Regex.Match(dragonUrl, @"did=([\d]*)").Groups[1].Value);
                    dragon = FRHelpers.GetDragonFromDragonId(dragonId);
                }

                if (dragon.DragonType.IsAncientBreed())
                {
                    return(result.WithErrorMessage("Ancient breeds cannot wear apparal."));
                }

                dragon.Apparel = apparelDragon.Apparel;
                if (dragon.GetApparel().Length == 0)
                {
                    return(result.WithErrorMessage("This dressing room URL contains no apparel."));
                }

                result = await GenerateOrFetchPreview(result, skinId, version, dragon, true, false, force);
            }
            else if (dragonUrl.Contains("dgen/preview/dragon"))
            {
                // Scry image link
                result = new PreviewResult(PreviewSource.ScryImage)
                {
                    Forced = force
                };

                var dragon = FRHelpers.ParseUrlForDragon(dragonUrl);
                result = await GenerateOrFetchPreview(result, skinId, version, dragon, false, false, force);
            }
            else if (dragonUrl.Contains("scrying/predict"))
            {
                result = new PreviewResult(PreviewSource.ScryLink)
                {
                    Forced = force
                };

                DragonCache dragon;
                var         scryId = Regex.Match(dragonUrl, @"morph=(\d*)");
                if (scryId.Success)
                {
                    // Saved morph link
                    var scryUrl = FRHelpers.GetDragonImageUrlFromScryId(int.Parse(scryId.Groups[1].Value));
                    dragon = FRHelpers.ParseUrlForDragon(scryUrl);
                }
                else
                {
                    // Scry predict link
                    dragon = FRHelpers.ParseUrlForDragon(GeneratedFRHelpers.GenerateDragonImageUrl(FRHelpers.ParseUrlForDragon(dragonUrl, forced: true)));
                }

                result = await GenerateOrFetchPreview(result, skinId, version, dragon, false, false, force);
            }
            else
            {
                return(new PreviewResult(PreviewSource.Unknown).WithErrorMessage("The URL provided is not valid."));
            }

            result.DragonUrl = dragonUrl;
            return(result);
        }