Merge branch 'dev' of https://github.com/Regalis11/Barotrauma.git into unstable-tests

This commit is contained in:
Evil Factory
2022-04-08 15:28:28 -03:00
20 changed files with 156 additions and 145 deletions
@@ -1784,7 +1784,7 @@ namespace Barotrauma
AnimController.Anim != AnimController.Animation.UsingConstruction &&
AnimController.Anim != AnimController.Animation.CPR &&
(GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient || Controlled == this) &&
(AnimController.OnGround && !AnimController.InWater || IsKeyDown(InputType.Aim) && HeldItems.None(i => i.RequireAimToUse)))
AnimController.OnGround && !AnimController.InWater)
{
if (dontFollowCursor)
{
@@ -1794,30 +1794,13 @@ namespace Barotrauma
{
// Values lower than this seem to cause constantious flipping when the mouse is near the player and the player is running, because the root collider moves after flipping.
float followMargin = 40;
Vector2 diff = CursorPosition - AnimController.Collider.Position;
if (InWater)
if (CursorPosition.X < AnimController.Collider.Position.X - followMargin)
{
followMargin = 80;
diff = Vector2.Transform(diff, Matrix.CreateRotationZ(-AnimController.Collider.Rotation));
if (diff.X < followMargin)
{
AnimController.TargetDir = Direction.Left;
}
else if (diff.X > followMargin)
{
AnimController.TargetDir = Direction.Right;
}
AnimController.TargetDir = Direction.Left;
}
else
else if (CursorPosition.X > AnimController.Collider.Position.X + followMargin)
{
if (CursorPosition.X < AnimController.Collider.Position.X - followMargin)
{
AnimController.TargetDir = Direction.Left;
}
else if (CursorPosition.X > AnimController.Collider.Position.X + followMargin)
{
AnimController.TargetDir = Direction.Right;
}
AnimController.TargetDir = Direction.Right;
}
}
}
@@ -21,7 +21,7 @@ namespace Barotrauma
public override void UnloadFile()
{
SubmarineInfo.RefreshSavedSub(Path.Value);
SubmarineInfo.RemoveSavedSub(Path.Value);
}
public override void Sort()
@@ -469,15 +469,22 @@ namespace Barotrauma
}
var corePackageElement = contentPackagesElement.GetChildElement(CorePackageElementName);
var configEnabledCorePackage = findPackage(CorePackages, corePackageElement);
if (configEnabledCorePackage == null)
if (corePackageElement == null)
{
string packageStr = corePackageElement.GetAttributeString("name", null) ?? corePackageElement.GetAttributeStringUnrestricted("path", "UNKNOWN");
DebugConsole.ThrowError($"Could not find the selected core package \"{packageStr}\". Switching to the \"{enabledCorePackage.Name}\" package.");
DebugConsole.AddWarning($"No core package selected. Switching to the \"{enabledCorePackage.Name}\" package.");
}
else
{
enabledCorePackage = configEnabledCorePackage;
var configEnabledCorePackage = findPackage(CorePackages, corePackageElement);
if (configEnabledCorePackage == null)
{
string packageStr = corePackageElement.GetAttributeString("name", null) ?? corePackageElement.GetAttributeStringUnrestricted("path", "UNKNOWN");
DebugConsole.ThrowError($"Could not find the selected core package \"{packageStr}\". Switching to the \"{enabledCorePackage.Name}\" package.");
}
else
{
enabledCorePackage = configEnabledCorePackage;
}
}
var regularPackagesElement = contentPackagesElement.GetChildElement(RegularPackagesElementName);
@@ -110,7 +110,7 @@ namespace Barotrauma
set { defaultRect = value; }
}
private Dictionary<string, Connection> connections;
private readonly Dictionary<string, Connection> connections;
private readonly List<Repairable> repairables;
@@ -517,74 +517,7 @@ namespace Barotrauma
get { return condition; }
set
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
if (!MathUtils.IsValid(value)) { return; }
if (Indestructible) { return; }
if (InvulnerableToDamage && value <= condition) { return; }
float prev = condition;
bool wasInFullCondition = IsFullCondition;
condition = MathHelper.Clamp(value, 0.0f, MaxCondition);
if (condition == 0.0f && prev > 0.0f)
{
//Flag connections to be updated as device is broken
flagChangedConnections(connections);
#if CLIENT
foreach (ItemComponent ic in components)
{
ic.PlaySound(ActionType.OnBroken);
}
if (Screen.Selected == GameMain.SubEditorScreen) { return; }
#endif
ApplyStatusEffects(ActionType.OnBroken, 1.0f, null);
}
else if (condition > 0.0f && prev <= 0.0f)
{
//Flag connections to be updated as device is now working again
flagChangedConnections(connections);
}
SetActiveSprite();
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
if (Math.Abs(lastSentCondition - condition) > 1.0f)
{
conditionUpdatePending = true;
isActive = true;
}
else if (wasInFullCondition != IsFullCondition)
{
conditionUpdatePending = true;
isActive = true;
}
else if (!MathUtils.NearlyEqual(lastSentCondition, condition) && (condition <= 0.0f || condition >= MaxCondition))
{
sendConditionUpdateTimer = 0.0f;
conditionUpdatePending = true;
isActive = true;
}
}
LastConditionChange = condition - prev;
ConditionLastUpdated = Timing.TotalTime;
static void flagChangedConnections(Dictionary<string, Connection> connections)
{
if (connections == null) { return; }
foreach (Connection c in connections.Values)
{
if (c.IsPower)
{
Powered.ChangedConnections.Add(c);
foreach (Connection conn in c.Recipients)
{
Powered.ChangedConnections.Add(conn);
}
}
}
}
SetCondition(value, isNetworkEvent: false);
}
}
@@ -1670,6 +1603,81 @@ namespace Barotrauma
return new AttackResult(damageAmount, null);
}
private void SetCondition(float value, bool isNetworkEvent)
{
if (!isNetworkEvent)
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
}
if (!MathUtils.IsValid(value)) { return; }
if (Indestructible) { return; }
if (InvulnerableToDamage && value <= condition) { return; }
float prev = condition;
bool wasInFullCondition = IsFullCondition;
condition = MathHelper.Clamp(value, 0.0f, MaxCondition);
if (condition == 0.0f && prev > 0.0f)
{
//Flag connections to be updated as device is broken
flagChangedConnections(connections);
#if CLIENT
foreach (ItemComponent ic in components)
{
ic.PlaySound(ActionType.OnBroken);
}
if (Screen.Selected == GameMain.SubEditorScreen) { return; }
#endif
ApplyStatusEffects(ActionType.OnBroken, 1.0f, null);
}
else if (condition > 0.0f && prev <= 0.0f)
{
//Flag connections to be updated as device is now working again
flagChangedConnections(connections);
}
SetActiveSprite();
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
if (Math.Abs(lastSentCondition - condition) > 1.0f)
{
conditionUpdatePending = true;
isActive = true;
}
else if (wasInFullCondition != IsFullCondition)
{
conditionUpdatePending = true;
isActive = true;
}
else if (!MathUtils.NearlyEqual(lastSentCondition, condition) && (condition <= 0.0f || condition >= MaxCondition))
{
sendConditionUpdateTimer = 0.0f;
conditionUpdatePending = true;
isActive = true;
}
}
LastConditionChange = condition - prev;
ConditionLastUpdated = Timing.TotalTime;
static void flagChangedConnections(Dictionary<string, Connection> connections)
{
if (connections == null) { return; }
foreach (Connection c in connections.Values)
{
if (c.IsPower)
{
Powered.ChangedConnections.Add(c);
foreach (Connection conn in c.Recipients)
{
Powered.ChangedConnections.Add(conn);
}
}
}
}
}
private bool IsInWater()
{
if (CurrentHull == null) { return true; }
@@ -545,7 +545,7 @@ namespace Barotrauma
savedSubmarines.Add(subInfo);
}
public static void RefreshSavedSub(string filePath)
public static void RemoveSavedSub(string filePath)
{
string fullPath = Path.GetFullPath(filePath);
for (int i = savedSubmarines.Count - 1; i >= 0; i--)
@@ -555,7 +555,11 @@ namespace Barotrauma
savedSubmarines[i].Dispose();
}
}
}
public static void RefreshSavedSub(string filePath)
{
RemoveSavedSub(filePath);
if (File.Exists(filePath))
{
var subInfo = new SubmarineInfo(filePath);
@@ -14,7 +14,7 @@ namespace Barotrauma
public override bool Loaded => left.Loaded || right.Loaded;
public override void RetrieveValue()
{
cachedValue = left.Value + right.Value;
cachedValue = (left.Value ?? string.Empty) + (right.Value ?? string.Empty);
UpdateLanguage();
}
}
@@ -2,7 +2,6 @@ using Barotrauma.Extensions;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Linq;