private static bool RemoveRequiredItemsFromInventory(GameSession session, RecipeMetadata recipe) { List <Item> playerInventoryItems = new(session.Player.Inventory.Items.Values); List <RecipeItem> ingredients = recipe.GetIngredients(); for (int i = 0; i < ingredients.Count; i++) { RecipeItem ingredient = ingredients.ElementAt(i); Item item = playerInventoryItems.FirstOrDefault(x => x.Id == ingredient.Id); if (item == null) { continue; } // check if whole stack will be used, and remove the item // otherwise we want to just want to subtract the amount if (ingredient.Amount == item.Amount) { InventoryController.Remove(session, item.Uid, out Item _); } else { InventoryController.Update(session, item.Uid, item.Amount - ingredient.Amount); } } return(true); }
private static bool PlayerHasAllIngredients(GameSession session, RecipeMetadata recipe) { List <Item> playerInventoryItems = new(session.Player.Inventory.Items.Values); List <RecipeItem> ingredients = recipe.GetIngredients(); for (int i = 0; i < ingredients.Count; i++) { RecipeItem ingredient = ingredients.ElementAt(i); Item item = playerInventoryItems.FirstOrDefault(x => x.Id == ingredient.Id); if (item != null) { return(item.Amount >= ingredient.Amount); } } return(false); }