Merge pull request #5 from Regalis11/master

0.13.3.11
This commit is contained in:
Evil Factory
2021-04-29 13:15:54 -03:00
committed by GitHub
88 changed files with 800 additions and 428 deletions
@@ -37,7 +37,7 @@ namespace Barotrauma.Items.Components
: base(item,element)
{
}
public override bool Use(float deltaTime, Character character = null)
{
if (character == null || character.Removed) return false;
@@ -61,7 +61,7 @@ namespace Barotrauma.Items.Components
Vector2 propulsion = dir * Force * character.PropulsionSpeedMultiplier;
if (character.AnimController.InWater) character.AnimController.TargetMovement = dir;
if (character.AnimController.InWater && Force > 0.0f) { character.AnimController.TargetMovement = dir; }
foreach (Limb limb in character.AnimController.Limbs)
{
@@ -757,7 +757,7 @@ namespace Barotrauma.Items.Components
bool reducesCondition = false;
foreach (StatusEffect effect in statusEffects)
{
if (broken && effect.type != ActionType.OnBroken) { continue; }
if (broken && !effect.AllowWhenBroken && effect.type != ActionType.OnBroken) { continue; }
if (user != null) { effect.SetUser(user); }
item.ApplyStatusEffect(effect, type, deltaTime, character, targetLimb, useTarget, false, false, worldPosition);
reducesCondition |= effect.ReducesItemCondition();
@@ -153,6 +153,7 @@ namespace Barotrauma.Items.Components
if (IsToggle)
{
item.SendSignal(State ? "1" : "0", "signal_out");
item.SendSignal(State ? "1" : "0", "trigger_out");
}
if (user == null
@@ -263,6 +264,8 @@ namespace Barotrauma.Items.Components
}
}
private double lastUsed;
public override bool Use(float deltaTime, Character activator = null)
{
if (activator != user)
@@ -277,7 +280,22 @@ namespace Barotrauma.Items.Components
return false;
}
item.SendSignal(new Signal("1", sender: user), "trigger_out");
if (IsToggle && (activator == null || lastUsed < Timing.TotalTime - 0.1))
{
if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)
{
State = !State;
#if SERVER
item.CreateServerEvent(this);
#endif
}
}
else
{
item.SendSignal(new Signal("1", sender: user), "trigger_out");
}
lastUsed = Timing.TotalTime;
ApplyStatusEffects(ActionType.OnUse, 1.0f, activator);
@@ -308,7 +308,15 @@ namespace Barotrauma.Items.Components
if (AutoPilot)
{
UpdateAutoPilot(deltaTime);
TargetVelocity = TargetVelocity.ClampLength(MathHelper.Lerp(AutoPilotMaxSpeed, AIPilotMaxSpeed, userSkill) * 100.0f);
float throttle = 1.0f;
if (controlledSub != null)
{
//if the sub is heading in the correct direction, throttle the speed according to the user's skill
//if it's e.g. sinking due to extra water, don't throttle, but allow emptying up the ballast completely
throttle = MathHelper.Clamp(Vector2.Dot(controlledSub.Velocity, TargetVelocity) / 100.0f, 0.0f, 1.0f);
}
float maxSpeed = MathHelper.Lerp(AutoPilotMaxSpeed, AIPilotMaxSpeed, userSkill) * 100.0f;
TargetVelocity = TargetVelocity.ClampLength(MathHelper.Lerp(100.0f, maxSpeed, throttle));
}
else
{
@@ -372,7 +372,7 @@ namespace Barotrauma.Items.Components
hits = hits.OrderBy(h => h.Fraction).ToList();
foreach (HitscanResult h in hits)
{
item.body.SetTransform(h.Point, rotation);
item.SetTransform(h.Point, rotation);
if (HandleProjectileCollision(h.Fixture, h.Normal, Vector2.Zero))
{
hitSomething = true;
@@ -23,6 +23,17 @@ namespace Barotrauma.Items.Components
}
}
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
[InGameEditable, Serialize("1", true, description: "The signal sent when the condition is met.", alwaysUseInstanceValues: true)]
public string Output
{
@@ -53,17 +64,6 @@ namespace Barotrauma.Items.Components
}
}
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
public AndComponent(Item item, XElement element)
: base(item, element)
{
@@ -15,6 +15,17 @@ namespace Barotrauma.Items.Components
//the output is sent if both inputs have received a signal within the timeframe
protected float timeFrame;
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
[InGameEditable, Serialize("1", true, description: "The signal sent when the condition is met.", alwaysUseInstanceValues: true)]
public string Output
{
@@ -45,17 +56,6 @@ namespace Barotrauma.Items.Components
}
}
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
[InGameEditable(DecimalCount = 2), Serialize(0.0f, true, description: "The maximum amount of time between the received signals. If set to 0, the signals must be received at the same time.", alwaysUseInstanceValues: true)]
public float TimeFrame
{
@@ -6,6 +6,17 @@ namespace Barotrauma.Items.Components
{
partial class MemoryComponent : ItemComponent, IServerSerializable
{
private int maxValueLength;
[Editable, Serialize(200, false, description: "The maximum length of the stored value. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxValueLength
{
get { return maxValueLength; }
set
{
maxValueLength = Math.Max(value, 0);
}
}
private string value;
[InGameEditable, Serialize("", true, description: "The currently stored signal the item outputs.", alwaysUseInstanceValues: true)]
@@ -23,17 +34,6 @@ namespace Barotrauma.Items.Components
}
}
private int maxValueLength;
[Editable, Serialize(200, false, description: "The maximum length of the stored value. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxValueLength
{
get { return maxValueLength; }
set
{
maxValueLength = Math.Max(value, 0);
}
}
protected bool writeable = true;
public MemoryComponent(Item item, XElement element)
@@ -74,6 +74,17 @@ namespace Barotrauma.Items.Components
}
}
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
private string output;
[InGameEditable, Serialize("1", true, description: "The signal the item outputs when it has detected movement.", alwaysUseInstanceValues: true)]
public string Output
@@ -106,17 +117,6 @@ namespace Barotrauma.Items.Components
}
}
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
[Editable(DecimalCount = 3), Serialize(0.01f, true, description: "How fast the objects within the detector's range have to be moving (in m/s).", alwaysUseInstanceValues: true)]
public float MinimumVelocity
{
@@ -18,6 +18,17 @@ namespace Barotrauma.Items.Components
private bool nonContinuousOutputSent;
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output string. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
private string output;
[InGameEditable, Serialize("1", true, description: "The signal this item outputs when the received signal matches the regular expression.", alwaysUseInstanceValues: true)]
@@ -61,23 +72,11 @@ namespace Barotrauma.Items.Components
catch
{
item.SendSignal("ERROR", "signal_out");
return;
}
}
}
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output string. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
public RegExFindComponent(Item item, XElement element)
: base(item, element)
{
@@ -5,6 +5,17 @@ namespace Barotrauma.Items.Components
{
class SignalCheckComponent : ItemComponent
{
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
private string output;
[InGameEditable, Serialize("1", true, description: "The signal this item outputs when the received signal matches the target signal.", alwaysUseInstanceValues: true)]
public string Output
@@ -40,17 +51,6 @@ namespace Barotrauma.Items.Components
[InGameEditable, Serialize("", true, description: "The value to compare the received signals against.", alwaysUseInstanceValues: true)]
public string TargetSignal { get; set; }
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
public SignalCheckComponent(Item item, XElement element)
: base(item, element)
{
@@ -10,6 +10,17 @@ namespace Barotrauma.Items.Components
private bool fireInRange;
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
private string output;
[InGameEditable, Serialize("1", true, description: "The signal the item outputs when it has detected a fire.", alwaysUseInstanceValues: true)]
public string Output
@@ -42,17 +53,6 @@ namespace Barotrauma.Items.Components
}
}
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
public SmokeDetector(Item item, XElement element)
: base(item, element)
{
@@ -12,6 +12,17 @@ namespace Barotrauma.Items.Components
private bool isInWater;
private float stateSwitchDelay;
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
private string output;
[InGameEditable, Serialize("1", true, description: "The signal the item sends out when it's underwater.", alwaysUseInstanceValues: true)]
public string Output
@@ -44,17 +55,6 @@ namespace Barotrauma.Items.Components
}
}
private int maxOutputLength;
[Editable, Serialize(200, false, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
public int MaxOutputLength
{
get { return maxOutputLength; }
set
{
maxOutputLength = Math.Max(value, 0);
}
}
public WaterDetector(Item item, XElement element)
: base(item, element)
{
@@ -144,6 +144,11 @@ namespace Barotrauma
// If the variant does not exist, parse the path so that it uses first variant.
SpritePath = tempPath.Replace("[VARIANT]", "1");
}
if (!File.Exists(SpritePath) && _gender == Gender.None)
{
// If there's no sprite for Gender.None does not exist, try to use male sprite
SpritePath = tempPath.Replace("[GENDER]", "male");
}
if (parseSpritePath)
{
Sprite.ParseTexturePath(file: SpritePath);
@@ -507,7 +507,8 @@ namespace Barotrauma
#if CLIENT
if (visualSlots != null)
{
visualSlots[i]?.ShowBorderHighlight(Color.White, 0.1f, 0.4f);
visualSlots[i].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
if (selectedSlot?.Inventory == this) { selectedSlot.ForceTooltipRefresh = true; }
}
#endif
@@ -625,7 +626,10 @@ namespace Barotrauma
else
{
existingItems.Add(slots[index].FirstOrDefault());
slots[index].RemoveItem(existingItems.First());
for (int j = 0; j < capacity; j++)
{
if (existingItems.Any(existingItem => slots[j].Contains(existingItem))) { slots[j].RemoveItem(existingItems.First()); }
}
}
List<Item> stackedItems = new List<Item>();
@@ -831,7 +835,14 @@ namespace Barotrauma
if (!slots[n].Contains(item)) { continue; }
slots[n].RemoveItem(item);
item.ParentInventory = null;
item.ParentInventory = null;
#if CLIENT
if (visualSlots != null)
{
visualSlots[n].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
if (selectedSlot?.Inventory == this) { selectedSlot.ForceTooltipRefresh = true; }
}
#endif
}
}
@@ -1356,11 +1356,11 @@ namespace Barotrauma
{
if (!isNetworkEvent && checkCondition)
{
if (condition == 0.0f && effect.type != ActionType.OnBroken) return;
if (condition == 0.0f && !effect.AllowWhenBroken && effect.type != ActionType.OnBroken) { return; }
}
if (effect.type != type) return;
if (effect.type != type) { return; }
bool hasTargets = (effect.TargetIdentifiers == null);
bool hasTargets = effect.TargetIdentifiers == null;
targets.Clear();
@@ -2611,7 +2611,7 @@ namespace Barotrauma
foreach (XAttribute attribute in element.Attributes())
{
if (!item.SerializableProperties.TryGetValue(attribute.Name.ToString(), out SerializableProperty property)) continue;
if (!item.SerializableProperties.TryGetValue(attribute.Name.ToString(), out SerializableProperty property)) { continue; }
bool shouldBeLoaded = false;
foreach (var propertyAttribute in property.Attributes.OfType<Serialize>())
{
@@ -2622,7 +2622,31 @@ namespace Barotrauma
}
}
if (shouldBeLoaded) { property.TrySetValue(item, attribute.Value); }
if (shouldBeLoaded)
{
object prevValue = property.GetValue(item);
property.TrySetValue(item, attribute.Value);
//create network events for properties that differ from the prefab values
//(e.g. if a character has an item with modified colors in their inventory)
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer && property.Attributes.OfType<Editable>().Any() &&
(submarine == null || !submarine.Loading ))
{
switch (property.Name)
{
case "Tags":
case "Condition":
case "Description":
//these can be ignored, they're always written in the spawn data
break;
default:
if (!(property.GetValue(item)?.Equals(prevValue) ?? true))
{
GameMain.NetworkMember.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ChangeProperty, property });
}
break;
}
}
}
}
item.ParseLinks(element, idRemap);