Example #1
0
        private void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
        {
            var player  = args.Player;
            var session = Plugin.GetOrCreateSession(player);

            if (args.Handled || !session.IsWandMode)
            {
                return;
            }

            var action   = args.Action;
            var x        = args.X;
            var y        = args.Y;
            var position = new Vector(x, y);

            if (action == GetDataHandlers.EditAction.PlaceWire)
            {
                session.Selector = session.Selector.WithPrimary(position);
                player.SendSuccessMessage($"Set primary position to {position}.");
                args.Handled = true;
                player.SendTileSquare(x, y, 1);
            }
            else if (action == GetDataHandlers.EditAction.PlaceWire2)
            {
                session.Selector = session.Selector.WithSecondary(position);
                player.SendSuccessMessage($"Set secondary position to {position}.");
                args.Handled = true;
                player.SendTileSquare(x, y, 1);
            }
        }
Example #2
0
        private async void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
        {
            var player  = args.Player;
            var session = Plugin.GetOrCreateSession(player);

            if (args.Handled || !session.IsWandMode)
            {
                return;
            }

            if (args.Action == GetDataHandlers.EditAction.PlaceWire3)
            {
                var x        = args.X;
                var y        = args.Y;
                var position = new Vector(x, y);
                player.SendTileSquare(x, y, 1);
                args.Handled = true;

                var editSession = session.ToolSession;
                if (editSession == null || DateTime.UtcNow - session.LastToolUse > ToolInactivityTime)
                {
                    editSession         = session.CreateEditSession();
                    session.ToolSession = editSession;
                }

                session.LastToolUse = DateTime.UtcNow;
                await Task.Run(() => session.Tool.Apply(editSession, position)).SendExceptions(player);
            }
        }
Example #3
0
 public static void OnTileEdit(object o, GetDataHandlers.TileEditEventArgs args)
 {
     try
     {
         if (Main.tileSign[Main.tile[args.X, args.Y].type] && args.Action == GetDataHandlers.EditAction.KillTile && args.EditData == 0)
         {
             var plr = args.Player;
             if (Utils.TryGetSignByGuess(args.X, args.Y, out var s))
             {
                 if (s.Owner != args.Player.AccountEX().ID&& !plr.HasPermission("ps.admin.destroy"))
                 {
                     plr.SendErrorMessage($"[C/66D093:<PowerfulSign>] 你没有权限摧毁此标牌.");
                     plr.SendTileSquare(s.X, s.Y, 2);
                     plr.SendSignData(s);
                     args.Handled = true;
                 }
                 else
                 {
                     PSPlugin.SignList.Remove(s);
                     Utils.DropItem(args.X, args.Y, Utils.GetItemFromTile(args.X, args.Y, Main.tile[args.X, args.Y]).Result[0]);
                 }
             }
         }
     }
     catch { }
 }
Example #4
0
        private void OnTileEdit(object sender, 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);
                }
            }
        }
Example #5
0
 private void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
 {
     if (args.Action == GetDataHandlers.EditAction.PlaceWire)
     {
         if (storage.ContainsKey(args.Player.Index))
         {
             WireX = args.X;
             WireY = args.Y;
             WirePlace(args.Player.Index, WireX, WireY);
             args.Handled = true;
         }
     }
 }
 public static void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
 {
     if (args.Action == GetDataHandlers.EditAction.PlaceTile)
     {
         if (Main.tile[args.X, args.Y] != null && Main.tile[args.X, args.Y].type == 127)
         {
             args.Handled = true;
             return;
         }
         if (args.Player.SelectedItem.placeStyle != args.Style)
         {
             args.Handled = true;
             return;
         }
     }
 }
        private void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
        {
            if (players[args.Player.Index])
            {
                switch (args.EditType)
                {
                case 0:
                case 4:
                {
                    Recursive      re  = new Recursive();
                    List <Vector2> del = re.RecursiveEdit(args.X, args.Y, args.EditType);
                    foreach (Vector2 tip in del)
                    {
                        WorldGen.KillTile(Convert.ToInt16(tip.X), Convert.ToInt16(tip.Y));
                        TSPlayer.All.SendTileSquare(Convert.ToInt16(tip.X), Convert.ToInt16(tip.Y), 1);
                    }
                    break;
                }

                case 2:
                {
                    Recursive      re  = new Recursive();
                    List <Vector2> del = re.RecursiveEdit(args.X, args.Y, args.EditType);
                    foreach (Vector2 tip in del)
                    {
                        WorldGen.KillWall(Convert.ToInt16(tip.X), Convert.ToInt16(tip.Y));
                        TSPlayer.All.SendTileSquare(Convert.ToInt16(tip.X), Convert.ToInt16(tip.Y), 1);
                    }
                    break;
                }

                case 6:
                {
                    Recursive      re  = new Recursive();
                    List <Vector2> del = re.RecursiveEdit(args.X, args.Y, args.EditType);
                    foreach (Vector2 tip in del)
                    {
                        WorldGen.KillWire(Convert.ToInt16(tip.X), Convert.ToInt16(tip.Y));
                        TSPlayer.All.SendTileSquare(Convert.ToInt16(tip.X), Convert.ToInt16(tip.Y), 1);
                    }
                    break;
                }
                }
            }
        }
Example #8
0
        /// <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, 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);
            }
        }
Example #9
0
        private void TileKill(object sender, GetDataHandlers.TileEditEventArgs args)
        {
            if (args.Player.Group.HasPermission("breakinvincible"))
            {
                return;
            }

            if (args.Action == GetDataHandlers.EditAction.KillWall && blacklistedWalls.Contains(Main.tile[args.X, args.Y].wall))
            {
                args.Handled = true;
                TSPlayer.All.SendTileSquare(args.X, args.Y, 1);
            }
            else if ((args.Action == GetDataHandlers.EditAction.KillTile || args.Action == GetDataHandlers.EditAction.KillTileNoItem || args.Action == GetDataHandlers.EditAction.PoundTile) && blacklistedTiles.Contains(Main.tile[args.X, args.Y].type))
            {
                args.Handled = true;
                TSPlayer.All.SendTileSquare(args.X, args.Y, 1);
            }
        }
Example #10
0
        private void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
        {
            var player = args.Player;

            if (args.Handled || player.AwaitingTempPoint != -1)
            {
                return;
            }

            var x    = args.X;
            var y    = args.Y;
            var tile = Main.tile[x, y];

            player.SendInfoMessage($"X: {x}, Y: {y}");
            player.SendInfoMessage($"Type: {tile.type}, FrameX: {tile.frameX}, FrameY: {tile.frameY}");
            player.AwaitingTempPoint = 0;
            args.Handled             = true;
            player.SendTileSquare(x, y, 5);
        }
Example #11
0
 public void TileEdit(Object sender, GetDataHandlers.TileEditEventArgs args)
 {
     if ((args.EditType == 0 || args.EditType == 4) && new int[] { 3, 24, 32, 51, 52, 61, 62, 69, 71, 73, 74, 80, 82, 83, 84, 110, 113, 115, 138 }.Contains(Main.tile[args.X, args.Y].type))
     {
         try
         {
             foreach (Region reg in regionList)
             {
                 if (reg != null && reg.InArea(args.X, args.Y))
                 {
                     WorldGen.KillTile(args.X, args.Y);
                     TSPlayer.All.SendTileSquare(args.X, args.Y, 3);
                     args.Handled = true;
                     break;
                 }
             }
         }
         catch (Exception ex) { Log.ConsoleError(ex.ToString()); }
     }
 }
Example #12
0
        private void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
        {
            if (args.Action != GetDataHandlers.EditAction.PlaceTile)
            {
                return;
            }
            var rt = RtRegions.GetTopRegion(RtRegions.Regions.Where(r => r.Region.InArea(args.X, args.Y)));

            if (rt == null || !rt.HasEvent(Events.Tileban))
            {
                return;
            }

            if (rt.TileIsBanned(args.EditData) && !args.Player.HasPermission("regiontrigger.bypass.tileban"))
            {
                args.Player.SendTileSquare(args.X, args.Y, 1);
                args.Player.SendErrorMessage("You do not have permission to place this tile.");
                args.Handled = true;
            }
        }
Example #13
0
        /// <summary>Returns the item used to attempt a rejected foreground tile 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 giveTile(Player player, 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.createTile == e.EditData && item.placeStyle == e.Style)
                {
                    if (item.tileWand != -1)
                    {
                        item.SetDefaults(item.tileWand, true);
                    }
                    found = true;
                    break;
                }
            }
            if (found)
            {
                giveItem(player, item);
            }
        }
