Exemplo n.º 1
0
        /// <summary>Removes the Pet, Horse, or FarmAnimal with the given LongID from the A&S database</summary>
        internal void RemoveCreature(long longID)
        {
            if (!ModApi.IsInDatabase(longID))
            {
                return;
            }

            // Ensure creature is not on map
            Character creature = GetCreature(longID);

            if (creature != null && (creature is Pet || creature is Horse))
            {
                Game1.removeThisCharacterFromAllLocations(creature as NPC);
            }
            // Remove FarmAnimal-specific ID markers from lists
            else if (AnimalLongToShortIDs.ContainsKey(longID))
            {
                int shortID = AnimalLongToShortIDs[longID];
                AnimalLongToShortIDs.Remove(longID);
                AnimalShortToLongIDs.Remove(shortID);
            }

            // Scrub internal IDs and skin mapping from system
            IDToCategory.Remove(longID);
            SkinMap.Remove(longID);
        }
Exemplo n.º 2
0
        /************************
        ** Skin Handling
        *************************/

        /// <param name="creature">The creature (Pet, Horse, or FarmAnimal) to set the skin for</param>
        /// <param name="skinID">The file ID of the skin to set.</param>
        internal static int SetSkin(Character creature, int skinID)
        {
            if (!ModApi.IsInDatabase(creature) || !ModApi.HasSkins(ModApi.GetInternalType(creature)))
            {
                return(0);
            }

            SkinMap[GetLongID(creature)] = skinID;
            UpdateSkin(creature);
            return(skinID);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        /// <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]);
            }
        }
Exemplo n.º 5
0
        /// <summary>Removes the Pet, Horse, or FarmAnimal with the given LongID from the A&S database</summary>
        internal void RemoveCreature(long longID)
        {
            if (!ModApi.IsInDatabase(longID))
            {
                return;
            }

            // Ensure creature is not on map
            Character creature = GetCreature(longID);

            if (creature != null && (creature is Pet || creature is Horse))
            {
                Game1.removeThisCharacterFromAllLocations(creature as NPC);
            }

            // Scrub internal IDs and skin mapping from system
            IDToCategory.Remove(longID);
            SkinMap.Remove(longID);
        }
Exemplo n.º 6
0
        internal static int GetShortID(Character creature)
        {
            if (!ModApi.IsInDatabase(creature))
            {
                return(0);
            }

            if (creature is Pet pet)
            {
                return(pet.Manners);
            }
            else if (creature is Horse horse)
            {
                return(horse.Manners);
            }
            else if (creature is FarmAnimal animal && AnimalLongToShortIDs.ContainsKey(GetLongID(animal)))
            {
                return(AnimalLongToShortIDs[GetLongID(animal)]);
            }
            return(0);
        }
Exemplo n.º 7
0
        /// <summary>Determines whether an animal has been removed or added in the game, and either removes or adds it to the A&S database.</summary>
        internal void AnimalListChangeCheck()
        {
            if (Game1.getFarm() != null && AnimalCount != Game1.getFarm().getAllFarmAnimals().Count)
            {
                List <long>       existingAnimalIDs = new List <long>();
                List <FarmAnimal> newAnimals        = new List <FarmAnimal>();

                // Check for new animals and populate lists containing existing and new animals
                foreach (FarmAnimal animal in ModApi.GetAnimals().ToList())
                {
                    if (!ModApi.IsInDatabase(animal))
                    {
                        newAnimals.Add(animal);
                    }
                    else
                    {
                        existingAnimalIDs.Add(animal.myID.Value);
                    }
                }

                // Remove animals that no longer exist
                List <long> animalIDs = new List <long>(SkinMap.Keys);
                foreach (long id in animalIDs)
                {
                    if (IDToCategory[id] == CreatureCategory.Animal && !existingAnimalIDs.Contains(id))
                    {
                        RemoveCreature(id);
                    }
                }

                // Add new animals
                foreach (FarmAnimal animal in newAnimals)
                {
                    AddCreature(animal);
                }

                // Update last known animal count
                AnimalCount = Game1.getFarm().getAllFarmAnimals().Count;
            }
        }
Exemplo n.º 8
0
        /// <summary>Adds the given Pet, Horse, or FarmAnimal into the A&S database</summary>
        internal void AddCreature(Character creature, int skinID = 0, Farmer owner = null)
        {
            string type = ModApi.GetInternalType(creature);

            if (ModApi.IsInDatabase(creature) || !ModApi.IsRegisteredType(type))
            {
                return;
            }

            // Set internal IDs
            SetShortID(creature, GetUnusedShortID());
            IDToCategory[GetLongID(creature)] = ModApi.GetCreatureCategory(type);

            // Set ownership
            if (creature is Horse)
            {
                if (owner != null)
                {
                    HorseOwnershipMap.Add(GetLongID(creature), owner);
                    // DEBUG
                    Monitor.Log($"Horse ID: {GetShortID(creature)}\nOwner: {owner.Name}", LogLevel.Debug);
                }
                else
                {
                    Monitor.Log($"No adopter able to be detected. Horse {GetShortID(creature)} will be owned by the host player.", LogLevel.Debug);
                    HorseOwnershipMap.Add(GetLongID(creature), Game1.MasterPlayer);
                }
            }

            // Give a skin
            if (skinID != 0)
            {
                SetSkin(creature, skinID);
            }
            else
            {
                RandomizeSkin(creature);
            }
        }
Exemplo n.º 9
0
        /****************************
        ** 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);
        }
Exemplo n.º 10
0
        /// <summary>Adds the given Pet, Horse, or FarmAnimal into the A&S database</summary>
        internal void AddCreature(Character creature, int skinID = 0)
        {
            string type = ModApi.GetInternalType(creature);

            if (ModApi.IsInDatabase(creature) || !ModApi.IsRegisteredType(type))
            {
                return;
            }

            // Set internal IDs
            SetShortID(creature, GetUnusedShortID());
            IDToCategory[GetLongID(creature)] = ModApi.GetCreatureCategory(type);

            // Give a skin
            if (skinID != 0)
            {
                SetSkin(creature, skinID);
            }
            else
            {
                RandomizeSkin(creature);
            }
        }
Exemplo n.º 11
0
        /// <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.IsInDatabase(horse))
                    {
                        Game1.warpCharacter(horse, "farm", stableWarp);
                    }
                }

                ModEntry.SMonitor.Log("All horses have been warped to the stable.", LogLevel.Alert);
                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.\"");
        }