private static bool PrefixCanBePlacedHere(Furniture __instance, GameLocation l, Vector2 tile, ref bool __result)
 {
     try
     {
         if (!ModEntry.Config.Enabled || !ModEntry.Config.CanPlaceRugsUnder ||
             !__instance.furniture_type.Value.Equals(Furniture.rug) ||
             __instance.placementRestriction != 0 || // someone requested a custom placement restriction, respect that.
             l.CanPlaceThisFurnitureHere(__instance)
             /*|| __instance.GetAdditionalFurniturePlacementStatus(l, (int)tile.X * 64, (int)tile.Y * 64) != 0*/)
         {
             return(true);
         }
         Rectangle bounds = __instance.boundingBox.Value;
         (int tileX, int tileY) = tile.ToPoint();
         for (int x = 0; x < bounds.Width / 64; x++)
         {
             for (int y = 0; y < bounds.Height / 64; y++)
             {
                 Vector2 currentTile = new(tileX + x, tileY + y);
                 if ((l.terrainFeatures.TryGetValue(currentTile, out TerrainFeature possibletree) && possibletree is Tree) ||
                     l.isTerrainFeatureAt((int)currentTile.X, (int)currentTile.Y))
                 {
                     __result = false;
                     return(false);
                 }
             }
         }
         __result = true;
         return(false);
     }
     catch (Exception ex)
     {
         ModEntry.ModMonitor.Log($"Ran into errors in PrefixCanBePlacedHere for {__instance.Name} at {l.NameOrUniqueName} ({tile.X}, {tile.Y})\n\n{ex}", LogLevel.Error);
     }
     return(true);
 }
        /*********
        ** Private methods
        *********/
        /// <summary>The method to call before <see cref="Utility.playerCanPlaceItemHere"/>.</summary>
        private static bool Before_PlayersCanPlaceItemHere(GameLocation location, Item item, int x, int y, Farmer f, ref bool __result)
        {
            if (!(item is StardewValley.Object obj && obj.bigCraftable.Value))
            {
                return(true);
            }
            var entry = Mod.Entries.SingleOrDefault(cle => cle.Name == obj.Name);

            if (entry == null)
            {
                return(true);
            }

            if (Utility.isPlacementForbiddenHere(location))
            {
                __result = false;
                return(false);
            }
            if (item == null || item is Tool || Game1.eventUp || f.bathingClothes.Value || f.onBridge.Value)
            {
                __result = false;
                return(false);
            }
            bool    withinRadius = false;
            Vector2 tileLocation = new Vector2(x / 64, y / 64);
            Vector2 playerTile   = f.getTileLocation();

            for (int ix = (int)tileLocation.X; ix < (int)tileLocation.X + entry.Width; ++ix)
            {
                for (int iy = (int)tileLocation.Y; iy < (int)tileLocation.Y + entry.Length; ++iy)
                {
                    if (Math.Abs(ix - playerTile.X) <= 1 && Math.Abs(iy - playerTile.Y) <= 1)
                    {
                        withinRadius = true;
                    }
                }
            }

            if (withinRadius || (item is Wallpaper && location is DecoratableLocation) || (item is Furniture furniture && location.CanPlaceThisFurnitureHere(furniture)))
            {
                if (item.canBePlacedHere(location, tileLocation))
                {
                    if (!((StardewValley.Object)item).isPassable())
                    {
                        foreach (Farmer farmer in location.farmers)
                        {
                            for (int ix = (int)tileLocation.X; ix < (int)tileLocation.X + entry.Width; ++ix)
                            {
                                for (int iy = (int)tileLocation.Y; iy < (int)tileLocation.Y + entry.Length; ++iy)
                                {
                                    if (farmer.GetBoundingBox().Intersects(new Rectangle(ix * 64, iy * 64, 64, 64)))
                                    {
                                        __result = false;
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    var itemCanBePlaced = Mod.Instance.Helper.Reflection.GetMethod(typeof(Utility), "itemCanBePlaced");
                    if (itemCanBePlaced.Invoke <bool>(location, tileLocation, item) || Utility.isViableSeedSpot(location, tileLocation, item))
                    {
                        __result = true;
                        return(false);
                    }
                }
            }

            __result = false;
            return(false);
        }
Esempio n. 3
0
        private static bool Impl(GameLocation location, Item item, int x, int y, Farmer f)
        {
            if (Utility.isPlacementForbiddenHere(location))
            {
                return(false);
            }
            if (item is null or Tool || Game1.eventUp || f.bathingClothes.Value || f.onBridge.Value)
            {
                return(false);
            }
            bool    withinRadius = false;
            Vector2 tileLocation = new Vector2(x / 64, y / 64);
            Vector2 playerTile   = f.getTileLocation();

            for (int ix = (int)tileLocation.X; ix < (int)tileLocation.X + 4; ++ix)
            {
                for (int iy = (int)tileLocation.Y; iy < (int)tileLocation.Y + 2; ++iy)
                {
                    if (Math.Abs(ix - playerTile.X) <= 1 && Math.Abs(iy - playerTile.Y) <= 1)
                    {
                        withinRadius = true;
                    }
                }
            }

            if (withinRadius || (item is Wallpaper && location is DecoratableLocation) || (item is Furniture furniture && location.CanPlaceThisFurnitureHere(furniture)))
            {
                if (item.canBePlacedHere(location, tileLocation))
                {
                    if (!((StardewValley.Object)item).isPassable())
                    {
                        foreach (Farmer farmer in location.farmers)
                        {
                            for (int ix = (int)tileLocation.X; ix < (int)tileLocation.X + 4; ++ix)
                            {
                                for (int iy = (int)tileLocation.Y; iy < (int)tileLocation.Y + 2; ++iy)
                                {
                                    if (farmer.GetBoundingBox().Intersects(new Rectangle(ix * 64, iy * 64, 64, 64)))
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    var itemCanBePlaced = Mod.instance.Helper.Reflection.GetMethod(typeof(Utility), "itemCanBePlaced");
                    if (itemCanBePlaced.Invoke <bool>(location, tileLocation, item) || Utility.isViableSeedSpot(location, tileLocation, item))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }