示例#1
0
        ////////////////

        public static void ClearBramblesWithinArea(Rectangle area, bool syncFromServer)
        {
            if (syncFromServer && Main.netMode == NetmodeID.MultiplayerClient)
            {
                return;
            }

            int brambleType = ModContent.TileType <CursedBrambleTile>();

            for (int i = area.Left; i < area.Right; i++)
            {
                for (int j = area.Top; j < area.Bottom; j++)
                {
                    Tile tile = Main.tile[i, j];
                    if (tile?.active() != true || tile.type != brambleType)
                    {
                        continue;
                    }

                    TileLibraries.KillTile(i, j, false, false, true, false, syncFromServer);
                    //if( syncFromServer ) {
                    //} else {
                    //	WorldGen.KillTile( i, j );
                    //	WorldGen.SquareTileFrame( i, j );
                    //}
                }
            }
        }
        private static void ErodeBramblesAtRandomly(int tileX, int tileY)
        {
            int minTicks    = 3;
            int maxTicks    = 60 * 60;
            int brambleType = ModContent.TileType <CursedBrambleTile>();

            Timers.SetTimer(TmlLibraries.SafelyGetRand().Next(minTicks, maxTicks), false, () => {
                Tile tile = Framing.GetTileSafely(tileX, tileY);

                if (tile.active() && tile.type == brambleType)
                {
                    TileLibraries.KillTile(tileX, tileY, false, false, true);
                }
                return(false);
            });
        }
        /// <summary>
        /// Attempts to remove a random bramble within a given (tile) area.
        /// </summary>
        /// <param name="minTileX"></param>
        /// <param name="minTileY"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="adjacentRadius"></param>
        /// <param name="sync"></param>
        /// <returns>`true` if a bramble was found and removed.</returns>
        public static bool ErodeRandomBrambleWithinArea(
            int minTileX,
            int minTileY,
            int width,
            int height,
            int adjacentRadius,
            bool sync)
        {
            int randTileX = minTileX + TmlLibraries.SafelyGetRand().Next(width);
            int randTileY = minTileY + TmlLibraries.SafelyGetRand().Next(height);

            Tile tile = Framing.GetTileSafely(randTileX, randTileY);

            if (!tile.active() || tile.type != ModContent.TileType <CursedBrambleTile>())
            {
                return(false);
            }

            if (!sync)
            {
                WorldGen.KillTile(
                    i: randTileX,
                    j: randTileY,
                    fail: false,
                    effectOnly: false,
                    noItem: true
                    );
                WorldGen.SquareTileFrame(randTileX, randTileY);
            }
            else
            {
                TileLibraries.KillTile(
                    tileX: randTileX,
                    tileY: randTileY,
                    effectOnly: false,
                    dropsItem: false,
                    forceSyncIfUnchanged: true
                    );
            }

            CursedBrambleTile.ErodeBramblesWithinAreaRadiusRandomly(minTileX, minTileY, adjacentRadius);

            return(true);
        }
        ////////////////

        private static bool ApplyBarrierCollision_SoulBarriers_WeakRef(
            object rawBarrier,
            int tileX,
            int tileY,
            double damage)
        {
            var wldHitAt = new Vector2(tileX * 16, tileY * 16);
            var barrier  = rawBarrier as SoulBarriers.Barriers.BarrierTypes.Barrier;

            if (!barrier.IsActive)
            {
                return(false);
            }

            barrier.ApplyMetaphysicalHit(wldHitAt, damage, true);

            TileLibraries.KillTile(tileX, tileY, false, false, true);

            return(true);
        }
        ////////////////

        /// <summary>
        /// Attempts to remove a random bramble within a given (tile) radius of a given tile.
        /// </summary>
        /// <param name="tileX"></param>
        /// <param name="tileY"></param>
        /// <param name="radius"></param>
        /// <param name="adjacentRadius"></param>
        /// <returns>`true` if a bramble was found and removed.</returns>
        public static bool ErodeRandomBrambleWithinRadius(int tileX, int tileY, int radius, int adjacentRadius)
        {
            int randX     = TmlLibraries.SafelyGetRand().Next(radius * 2);
            int randY     = TmlLibraries.SafelyGetRand().Next(radius * 2);
            int randTileX = tileX + (randX - radius);
            int randTileY = tileY + (randY - radius);

            Tile tile = Framing.GetTileSafely(randTileX, randTileY);

            if (!tile.active() || tile.type != ModContent.TileType <CursedBrambleTile>())
            {
                return(false);
            }

            TileLibraries.KillTile(randTileX, randTileY, false, false, true);

            CursedBrambleTile.ErodeBramblesWithinAreaRadiusRandomly(tileX, tileY, adjacentRadius);

            return(true);
        }
        /// <summary>
        /// Attempts to remove a bramble at a given tile.
        /// </summary>
        /// <param name="tileX"></param>
        /// <param name="tileY"></param>
        /// <param name="sync"></param>
        /// <returns>`true` if a bramble was found and removed.</returns>
        public static bool ErodeBrambleAt(int tileX, int tileY, bool sync)
        {
            int  brambleType = ModContent.TileType <CursedBrambleTile>();
            Tile tile        = Framing.GetTileSafely(tileX, tileY);

            if (!tile.active() || tile.type != brambleType)
            {
                return(false);
            }

            return(TileLibraries.KillTile(
                       tileX: tileX,
                       tileY: tileY,
                       effectOnly: false,
                       dropsItem: false,
                       forceSyncIfUnchanged: false,
                       syncIfClient: sync,
                       syncIfServer: sync
                       ));
        }