Unstable 0.17.3.0
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
using Barotrauma.Networking;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.Networking;
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
@@ -12,8 +12,36 @@ namespace Barotrauma.Items.Components
|
||||
private ISpatialEntity source;
|
||||
private Item target;
|
||||
|
||||
private Vector2? launchDir;
|
||||
|
||||
private void SetSource(ISpatialEntity source)
|
||||
{
|
||||
this.source = source;
|
||||
if (source is Limb sourceLimb)
|
||||
{
|
||||
sourceLimb.AttachedRope = this;
|
||||
float offset = sourceLimb.Params.GetSpriteOrientation() - MathHelper.PiOver2;
|
||||
launchDir = VectorExtensions.Forward(sourceLimb.body.TransformedRotation - offset * sourceLimb.character.AnimController.Dir);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetSource()
|
||||
{
|
||||
if (source is Limb sourceLimb && sourceLimb.AttachedRope == this)
|
||||
{
|
||||
sourceLimb.AttachedRope = null;
|
||||
}
|
||||
source = null;
|
||||
}
|
||||
|
||||
private float snapTimer;
|
||||
private const float SnapAnimDuration = 1.0f;
|
||||
|
||||
[Serialize(1.0f, IsPropertySaveable.No, description: "")]
|
||||
public float SnapAnimDuration
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
private float raycastTimer;
|
||||
private const float RayCastInterval = 0.2f;
|
||||
@@ -46,6 +74,13 @@ namespace Barotrauma.Items.Components
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(360.0f, IsPropertySaveable.No, description: "How far the source item can be from the projectile until the rope breaks.")]
|
||||
public float MaxAngle
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(true, IsPropertySaveable.No, description: "Should the rope snap when it collides with a structure/submarine (if not, it will just go through it).")]
|
||||
public bool SnapOnCollision
|
||||
{
|
||||
@@ -115,8 +150,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(source != null);
|
||||
System.Diagnostics.Debug.Assert(target != null);
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
SetSource(source);
|
||||
Snapped = false;
|
||||
ApplyStatusEffects(ActionType.OnUse, 1.0f, worldPosition: item.WorldPosition);
|
||||
IsActive = true;
|
||||
@@ -127,7 +162,7 @@ namespace Barotrauma.Items.Components
|
||||
if (source == null || target == null || target.Removed ||
|
||||
(source is Entity sourceEntity && sourceEntity.Removed))
|
||||
{
|
||||
source = null;
|
||||
ResetSource();
|
||||
target = null;
|
||||
IsActive = false;
|
||||
return;
|
||||
@@ -144,12 +179,27 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
Vector2 diff = target.WorldPosition - source.WorldPosition;
|
||||
if (diff.LengthSquared() > MaxLength * MaxLength)
|
||||
float lengthSqr = diff.LengthSquared();
|
||||
if (lengthSqr > MaxLength * MaxLength)
|
||||
{
|
||||
Snap();
|
||||
return;
|
||||
}
|
||||
|
||||
if (MaxAngle < 180 && lengthSqr > 2500)
|
||||
{
|
||||
if (launchDir == null)
|
||||
{
|
||||
launchDir = diff;
|
||||
}
|
||||
float angle = MathHelper.ToDegrees(VectorExtensions.Angle(launchDir.Value, diff));
|
||||
if (angle > MaxAngle)
|
||||
{
|
||||
Snap();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#if CLIENT
|
||||
item.ResetCachedVisibleSize();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user