Пример #1
0
        /// <summary>
        /// Given the ID for an animal, pet, or horse, and that creature's type, return the AnimalSkin mapped to that creature.
        /// Return null if the creature type isn't handled.
        /// </summary>
        internal AnimalSkin GetSkin(Character creature)
        {
            switch (creature)
            {
            case Horse horse:
                // No horse skins are loaded
                if (HorseAssets[Sanitize(horse.GetType().Name)].Count == 0)
                {
                    return(null);
                }

                // A wild horse is being checked
                if (horse.Manners == WildHorse.WildID)
                {
                    this.Monitor.Log($"Wild ID: {Creator.HorseInfo.SkinID}", LogLevel.Info);
                    return(GetSkinFromID(horse.GetType().Name, Creator.HorseInfo.SkinID));
                }
                // Horse is not in system
                else if (horse.Manners == 0 || !HorseSkinMap.ContainsKey(horse.Manners))
                {
                    this.Monitor.Log($"Horse not in system: {horse.Name}", LogLevel.Error);
                    return(null);
                }

                // Ensure skin ID given is a valid number for the given horse type
                int horseSkinID = HorseSkinMap[horse.Manners];
                if (horseSkinID < 1 || horseSkinID > HorseAssets[Sanitize(horse.GetType().Name)].Count)
                {
                    this.Monitor.Log($"{horse.Name}'s skin ID no longer exists in `/assets/skins`. Skin will be randomized.", LogLevel.Alert);
                    horseSkinID = SetRandomSkin(horse);
                }

                // Horse has a skin. Return it.
                return(GetSkinFromID(horse.GetType().Name, horseSkinID));

            case Pet pet:
                string petType = Sanitize(pet.GetType().Name);

                // Break out of unhandled types
                if (!ModApi.GetHandledPetTypes().Contains(petType))
                {
                    break;
                }
                else if (PetAssets[Sanitize(pet.GetType().Name)].Count == 0)
                {
                    return(null);
                }

                // Pet is not in system
                if (pet.Manners == 0 || !PetSkinMap.ContainsKey(pet.Manners))
                {
                    this.Monitor.Log($"Pet not in system: {pet.Name}", LogLevel.Error);
                    return(null);
                }

                // Ensure skin ID given is a current valid number for the given pet type
                int petSkinID = PetSkinMap[pet.Manners];
                if (petSkinID < 1 || petSkinID > PetAssets[petType].Count)
                {
                    this.Monitor.Log($"{pet.Name}'s skin ID no longer exists in `/assets/skins`. Skin will be randomized.", LogLevel.Alert);
                    petSkinID = SetRandomSkin(pet);
                }
                return(GetSkinFromID(petType, petSkinID));

            case FarmAnimal animal:
                string animalType = Sanitize(animal.type.Value);

                // Break out of unhandled types
                if (!ModApi.GetHandledAnimalTypes().Contains(animalType))
                {
                    break;
                }
                else if (AnimalAssets[Sanitize(animal.type.Value)].Count == 0)
                {
                    return(null);
                }

                // Set sub-type if applicable
                if (ModApi.HasBabySprite(animalType) && animal.age.Value < animal.ageWhenMature.Value)
                {
                    animalType = "baby" + animalType;
                }
                else if (ModApi.HasShearedSprite(animalType) && animal.currentProduce.Value <= 0)
                {
                    animalType = "sheared" + animalType;
                }

                // Animal is not in system
                if (!AnimalSkinMap.ContainsKey(animal.myID.Value))
                {
                    return(null);
                }

                // Ensure skin ID given is a current valid number for the given animal type
                int animalSkinID = AnimalSkinMap[animal.myID.Value];
                if (animalSkinID < 1 || animalSkinID > AnimalAssets[animalType].Count)
                {
                    this.Monitor.Log($"{animal.Name}'s skin ID is no longer exists in `/assets/skins`. Skin will be randomized.", LogLevel.Alert);
                    animalSkinID = SetRandomSkin(animal);
                }
                return(GetSkinFromID(animalType, animalSkinID));

            default:
                break;
            }
            return(null);
        }