コード例 #1
0
ファイル: ModEntry.cs プロジェクト: TrichedOut/smapi-mod-dump
        internal static AnimalSkin GetSkin(Character creature)
        {
            if (!ModApi.HasSkins(ModApi.GetInternalType(creature)) || !ModApi.IsInDatabase(creature))
            {
                return(null);
            }


            int    skinID;
            string type = ModApi.GetInternalType(creature);

            // Take care of Strays and WildHorses
            if (Creator.StrayInfo != null && ModApi.IsStray(creature))
            {
                skinID = Creator.StrayInfo.SkinID;
            }
            else if (Creator.HorseInfo != null && ModApi.IsWildHorse(creature))
            {
                skinID = Creator.HorseInfo.SkinID;
            }
            // Take care of FarmAnimal subtypes
            else if (creature is FarmAnimal animal)
            {
                skinID = SkinMap[GetLongID(creature)];

                if (ModApi.HasBabySprite(type) && animal.age.Value < animal.ageWhenMature.Value)
                {
                    type = "baby" + type;
                }
                else if (ModApi.HasShearedSprite(type) && animal.showDifferentTextureWhenReadyForHarvest.Value && animal.currentProduce.Value <= 0)
                {
                    type = "sheared" + type;
                }
            }
            // Take care of owned Pets and Horses
            else
            {
                skinID = SkinMap[GetLongID(creature)];
            }


            if (!Assets[ModApi.GetInternalType(creature)].ContainsKey(skinID))
            {
                ModEntry.SMonitor.Log($"{creature.Name}'s skin ID no longer exists in `/assets/skins`. Skin will be randomized.", LogLevel.Alert);
                skinID = RandomizeSkin(creature);
            }
            else if (skinID == 0)
            {
                return(null);
            }

            return(GetSkin(type, skinID));
        }
コード例 #2
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)
                {
                    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);
                }

                // A stray pet is being checked
                if (pet.Manners == Stray.StrayID)
                {
                    return(GetSkinFromID(pet.GetType().Name, Creator.StrayInfo.SkinID));
                }
                // Pet is not in system
                else 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);
        }