Example #14
0
        private void TileKill(object sender, GetDataHandlers.TileEditEventArgs args)
        {
            if (args.Player.Group.HasPermission("breakinvincible"))
            {
                return;
            }

            var wall = Main.tile[args.X, args.Y].wall;
            var type = Main.tile[args.X, args.Y].type;

            if (
                (args.Action == GetDataHandlers.EditAction.KillWall && blacklistedWalls.IsBanned(args.X, args.Y, wall)) ||
                ((args.Action == GetDataHandlers.EditAction.KillTile || args.Action == GetDataHandlers.EditAction.KillTileNoItem || args.Action == GetDataHandlers.EditAction.PoundTile) && blacklistedTiles.IsBanned(args.X, args.Y, type)) ||
                (args.Action == GetDataHandlers.EditAction.KillWire && blacklistedWires.IsBanned(args.X, args.Y, 1)) ||
                (args.Action == GetDataHandlers.EditAction.KillWire2 && blacklistedWires.IsBanned(args.X, args.Y, 2)) ||
                (args.Action == GetDataHandlers.EditAction.KillWire3 && blacklistedWires.IsBanned(args.X, args.Y, 3))
                )
            {
                args.Handled = true;
                TSPlayer.All.SendTileSquare(args.X, args.Y, 1);
            }
        }
Example #15
0
        private void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs e)
        {
            var player = e.Player;

            #region Region Information Display

            if (player.AwaitingName)
            {
                bool includeUnprotected = false;
                bool includeZIndexes    = false;
                bool persistentMode     = false;

                foreach (string nameParameter in player.AwaitingNameParameters)
                {
                    // If this flag is passed the final output will include unprotected regions, i.e regions
                    // that have the DisableBuild flag set to false
                    if (nameParameter.Equals("-u", StringComparison.InvariantCultureIgnoreCase))
                    {
                        includeUnprotected = true;
                    }

                    // If this flag is passed the final output will include a region's Z index
                    if (nameParameter.Equals("-z", StringComparison.InvariantCultureIgnoreCase))
                    {
                        includeZIndexes = true;
                    }

                    // If this flag is passed the player will continue to receive region information upon editing tiles
                    if (nameParameter.Equals("-p", StringComparison.InvariantCultureIgnoreCase))
                    {
                        persistentMode = true;
                    }
                }

                var output = new List <string>();
                foreach (Region region in _regionManager.Regions.OrderBy(r => r.Z).Reverse())
                {
                    // Ensure that the specified tile is region protected
                    if (e.X < region.Area.Left || e.X > region.Area.Right)
                    {
                        continue;
                    }

                    if (e.Y < region.Area.Top || e.Y > region.Area.Bottom)
                    {
                        continue;
                    }

                    // Do not include the current region if it has not been protected and the includeUnprotected flag has not been set
                    if (!region.DisableBuild && !includeUnprotected)
                    {
                        continue;
                    }

                    output.Add($"{region.Name} {(includeZIndexes ? $"(Z:{region.Z}" : string.Empty)}");
                }

                if (output.Count == 0)
                {
                    player.SendInfoMessage(includeUnprotected
                                                ? "There are no regions at this point."
                                                : "There are no regions at this point, or they are not protected.");
                }
                else
                {
                    player.SendInfoMessage(includeUnprotected ? "Regions at this point: " : "Protected regions at this point: ");

                    foreach (string line in PaginationTools.BuildLinesFromTerms(output))
                    {
                        player.SendMessage(line, Color.White);
                    }
                }

                if (!persistentMode)
                {
                    player.AwaitingName           = false;
                    player.AwaitingNameParameters = null;
                }

                // Revert all tile changes and handle the event
                player.SendTileSquare(e.X, e.Y, 4);
                e.Handled = true;
            }

            #endregion

            #region TempPoints Setup

            if (player.AwaitingTempPoint != 0)
            {
                // Set temp point coordinates to current tile coordinates
                player.TempPoints[player.AwaitingTempPoint - 1].X = e.X;
                player.TempPoints[player.AwaitingTempPoint - 1].Y = e.Y;
                player.SendInfoMessage($"Set temp point {player.AwaitingTempPoint}.");

                // Reset the awaiting temp point
                player.AwaitingTempPoint = 0;

                // Revert all tile changes and handle the event
                player.SendTileSquare(e.X, e.Y, 4);
                e.Handled = true;
            }

            #endregion
        }