Handle the MassWireOperation packet. Fixes #1190
This commit is contained in:
parent
825c3bc322
commit
e31cdfb7d5
2 changed files with 135 additions and 11 deletions
|
|
@ -1248,7 +1248,8 @@ namespace TShockAPI
|
|||
{ PacketTypes.PaintWall, HandlePaintWall },
|
||||
{ PacketTypes.DoorUse, HandleDoorUse },
|
||||
{ PacketTypes.CompleteAnglerQuest, HandleCompleteAnglerQuest },
|
||||
{ PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted }
|
||||
{ PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted },
|
||||
{ PacketTypes.MassWireOperation, HandleMassWireOperation }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -2364,15 +2365,15 @@ namespace TShockAPI
|
|||
return false;
|
||||
}
|
||||
|
||||
private static bool HandlePlayerTeam(GetDataHandlerArgs args)
|
||||
{
|
||||
byte id = args.Data.ReadInt8();
|
||||
byte team = args.Data.ReadInt8();
|
||||
if (OnPlayerTeam(id, team))
|
||||
return true;
|
||||
private static bool HandlePlayerTeam(GetDataHandlerArgs args)
|
||||
{
|
||||
byte id = args.Data.ReadInt8();
|
||||
byte team = args.Data.ReadInt8();
|
||||
if (OnPlayerTeam(id, team))
|
||||
return true;
|
||||
|
||||
if (id != args.Player.Index)
|
||||
return true;
|
||||
if (id != args.Player.Index)
|
||||
return true;
|
||||
|
||||
if ((DateTime.UtcNow - args.Player.LastPvPTeamChange).TotalSeconds < 5)
|
||||
{
|
||||
|
|
@ -2381,8 +2382,8 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
args.Player.LastPvPTeamChange = DateTime.UtcNow;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HandlePlayerUpdate(GetDataHandlerArgs args)
|
||||
{
|
||||
|
|
@ -3838,5 +3839,42 @@ namespace TShockAPI
|
|||
// Never sent by vanilla client, ignore this
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool HandleMassWireOperation(GetDataHandlerArgs args)
|
||||
{
|
||||
short startX = args.Data.ReadInt16();
|
||||
short startY = args.Data.ReadInt16();
|
||||
short endX = args.Data.ReadInt16();
|
||||
short endY = args.Data.ReadInt16();
|
||||
args.Data.ReadByte(); // Ignore toolmode
|
||||
|
||||
List<Point> points = Utils.Instance.GetMassWireOperationRange(
|
||||
new Point(startX, startY),
|
||||
new Point(endX, endY),
|
||||
args.Player.TPlayer.direction == 1);
|
||||
|
||||
int x;
|
||||
int y;
|
||||
foreach (Point p in points)
|
||||
{
|
||||
/* Perform similar checks to TileKill
|
||||
* The server-side nature of this packet removes the need to use SendTileSquare
|
||||
* Range checks are currently ignored here as the items that send this seem to have infinite range */
|
||||
|
||||
x = p.X;
|
||||
y = p.Y;
|
||||
|
||||
if (!TShock.Utils.TilePlacementValid(x, y) || (args.Player.Dead && TShock.Config.PreventDeadModification))
|
||||
return true;
|
||||
|
||||
if (TShock.CheckIgnores(args.Player))
|
||||
return true;
|
||||
|
||||
if (TShock.CheckTilePermission(args.Player, x, y))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1086,5 +1086,91 @@ namespace TShockAPI
|
|||
string options = stack > 1 ? "/s" + stack : prefix != 0 ? "/p" + prefix : "";
|
||||
return String.Format("[i{0}:{1}]", options, netID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of points selected by a mass-wiring tool.
|
||||
/// </summary>
|
||||
/// <param name="start">The starting point for the selection.</param>
|
||||
/// <param name="end">The ending point for the selection.</param>
|
||||
/// <param name="direction">False if facing left, True if facing right.</param>
|
||||
/// <returns>
|
||||
/// A list of coordinates containing the <paramref name="start"/> and <paramref name="end"/>
|
||||
/// points and a list of points between them, forming an L shape based on <paramref name="direction"/>.
|
||||
/// </returns>
|
||||
public List<Point> GetMassWireOperationRange(Point start, Point end, bool direction = false)
|
||||
{
|
||||
List<Point> points = new List<Point>();
|
||||
|
||||
#region Tile Selection Logic stolen from Wiring.cs
|
||||
|
||||
// Slightly modified version of Wiring.MassWireOperationInner, ignores a player's wire count
|
||||
int num = Math.Sign(end.X - start.X);
|
||||
int num2 = Math.Sign(end.Y - start.Y);
|
||||
Point pt = new Point();
|
||||
int num3;
|
||||
int num4;
|
||||
int num5;
|
||||
if (direction)
|
||||
{
|
||||
pt.X = start.X;
|
||||
num3 = start.Y;
|
||||
num4 = end.Y;
|
||||
num5 = num2;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt.Y = start.Y;
|
||||
num3 = start.X;
|
||||
num4 = end.X;
|
||||
num5 = num;
|
||||
}
|
||||
int num6 = num3;
|
||||
while (num6 != num4)
|
||||
{
|
||||
if (direction)
|
||||
{
|
||||
pt.Y = num6;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt.X = num6;
|
||||
}
|
||||
points.Add(pt);
|
||||
num6 += num5;
|
||||
}
|
||||
if (direction)
|
||||
{
|
||||
pt.Y = end.Y;
|
||||
num3 = start.X;
|
||||
num4 = end.X;
|
||||
num5 = num;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt.X = end.X;
|
||||
num3 = start.Y;
|
||||
num4 = end.Y;
|
||||
num5 = num2;
|
||||
}
|
||||
int num7 = num3;
|
||||
while (num7 != num4)
|
||||
{
|
||||
if (!direction)
|
||||
{
|
||||
pt.Y = num7;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt.X = num7;
|
||||
}
|
||||
points.Add(pt);
|
||||
num7 += num5;
|
||||
}
|
||||
points.Add(end);
|
||||
|
||||
#endregion
|
||||
|
||||
return points;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue