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 unused Short ID for a new creature to use.</summary> private int GetUnusedShortID() { int newShortID = 1; // Gather all current ShortIDs List <int> usedIDs = new List <int>(); foreach (Horse horse in ModApi.GetHorses()) { usedIDs.Add(GetShortID(horse)); } foreach (Pet pet in ModApi.GetPets()) { usedIDs.Add(GetShortID(pet)); } foreach (FarmAnimal animal in ModApi.GetAnimals()) { usedIDs.Add(GetShortID(animal)); } // Find an unused ShortID and return it while (usedIDs.Contains(newShortID)) { newShortID++; } return(newShortID); }
/**************************** ** 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); }
/**************************** ** 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(int id = 0) { // Make sure that the player is calling the horse while outside if (!Game1.player.currentLocation.IsOutdoors) { 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 first horse you find that the player actually owns List <Horse> taxis = ModApi.GetHorses().ToList(); taxis.Reverse(); foreach (Horse taxi in taxis) { long longID = GetLongID(taxi); // If the player called for a specific horse if (id != 0 && GetShortID(taxi) == id) { // Ensure that the player owns this horse if (HorseOwnershipMap[longID] != Game1.player) { SMonitor.Log($"Horse {id} ({taxi.Name}) does not belong to this player. (Belongs to ({HorseOwnershipMap[longID].Name}))", LogLevel.Error); return(false); } Game1.warpCharacter(taxi, Game1.player.currentLocation, Game1.player.getTileLocation()); return(true); } // Otherwise else if (id == 0) { // Ensure that the player owns this horse if (HorseOwnershipMap[longID] != Game1.player) { continue; } else { Game1.warpCharacter(taxi, Game1.player.currentLocation, Game1.player.getTileLocation()); return(true); } } } SMonitor.Log("This player does not own any horses to call.", LogLevel.Debug); return(false); }
/**************************** ** 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.Alert); 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 first horse you find that the player actually owns foreach (Horse taxi in ModApi.GetHorses()) { if (ModApi.IsInDatabase(taxi) && (id == 0 || id == GetLongID(taxi))) { Game1.warpCharacter(taxi, Game1.player.currentLocation, Game1.player.getTileLocation()); return(true); } } return(false); }
/// <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.\""); }
/// <summary>Calls all horses owned by the player to return to the player's stable</summary> internal static void CorralHorses() { // Gather the taxis List <Horse> horses = new List <Horse>(); foreach (Horse horse in ModApi.GetHorses()) { horses.Add(horse); } // Ensure you own at least one taxi if (horses.Count == 0) { ModEntry.SMonitor.Log("NOTICE: You do not own any horses", LogLevel.Error); Game1.chatBox.addInfoMessage("Your Grandfather's voice echoes in your head.. \"You aren't yet ready for this gift.\""); return; } // Find the farm's stable(s) List <Stable> horsehuts = new List <Stable>(); foreach (Building building in Game1.getFarm().buildings) { if (building is Stable stable) { foreach (Horse horse in horses) { if (stable.HorseId == horse.HorseId) { horsehuts.Add(building as Stable); break; } } } } // Player does not own a stable if (horsehuts.Count == 0) { 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.\""); return; } // WARP THEM. WARP THEM ALL. foreach (Horse horse in horses) { foreach (Stable stable in horsehuts) { if (horse.HorseId == stable.HorseId) { int stableX = int.Parse(stable.tileX.ToString()) + 1; int stableY = int.Parse(stable.tileY.ToString()) + 1; Vector2 stableWarp = new Vector2(stableX, stableY); Game1.warpCharacter(horse, "farm", stableWarp); break; } } } ModEntry.SMonitor.Log("All horses have been warped to the stable.", LogLevel.Info); }
/// <summary>Initiate A&S data on farm</summary> public void UpdateCreatureCount() { // TODO: Put this where it belongs. Use to load game, then check in UpdateTicked to make sure all farmhands and host have animals and skins known if (Game1.getFarm() != null) { Game1.getFarm().modData[$"{this.ModManifest.UniqueID}/count-farmanimals"] = Game1.getFarm().getAllFarmAnimals().Count.ToString(); Game1.getFarm().modData[$"{this.ModManifest.UniqueID}/count-pets"] = ModApi.GetPets().Count().ToString(); Game1.getFarm().modData[$"{this.ModManifest.UniqueID}/count-horses"] = ModApi.GetHorses().Count().ToString(); } }