コード例 #1
0
 /// <summary>
 /// Replace logic determining item drop-in actions on garden bed objects.
 /// </summary>
 public static bool Utility_IsThereAnObjectHereWhichAcceptsThisItem_Prefix(
     ref bool __result,
     GameLocation location,
     Item item,
     int x,
     int y)
 {
     try
     {
         Vector2 tileLocation = new Vector2(x / Game1.tileSize, y / Game1.tileSize);
         if (location.Objects.TryGetValue(tileLocation, out StardewValley.Object o) && o != null && o is OutdoorPot op)
         {
             if (!OutdoorPot.CanAcceptItemOrSeed(item: item) && OutdoorPot.CanAcceptAnything(op: op))
             {
                 __result = op.performObjectDropInAction(dropInItem: (StardewValley.Object)item, probe: true, who: Game1.player);
             }
             else
             {
                 __result = false;
             }
             return(false);
         }
     }
     catch (Exception e)
     {
         HarmonyPatches.ErrorHandler(e);
     }
     return(true);
 }
コード例 #2
0
        /// <summary>
        /// Replace logic for crafting objects in base game crafting menu to create the appropriate garden bed for the crafting recipe variant.
        /// </summary>
        public static bool CraftingPage_ClickCraftingRecipe_Prefix(
            CraftingPage __instance,
            int ___currentCraftingPage,
            ref Item ___heldItem,
            ClickableTextureComponent c,
            bool playSound = true)
        {
            try
            {
                // Fetch an instance of any clicked-on craftable in the crafting menu
                CraftingRecipe recipe = __instance.pagesOfCraftingRecipes[___currentCraftingPage][c];

                // Fall through to default method for any other craftables
                if (!recipe.name.StartsWith(OutdoorPot.GenericName))
                {
                    return(true);
                }

                OutdoorPot item = new OutdoorPot(
                    variantKey: OutdoorPot.GetVariantKeyFromName(recipe.name),
                    tileLocation: Vector2.Zero);

                // Behaviours as from base method
                recipe.consumeIngredients(null);
                if (playSound)
                {
                    Game1.playSound("coin");
                }
                if (___heldItem == null)
                {
                    ___heldItem = item;
                }
                else if (___heldItem.canStackWith(item))
                {
                    ___heldItem.addToStack(item);
                }
                if (Game1.player.craftingRecipes.ContainsKey(recipe.name))
                {
                    Game1.player.craftingRecipes[recipe.name] += recipe.numberProducedPerCraft;
                }
                Game1.stats.checkForCraftingAchievements();
                if (Game1.options.gamepadControls && ___heldItem != null && Game1.player.couldInventoryAcceptThisItem(___heldItem))
                {
                    Game1.player.addItemToInventoryBool(___heldItem);
                    ___heldItem = null;
                }

                return(false);
            }
            catch (Exception e)
            {
                HarmonyPatches.ErrorHandler(e);
            }
            return(true);
        }
コード例 #3
0
 /// <summary>
 /// Add logic to consider new conditions for planting seeds in garden bed objects.
 /// </summary>
 public static bool Utility_IsViableSeedSpot_Prefix(
     GameLocation location,
     Vector2 tileLocation,
     Item item)
 {
     try
     {
         if (location.Objects.TryGetValue(tileLocation, out StardewValley.Object o) && o != null && o is OutdoorPot op)
         {
             return(OutdoorPot.CanAcceptItemOrSeed(item) && OutdoorPot.CanAcceptSeed(item: item, op: op) && OutdoorPot.CanAcceptAnything(op: op));
         }
     }
     catch (Exception e)
     {
         HarmonyPatches.ErrorHandler(e);
     }
     return(true);
 }
コード例 #4
0
        private void Initialise()
        {
            Log.T("Initialising mod data.");

            // Assets
            AssetManager assetManager = new AssetManager(helper: this.Helper);

            this.Helper.Content.AssetLoaders.Add(assetManager);
            this.Helper.Content.AssetEditors.Add(assetManager);

            // Content
            Translations.Initialise();
            this.LoadContentPacks();
            this.AddGenericModConfigMenu();

            // Patches
            HarmonyPatches.Patch(id: this.ModManifest.UniqueID);

            // Events
            this.Helper.Events.Specialized.LoadStageChanged += this.Specialized_LoadStageChanged;
            this.Helper.Events.GameLoop.SaveLoaded          += this.GameLoop_SaveLoaded;
            this.Helper.Events.GameLoop.DayStarted          += this.GameLoop_DayStarted;
            this.Helper.Events.GameLoop.DayEnding           += this.GameLoop_DayEnding;
            SpaceCore.Events.SpaceEvents.ShowNightEndMenus  += this.SpaceEvents_ShowNightEndMenus;

            // Console commands
            this.Helper.ConsoleCommands.Add(
                name: ModEntry.CommandPrefix + "eventget",
                documentation: $"Check if event has been seen.{Environment.NewLine}Optional event ID, defaults to root event.",
                callback: ModEntry.Cmd_IsEventSeen);
            this.Helper.ConsoleCommands.Add(
                name: ModEntry.CommandPrefix + "eventset",
                documentation: $"Set state for having seen any event.{Environment.NewLine}Optional event ID, defaults to root event.",
                callback: ModEntry.Cmd_ToggleEventSeen);
            this.Helper.ConsoleCommands.Add(
                name: ModEntry.CommandPrefix + "give",
                documentation: $"Give several of all currently unlocked varieties of raised beds.",
                callback: ModEntry.Cmd_Give);
            this.Helper.ConsoleCommands.Add(
                name: ModEntry.CommandPrefix + "giveall",
                documentation: "Give several of all varieties of raised beds.",
                callback: ModEntry.Cmd_GiveAll);
        }
コード例 #5
0
 /// <summary>
 /// Replace logic for garden bed objects being watered by sprinklers.
 /// </summary>
 public static bool Object_ApplySprinkler_Prefix(
     GameLocation location,
     Vector2 tile)
 {
     try
     {
         if (ModEntry.Config.SprinklersEnabled &&
             location.Objects.TryGetValue(tile, out StardewValley.Object o) && o != null && o is OutdoorPot op)
         {
             if (OutdoorPot.CanAcceptAnything(op: op, ignoreCrops: true))
             {
                 op.Water();
             }
             return(false);
         }
     }
     catch (Exception e)
     {
         HarmonyPatches.ErrorHandler(e);
     }
     return(true);
 }