void KillSign(int x, int y, int plr)
{
TSPlayer player = TShock.Players[plr];
bool[] attached = new bool[4];
bool[] attachedNext = new bool[4];
var positions = new List <Point>();
if (Main.tile[x, y].IsSign())
{
if (TryKillSign(Sign.GetSign(x, y).X, Sign.GetSign(x, y).Y, plr))
{
WorldGen.KillTile(x, y);
TSPlayer.All.SendTileSquare(x, y, 3);
return;
}
else
{
player.SendErrorMessage("This sign is protected.");
player.SendTileSquare(x, y, 5);
return;
}
}
else
{
if (TileValid(x - 1, y) && Main.tile[x - 1, y].IsSign())
{
positions.Add(Sign.GetSign(x - 1, y));
}
if (TileValid(x + 1, y) && Main.tile[x + 1, y].IsSign())
{
positions.Add(Sign.GetSign(x + 1, y));
}
if (TileValid(x, y - 1) && Main.tile[x, y - 1].IsSign())
{
positions.Add(Sign.GetSign(x, y - 1));
}
if (TileValid(x, y + 1) && Main.tile[x, y + 1].IsSign())
{
positions.Add(Sign.GetSign(x, y + 1));
}
foreach (Point p in positions)
{
attached[0] = TileValid(p.X, p.Y + 2) && Main.tile[p.X, p.Y + 2].IsSolid() &&
TileValid(p.X + 1, p.Y + 2) && Main.tile[p.X + 1, p.Y + 2].IsSolid();
attached[1] = TileValid(p.X, p.Y - 1) && Main.tile[p.X, p.Y - 1].IsSolid() &&
TileValid(p.X + 1, p.Y - 1) && Main.tile[p.X + 1, p.Y - 1].IsSolid();
attached[2] = TileValid(p.X - 1, p.Y) && Main.tile[p.X - 1, p.Y].IsSolid() &&
TileValid(p.X - 1, p.Y + 1) && Main.tile[p.X - 1, p.Y + 1].IsSolid();
attached[3] = TileValid(p.X + 2, p.Y) && Main.tile[p.X + 2, p.Y].IsSolid() &&
TileValid(p.X + 2, p.Y + 1) && Main.tile[p.X + 2, p.Y + 1].IsSolid();
bool prev = Main.tile[x, y].active();
Main.tile[x, y].active(false);
attachedNext[0] = TileValid(p.X, p.Y + 2) && Main.tile[p.X, p.Y + 2].IsSolid() &&
TileValid(p.X + 1, p.Y + 2) && Main.tile[p.X + 1, p.Y + 2].IsSolid();
attachedNext[1] = TileValid(p.X, p.Y - 1) && Main.tile[p.X, p.Y - 1].IsSolid() &&
TileValid(p.X + 1, p.Y - 1) && Main.tile[p.X + 1, p.Y - 1].IsSolid();
attachedNext[2] = TileValid(p.X - 1, p.Y) && Main.tile[p.X - 1, p.Y].IsSolid() &&
TileValid(p.X - 1, p.Y + 1) && Main.tile[p.X - 1, p.Y + 1].IsSolid();
attachedNext[3] = TileValid(p.X + 2, p.Y) && Main.tile[p.X + 2, p.Y].IsSolid() &&
TileValid(p.X + 2, p.Y + 1) && Main.tile[p.X + 2, p.Y + 1].IsSolid();
Main.tile[x, y].active(prev);
if (attached.Count(b => b) > 1 || attached.Count(b => b) == attachedNext.Count(b => b))
{
continue;
}
if (TryKillSign(p.X, p.Y, plr))
{
WorldGen.KillTile(p.X, p.Y);
TSPlayer.All.SendTileSquare(p.X, p.Y, 3);
}
else
{
player.SendErrorMessage("This sign is protected.");
player.SendTileSquare(x, y, 5);
}
}
}
}