コード例 #1
0
ファイル: RegionVision.cs プロジェクト: UB1AFU/Region-Vision
        private void OnTileEdit(object sender, TShockAPI.GetDataHandlers.TileEditEventArgs e)
        {
            if (e.Action > GetDataHandlers.EditAction.KillTileNoItem ||
                e.Action == GetDataHandlers.EditAction.KillWall)
            {
                return;
            }
            if (e.Action == GetDataHandlers.EditAction.PlaceTile && e.EditData == Terraria.ID.TileID.MagicalIceBlock)
            {
                return;
            }

            lock (players) {
                Player player = findPlayer(e.Player.Index);
                if (player == null)
                {
                    return;
                }
                if (player.regions.Count == 0)
                {
                    return;
                }

                // Stop the edit if a phantom tile is the only thing making it possible.
                foreach (Region region in player.regions)
                {
                    // Clear the region borders if they break one of the phantom ice blocks.
                    if ((e.Action == GetDataHandlers.EditAction.KillTile || e.Action == GetDataHandlers.EditAction.KillTileNoItem) && (Main.tile[e.X, e.Y] == null || !Main.tile[e.X, e.Y].active()) &&
                        e.X >= region.showArea.Left - 1 && e.X <= region.showArea.Right + 1 && e.Y >= region.showArea.Top - 1 && e.Y <= region.showArea.Bottom + 1 &&
                        !(e.X >= region.showArea.Left + 2 && e.X <= region.showArea.Right - 2 && e.Y >= region.showArea.Top + 2 && e.Y <= region.showArea.Bottom - 2))
                    {
                        e.Handled = true;
                        //clearRegions(player);
                        break;
                    }
                    if ((e.Action == GetDataHandlers.EditAction.PlaceTile || e.Action == GetDataHandlers.EditAction.PlaceWall) && !tileValidityCheck(region, e.X, e.Y, e.Action))
                    {
                        e.Handled = true;
                        player.TSPlayer.SendData(PacketTypes.TileSendSquare, "", 1, e.X, e.Y, 0, 0);
                        if (e.Action == GetDataHandlers.EditAction.PlaceTile)
                        {
                            giveTile(player, e);
                        }
                        if (e.Action == GetDataHandlers.EditAction.PlaceWall)
                        {
                            giveWall(player, e);
                        }
                        break;
                    }
                }
                if (e.Handled)
                {
                    clearRegions(player);
                }
            }
        }
コード例 #2
0
ファイル: RegionVision.cs プロジェクト: UB1AFU/Region-Vision
        /// <summary>Returns the item used to attempt a rejected background wall edit to the player.</summary>
        /// <param name="player">The player attempting the edit</param>
        /// <param name="e">The data from the edit event</param>
        public void giveWall(Player player, TShockAPI.GetDataHandlers.TileEditEventArgs e)
        {
            Item item = new Item(); bool found = false;

            for (int i = 1; i <= Terraria.ID.ItemID.Count; i++)
            {
                item.SetDefaults(i, true);
                if (item.createWall == e.EditData)
                {
                    found = true;
                    break;
                }
            }
            if (found)
            {
                giveItem(player, item);
            }
        }