示例#1
0
        /// <summary>Edits a subtype.</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="newSubtypeValues">The new subtype values.</param>
        /// <param name="subtypeSprites">The subtype sprites and corresponding names of the animal type.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="internalAnimalName"/>, <paramref name="internalSubtypeName"/>, or <paramref name="newSubtypeValues"/> is <see langword="null"/>.</exception>
        private void EditSubtype(string internalAnimalName, string internalSubtypeName, ParsedCustomAnimalType newSubtypeValues)
        {
            // validate
            if (internalAnimalName == null)
            {
                throw new ArgumentNullException(nameof(internalAnimalName));
            }

            if (internalSubtypeName == null)
            {
                throw new ArgumentNullException(nameof(internalSubtypeName));
            }

            if (newSubtypeValues == null)
            {
                throw new ArgumentNullException(nameof(newSubtypeValues));
            }

            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} while trying to edit it", 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;
            }

            // edit subtype
            subtype.Name                     = newSubtypeValues.Name ?? subtype.Name;
            subtype.IsBuyable                = newSubtypeValues.IsBuyable ?? subtype.IsBuyable;
            subtype.IsIncubatable            = newSubtypeValues.IsIncubatable ?? subtype.IsIncubatable;
            subtype.AllowForageRepeats       = newSubtypeValues.AllowForageRepeats ?? subtype.AllowForageRepeats;
            subtype.DaysTillMature           = newSubtypeValues.DaysTillMature ?? subtype.DaysTillMature;
            subtype.SoundId                  = newSubtypeValues.SoundId ?? subtype.SoundId;
            subtype.FrontAndBackSpriteWidth  = newSubtypeValues.FrontAndBackSpriteWidth ?? subtype.FrontAndBackSpriteWidth;
            subtype.FrontAndBackSpriteHeight = newSubtypeValues.FrontAndBackSpriteHeight ?? subtype.FrontAndBackSpriteHeight;
            subtype.SideSpriteWidth          = newSubtypeValues.SideSpriteWidth ?? subtype.SideSpriteWidth;
            subtype.SideSpriteHeight         = newSubtypeValues.SideSpriteHeight ?? subtype.SideSpriteHeight;
            subtype.MeatId                   = (newSubtypeValues.MeatId != null) ? ResolveToken(newSubtypeValues.MeatId) : subtype.MeatId;
            subtype.HappinessDrain           = newSubtypeValues.HappinessDrain ?? subtype.HappinessDrain;
            subtype.FullnessGain             = newSubtypeValues.FullnessGain ?? subtype.FullnessGain;
            subtype.HappinessGain            = newSubtypeValues.HappinessGain ?? subtype.HappinessGain;
            subtype.AutoPetterFriendshipGain = newSubtypeValues.AutoPetterFriendshipGain ?? subtype.AutoPetterFriendshipGain;
            subtype.HandPetFriendshipGain    = newSubtypeValues.HandPetFriendshipGain ?? subtype.HandPetFriendshipGain;
            subtype.WalkSpeed                = newSubtypeValues.WalkSpeed ?? subtype.WalkSpeed;
            subtype.BabySellPrice            = newSubtypeValues.BabySellPrice ?? subtype.BabySellPrice;
            subtype.AdultSellPrice           = newSubtypeValues.AdultSellPrice ?? subtype.AdultSellPrice;
            subtype.IsMale                   = newSubtypeValues.IsMale ?? subtype.IsMale;
            subtype.SeasonsAllowedOutdoors   = newSubtypeValues.SeasonsAllowedOutdoors ?? subtype.SeasonsAllowedOutdoors;

            // order the produce by action first (so they get added first, then edited, then deleted)
            if (newSubtypeValues.Produce != null)
            {
                foreach (var produce in newSubtypeValues.Produce.OrderBy(produce => produce.Action))
                {
                    switch (produce.Action)
                    {
                    case (Action.Add):
                        AddProduce(produce, subtype.Produce);
                        break;

                    case (Action.Edit):
                        EditProduce(internalAnimalName, internalSubtypeName, produce);
                        break;

                    case (Action.Delete):
                        DeleteProduce(internalAnimalName, internalSubtypeName, produce.UniqueName);
                        break;

                    default:
                        ModEntry.Instance.Monitor.Log($"Action: {produce.Action} on animal: {animal.InternalName} subtype: {subtype.InternalName} produce: <DefaultProductId: {produce.DefaultProductId}, UpgradedProductId: {produce.UpgradedProductId}> is invalid", LogLevel.Error);
                        break;
                    }
                }
            }
        }
