예제 #1
0
        public void RegisterBFAVAnimals()
        {
            Dictionary <string, string[]> bfavAnimals = BFAVApi.GetFarmAnimalsByCategory("2");

            foreach (KeyValuePair <string, string[]> pair in bfavAnimals)
            {
                foreach (string type in pair.Value)
                {
                    // Only register types that are not already registered
                    if (!ModApi.IsRegisteredType(type))
                    {
                        string newType = ModEntry.Sanitize(pair.Key);
                        if (newType.Contains("dinosaur"))
                        {
                            ModApi.RegisterAnimalType(type, false, false);
                        }
                        else if (newType.Contains("sheep"))
                        {
                            ModApi.RegisterAnimalType(type, true, true);
                        }
                        else
                        {
                            ModApi.RegisterAnimalType(type);
                        }
                    }
                }
            }
        }
        /// <summary>Checks that the given argument is of a recognized creature group or recognized creature type.</summary>
        /// <param name="arg">The argument to be checked</param>
        /// <returns>Returns true if the given argument is stored in CreatureGroups or is a known FarmAnimal, Pet, or Horse type. Otherwise gives a console error report and returns false.</returns>
        internal static bool EnforceArgTypeGroup(string arg)
        {
            string        type         = ModEntry.Sanitize(arg);
            List <string> handledTypes = ModApi.GetHandledAllTypes();

            if (!ModEntry.CreatureGroups.Contains(type) && !handledTypes.Contains(type))
            {
                ModEntry.SMonitor.Log($"Argument given isn't one of {string.Join(", ", ModEntry.CreatureGroups)}, or a handled creature type. Handled types:\n{string.Join(", ", handledTypes)}", LogLevel.Error);
                return(false);
            }

            return(true);
        }
        /// <summary>Return the information on a pet or horse that the list_animals console command uses.
        internal static string GetPrintString(Character creature)
        {
            List <string> handledTypes = new List <string>();
            string        name         = "";
            string        type         = "";
            int           shortID      = 0;
            int           skinID       = 0;

            switch (creature)
            {
            case Horse horse:
                handledTypes = ModApi.GetHandledHorseTypes();
                name         = horse.Name;
                type         = ModEntry.Sanitize(horse.GetType().Name);
                shortID      = horse.Manners;
                skinID       = ModEntry.HorseSkinMap[horse.Manners];
                break;

            case Pet pet:
                handledTypes = ModApi.GetHandledPetTypes();
                name         = pet.Name;
                type         = ModEntry.Sanitize(pet.GetType().Name);
                shortID      = pet.Manners;
                skinID       = ModEntry.PetSkinMap[pet.Manners];
                break;

            case FarmAnimal animal:
                handledTypes = ModApi.GetHandledAnimalTypes();
                name         = animal.Name;
                type         = ModEntry.Sanitize(animal.type.Value);
                shortID      = ModEntry.AnimalLongToShortIDs[animal.myID.Value];
                skinID       = ModEntry.AnimalSkinMap[animal.myID.Value];
                break;

            default:
                return("");
            }

            if (handledTypes.Contains(type))
            {
                return($"\n # {name}:  Type - {type}\n" +
                       $"Short ID:   {shortID}\n" +
                       $"Skin ID:    {skinID}");
            }
            else
            {
                return($"\n # {name}:  Type - {type}\n" +
                       "Skin type not handled\n");
            }
        }
        /******************
        ** Print Strings
        ******************/

        /// <summary>Prints the the requested creature information from the list_animals console command.</summary>
        internal static void PrintRequestedCreatures(string arg)
        {
            string type = ModEntry.Sanitize(arg);

            // Handle animal portion of "all" argument and the "animal" argument
            if (type == "all" || type == "animal")
            {
                List <string> animalInfo = new List <string>();

                foreach (FarmAnimal animal in ModEntry.GetAnimals())
                {
                    animalInfo.Add(GetPrintString(animal));
                }

                ModEntry.SMonitor.Log("Animals:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", animalInfo)}", LogLevel.Info);
            }
            // Handle coop animal types only
            else if (type == "coop")
            {
                List <string> coopInfo = new List <string>();

                foreach (FarmAnimal animal in ModEntry.GetAnimals())
                {
                    if (animal.isCoopDweller())
                    {
                        coopInfo.Add(GetPrintString(animal));
                    }
                }

                ModEntry.SMonitor.Log("Coop Animals:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", coopInfo)}", LogLevel.Info);
            }
            // Handle barn animal types only
            else if (type == "barn")
            {
                List <string> barnInfo = new List <string>();

                foreach (FarmAnimal animal in ModEntry.GetAnimals())
                {
                    if (!animal.isCoopDweller())
                    {
                        barnInfo.Add(GetPrintString(animal));
                    }
                }

                ModEntry.SMonitor.Log("Barn Animals:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", barnInfo)}", LogLevel.Info);
            }
            // Handle chicken type arguments
            else if (type == "chicken")
            {
                List <string> chickenInfo = new List <string>();

                foreach (FarmAnimal animal in ModEntry.GetAnimals())
                {
                    string potentialChicken = ModEntry.Sanitize(animal.type.Value);

                    if (ModApi.IsChicken(potentialChicken))
                    {
                        chickenInfo.Add(GetPrintString(animal));
                    }
                }
                ModEntry.SMonitor.Log("Chickens:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", chickenInfo)}", LogLevel.Info);
            }
            // Handle cow type arguments
            else if (type == "cow")
            {
                List <string> cowInfo = new List <string>();

                foreach (FarmAnimal animal in ModEntry.GetAnimals())
                {
                    string potentialCow = ModEntry.Sanitize(animal.type.Value);

                    if (ModApi.IsCow(potentialCow))
                    {
                        cowInfo.Add(GetPrintString(animal));
                    }
                }
                ModEntry.SMonitor.Log("Cows:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", cowInfo)}", LogLevel.Info);
            }
            // Handle other animal type arguments
            else if (ModApi.GetHandledAnimalTypes().Contains(type))
            {
                List <string> animalInfo = new List <string>();

                foreach (FarmAnimal animal in ModEntry.GetAnimals())
                {
                    if (type == ModEntry.Sanitize(animal.type.Value))
                    {
                        animalInfo.Add(GetPrintString(animal));
                    }
                }
                ModEntry.SMonitor.Log($"{arg}s:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", animalInfo)}", LogLevel.Info);
            }


            // Handle the pet portion of the "all" argument and the "pet" argument
            if (type == "all" || type == "pet")
            {
                List <string> petInfo = new List <string>();

                foreach (Pet pet in ModEntry.GetPets())
                {
                    petInfo.Add(GetPrintString(pet));
                }

                ModEntry.SMonitor.Log("Pets:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", petInfo)}", LogLevel.Info);
            }
            else if (ModApi.GetHandledPetTypes().Contains(type))
            {
                List <string> petInfo = new List <string>();

                foreach (Pet pet in ModEntry.GetPets())
                {
                    if (type == ModEntry.Sanitize(pet.GetType().Name))
                    {
                        petInfo.Add(GetPrintString(pet));
                    }
                }
                ModEntry.SMonitor.Log($"{arg}s:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", petInfo)}", LogLevel.Info);
            }


            // Handle the horse portion of the "all" argument and the horse argument
            if (type == "all" || ModApi.GetHandledHorseTypes().Contains(type))
            {
                List <string> horseInfo = new List <string>();

                foreach (Horse horse in ModEntry.GetHorses())
                {
                    if (horse.Manners != 0 && horse.Manners != WildHorse.WildID)
                    {
                        horseInfo.Add(GetPrintString(horse));
                    }
                }

                ModEntry.SMonitor.Log("Horses:", LogLevel.Alert);
                ModEntry.SMonitor.Log($"{string.Join(", ", horseInfo)}", LogLevel.Info);
            }
        }