public void SetLocalRequiredFarmers(string checkName, IEnumerable <Farmer> required_farmers) { if (!readyChecks.ContainsKey(checkName)) { readyChecks.Add(checkName, new ReadyCheck(checkName)); } readyChecks[checkName].SetRequiredFarmers(required_farmers); }
public void UpdateLocalStockWithSyncedQuanitities(SynchedShop shop, Dictionary <ISalable, int[]> localStock, Dictionary <string, Func <bool> > conditionalItemFilters = null) { List <Item> itemsToRemove = new List <Item>(); NetStringDictionary <int, NetInt> sharedStock = getSharedStock(shop); if (getLastDayUpdated(shop) != Game1.Date.TotalDays) { setLastDayUpdated(shop, Game1.Date.TotalDays); sharedStock.Clear(); foreach (Item item5 in localStock.Keys) { string itemString3 = Utility.getStandardDescriptionFromItem(item5, 1); sharedStock.Add(itemString3, localStock[item5][1]); if (sharedStock[itemString3] != int.MaxValue) { item5.Stack = sharedStock[itemString3]; } } } else { itemsToRemove.Clear(); foreach (Item item4 in localStock.Keys) { string itemString2 = Utility.getStandardDescriptionFromItem(item4, 1); if (sharedStock.ContainsKey(itemString2) && sharedStock[itemString2] > 0) { localStock[item4][1] = sharedStock[itemString2]; if (sharedStock[itemString2] != int.MaxValue) { item4.Stack = sharedStock[itemString2]; } } else { itemsToRemove.Add(item4); } } foreach (Item item3 in itemsToRemove) { localStock.Remove(item3); } } itemsToRemove.Clear(); if (conditionalItemFilters != null) { foreach (Item item2 in localStock.Keys) { string itemString = Utility.getStandardDescriptionFromItem(item2, 1); if (conditionalItemFilters.ContainsKey(itemString) && !conditionalItemFilters[itemString]()) { itemsToRemove.Add(item2); } } foreach (Item item in itemsToRemove) { localStock.Remove(item); } } }
private void LoadRecipes(IContentPack contentPack, IEnumerable <ContentPackDataInfo> sources) { var recipes = (from source in sources from entry in source.Content.Recipes select new { Source = source, Data = entry }).ToArray(); // Create each recipe foreach (var recipe in recipes) { // Create each ingredient IRecipePart[] ingredients = recipe.Data.Ingredients.Select(ConvertPart).ToArray(); // Create each result IRecipePart[] results = recipe.Data.Results.Select(ConvertPart).ToArray(); // Create the recipe ISprite sprite = results.FirstOrDefault()?.Sprite ?? ingredients.FirstOrDefault()?.Sprite ?? throw new InvalidOperationException("Unable to create a sprite for a recipe."); string recipeName = this._api.Items.RegisterCraftingRecipe(new ModRecipe(this._api.TranslationHelper, sprite, results, ingredients, recipe.Data.Name, recipe.Data.IsCooking)); // TODO: Add conditions when the recipe can be added this._api.Owner.Helper.Events.GameLoop.SaveLoaded += (sender, args) => { // Get the target dictionary NetStringDictionary <int, NetInt> targetDictionary = recipe.Data.IsCooking ? Game1.player.craftingRecipes : Game1.player.cookingRecipes; // Add the recipe to the target if (!targetDictionary.ContainsKey(recipeName)) { targetDictionary.Add(recipeName, 0); } }; this._api.Owner.Monitor.Log($" - Added recipe: {recipeName}, Ingredients: {ingredients.Length}, Results: {results.Length}", LogLevel.Debug); } IRecipePart ConvertPart(RecipeData.Part part) { return(part.Match <RecipeData.Part, IRecipePart>() .When <RecipeData.ModPart>(modPart => { if (!this._api.Items.Delegator.TryParseKey(modPart.Id, out ItemKey key)) { key = new ItemKey(contentPack.Manifest, modPart.Id); } return new ModRecipePart(this._api, key, part.Quantity); }) .When <RecipeData.GamePart>(gamePart => gamePart.Type == RecipeData.ItemType.OBJECT, gamePart => new SObjectRecipePart(this._api, gamePart.Id, gamePart.Quantity)) .When <RecipeData.GamePart>(gamePart => gamePart.Type == RecipeData.ItemType.BIGCRAFTABLE, gamePart => new BigCraftableRecipePart(this._api, gamePart.Id, gamePart.Quantity)) .When <RecipeData.GamePart>(gamePart => gamePart.Type == RecipeData.ItemType.WEAPON, gamePart => new WeaponRecipePart(this._api, gamePart.Id, gamePart.Quantity)) .When <RecipeData.GamePart>(gamePart => gamePart.Type == RecipeData.ItemType.HAT, gamePart => new HatRecipePart(this._api, gamePart.Id, gamePart.Quantity)) .ElseThrow(_ => new InvalidOperationException($"Unknown part type: {part.GetType().FullName}"))); } }