/// <summary>Adds a produce to a collection.</summary> /// <param name="produceToAdd">The produce to add.</param> /// <param name="produces">The collection to add the produce to.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="produceToAdd"/> or <paramref name="produces"/> is <see langword="null"/>.</exception> private void AddProduce(ParsedAnimalProduce produceToAdd, List <AnimalProduce> produces) { // validate if (produceToAdd == null) { throw new ArgumentNullException(nameof(produceToAdd)); } if (produces == null) { throw new ArgumentNullException(nameof(produces)); } // add produce // ensure the produce being added has a valid action if (produceToAdd.Action != Action.Add) { ModEntry.Instance.Monitor.Log($"Cannot have a subtype action other than 'Add' when adding an animal", LogLevel.Error); return; } // ensure produce doesn't already exist if (produces.Any(produce => produce.UniqueName.ToLower() == produceToAdd.UniqueName.ToLower())) { ModEntry.Instance.Monitor.Log($"Cannot add produce to animal as animal already has a produce with the unique name: {produceToAdd.UniqueName}", LogLevel.Error); return; } // ensure a tool is specified if needed if (produceToAdd.HarvestType == HarvestType.Tool && string.IsNullOrWhiteSpace(produceToAdd.ToolName)) { ModEntry.Instance.Monitor.Log($"Cannot add produce to animal as no tool was specified but the harvest type is 'Tool'", LogLevel.Error); return; } var defaultProductId = ResolveToken(produceToAdd.DefaultProductId ?? "-1"); var upgradedProductId = ResolveToken(produceToAdd.UpgradedProductId ?? "-1"); produces.Add(new AnimalProduce(produceToAdd.UniqueName, defaultProductId, produceToAdd.DefaultProductMinFriendship ?? 0, produceToAdd.DefaultProductMaxFriendship ?? 1000, upgradedProductId, produceToAdd.UpgradedProductMinFriendship ?? 200, produceToAdd.UpgradedProductMaxFriendship ?? 1000, produceToAdd.PercentChanceForUpgradedProduct, produceToAdd.UpgradedProductIsRare ?? false, produceToAdd.HarvestType ?? HarvestType.Lay, produceToAdd.DaysToProduce ?? 1, produceToAdd.ProduceFasterWithCoopMaster ?? false, produceToAdd.ProduceFasterWithShepherd ?? false, produceToAdd.ToolName, produceToAdd.ToolHarvestSound, produceToAdd.Amount ?? 1, produceToAdd.Seasons, produceToAdd.PercentChance ?? 100, produceToAdd.PercentChanceForOneExtra ?? 0, produceToAdd.RequiresMale, produceToAdd.RequiresCoopMaster, produceToAdd.RequiresShepherd, produceToAdd.StandardQualityOnly ?? false, produceToAdd.DoNotAllowDuplicates ?? false, produceToAdd.ShowHarvestableSpriteSheet ?? true)); }
/// <summary>Edits a produce.</summary> /// <param name="internalAnimalName">The internal name of the animal containing the subtype to change.</param> /// <param name="internalSubtypeName">The internal name of the subtype to change.</param> /// <param name="newProduceValues">The new produce values.</param> private void EditProduce(string internalAnimalName, string internalSubtypeName, ParsedAnimalProduce newProduceValues) { // validate if (internalAnimalName == null) { throw new ArgumentNullException(nameof(internalAnimalName)); } if (internalSubtypeName == null) { throw new ArgumentNullException(nameof(internalSubtypeName)); } if (newProduceValues == null) { throw new ArgumentNullException(nameof(newProduceValues)); } var animal = ModEntry.Instance.Api.GetAnimalByInternalName(internalAnimalName); if (animal == null) { ModEntry.Instance.Monitor.Log($"Couldn't find animal with internal name of: {internalAnimalName} while editing a subtype with internal name of: {internalSubtypeName}", LogLevel.Error); return; } var subtype = animal.Subtypes.FirstOrDefault(st => st.InternalName.ToLower() == internalSubtypeName.ToLower()); if (subtype == null) { ModEntry.Instance.Monitor.Log($"Couldn't find animal subtype with internal name of: {internalSubtypeName} in animal with internal name of: {internalAnimalName} while trying to edit it", LogLevel.Error); return; } var produce = subtype.Produce.FirstOrDefault(p => p.UniqueName.ToLower() == newProduceValues.UniqueName.ToLower()); if (produce == null) { ModEntry.Instance.Monitor.Log($"Couldn't find produce with a unique name of: {newProduceValues.UniqueName} in animal subtype with internal name of: {internalSubtypeName} in animal with internal name of: {internalAnimalName} while trying to edit it", LogLevel.Error); return; } // edit produce produce.DefaultProductMinFriendship = newProduceValues.DefaultProductMinFriendship ?? produce.DefaultProductMinFriendship; produce.DefaultProductMaxFriendship = newProduceValues.DefaultProductMaxFriendship ?? produce.DefaultProductMaxFriendship; produce.UpgradedProductMinFriendship = newProduceValues.UpgradedProductMinFriendship ?? produce.UpgradedProductMinFriendship; produce.UpgradedProductMaxFriendship = newProduceValues.UpgradedProductMaxFriendship ?? produce.UpgradedProductMaxFriendship; produce.PercentChanceForUpgradedProduct = newProduceValues.PercentChanceForUpgradedProduct ?? produce.PercentChanceForUpgradedProduct; produce.UpgradedProductIsRare = newProduceValues.UpgradedProductIsRare ?? produce.UpgradedProductIsRare; produce.HarvestType = newProduceValues.HarvestType ?? produce.HarvestType; produce.DaysToProduce = newProduceValues.DaysToProduce ?? produce.DaysToProduce; produce.ProduceFasterWithCoopMaster = newProduceValues.ProduceFasterWithCoopMaster ?? produce.ProduceFasterWithCoopMaster; produce.ProduceFasterWithShepherd = newProduceValues.ProduceFasterWithShepherd ?? produce.ProduceFasterWithShepherd; produce.ToolName = newProduceValues.ToolName ?? produce.ToolName; produce.ToolHarvestSound = newProduceValues.ToolHarvestSound ?? produce.ToolHarvestSound; produce.Amount = newProduceValues.Amount ?? produce.Amount; produce.Seasons = newProduceValues.Seasons ?? produce.Seasons; produce.PercentChance = newProduceValues.PercentChance ?? produce.PercentChance; produce.PercentChanceForOneExtra = newProduceValues.PercentChanceForOneExtra ?? produce.PercentChanceForOneExtra; produce.RequiresMale = newProduceValues.RequiresMale ?? produce.RequiresMale; produce.RequiresCoopMaster = newProduceValues.RequiresCoopMaster ?? produce.RequiresCoopMaster; produce.RequiresShepherd = newProduceValues.RequiresShepherd ?? produce.RequiresShepherd; produce.StandardQualityOnly = newProduceValues.StandardQualityOnly ?? produce.StandardQualityOnly; produce.DoNotAllowDuplicates = newProduceValues.DoNotAllowDuplicates ?? produce.DoNotAllowDuplicates; produce.ShowHarvestableSpriteSheet = newProduceValues.ShowHarvestableSpriteSheet ?? produce.ShowHarvestableSpriteSheet; }