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 RequestLimitedNutDrops(string key, GameLocation location, int x, int y, int limit, int reward_amount = 1) { if (!limitedNutDrops.ContainsKey(key) || limitedNutDrops[key] < limit) { if (location == null) { requestNutDrop.Fire(new NutDropRequest(key, null, new Point(x, y), limit, reward_amount)); } else { requestNutDrop.Fire(new NutDropRequest(key, location.NameOrUniqueName, new Point(x, y), limit, reward_amount)); } } }
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); } } }
public void OnItemPurchased(SynchedShop shop, ISalable item, int amount) { NetStringDictionary <int, NetInt> sharedStock = getSharedStock(shop); string itemString = Utility.getStandardDescriptionFromItem(item as Item, 1); if (sharedStock.ContainsKey(itemString) && sharedStock[itemString] != int.MaxValue && (!(item is Object) || !(item as Object).IsRecipe)) { sharedStock[itemString] -= amount; } }
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}"))); } }
/// <summary>Allows generic interactions with NPCs in <see cref="MovieTheater"/> under certain conditions.</summary> /// <param name="__instance">The <see cref="MovieTheater"/> instance.</param> /// <param name="tileLocation">The tile targeted by this action.</param> /// <param name="viewport">The viewport of the player performing this action.</param> /// <param name="who">The player performing this action.</param> /// <param name="____playerInvitedPatrons">The list of NPCs invited by the player. Non-public field for this <see cref="MovieTheater"/> instance.</param> /// <param name="____characterGroupLookup">The list of NPC patrons currently present. Non-public field for this <see cref="MovieTheater"/> instance.</param> /// <param name="__result">The result of the original method.</param> private static void MovieTheater_checkAction(MovieTheater __instance, Location tileLocation, xTile.Dimensions.Rectangle viewport, Farmer who, NetStringDictionary <int, NetInt> ____playerInvitedPatrons, NetStringDictionary <bool, NetBool> ____characterGroupLookup, ref bool __result) { try { if (__result == true) //if the original method return true { PropertyValue action = null; __instance.map.GetLayer("Buildings").PickTile(new Location(tileLocation.X * 64, tileLocation.Y * 64), viewport.Size)?.Properties.TryGetValue("Action", out action); //get this tile's Action property if it exists if (action == null) //if this tile does NOT have an Action property { Microsoft.Xna.Framework.Rectangle tileRect = new Microsoft.Xna.Framework.Rectangle(tileLocation.X * 64, tileLocation.Y * 64, 64, 64); //get this tile's pixel area foreach (NPC npc in __instance.characters) //for each NPC in this location { if (npc.isVillager() && npc.GetBoundingBox().Intersects(tileRect)) //if this NPC is a villager and targeted by this action { string npcName = npc.Name; if (____playerInvitedPatrons.ContainsKey(npcName) == false && ____characterGroupLookup.ContainsKey(npcName) == false) //if this NPC is NOT here as a patron (i.e. does not have patron-specific dialogue or behavior) { __result = npc.checkAction(who, __instance); //check action on this NPC (i.e. talk/give gifts/etc) and override the result return; } } } } } } catch (Exception ex) { Monitor.LogOnce($"Harmony patch \"{nameof(HarmonyPatch_MovieTheaterNPCs)}\" has encountered an error. Postfix \"{nameof(MovieTheater_checkAction)}\" might malfunction or revert to default behavior. Full error message: \n{ex.ToString()}", LogLevel.Error); return; //run the original method } }
public virtual string Parse(string data) { data = data.Trim(); GetData(); data = MakeLocalizationReplacements(data); int open_index = 0; do { open_index = data.LastIndexOf('{'); if (open_index < 0) { continue; } int close_index = data.IndexOf('}', open_index); if (close_index == -1) { return(data); } string inner = data.Substring(open_index + 1, close_index - open_index - 1); string value = inner; string key = inner; string subkey = null; if (inner.Contains(":")) { string[] split2 = inner.Split(':'); key = split2[0]; if (split2.Length > 1) { subkey = split2[1]; } } if (_orderData.RandomizedElements != null) { if (preSelectedItems.ContainsKey(key)) { Object requested_item = new Object(Vector2.Zero, preSelectedItems[key], 0); switch (subkey) { case "Text": value = requested_item.DisplayName; break; case "TextPlural": value = Lexicon.makePlural(requested_item.DisplayName); break; case "TextPluralCapitalized": value = Utility.capitalizeFirstLetter(Lexicon.makePlural(requested_item.DisplayName)); break; case "Tags": { string alternate_id = "id_" + Utility.getStandardDescriptionFromItem(requested_item, 0, '_'); alternate_id = alternate_id.Substring(0, alternate_id.Length - 2).ToLower(); value = alternate_id; break; } case "Price": value = string.Concat(requested_item.sellToStorePrice(-1L)); break; } } else if (selectedRandomElements.ContainsKey(key)) { foreach (RandomizedElement randomized_element in _orderData.RandomizedElements) { if (randomized_element.Name == key) { value = MakeLocalizationReplacements(randomized_element.Values[selectedRandomElements[key]].Value); break; } } } } if (subkey != null) { string[] split = value.Split('|'); for (int i = 0; i < split.Length; i += 2) { if (i + 1 <= split.Length && split[i] == subkey) { value = split[i + 1]; break; } } } data = data.Remove(open_index, close_index - open_index + 1); data = data.Insert(open_index, value); }while (open_index >= 0); return(data); }