示例#2
0
        /*********
        ** Private Methods
        *********/
        /// <summary>Validates and adds a subtype to a collection.</summary>
        /// <param name="internalAnimalName">The internal name of the animal.</param>
        /// <param name="internalSubtypeName">The internal name of the animal subtype.</param>
        /// <param name="subtypeToAdd">The subtype to add.</param>
        /// <param name="subtypeSprites">The subtype sprites and corresponding names of the animal type.</param>
        /// <param name="animalTypes">The collection to add the created subtype to.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="internalAnimalName"/>, <paramref name="internalSubtypeName"/>, <paramref name="subtypeToAdd"/>, <paramref name="subtypeSprites"/>, or <paramref name="animalTypes"/> is <see langword="null"/>.</exception>
        private void AddSubtype(string internalAnimalName, string internalSubtypeName, ParsedCustomAnimalType subtypeToAdd, List <CustomAnimalType> animalTypes)
        {
            // validate
            if (internalAnimalName == null)
            {
                throw new ArgumentNullException(nameof(internalAnimalName));
            }

            if (internalSubtypeName == null)
            {
                throw new ArgumentNullException(nameof(internalSubtypeName));
            }

            if (subtypeToAdd == null)
            {
                throw new ArgumentNullException(nameof(subtypeToAdd));
            }

            if (animalTypes == null)
            {
                throw new ArgumentNullException(nameof(animalTypes));
            }

            if (ModEntry.Instance.Api.GetAnimalSubtypeByInternalName(internalSubtypeName) != null)
            {
                ModEntry.Instance.Monitor.Log($"A subtype with the internal name: {internalSubtypeName} already exists", LogLevel.Error);
                return;
            }

            // ensure the subtype being added has a valid action
            if (subtypeToAdd.Action != Action.Add)
            {
                ModEntry.Instance.Monitor.Log($"Cannot have a subtype action other than 'Add' when adding an animal (in subtype: {subtypeToAdd.InternalName})", LogLevel.Error);
                return;
            }

            // convert produce data
            var produce = new List <AnimalProduce>();

            if (subtypeToAdd.Produce != null)
            {
                foreach (var produceToAdd in subtypeToAdd.Produce)
                {
                    AddProduce(produceToAdd, produce);
                }
            }

            animalTypes.Add(new CustomAnimalType(internalSubtypeName, subtypeToAdd.Name, subtypeToAdd.IsBuyable ?? true, subtypeToAdd.IsIncubatable ?? true, produce, subtypeToAdd.AllowForageRepeats ?? true, subtypeToAdd.DaysTillMature ?? 3, subtypeToAdd.SoundId, subtypeToAdd.FrontAndBackSpriteWidth ?? 16, subtypeToAdd.FrontAndBackSpriteHeight ?? 16, subtypeToAdd.SideSpriteWidth ?? 16, subtypeToAdd.SideSpriteHeight ?? 16, ResolveToken(subtypeToAdd.MeatId), subtypeToAdd.HappinessDrain ?? 7, subtypeToAdd.FullnessGain ?? 255, subtypeToAdd.HappinessGain ?? (byte)(40 - subtypeToAdd.HappinessDrain), subtypeToAdd.AutoPetterFriendshipGain ?? 7, subtypeToAdd.HandPetFriendshipGain ?? 15, subtypeToAdd.WalkSpeed ?? 2, subtypeToAdd.BabySellPrice, subtypeToAdd.AdultSellPrice, subtypeToAdd.IsMale, subtypeToAdd.SeasonsAllowedOutdoors));
        }