Exemplo n.º 1
0
        private static bool isPassableTile(GameLocation location, int x, int y)
        {
            var tile = new Vector2(x, y);

            Location displayLoc = new Location(x * Game1.tileSize, y * Game1.tileSize);

            StardewValley.Object obj = null;
            location.objects.TryGetValue(tile, out obj);

            TerrainFeature terrainObj = null;

            location.terrainFeatures.TryGetValue(tile, out terrainObj);

            Building building = null;

            if (location is BuildableGameLocation)
            {
                building = ((BuildableGameLocation)location).getBuildingAt(tile);
            }

            return(location.isPointPassable(displayLoc, Game1.viewport) &&
                   building == null &&
                   (obj == null || obj.isPassable()) &&
                   (terrainObj == null || terrainObj.isPassable()));
        }
        public bool isPath(Vector2 tileLocation)
        {
            Object         obj = null;
            TerrainFeature tf  = null;

            objects.TryGetValue(tileLocation, out obj);
            terrainFeatures.TryGetValue(tileLocation, out tf);
            if (tf != null && tf.isPassable())
            {
                return(obj?.isPassable() ?? true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public static bool checkIfICanPlaceHere(TileNode t, Vector2 pos, GameLocation loc = null, bool checkForPassableTerrainFeatures = true)
        {
            bool cry = false;

            if (t.thisLocation == null)
            {
                t.thisLocation = loc;
                cry            = true;
            }


            if (t == null)
            {
                Console.WriteLine("OK T IS NULL");
            }
            if (t.thisLocation == null)
            {
                Console.WriteLine("OK T LOCATION IS NULL");
            }


            if (t.thisLocation.isObjectAt((int)pos.X, (int)pos.Y))
            {
                //ModCore.CoreMonitor.Log("Object at this tile position!: " + t.thisLocation.objects[new Vector2(pos.X/Game1.tileSize,pos.Y/Game1.tileSize)].name, LogLevel.Warn);
                if (cry == true)
                {
                    t.thisLocation = null;
                }
                return(false);
            }



            if (checkForPassableTerrainFeatures)
            {
                bool terrainFeature = t.thisLocation.terrainFeatures.ContainsKey(pos / Game1.tileSize);
                if (terrainFeature)
                {
                    TerrainFeature terrain = t.thisLocation.terrainFeatures[pos / Game1.tileSize];
                    if (terrain.isPassable())
                    {
                        return(true);
                    }
                }
            }
            if (t.thisLocation.isTileOccupied(pos / Game1.tileSize))
            {
                // ModCore.CoreMonitor.Log("Tile occupied!: " + t.thisLocation.name, LogLevel.Error);
                if (cry == true)
                {
                    t.thisLocation = null;
                }
                return(false);
            }

            if (t.thisLocation.isTilePlaceable(pos / Game1.tileSize) == false)
            {
                //ModCore.CoreMonitor.Log("Tile Not placeable at location. " + t.thisLocation.name, LogLevel.Error);
                if (cry == true)
                {
                    t.thisLocation = null;
                }
                return(false);
            }



            if (t.thisLocation.isTilePassable(new xTile.Dimensions.Location((int)(pos.X / Game1.tileSize), (int)(pos.Y / Game1.tileSize)), Game1.viewport) == false)
            {
                // ModCore.CoreMonitor.Log("Tile not passable check 2?????!!!!: " + t.thisLocation.name, LogLevel.Error);
                if (cry == true)
                {
                    t.thisLocation = null;
                }
                return(false);
            }



            if (cry == true)
            {
                t.thisLocation = null;
            }
            return(true);
        }
        public static bool checkIfICanPlaceHere(TileNode t, Vector2 pos, GameLocation loc = null, bool ignorePlacement = true, bool utilityCheck = false)
        {
            bool cry = false;

            if (t.thisLocation == null)
            {
                t.thisLocation = loc;
                cry            = true;
            }


            if (t == null)
            {
                Console.WriteLine("OK T IS NULL");
            }
            if (t.thisLocation == null)
            {
                Console.WriteLine("OK T LOCATION IS NULL");
            }
            //ModCore.CoreMonitor.Log("TRY TO PLACE A TILE AT:" + loc + pos);

            if (t.thisLocation.isObjectAt((int)pos.X, (int)pos.Y))
            {
                // ModCore.CoreMonitor.Log("OBJECt??? " + t.thisLocation.name, LogLevel.Error);
                //ModCore.CoreMonitor.Log("Object at this tile position!: " + t.thisLocation.objects[new Vector2(pos.X/Game1.tileSize,pos.Y/Game1.tileSize)].name, LogLevel.Warn);
                if (cry == true)
                {
                    t.thisLocation = null;
                }
                return(false);
            }

            if (utilityCheck)
            {
                foreach (var v in Utilities.tileExceptionList)
                {
                    // ModCore.CoreMonitor.Log(v.actionType);
                    //  ModCore.CoreMonitor.Log("UTILITY????: " + t.thisLocation.name, LogLevel.Error);
                    if (v.tile.position == pos)
                    {
                        //    ModCore.CoreMonitor.Log("DERP????: " + t.thisLocation.name, LogLevel.Error);
                        return(false);
                    }
                    if (v.tile.tileLocation == pos / Game1.tileSize)
                    {
                        //    ModCore.CoreMonitor.Log("BLURP " + t.thisLocation.name, LogLevel.Error);
                        return(false);
                    }
                }
            }

            bool terrainFeature = t.thisLocation.terrainFeatures.ContainsKey(pos / Game1.tileSize);

            if (terrainFeature)
            {
                TerrainFeature terrain = t.thisLocation.terrainFeatures[pos / Game1.tileSize];
                //  ModCore.CoreMonitor.Log("TERRAIN NOPE!: " + t.thisLocation.name, LogLevel.Error);
                if (terrain.isPassable())
                {
                    return(true);
                }
            }

            if (t.thisLocation.isTileOccupied(pos / Game1.tileSize))
            {
                //  ModCore.CoreMonitor.Log("Tile occupied!: " + t.thisLocation.name, LogLevel.Error);
                if (isTileExempt(t, pos))
                {
                    return(true);
                }
                if (cry == true)
                {
                    t.thisLocation = null;
                }
                return(false);
            }

            if (ignorePlacement == false)
            {
                if (t.thisLocation.isTilePlaceable(pos / Game1.tileSize) == false)
                {
                    // ModCore.CoreMonitor.Log("Tile Not placeable at location. " + t.thisLocation.name, LogLevel.Error);
                    if (cry == true)
                    {
                        t.thisLocation = null;
                    }
                    return(false);
                }
            }


            if (t.thisLocation.isTilePassable(new xTile.Dimensions.Location((int)(pos.X / Game1.tileSize), (int)(pos.Y / Game1.tileSize)), Game1.viewport) == false)
            {
                //ModCore.CoreMonitor.Log("Tile not passable check 2?????!!!!: " + t.thisLocation.name, LogLevel.Error);
                if (isTileExempt(t, pos))
                {
                    return(true);
                }
                if (cry == true)
                {
                    t.thisLocation = null;
                }
                else
                {
                    return(false);
                }
            }



            if (cry == true)
            {
                t.thisLocation = null;
            }
            return(true);
        }