Beispiel #1
0
        /// <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)
        {
            Config = helper.ReadConfig <ModConfig>();

            Util.Config     = Config;
            Util.Reflection = helper.Reflection;

            JunimoAbilities junimoAbilities = new JunimoAbilities();

            junimoAbilities.Capabilities = Config.JunimoCapabilities;
            JunimoPayments junimoPayments = new JunimoPayments();

            junimoPayments.Payment = Config.JunimoPayment;

            Util.Abilities = junimoAbilities;
            Util.Payments  = junimoPayments;
            Util.MaxRadius = Config.JunimoPayment.WorkForWages ? Util.UnpaidRadius : Config.JunimoHuts.MaxRadius;

            helper.Content.AssetEditors.Add(new JunimoEditor(helper.Content));
            helper.Content.AssetEditors.Add(new BlueprintEditor());

            helper.Events.Input.ButtonPressed += OnButtonPressed;
            helper.Events.Display.MenuChanged += OnMenuChanged;
            helper.Events.GameLoop.DayStarted += OnDayStarted;
            helper.Events.GameLoop.SaveLoaded += OnSaveLoaded;

            DoHarmonyRegistration();
        }
        public override void Entry(IModHelper helper)
        {
            Config = Helper.ReadConfig <ModConfig>();

            Util.Config     = Config;
            Util.Reflection = Helper.Reflection;

            JunimoAbilities junimoAbilities = new JunimoAbilities();

            junimoAbilities.Capabilities = Config.JunimoCapabilities;
            JunimoPayments junimoPayments = new JunimoPayments();

            junimoPayments.Payment = Config.JunimoPayment;

            Util.Abilities = junimoAbilities;
            Util.Payments  = junimoPayments;
            Util.MaxRadius = Config.JunimoPayment.WorkForWages ? Util.UnpaidRadius : Config.JunimoHuts.MaxRadius;

            Helper.Content.AssetEditors.Add(new JunimoEditor(Helper.Content));
            Helper.Content.AssetEditors.Add(new BlueprintEditor());

            InputEvents.ButtonPressed  += InputEvents_ButtonPressed;
            MenuEvents.MenuClosed      += MenuEvents_MenuClosed;
            MenuEvents.MenuChanged     += MenuEvents_MenuChanged;
            TimeEvents.AfterDayStarted += TimeEvents_AfterDayStarted;
            SaveEvents.AfterLoad       += SaveEvents_AfterLoad;

            DoHarmonyRegistration();
        }
        // BUG: player warps back to wizard hut after use
        private void OpenJunimoHutMenu()
        {
            var menu          = new CarpenterMenu(true);
            var blueprints    = Helper.Reflection.GetField <List <BluePrint> >(menu, "blueprints");
            var newBluePrints = new List <BluePrint> {
                new("Junimo Hut")
            };

            blueprints.SetValue(newBluePrints);
            Game1.activeClickableMenu = menu;
        }

        /// <summary>Raised after a game menu is opened, closed, or replaced.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        void OnMenuChanged(object sender, MenuChangedEventArgs e)
        {
            // closed Junimo Hut menu
            //
            // check that e.NewMenu is null because this event also fires when items are added to the chest
            // caution: this runs after any chest is closed, not just Junimo huts

            // closed menu
            if (e.OldMenu is ItemGrabMenu menu && e.NewMenu is null)
            {
                if (menu.context is not(JunimoHut or Chest))
                {
                    return;
                }
                if (menu.context is Chest chest &&
                    !chest.modData.ContainsKey($"{ModManifest.UniqueID}/JunimoChest"))
                {
                    return;
                }
                CheckHutsForWagesAndProgressionItems();
                JunimoAbilities.ResetCooldowns();
            }

            // opened menu
            if (e.OldMenu != null || e.NewMenu is not CarpenterMenu)
            {
                return;
            }
            if (!Helper.Reflection.GetField <bool>(e.NewMenu, "magicalConstruction").GetValue())
            {
                return;
            }
            // limit to only junimo hut
            if (!Game1.MasterPlayer.mailReceived.Contains("hasPickedUpMagicInk"))
            {
                OpenJunimoHutMenu();
            }
        }

        /// <summary>Raised after the game begins a new day (including when the player loads a save).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        void OnDayStarted(object sender, DayStartedEventArgs e)
        {
            if (Config.JunimoPayment.WorkForWages)
            {
                Util.Payments.JunimoPaymentsToday.Clear();
                Util.Payments.WereJunimosPaidToday = false;
            }

            var huts = Game1.getFarm().buildings.OfType <JunimoHut>().ToList();

            // tag each hut chest so later we can tell whether a GrabMenu close is for a Junimo chest or some other chest
            foreach (var hut in huts)
            {
                hut.output.Value.modData[$"{ModManifest.UniqueID}/JunimoChest"] = "true";
            }

            if (huts.Any())
            {
                CheckHutsForWagesAndProgressionItems();
                Util.Progression.DayStartedProgressionPrompt(Game1.IsWinter, Game1.isRaining);
                JunimoAbilities.ResetCooldowns();
            }

            foreach (var location in Game1.locations)
            {
                var toRemove = location.characters.Where(npc => npc is JunimoHarvester).ToList();
                if (toRemove.Count > 0)
                {
                    Monitor.Log($"{location.Name} has {toRemove.Count} Junimos", LogLevel.Trace);
                }

                foreach (var npc in toRemove)
                {
                    var junimo = (JunimoHarvester)npc;
                    Monitor.Log($"    Removing Junimo {junimo.whichJunimoFromThisHut} from {location.Name}",
                                LogLevel.Trace);
                    location.characters.Remove(npc);
                }
            }

            // reset for rainy days, winter, or Generic Mod Config Menu options change
            SaveConfig();
        }
 private void ResetCooldowns(string command, string[] args)
 {
     JunimoAbilities.ResetCooldowns();
 }