Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 4
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);
 }