示例#1
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)
        {
            // init
            ModEntry.Config   = helper.ReadConfig <ModConfig>();
            ModEntry.SHelper  = helper;
            ModEntry.SMonitor = this.Monitor;

            // Event listeners
            helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
            helper.Events.GameLoop.SaveLoaded   += this.LoadSkinMap;
            helper.Events.GameLoop.Saving       += this.SaveSkinMap;
            helper.Events.GameLoop.Saved        += this.LoadSkinMap;

            // add commands
            helper.ConsoleCommands.Add("abandon_pet", "Remove a pet with the given name.", this.OnCommandReceived);
            helper.ConsoleCommands.Add("abandon_all_pets", "Remove all pets adopted using this mod, you monster.", this.OnCommandReceived);
            helper.ConsoleCommands.Add("list_animal_types", "Lists all animal types on your farm.", this.OnCommandReceived);
            helper.ConsoleCommands.Add("list_animal_skins", "Lists all animal skins used on your farm.", this.OnCommandReceived);
            helper.ConsoleCommands.Add("reset_animal_skins", "Lists all animal skins used on your farm.", this.OnCommandReceived);

            // Prepare BabyDuck override
            try
            {
                string asset = this.Helper.Content.GetActualAssetKey(Path.Combine("assets", "skins", "BabyDuck.png"));
                Game1.content.Load <Texture2D>(asset);
                BabyDuck = new AnimalSkin("BabyDuck", 0, asset);
            }
            catch (Exception e)
            {
                this.Monitor.Log("Unable to patch BabyDuck due to exception:", LogLevel.Error, e);
            }

            // Register default supported animal types
            Api.RegisterAnimalType("Blue Chicken");
            Api.RegisterAnimalType("Brown Chicken");
            Api.RegisterAnimalType("Brown Cow");
            Api.RegisterAnimalType("Dinosaur", false);
            Api.RegisterAnimalType("Duck");
            Api.RegisterAnimalType("Goat");
            Api.RegisterAnimalType("Pig");
            Api.RegisterAnimalType("Rabbit");
            Api.RegisterAnimalType("Sheep", true, true);
            Api.RegisterAnimalType("Void Chicken");
            Api.RegisterAnimalType("White Chicken");
            Api.RegisterAnimalType("White Cow");

            if (Config.ExtraTypes != null && Config.ExtraTypes.Length > 0)
            {
                foreach (string type in Config.ExtraTypes)
                {
                    Api.RegisterAnimalType(type, false);
                }
            }

            // Register default supported pet types
            Api.RegisterPetType("cat", typeof(Cat));
            Api.RegisterPetType("dog", typeof(Dog));

            // configure bus replacement
            if (ModEntry.Config.AnimalsOnly)
            {
                this.ReplaceBus = false;
            }
            if (this.ReplaceBus)
            {
                try
                {
                    string asset = this.Helper.Content.GetActualAssetKey(Path.Combine("assets", "box.png"));
                    Game1.content.Load <Texture2D>(asset);
                }
                catch (Exception e)
                {
                    this.ReplaceBus = false;
                    this.Monitor.Log("Unable to patch BusStop due to exception:", LogLevel.Error, e);
                }
            }
        }