2f107db...5202af9
This commit is contained in:
@@ -14,13 +14,24 @@ namespace Barotrauma.Items.Components
|
||||
partial class WireSection
|
||||
{
|
||||
private Vector2 start;
|
||||
private Vector2 end;
|
||||
|
||||
private float angle;
|
||||
private float length;
|
||||
|
||||
public Vector2 Start
|
||||
{
|
||||
get { return start; }
|
||||
}
|
||||
public Vector2 End
|
||||
{
|
||||
get { return end; }
|
||||
}
|
||||
|
||||
public WireSection(Vector2 start, Vector2 end)
|
||||
{
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
angle = MathUtils.VectorToAngle(end - start);
|
||||
length = Vector2.Distance(start, end);
|
||||
@@ -41,6 +52,8 @@ namespace Barotrauma.Items.Components
|
||||
private bool canPlaceNode;
|
||||
private Vector2 newNodePos;
|
||||
|
||||
private Vector2 sectionExtents;
|
||||
|
||||
public bool Hidden;
|
||||
|
||||
private bool locked;
|
||||
@@ -185,7 +198,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (connections[0] != null && connections[1] != null)
|
||||
{
|
||||
foreach (ItemComponent ic in item.components)
|
||||
foreach (ItemComponent ic in item.Components)
|
||||
{
|
||||
if (ic == this) continue;
|
||||
ic.Drop(null);
|
||||
@@ -202,10 +215,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (sendNetworkEvent)
|
||||
{
|
||||
#if SERVER
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
CreateNetworkEvent();
|
||||
}
|
||||
#endif
|
||||
//the wire is active if only one end has been connected
|
||||
IsActive = connections[0] == null ^ connections[1] == null;
|
||||
}
|
||||
@@ -274,8 +289,7 @@ namespace Barotrauma.Items.Components
|
||||
//prevent the wire from extending too far when rewiring
|
||||
if (nodes.Count > 0)
|
||||
{
|
||||
Character user = item.ParentInventory?.Owner as Character;
|
||||
if (user == null) return;
|
||||
if (!(item.ParentInventory?.Owner is Character user)) return;
|
||||
|
||||
Vector2 prevNodePos = nodes[nodes.Count - 1];
|
||||
if (sub != null) { prevNodePos += sub.HiddenSubPosition; }
|
||||
@@ -294,11 +308,17 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
user.AnimController.Collider.ApplyForce(pullBackDir * user.Mass * 50.0f);
|
||||
user.AnimController.UpdateUseItem(true, user.WorldPosition + pullBackDir * 200.0f);
|
||||
if (currLength > MaxLength * 1.5f && GameMain.Client == null)
|
||||
|
||||
if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)
|
||||
{
|
||||
ClearConnections();
|
||||
CreateNetworkEvent();
|
||||
return;
|
||||
if (currLength > MaxLength * 1.5f)
|
||||
{
|
||||
ClearConnections();
|
||||
#if SERVER
|
||||
CreateNetworkEvent();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,12 +328,18 @@ namespace Barotrauma.Items.Components
|
||||
newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition;
|
||||
canPlaceNode = true;
|
||||
}
|
||||
|
||||
sectionExtents = new Vector2(
|
||||
Math.Max(Math.Abs((newNodePos.X + sub.HiddenSubPosition.X) - item.Position.X), sectionExtents.X),
|
||||
Math.Max(Math.Abs((newNodePos.Y + sub.HiddenSubPosition.Y) - item.Position.Y), sectionExtents.Y));
|
||||
}
|
||||
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null) return false;
|
||||
#if CLIENT
|
||||
if (character == Character.Controlled && character.SelectedConstruction != null) return false;
|
||||
#endif
|
||||
|
||||
if (newNodePos != Vector2.Zero && canPlaceNode && nodes.Count > 0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
|
||||
{
|
||||
@@ -328,10 +354,12 @@ namespace Barotrauma.Items.Components
|
||||
Drawable = true;
|
||||
newNodePos = Vector2.Zero;
|
||||
|
||||
#if SERVER
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
CreateNetworkEvent();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -393,18 +421,33 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
sections.Clear();
|
||||
|
||||
for (int i = 0; i < nodes.Count-1; i++)
|
||||
for (int i = 0; i < nodes.Count - 1; i++)
|
||||
{
|
||||
sections.Add(new WireSection(nodes[i], nodes[i + 1]));
|
||||
}
|
||||
Drawable = IsActive || sections.Count > 0;
|
||||
CalculateExtents();
|
||||
}
|
||||
|
||||
private void CalculateExtents()
|
||||
{
|
||||
sectionExtents = Vector2.Zero;
|
||||
if (sections.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < nodes.Count; i++)
|
||||
{
|
||||
sectionExtents.X = Math.Max(Math.Abs(nodes[i].X - item.Position.X), sectionExtents.X);
|
||||
sectionExtents.Y = Math.Max(Math.Abs(nodes[i].Y - item.Position.Y), sectionExtents.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearConnections(Character user = null)
|
||||
{
|
||||
nodes.Clear();
|
||||
sections.Clear();
|
||||
|
||||
|
||||
#if SERVER
|
||||
if (user != null)
|
||||
{
|
||||
if (connections[0] != null && connections[1] != null)
|
||||
@@ -424,6 +467,7 @@ namespace Barotrauma.Items.Components
|
||||
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SetConnectedDirty();
|
||||
|
||||
@@ -627,33 +671,6 @@ namespace Barotrauma.Items.Components
|
||||
base.RemoveComponentSpecific();
|
||||
}
|
||||
|
||||
private void CreateNetworkEvent()
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
//split into multiple events because one might not be enough to fit all the nodes
|
||||
int eventCount = Math.Max((int)Math.Ceiling(nodes.Count / (float)MaxNodesPerNetworkEvent), 1);
|
||||
for (int i = 0; i < eventCount; i++)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, item.components.IndexOf(this), i });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
|
||||
{
|
||||
int eventIndex = (int)extraData[2];
|
||||
int nodeStartIndex = eventIndex * MaxNodesPerNetworkEvent;
|
||||
int nodeCount = MathHelper.Clamp(nodes.Count - nodeStartIndex, 0, MaxNodesPerNetworkEvent);
|
||||
|
||||
msg.WriteRangedInteger(0, (int)Math.Ceiling(MaxNodeCount / (float)MaxNodesPerNetworkEvent), eventIndex);
|
||||
msg.WriteRangedInteger(0, MaxNodesPerNetworkEvent, nodeCount);
|
||||
for (int i = nodeStartIndex; i < nodeStartIndex + nodeCount; i++)
|
||||
{
|
||||
msg.Write(nodes[i].X);
|
||||
msg.Write(nodes[i].Y);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||
{
|
||||
int eventIndex = msg.ReadRangedInteger(0, (int)Math.Ceiling(MaxNodeCount / (float)MaxNodesPerNetworkEvent));
|
||||
|
||||
Reference in New Issue
Block a user