(f0d812055) v0.9.9.0

This commit is contained in:
Joonas Rikkonen
2020-04-23 19:19:37 +03:00
parent b647059b93
commit ac37a3b0e4
391 changed files with 15054 additions and 5420 deletions
@@ -88,7 +88,7 @@ namespace Barotrauma.Items.Components
{
foreach (XElement subElement in item.Prefab.ConfigElement.Elements())
{
if (subElement.Name.ToString().ToLowerInvariant() != "connectionpanel") { continue; }
if (!subElement.Name.ToString().Equals("connectionpanel", StringComparison.OrdinalIgnoreCase)) { continue; }
foreach (XElement connectionElement in subElement.Elements())
{
@@ -192,6 +192,8 @@ namespace Barotrauma.Items.Components
public bool CheckCharacterSuccess(Character character)
{
if (character == null) { return false; }
//no electrocution in sub editor
if (Screen.Selected == GameMain.SubEditorScreen) { return true; }
var powered = item.GetComponent<Powered>();
if (powered != null)
@@ -203,7 +205,7 @@ namespace Barotrauma.Items.Components
float degreeOfSuccess = DegreeOfSuccess(character);
if (Rand.Range(0.0f, 0.5f) < degreeOfSuccess) { return true; }
item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, character);
ApplyStatusEffects(ActionType.OnFailure, 1.0f, character);
return false;
}
@@ -262,7 +264,18 @@ namespace Barotrauma.Items.Components
{
if (wire.OtherConnection(null) == null) //wire not connected to anything else
{
#if CLIENT
if (SubEditorScreen.IsSubEditor())
{
wire.Item.Remove();
}
else
{
wire.Item.Drop(null);
}
#else
wire.Item.Drop(null);
#endif
}
}
@@ -275,7 +288,18 @@ namespace Barotrauma.Items.Components
if (wire.OtherConnection(c) == null) //wire not connected to anything else
{
#if CLIENT
if (SubEditorScreen.IsSubEditor())
{
wire.Item.Remove();
}
else
{
wire.Item.Drop(null);
}
#else
wire.Item.Drop(null);
#endif
}
else
{
@@ -12,6 +12,7 @@ namespace Barotrauma.Items.Components
public bool ContinuousSignal;
public bool State;
public string ConnectionName;
public string PropertyName;
public Connection Connection;
[Serialize("", false, translationTextTag: "Label.", description: "The text displayed on this button/tickbox."), Editable]
public string Label { get; set; }
@@ -28,11 +29,12 @@ namespace Barotrauma.Items.Components
{
Label = element.GetAttributeString("text", "");
ConnectionName = element.GetAttributeString("connection", "");
PropertyName = element.GetAttributeString("propertyname", "").ToLowerInvariant();
Signal = element.GetAttributeString("signal", "1");
foreach (XElement subElement in element.Elements())
{
if (subElement.Name.ToString().ToLowerInvariant() == "statuseffect")
if (subElement.Name.ToString().Equals("statuseffect", System.StringComparison.OrdinalIgnoreCase))
{
StatusEffects.Add(StatusEffect.Load(subElement, parentDebugName: "custom interface element (label " + Label + ")"));
}
@@ -89,6 +91,7 @@ namespace Barotrauma.Items.Components
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "button":
case "textbox":
var button = new CustomInterfaceElement(subElement)
{
ContinuousSignal = false
@@ -106,7 +109,7 @@ namespace Barotrauma.Items.Components
};
if (string.IsNullOrEmpty(tickBox.Label))
{
tickBox.Label = "Signal out " + customInterfaceElementList.Count(e => !e.ContinuousSignal);
tickBox.Label = "Signal out " + customInterfaceElementList.Count(e => e.ContinuousSignal);
}
customInterfaceElementList.Add(tickBox);
break;
@@ -168,6 +171,18 @@ namespace Barotrauma.Items.Components
tickBoxElement.State = state;
}
private void TextChanged(CustomInterfaceElement textElement, string text)
{
textElement.Signal = text;
foreach (ISerializableEntity e in item.AllPropertyObjects)
{
if (e.SerializableProperties.ContainsKey(textElement.PropertyName))
{
e.SerializableProperties[textElement.PropertyName].TrySetValue(e, text);
}
}
}
public override void Update(float deltaTime, Camera cam)
{
UpdateProjSpecific();
@@ -15,13 +15,13 @@ namespace Barotrauma.Items.Components
private float lightBrightness;
private float blinkFrequency;
private float range;
private float flicker;
private float flicker, flickerState;
private bool castShadows;
private bool drawBehindSubs;
private float blinkTimer;
private bool itemLoaded;
private double lastToggleSignalTime;
public PhysicsBody ParentBody;
@@ -34,6 +34,7 @@ namespace Barotrauma.Items.Components
{
range = MathHelper.Clamp(value, 0.0f, 4096.0f);
#if CLIENT
item.ResetCachedVisibleSize();
if (light != null) { light.Range = range; }
#endif
}
@@ -78,13 +79,11 @@ namespace Barotrauma.Items.Components
if (IsActive == value) { return; }
IsActive = value;
#if SERVER
if (GameMain.Server != null && itemLoaded) { item.CreateServerEvent(this); }
#endif
OnStateChanged();
}
}
[Serialize(0.0f, false, description: "How heavily the light flickers. 0 = no flickering, 1 = the light will alternate between completely dark and full brightness.")]
[Editable, Serialize(0.0f, false, description: "How heavily the light flickers. 0 = no flickering, 1 = the light will alternate between completely dark and full brightness.")]
public float Flicker
{
get { return flicker; }
@@ -94,6 +93,13 @@ namespace Barotrauma.Items.Components
}
}
[Editable, Serialize(1.0f, false, description: "How fast the light flickers.")]
public float FlickerSpeed
{
get;
set;
}
[Editable, Serialize(0.0f, true, description: "How rapidly the light blinks on and off (in Hz). 0 = no blinking.")]
public float BlinkFrequency
{
@@ -117,6 +123,13 @@ namespace Barotrauma.Items.Components
}
}
[Serialize(false, false, description: "If enabled, the component will ignore continuous signals received in the toggle input (i.e. a continuous signal will only toggle it once).")]
public bool IgnoreContinuousToggle
{
get;
set;
}
public override void Move(Vector2 amount)
{
#if CLIENT
@@ -158,14 +171,7 @@ namespace Barotrauma.Items.Components
IsActive = IsOn;
item.AddTag("light");
}
public override void OnItemLoaded()
{
base.OnItemLoaded();
itemLoaded = true;
SetLightSourceState(IsActive, lightBrightness);
}
public override void Update(float deltaTime, Camera cam)
{
if (item.AiTarget != null)
@@ -219,7 +225,7 @@ namespace Barotrauma.Items.Components
}
else
{
lightBrightness = MathHelper.Lerp(lightBrightness, Math.Min(Voltage, 1.0f), 0.1f);
lightBrightness = MathHelper.Lerp(lightBrightness, powerConsumption <= 0.0f ? 1.0f : Math.Min(Voltage, 1.0f), 0.1f);
}
if (blinkFrequency > 0.0f)
@@ -233,7 +239,10 @@ namespace Barotrauma.Items.Components
}
else
{
SetLightSourceState(true, lightBrightness * (1.0f - Rand.Range(0.0f, flicker)));
flickerState += deltaTime * FlickerSpeed;
flickerState %= 255;
float noise = PerlinNoise.GetPerlin(flickerState, flickerState * 0.5f) * flicker;
SetLightSourceState(true, lightBrightness * (1.0f - noise));
}
if (powerIn == null && powerConsumption > 0.0f) { Voltage -= deltaTime; }
@@ -249,15 +258,21 @@ namespace Barotrauma.Items.Components
return true;
}
partial void OnStateChanged();
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
{
switch (connection.Name)
{
case "toggle":
IsActive = !IsActive;
if (!IgnoreContinuousToggle || lastToggleSignalTime < Timing.TotalTime - 0.1)
{
IsOn = !IsOn;
}
lastToggleSignalTime = Timing.TotalTime;
break;
case "set_state":
IsActive = (signal != "0");
IsOn = signal != "0";
break;
case "set_color":
LightColor = XMLExtensions.ParseColor(signal, false);
@@ -265,11 +280,6 @@ namespace Barotrauma.Items.Components
}
}
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null)
{
msg.Write(IsOn);
}
private void UpdateAITarget(AITarget target)
{
if (!IsActive) { return; }
@@ -40,6 +40,9 @@ namespace Barotrauma.Items.Components
set
{
rangeX = MathHelper.Clamp(value, 0.0f, 1000.0f);
#if CLIENT
item.ResetCachedVisibleSize();
#endif
}
}
[InGameEditable, Serialize(0.0f, true, description: "Vertical movement detection range.")]
@@ -26,7 +26,13 @@ namespace Barotrauma.Items.Components
public float Range
{
get { return range; }
set { range = Math.Max(value, 0.0f); }
set
{
range = Math.Max(value, 0.0f);
#if CLIENT
item.ResetCachedVisibleSize();
#endif
}
}
[InGameEditable, Serialize(1, true, description: "WiFi components can only communicate with components that use the same channel.")]
@@ -39,6 +45,14 @@ namespace Barotrauma.Items.Components
}
}
[Serialize(false, false, description: "Can the component communicate with wifi components in another team's submarine (e.g. enemy sub in Combat missions, respawn shuttle). Needs to be enabled on both the component transmitting the signal and the component receiving it.")]
public bool AllowCrossTeamCommunication
{
get;
set;
}
[Editable, Serialize(false, false, description: "If enabled, any signals received from another chat-linked wifi component are displayed " +
"as chat messages in the chatbox of the player holding the item.")]
public bool LinkToChat
@@ -84,7 +98,7 @@ namespace Barotrauma.Items.Components
{
if (sender == null || sender.channel != channel) { return false; }
if (sender.TeamID != TeamID)
if (sender.TeamID != TeamID && !AllowCrossTeamCommunication)
{
return false;
}
@@ -97,6 +111,10 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
chatMsgCooldown -= deltaTime;
if (chatMsgCooldown <= 0.0f)
{
IsActive = false;
}
}
public void TransmitSignal(int stepsTaken, string signal, Item source, Character sender, bool sendToChat, float signalStrength = 1.0f)
@@ -164,7 +182,11 @@ namespace Barotrauma.Items.Components
}
}
}
if (chatMsgSent) chatMsgCooldown = MinChatMessageInterval;
if (chatMsgSent)
{
chatMsgCooldown = MinChatMessageInterval;
IsActive = true;
}
prevSignal = signal;
}
@@ -5,6 +5,9 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;
#if CLIENT
using Microsoft.Xna.Framework.Input;
#endif
namespace Barotrauma.Items.Components
{
@@ -39,7 +42,7 @@ namespace Barotrauma.Items.Components
const float MaxAttachDistance = 150.0f;
const float MinNodeDistance = 15.0f;
const float MinNodeDistance = 7.0f;
const int MaxNodeCount = 255;
const int MaxNodesPerNetworkEvent = 30;
@@ -177,6 +180,8 @@ namespace Barotrauma.Items.Components
newConnection.Item.Position :
newConnection.Item.Position - refSub.HiddenSubPosition;
nodePos = RoundNode(nodePos);
if (nodes.Count > 0 && nodes[0] == nodePos) { break; }
if (nodes.Count > 1 && nodes[nodes.Count - 1] == nodePos) { break; }
@@ -334,7 +339,12 @@ namespace Barotrauma.Items.Components
}
else
{
#if CLIENT
bool disableGrid = SubEditorScreen.IsSubEditor() && (PlayerInput.KeyDown(Keys.LeftShift) || PlayerInput.KeyDown(Keys.RightShift));
newNodePos = disableGrid ? item.Position : RoundNode(item.Position);
#else
newNodePos = RoundNode(item.Position);
#endif
if (sub != null) { newNodePos -= sub.HiddenSubPosition; }
canPlaceNode = true;
}
@@ -497,6 +507,9 @@ namespace Barotrauma.Items.Components
sectionExtents.Y = Math.Max(Math.Abs(nodes[i].Y - item.Position.Y), sectionExtents.Y);
}
}
#if CLIENT
item.ResetCachedVisibleSize();
#endif
}
public void ClearConnections(Character user = null)
@@ -507,7 +520,7 @@ namespace Barotrauma.Items.Components
foreach (Item item in Item.ItemList)
{
var connectionPanel = item.GetComponent<ConnectionPanel>();
if (connectionPanel != null && connectionPanel.DisconnectedWires.Contains(this))
if (connectionPanel != null && connectionPanel.DisconnectedWires.Contains(this) && !item.Removed)
{
#if SERVER
item.CreateServerEvent(connectionPanel);
@@ -526,18 +539,18 @@ namespace Barotrauma.Items.Components
if (connections[0] != null && connections[1] != null)
{
GameServer.Log(user.LogName + " disconnected a wire from " +
GameServer.Log(GameServer.CharacterLogName(user) + " disconnected a wire from " +
connections[0].Item.Name + " (" + connections[0].Name + ") to "+
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (connections[0] != null)
{
GameServer.Log(user.LogName + " disconnected a wire from " +
GameServer.Log(GameServer.CharacterLogName(user) + " disconnected a wire from " +
connections[0].Item.Name + " (" + connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (connections[1] != null)
{
GameServer.Log(user.LogName + " disconnected a wire from " +
GameServer.Log(GameServer.CharacterLogName(user) + " disconnected a wire from " +
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
}