public void ReLoadDefinitions() { Definitions.Where(n => !Recipes.Any(o => o.RecipeID == n.RecipeID)).ToList().ForEach(x => { Recipes.Add(x); }); }
public void LearnRecipe(Recipe recipe) { if (!Recipes.Any(r => r.ID == recipe.ID)) { Recipes.Add(recipe); } }
public void CheckIfDbEmpty() { if (!Recipes.Any()) { OnModelCreating(null); } }
/********* ** Private Methods *********/ /// <summary>Invoked when the player loads a save.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> /// <remarks>This is used to load the content packs.</remarks> private void OnSaveLoaded(object sender, SaveLoadedEventArgs e) { // clear all old recipes as to not duplicate Recipes.Clear(); LoadDefaultRecipes(); // load content packs foreach (var contentPack in this.Helper.ContentPacks.GetOwned()) { try { this.Monitor.Log($"Loading content pack: {contentPack.Manifest.Name}", LogLevel.Info); // ensure content.json exists var contentFile = Path.Combine(contentPack.DirectoryPath, "content.json"); if (!File.Exists(contentFile)) { this.Monitor.Log($"Couldn't find content.json file, skipping", LogLevel.Error); continue; } // load recipes var recipes = contentPack.ReadJsonFile <List <ParsedRecipe> >("content.json") ?? new List <ParsedRecipe>(); foreach (var recipe in recipes) { // resolve and validate input and ouput items var inputId = ResolveToken(recipe.InputId); var outputId = ResolveToken(recipe.Output?.Id ?? "-1"); if (inputId == -1 || outputId == -1) { this.Monitor.Log($"Cannot load recipe: {recipe} as the input or output was invalid, this recipe will be skipped", LogLevel.Error); continue; } // ensure no recipes with this input id already exist if (Recipes.Any(r => r.InputId == inputId)) { this.Monitor.Log($"A recipe with an input product id of: {inputId} has already been added, this recipe will be skipped", LogLevel.Warn); continue; } Recipes.Add(new Recipe(inputId, new Output(outputId, recipe.Output.Amount))); } } catch (Exception ex) { this.Monitor.Log($"Failed to load content pack: {ex}", LogLevel.Error); } } }
public override bool OnDragDrop(Mobile from, Item dropped) { if (!IsChildOf(from.Backpack) && !IsLockedDown) { from.SendLocalizedMessage(1158823); // You must have the book in your backpack to add recipes to it. return(false); } else if (dropped is RecipeScroll) { RecipeScroll recipe = dropped as RecipeScroll; if (Recipes.Any(x => x.RecipeID == recipe.RecipeID)) { Recipes.ForEach(x => { if (x.RecipeID == recipe.RecipeID) { x.Amount += 1; } }); InvalidateProperties(); from.SendLocalizedMessage(1158826); // Recipe added to the book. if (from is PlayerMobile) { from.SendGump(new RecipeBookGump((PlayerMobile)from, this)); } dropped.Delete(); return(true); } else { from.SendLocalizedMessage(1158825); // That is not a recipe. return(false); } } else { from.SendLocalizedMessage(1158825); // That is not a recipe. return(false); } }
private async Task GetClosestAsync() { if (IsBusy || Recipes == null || !Recipes.Any()) { return; } try { if (await PermissionsManager.RequestPermissions(new[] { Permission.Location })) { var location = await Geolocation.GetLastKnownLocationAsync(); if (location == null) { location = await Geolocation.GetLocationAsync(new GeolocationRequest { DesiredAccuracy = GeolocationAccuracy.Medium, Timeout = TimeSpan.FromSeconds(30) }); } var closestRecipe = Recipes .OrderBy(m => location.CalculateDistance(new Location(m.Latitude, m.Longitude), DistanceUnits.Miles)) .FirstOrDefault(); if (closestRecipe == null) { await Application.Current.MainPage.DisplayAlert("No recipe found", "Something went wrong !", "OK"); } else { await Application.Current.MainPage.DisplayAlert("Closest recipe", closestRecipe.Name + " at " + closestRecipe.Location, "OK"); } } } catch (Exception ex) { Debug.WriteLine($"Unable to query location: {ex.Message}"); await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK"); } }