Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
 /// <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();
     }
 }