private static Character GetCreature(long longID) { // Check that LongID belongs to a creature in the database, or is otherwise a Stray or WildHorse. if (IDToCategory.ContainsKey(longID)) { switch (IDToCategory[longID]) { case CreatureCategory.Pet: foreach (Pet pet in ModApi.GetPets()) { if (GetLongID(pet) == longID) { return(pet); } } return(null); case CreatureCategory.Horse: foreach (Horse horse in ModApi.GetHorses()) { if (GetLongID(horse) == longID) { return(horse); } } return(null); case CreatureCategory.Animal: foreach (FarmAnimal animal in ModApi.GetAnimals()) { if (GetLongID(animal) == longID) { return(animal); } } return(null); default: return(null); } } else { if (ModApi.IsStray(longID)) { if (Creator.StrayInfo != null) { return(Creator.StrayInfo.PetInstance); } } else if (ModApi.IsWildHorse(longID)) { if (Creator.HorseInfo != null) { return(Creator.HorseInfo.HorseInstance); } } return(null); } }
/// <summary>Returns an enumerable list of all owned Pet instances. This excludes strays.</summary> public static IEnumerable <Pet> GetPets() { foreach (NPC npc in Utility.getAllCharacters()) { if (npc is Pet pet && !ModApi.IsStray(pet)) { yield return(pet); } } }
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)); }
/// <summary>Refreshes the texture of the creature's sprite if the texture it has is different from the one in the skin mapping</summary> internal static void UpdateSkin(Character creature) { if (!ModApi.IsInDatabase(creature) && !ModApi.IsStray(creature) && !ModApi.IsWildHorse(creature)) { return; } AnimalSkin skin = GetSkin(creature); if (skin != null && creature.Sprite.textureName.Value != skin.AssetKey) { int[] spriteInfo = ModApi.GetSpriteInfo(creature); creature.Sprite = new AnimatedSprite(skin.AssetKey, spriteInfo[0], spriteInfo[1], spriteInfo[2]); } }