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";
public static string GetDragonImageUrlFromScryId(int scryId) { var scryUrl = $"https://www1.flightrising.com/scrying/predict?morph={scryId}"; using (var client = new WebClient()) { var htmlPage = client.DownloadString(scryUrl); return(GeneratedFRHelpers.GenerateDragonImageUrl(GetRegexValue(Regex.Match(htmlPage, @"breed=(\d+)")), GetRegexValue(Regex.Match(htmlPage, @"gender=(\d+)")), 1, GetRegexValue(Regex.Match(htmlPage, @"bodygene=(\d+)")), GetRegexValue(Regex.Match(htmlPage, @"body=(\d+)")), GetRegexValue(Regex.Match(htmlPage, @"winggene=(\d+)")), GetRegexValue(Regex.Match(htmlPage, @"wings=(\d+)")), GetRegexValue(Regex.Match(htmlPage, @"tertgene=(\d+)")), GetRegexValue(Regex.Match(htmlPage, @"tert=(\d+)")), GetRegexValue(Regex.Match(htmlPage, @"element=(\d+)")), GetRegexValue(Regex.Match(htmlPage, @"eyetype=(\d+)")))); } }
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); }