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); } }
/**************************** ** Additional Functionality *****************************/ /// <summary>Calls a horse that the player owns to the player's location</summary> /// <returns>Returns true if a horse was successfully called.</returns> internal static bool CallHorse(long id = 0) { // Make sure that the player is calling the horse while outside if (!Game1.player.currentLocation.IsOutdoors) { ModEntry.SMonitor.Log("You cannot call for a horse while indoors.", LogLevel.Warn); Game1.chatBox.addInfoMessage("You hear your Grandfather's voice echo in your head.. \"Now is not the time to use that.\""); return(false); } // Teleport the horse with the given ID or the last horse ridden List <Horse> taxis = ModApi.GetHorses().ToList(); taxis.Reverse(); foreach (Horse taxi in taxis) { if (ModApi.IsWildHorse(taxi)) { continue; } else if (id != 0 && GetShortID(taxi) == id) { Game1.warpCharacter(taxi, Game1.player.currentLocation, Game1.player.getTileLocation()); return(true); } else if (id == 0) { Game1.warpCharacter(taxi, Game1.player.currentLocation, Game1.player.getTileLocation()); return(true); } } return(false); }
public static void ClearUnownedPets() { foreach (NPC npc in Utility.getAllCharacters()) { if (npc is Horse horse && ModApi.IsWildHorse(horse)) { Game1.removeThisCharacterFromAllLocations(horse); }
/// <summary>Update BeingRidden, such that horses can be manually re-added on dismount, preventing the disappearence of dismounted multihorses.</summary> internal static void HorseMountedCheck(object sender, NpcListChangedEventArgs e) { foreach (NPC npc in e.Removed) { if (npc is Horse horse && horse.rider != null && !ModApi.IsWildHorse(horse)) { BeingRidden.Add(horse); } } }
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>Returns an enumerable list of all owned Horse instances. This excludes WildHorses and tractors.</summary> public static IEnumerable <Horse> GetHorses() { foreach (NPC npc in Utility.getAllCharacters()) { if (npc is Horse horse && !ModApi.IsWildHorse(horse) && ModApi.IsNotATractorOrCart(horse)) { yield return(horse); } } // Horses being ridden don't technically exist, and must be added separately foreach (Horse horse in ModEntry.BeingRidden) { yield return(horse); } }
/// <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]); } }
/// <summary>Calls all horses owned by the player to return to the player's stable</summary> internal static void CorralHorses() { // Find the farm's stable Stable horsehut = null; foreach (Building building in Game1.getFarm().buildings) { if (building is Stable) { horsehut = building as Stable; } } if (horsehut != null) { // WARP THEM. WARP THEM ALL. int stableX = int.Parse(horsehut.tileX.ToString()) + 1; int stableY = int.Parse(horsehut.tileY.ToString()) + 1; Vector2 stableWarp = new Vector2(stableX, stableY); foreach (Horse horse in ModApi.GetHorses()) { if (!ModApi.IsWildHorse(horse)) { Game1.warpCharacter(horse, "farm", stableWarp); } } ModEntry.SMonitor.Log("All horses have been warped to the stable.", LogLevel.Info); return; } // Player does not own a stable ModEntry.SMonitor.Log("NOTICE: You don't have a stable to warp to!", LogLevel.Error); Game1.chatBox.addInfoMessage("Your Grandfather's voice echoes in your head.. \"You aren't yet ready for this gift.\""); }