Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
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;
            }
        }