Esempio n. 1
0
        internal PropertyMetadata FindOrCreate(Type ownerType, CreationHandler createHandler)
        {
            if (_table.TryGetValue(ownerType, out var value))
            {
                return((PropertyMetadata)value !);
            }

            var metadata = createHandler();

            _table[ownerType] = metadata;

            return(metadata);
        }
Esempio n. 2
0
        /************************
        ** Public methods
        *************************/

        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            // SMAPI helpers
            ModEntry.SHelper  = helper;
            ModEntry.SMonitor = this.Monitor;

            // Config settings
            Config = this.Helper.ReadConfig <ModConfig>();

            // SMAPI console command handler
            Commander = new CommandHandler(this);
            // Pet and Horse creation handler
            Creator = new CreationHandler(this);
            // Save/Load logic handler
            SaverLoader = new SaveLoadHandler(this);

            // Event Listeners
            helper.Events.GameLoop.SaveLoaded      += SaveLoadHandler.Setup;
            helper.Events.GameLoop.SaveLoaded      += SaveLoadHandler.LoadData;
            helper.Events.GameLoop.Saving          += SaveLoadHandler.SaveData;
            helper.Events.GameLoop.Saved           += SaveLoadHandler.LoadData;
            helper.Events.GameLoop.ReturnedToTitle += SaveLoadHandler.StopUpdateChecks;

            helper.Events.GameLoop.DayStarted  += Creator.ProcessNewDay;
            helper.Events.GameLoop.DayEnding   += Creator.ProcessEndDay;
            helper.Events.Display.RenderingHud += RenderHoverTooltip;


            // SMAPI Commands
            helper.ConsoleCommands.Add("list_creatures", $"Lists the creature IDs and skin IDs of the given type.\n(Options: '{string.Join("', '", CommandHandler.CreatureGroups)}', or a specific animal type (such as bluechicken))", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("randomize_all_skins", "Randomizes the skins for every farm animal, pet, and horse on the farm.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("randomize_skin", "Randomizes the skin for the given creature. Call `randomize_skin <animal/pet/horse> <creature ID>`. To find a creature's ID, call `list_creatures`.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("set_skin", "Sets the skin of the given creature to the given skin ID. Call `set_skin <skin ID> <animal/pet/horse> <creature ID>`. To find a creature's ID, call `list_creatures`.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("corral_horses", "Warp all horses to the farm's stable, giving you the honor of being a clown car chauffeur.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("horse_whistle", "Summons one of the player's horses to them. Can be called with a horse's ID to call a specific horse. To find a horse's ID, call `list_creatures horse`.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("sell", "Used to give away one of your pets or horses. Call `sell <pet/horse> <creature ID>`. To find a creature's ID, call `list_creatures`.", Commander.OnCommandReceived);

            // DEBUG
            if (Config.DebuggingMode)
            {
                helper.ConsoleCommands.Add("debug_reset", "DEBUG: ** WARNING ** Resets all skins and creature IDs, but ensures that all creatures are properly in the Adopt & Skin system.", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_skinmaps", "DEBUG: Prints all info in current skin maps", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_idmaps", "DEBUG: Prints AnimalLongToShortIDs", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_pets", "DEBUG: Print the information for every Pet instance on the map", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_horses", "DEBUG: Print the information for every Horse instance on the map", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_find", "DEBUG: Locate the creature with the given ID. Call `debug_find <horse/pet/animal> <creature ID>`.", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("summon_stray", "DEBUG: Summons a new stray at Marnie's.", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("summon_horse", "DEBUG: Summons a wild horse. Somewhere.", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_clearunowned", "DEBUG: Removes any wild horses or strays that exist, to clear out glitched extras", Commander.OnCommandReceived);
            }
        }
        /************************
        ** Public methods
        *************************/

        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            // SMAPI helpers
            ModEntry.SHelper  = helper;
            ModEntry.SMonitor = this.Monitor;

            // Pet and Horse creation handler
            Creator = new CreationHandler(this);

            // SMAPI console command handler
            Commander = new CommandHandler(this);

            // Event Listeners
            helper.Events.GameLoop.SaveLoaded += this.Setup;
            helper.Events.GameLoop.SaveLoaded += this.LoadData;
            helper.Events.GameLoop.Saving     += this.SaveData;
            helper.Events.GameLoop.Saved      += this.LoadData;

            helper.Events.World.NpcListChanged += this.SaveTheHorse;
            helper.Events.GameLoop.DayStarted  += Creator.ProcessNewDay;
            helper.Events.Input.ButtonPressed  += Creator.HorseCheck;

            helper.Events.Display.RenderingHud += this.RenderHoverTooltip;

            // ** TODO: Implement handling added and removed animals


            // SMAPI Commands (CommandHandler? Internal?)
            helper.ConsoleCommands.Add("list_creatures", $"Lists the creature IDs and skin IDs of the given type.\n(Options: '{string.Join("', '", CreatureGroups)}', or a specific animal type (such as bluechicken))", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("randomize_all_skins", "Randomizes the skins for every farm animal, pet, and horse on the farm.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("randomize_skin", "Randomizes the skin for the given creature. Call `randomize_skin <animal/pet/horse> <creature ID>`. To find a creature's ID, call list_creatures.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("set_skin", "Sets the skin of the given creature to the given skin ID. Call `set_skin <skin ID> <animal/pet/horse> <creature ID>`. To find a creature's ID, call list_creatures.", Commander.OnCommandReceived);

            // DEBUG
            helper.ConsoleCommands.Add("debug_skinmaps", "DEBUG: Prints all info in current skin maps", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("debug_idmaps", "DEBUG: Prints AnimalLongToShortIDs", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("debug_manners", "DEBUG: Print all manners", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("debug_horses", "DEBUG: Print all horses that exist on the map, not just player-owned ones", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("find_horse", "DEBUG: Find where the heck dat horse at. Format: debug_find_horse <horse ID>.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("adopt_pet", "DEBUG: Add pet. Warp to farm.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("summon_horse", "DEBUG: Summons a wild horse. Somewhere.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("corral_horses", "DEBUG: Warp all horses to the farm's stable, giving you the honor of being a clown car chauffeur.", Commander.OnCommandReceived);
        }
Esempio n. 4
0
        /************************
        ** Public methods
        *************************/

        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            // SMAPI helpers
            ModEntry.SHelper  = helper;
            ModEntry.SMonitor = this.Monitor;

            // Config settings
            Config = this.Helper.ReadConfig <ModConfig>();

            // Internal helpers
            Commander   = new CommandHandler(this);
            Creator     = new CreationHandler(this);
            SaverLoader = new SaveLoadHandler(this);

            var loaders = Helper.Content.AssetLoaders;

            loaders.Add(this);

            WildHorse.PlayerSpecifiedSpawnMaps = new List <string>(Config.WildHorseSpawnLocations);
            // Check that Wild Horse spawn maps set in the Config file are all valid
            foreach (string loc in Config.WildHorseSpawnLocations)
            {
                if (!WildHorse.SpawningMaps.Contains(Sanitize(loc)))
                {
                    SMonitor.Log($"Invalid map \"{loc}\" is listed in Wild Horse spawning locations and will be ignored.\nMaps must all be one of: Forest, BusStop, Mountain, Town, Railroad, or Beach.", LogLevel.Warn);
                    WildHorse.PlayerSpecifiedSpawnMaps.Remove(loc);
                }
            }

            // Event Listeners
            helper.Events.GameLoop.SaveLoaded      += SaveLoadHandler.Setup;
            helper.Events.GameLoop.SaveLoaded      += SaveLoadHandler.LoadData;
            helper.Events.GameLoop.Saving          += SaveLoadHandler.SaveData;
            helper.Events.GameLoop.Saved           += SaveLoadHandler.LoadData;
            helper.Events.GameLoop.ReturnedToTitle += SaveLoadHandler.StopUpdateChecks;

            helper.Events.GameLoop.DayStarted += Creator.ProcessNewDay;
            helper.Events.GameLoop.DayEnding  += Creator.ProcessEndDay;

            // SMAPI Commands
            helper.ConsoleCommands.Add("list_creatures", $"Lists the creature IDs and skin IDs of the given type.\n(Options: '{string.Join("', '", CommandHandler.CreatureGroups)}', or a specific animal type (such as bluechicken))", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("randomize_skin", $"Randomizes the skin for the given group of creatures or the creature with the given ID. Call `randomize_skin <creature group or creature ID>`.\nCallable creature groups: {string.Join(",", CommandHandler.CreatureGroups)}, or an adult creature type\nTo find a creature's ID, call `list_creatures`.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("set_skin", "Sets the skin of the given creature to the given skin ID. Call `set_skin <skin ID> <creature ID>`. To find a creature's ID, call `list_creatures`.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("corral_horses", "Warp all horses to the farm's stable, giving you the honor of being a professional clown car chauffeur.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("horse_whistle", "Summons one of the player's horses to them. Can be called with a horse's ID to call a specific horse. To find a horse's ID, call `list_creatures horse`.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("rename", "Renames the pet or horse of the given ID to the given name. Call `rename <creature ID> \"new name\"`.", Commander.OnCommandReceived);
            helper.ConsoleCommands.Add("sell", "Used to give away one of your pets or horses. Call `sell <creature ID>`. To find a creature's ID, call `list_creatures`.", Commander.OnCommandReceived);

            // DEBUG
            if (Config.DebuggingMode)
            {
                helper.ConsoleCommands.Add("debug_asreset", "DEBUG: ** WARNING ** Resets all skins and creature IDs, but ensures that all creatures are properly in the Adopt & Skin system.", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_skinmaps", "DEBUG: Prints all info in current skin maps", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_idmaps", "DEBUG: Prints AnimalLongToShortIDs", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_pets", "DEBUG: Print the information for every Pet instance on the map", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_horses", "DEBUG: Print the information for every Horse instance on the map", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_find", "DEBUG: Locate the creature with the given ID. Call `debug_find <creature ID>`.", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("summon_stray", "DEBUG: Summons a new stray at Marnie's.", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("summon_horse", "DEBUG: Summons a wild horse. Somewhere.", Commander.OnCommandReceived);
                helper.ConsoleCommands.Add("debug_clearunowned", "DEBUG: Removes any wild horses or strays that exist, to clear out glitched extras", Commander.OnCommandReceived);
            }
        }