(bf212a41f) v0.9.2.0 pre-release test version
This commit is contained in:
@@ -24,7 +24,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public readonly bool IsOutput;
|
||||
|
||||
public readonly List<StatusEffect> effects;
|
||||
public readonly List<StatusEffect> Effects;
|
||||
|
||||
public readonly ushort[] wireId;
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
IsPower = Name == "power_in" || Name == "power" || Name == "power_out";
|
||||
|
||||
effects = new List<StatusEffect>();
|
||||
Effects = new List<StatusEffect>();
|
||||
|
||||
wireId = new ushort[MaxLinked];
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Barotrauma.Items.Components
|
||||
break;
|
||||
|
||||
case "statuseffect":
|
||||
effects.Add(StatusEffect.Load(subElement, item.Name + ", connection " + Name));
|
||||
Effects.Add(StatusEffect.Load(subElement, item.Name + ", connection " + Name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -222,6 +222,7 @@ namespace Barotrauma.Items.Components
|
||||
recipientsDirty = true;
|
||||
if (wire != null)
|
||||
{
|
||||
ConnectionPanel.DisconnectedWires.Remove(wire);
|
||||
var otherConnection = wire.OtherConnection(this);
|
||||
if (otherConnection != null)
|
||||
{
|
||||
@@ -251,10 +252,10 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
bool broken = recipient.Item.Condition <= 0.0f;
|
||||
foreach (StatusEffect effect in recipient.effects)
|
||||
foreach (StatusEffect effect in recipient.Effects)
|
||||
{
|
||||
if (broken && effect.type != ActionType.OnBroken) continue;
|
||||
recipient.Item.ApplyStatusEffect(effect, ActionType.OnUse, 1.0f, null, null, false, false);
|
||||
recipient.Item.ApplyStatusEffect(effect, ActionType.OnUse, (float)Timing.Step, null, null, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,11 +278,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
for (int i = 0; i < MaxLinked; i++)
|
||||
{
|
||||
if (wireId[i] == 0) continue;
|
||||
if (wireId[i] == 0) { continue; }
|
||||
|
||||
Item wireItem = Entity.FindEntityByID(wireId[i]) as Item;
|
||||
|
||||
if (wireItem == null) continue;
|
||||
if (!(Entity.FindEntityByID(wireId[i]) is Item wireItem)) { continue; }
|
||||
wires[i] = wireItem.GetComponent<Wire>();
|
||||
recipientsDirty = true;
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private Character user;
|
||||
|
||||
/// <summary>
|
||||
/// Wires that have been disconnected from the panel, but not removed completely (visible at the bottom of the connection panel).
|
||||
/// </summary>
|
||||
public readonly HashSet<Wire> DisconnectedWires = new HashSet<Wire>();
|
||||
|
||||
[Serialize(false, true), Editable(ToolTip = "Locked connection panels cannot be rewired in-game.")]
|
||||
public bool Locked
|
||||
{
|
||||
@@ -103,6 +108,23 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
#if CLIENT
|
||||
foreach (Wire wire in DisconnectedWires)
|
||||
{
|
||||
if (Rand.Range(0.0f, 500.0f) < 1.0f)
|
||||
{
|
||||
SoundPlayer.PlaySound("zap", item.WorldPosition, hullGuess: item.CurrentHull);
|
||||
Vector2 baseVel = new Vector2(0.0f, -100.0f);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var particle = GameMain.ParticleManager.CreateParticle("spark", item.WorldPosition,
|
||||
baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull);
|
||||
if (particle != null) { particle.Size *= Rand.Range(0.5f, 1.0f); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (user == null || user.SelectedConstruction != item)
|
||||
{
|
||||
user = null;
|
||||
@@ -192,11 +214,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
protected override void RemoveComponentSpecific()
|
||||
{
|
||||
DisconnectedWires.Clear();
|
||||
foreach (Connection c in Connections)
|
||||
{
|
||||
foreach (Wire wire in c.Wires)
|
||||
{
|
||||
if (wire == null) continue;
|
||||
if (wire == null) { continue; }
|
||||
|
||||
if (wire.OtherConnection(c) == null) //wire not connected to anything else
|
||||
{
|
||||
@@ -219,6 +242,12 @@ namespace Barotrauma.Items.Components
|
||||
msg.Write(wire?.Item == null ? (ushort)0 : wire.Item.ID);
|
||||
}
|
||||
}
|
||||
|
||||
msg.Write((ushort)DisconnectedWires.Count());
|
||||
foreach (Wire disconnectedWire in DisconnectedWires)
|
||||
{
|
||||
msg.Write(disconnectedWire.Item.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +165,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
base.OnItemLoaded();
|
||||
itemLoaded = true;
|
||||
#if CLIENT
|
||||
light.Color = IsActive ? lightColor : Color.Transparent;
|
||||
if (!IsActive) lightBrightness = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
@@ -217,10 +221,9 @@ namespace Barotrauma.Items.Components
|
||||
if (Rand.Range(0.0f, 1.0f) < 0.05f && voltage < Rand.Range(0.0f, minVoltage))
|
||||
{
|
||||
#if CLIENT
|
||||
if (voltage > 0.1f && sparkSounds.Count > 0)
|
||||
if (voltage > 0.1f)
|
||||
{
|
||||
var sparkSound = sparkSounds[Rand.Int(sparkSounds.Count)];
|
||||
SoundPlayer.PlaySound(sparkSound.Sound, item.WorldPosition, sparkSound.Volume, sparkSound.Range, item.CurrentHull);
|
||||
SoundPlayer.PlaySound("zap", item.WorldPosition, hullGuess: item.CurrentHull);
|
||||
}
|
||||
#endif
|
||||
lightBrightness = 0.0f;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Barotrauma.Networking;
|
||||
using Lidgren.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
@@ -11,6 +12,17 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private bool isOn;
|
||||
|
||||
private static readonly Dictionary<string, string> connectionPairs = new Dictionary<string, string>
|
||||
{
|
||||
{ "power_in", "power_out"},
|
||||
{ "signal_in", "signal_out" },
|
||||
{ "signal_in1", "signal_out1" },
|
||||
{ "signal_in2", "signal_out2" },
|
||||
{ "signal_in3", "signal_out3" },
|
||||
{ "signal_in4", "signal_out4" },
|
||||
{ "signal_in5", "signal_out5" }
|
||||
};
|
||||
|
||||
[Editable, Serialize(1000.0f, true)]
|
||||
public float MaxPower
|
||||
{
|
||||
@@ -59,17 +71,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
|
||||
{
|
||||
if (connection.IsPower || item.Condition <= 0.0f) return;
|
||||
if (connection.IsPower || item.Condition <= 0.0f) { return; }
|
||||
|
||||
if (connection.Name.Contains("_in"))
|
||||
if (connectionPairs.TryGetValue(connection.Name, out string outConnection))
|
||||
{
|
||||
if (!IsOn) return;
|
||||
|
||||
string outConnection = connection.Name.Contains("power_in") ? "power_out" : "signal_out";
|
||||
|
||||
int connectionNumber = -1;
|
||||
int.TryParse(connection.Name.Substring(connection.Name.Length - 1, 1), out connectionNumber);
|
||||
if (connectionNumber > 0) outConnection += connectionNumber;
|
||||
if (!IsOn) { return; }
|
||||
item.SendSignal(stepsTaken, signal, outConnection, sender, power, source, signalStrength);
|
||||
}
|
||||
else if (connection.Name == "toggle")
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public bool CanTransmit()
|
||||
{
|
||||
return HasRequiredContainedItems(true);
|
||||
return HasRequiredContainedItems(user: null, addMessage: false);
|
||||
}
|
||||
|
||||
public IEnumerable<WifiComponent> GetReceiversInRange()
|
||||
@@ -89,7 +89,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (Vector2.DistanceSquared(item.WorldPosition, sender.item.WorldPosition) > sender.range * sender.range) { return false; }
|
||||
|
||||
return HasRequiredContainedItems(false);
|
||||
return HasRequiredContainedItems(user: null, addMessage: false);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace Barotrauma.Items.Components
|
||||
private Vector2 start;
|
||||
private Vector2 end;
|
||||
|
||||
private float angle;
|
||||
private float length;
|
||||
private readonly float angle;
|
||||
private readonly float length;
|
||||
|
||||
public Vector2 Start
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace Barotrauma.Items.Components
|
||||
const int MaxNodesPerNetworkEvent = 30;
|
||||
|
||||
private List<Vector2> nodes;
|
||||
private List<WireSection> sections;
|
||||
private readonly List<WireSection> sections;
|
||||
|
||||
private Connection[] connections;
|
||||
|
||||
@@ -85,24 +85,23 @@ namespace Barotrauma.Items.Components
|
||||
#if CLIENT
|
||||
if (wireSprite == null)
|
||||
{
|
||||
wireSprite = new Sprite("Content/Items/wireHorizontal.png", new Vector2(0.5f, 0.5f));
|
||||
wireSprite.Depth = 0.85f;
|
||||
wireSprite = new Sprite("Content/Items/wireHorizontal.png", new Vector2(0.5f, 0.5f))
|
||||
{
|
||||
Depth = 0.85f
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
nodes = new List<Vector2>();
|
||||
sections = new List<WireSection>();
|
||||
|
||||
connections = new Connection[2];
|
||||
|
||||
connections = new Connection[2];
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
|
||||
public Connection OtherConnection(Connection connection)
|
||||
{
|
||||
if (connection == null) return null;
|
||||
if (connection == connections[0]) return connections[1];
|
||||
if (connection == connections[1]) return connections[0];
|
||||
if (connection == connections[0]) { return connections[1]; }
|
||||
if (connection == connections[1]) { return connections[0]; }
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -133,8 +132,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void RemoveConnection(Connection connection)
|
||||
{
|
||||
if (connection == connections[0]) connections[0] = null;
|
||||
if (connection == connections[1]) connections[1] = null;
|
||||
if (connection == connections[0]) { connections[0] = null; }
|
||||
if (connection == connections[1]) { connections[1] = null; }
|
||||
|
||||
SetConnectedDirty();
|
||||
}
|
||||
@@ -143,10 +142,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (connections[i] == newConnection) return false;
|
||||
if (connections[i] == newConnection) { return false; }
|
||||
}
|
||||
|
||||
if (!connections.Any(c => c == null)) return false;
|
||||
if (!connections.Any(c => c == null)) { return false; }
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
@@ -156,37 +155,39 @@ namespace Barotrauma.Items.Components
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (item.body != null) { item.Submarine = newConnection.Item.Submarine; }
|
||||
|
||||
if (item.body != null) item.Submarine = newConnection.Item.Submarine;
|
||||
newConnection.ConnectionPanel.DisconnectedWires.Remove(this);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (connections[i] != null) continue;
|
||||
if (connections[i] != null) { continue; }
|
||||
|
||||
connections[i] = newConnection;
|
||||
FixNodeEnds();
|
||||
|
||||
if (!addNode) break;
|
||||
if (!addNode) { break; }
|
||||
|
||||
Submarine refSub = newConnection.Item.Submarine;
|
||||
if (refSub == null)
|
||||
{
|
||||
Structure attachTarget = Structure.GetAttachTarget(newConnection.Item.WorldPosition);
|
||||
if (attachTarget == null) continue;
|
||||
if (attachTarget == null) { continue; }
|
||||
refSub = attachTarget.Submarine;
|
||||
}
|
||||
|
||||
Vector2 nodePos = refSub == null ?
|
||||
newConnection.Item.Position :
|
||||
newConnection.Item.Position - refSub.HiddenSubPosition;
|
||||
|
||||
if (nodes.Count > 0 && nodes[0] == nodePos) break;
|
||||
if (nodes.Count > 1 && nodes[nodes.Count - 1] == nodePos) break;
|
||||
|
||||
if (nodes.Count > 0 && nodes[0] == nodePos) { break; }
|
||||
if (nodes.Count > 1 && nodes[nodes.Count - 1] == nodePos) { break; }
|
||||
|
||||
//make sure we place the node at the correct end of the wire (the end that's closest to the new node pos)
|
||||
int newNodeIndex = 0;
|
||||
if (nodes.Count > 1)
|
||||
{
|
||||
if (Vector2.DistanceSquared(nodes[nodes.Count-1], nodePos) < Vector2.DistanceSquared(nodes[0], nodePos))
|
||||
if (Vector2.DistanceSquared(nodes[nodes.Count - 1], nodePos) < Vector2.DistanceSquared(nodes[0], nodePos))
|
||||
{
|
||||
newNodeIndex = nodes.Count;
|
||||
}
|
||||
@@ -244,21 +245,18 @@ namespace Barotrauma.Items.Components
|
||||
public override void Equip(Character character)
|
||||
{
|
||||
ClearConnections(character);
|
||||
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Unequip(Character character)
|
||||
{
|
||||
ClearConnections(character);
|
||||
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
public override void Drop(Character dropper)
|
||||
{
|
||||
ClearConnections(dropper);
|
||||
|
||||
ClearConnections(dropper);
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
@@ -399,7 +397,6 @@ namespace Barotrauma.Items.Components
|
||||
public override bool Pick(Character picker)
|
||||
{
|
||||
ClearConnections(picker);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -467,9 +464,26 @@ namespace Barotrauma.Items.Components
|
||||
nodes.Clear();
|
||||
sections.Clear();
|
||||
|
||||
foreach (Item item in Item.ItemList)
|
||||
{
|
||||
var connectionPanel = item.GetComponent<ConnectionPanel>();
|
||||
if (connectionPanel != null && connectionPanel.DisconnectedWires.Contains(this))
|
||||
{
|
||||
#if SERVER
|
||||
item.CreateServerEvent(connectionPanel);
|
||||
#endif
|
||||
connectionPanel.DisconnectedWires.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
#if SERVER
|
||||
if (user != null)
|
||||
{
|
||||
if (connections[0] != null || connections[1] != null)
|
||||
{
|
||||
GameMain.Server.KarmaManager.OnWireDisconnected(user, this);
|
||||
}
|
||||
|
||||
if (connections[0] != null && connections[1] != null)
|
||||
{
|
||||
GameServer.Log(user.LogName + " disconnected a wire from " +
|
||||
@@ -488,17 +502,21 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SetConnectedDirty();
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (connections[i] == null) continue;
|
||||
if (connections[i] == null) { continue; }
|
||||
int wireIndex = connections[i].FindWireIndex(item);
|
||||
|
||||
if (wireIndex == -1) continue;
|
||||
if (wireIndex == -1) { continue; }
|
||||
#if SERVER
|
||||
if (!connections[i].Item.Removed)
|
||||
{
|
||||
connections[i].Item.CreateServerEvent(connections[i].Item.GetComponent<ConnectionPanel>());
|
||||
}
|
||||
#endif
|
||||
connections[i].SetWire(wireIndex, null);
|
||||
|
||||
connections[i] = null;
|
||||
}
|
||||
|
||||
@@ -565,7 +583,27 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
} while (removed);
|
||||
}
|
||||
|
||||
private void FixNodeEnds()
|
||||
{
|
||||
if (connections[0] == null || connections[1] == null || nodes.Count == 0) { return; }
|
||||
|
||||
Vector2 nodePos = nodes[0];
|
||||
|
||||
Submarine refSub = connections[0].Item.Submarine ?? connections[1].Item.Submarine;
|
||||
if (refSub != null) { nodePos += refSub.HiddenSubPosition; }
|
||||
|
||||
float dist1 = Vector2.DistanceSquared(connections[0].Item.Position, nodePos);
|
||||
float dist2 = Vector2.DistanceSquared(connections[1].Item.Position, nodePos);
|
||||
|
||||
//first node is closer to the second item
|
||||
//= the nodes are "backwards", need to reverse them
|
||||
if (dist1 > dist2)
|
||||
{
|
||||
nodes.Reverse();
|
||||
UpdateSections();
|
||||
}
|
||||
}
|
||||
|
||||
private int GetClosestNodeIndex(Vector2 pos, float maxDist, out float closestDist)
|
||||
@@ -640,12 +678,8 @@ namespace Barotrauma.Items.Components
|
||||
string[] nodeCoords = nodeString.Split(';');
|
||||
for (int i = 0; i < nodeCoords.Length / 2; i++)
|
||||
{
|
||||
float x = 0.0f, y = 0.0f;
|
||||
|
||||
float.TryParse(nodeCoords[i * 2], NumberStyles.Float, CultureInfo.InvariantCulture, out x);
|
||||
|
||||
float.TryParse(nodeCoords[i * 2 + 1], NumberStyles.Float, CultureInfo.InvariantCulture, out y);
|
||||
|
||||
float.TryParse(nodeCoords[i * 2], NumberStyles.Float, CultureInfo.InvariantCulture, out float x);
|
||||
float.TryParse(nodeCoords[i * 2 + 1], NumberStyles.Float, CultureInfo.InvariantCulture, out float y);
|
||||
nodes.Add(new Vector2(x, y));
|
||||
}
|
||||
|
||||
@@ -687,7 +721,6 @@ namespace Barotrauma.Items.Components
|
||||
protected override void RemoveComponentSpecific()
|
||||
{
|
||||
ClearConnections();
|
||||
|
||||
base.RemoveComponentSpecific();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user