Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leashes #120

Merged
merged 14 commits into from
Aug 23, 2024
4 changes: 4 additions & 0 deletions Content.Client/Physics/JointVisualsOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Numerics;
using Content.Shared.Physics;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics.Joints;

Expand All @@ -27,6 +29,8 @@ protected override void Draw(in OverlayDrawArgs args)
{
_drawn.Clear();
var worldHandle = args.WorldHandle;
// Floofstation: fix incorrect drawing box location due to incorrect coordinate system
worldHandle.SetTransform(Vector2.Zero, Angle.Zero);

var spriteSystem = _entManager.System<SpriteSystem>();
var xformSystem = _entManager.System<SharedTransformSystem>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Shared.Floofstation.Leash.Components;

/// <summary>
/// Indicates that this entity or the entity that wears this entity can be leashed.
/// </summary>
[RegisterComponent]
public sealed partial class LeashAnchorComponent : Component
{
}
103 changes: 103 additions & 0 deletions Content.Shared/Floofstation/Leash/Components/LeashComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

namespace Content.Shared.Floofstation.Leash.Components;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class LeashComponent : Component
{
/// <summary>
/// Maximum number of leash joints that this entity can create.
/// </summary>
[DataField, AutoNetworkedField]
public int MaxJoints = 1;

/// <summary>
/// Default length of the leash joint.
/// </summary>
[DataField, AutoNetworkedField]
public float Length = 3.5f;

/// <summary>
/// Maximum distance between the anchor and the puller beyond which the leash will break.
/// </summary>
[DataField, AutoNetworkedField]
public float MaxDistance = 8f;

/// <summary>
/// The time it takes for one entity to attach/detach the leash to/from another entity.
/// </summary>
[DataField, AutoNetworkedField]
public TimeSpan AttachDelay = TimeSpan.FromSeconds(2f), DetachDelay = TimeSpan.FromSeconds(2f);

/// <summary>
/// The time it takes for the leashed entity to detach itself from this leash.
/// </summary>
[DataField, AutoNetworkedField]
public TimeSpan SelfDetachDelay = TimeSpan.FromSeconds(8f);

[DataField, AutoNetworkedField]
public SpriteSpecifier? LeashSprite;

[DataField]
public TimeSpan NextPull = TimeSpan.Zero;

[DataField, AutoNetworkedField]
public TimeSpan PullInterval = TimeSpan.FromSeconds(1.5f);

/// <summary>
/// How much damage each leash joint can sustain before it breaks.
/// </summary>
/// <remarks>Not currently implemented; needs to be reworked in order to work.</remarks>
[DataField, AutoNetworkedField]
public float BreakDamage = 20f;

/// <summary>
/// How much damage each leash joint loses every <see cref="DamageInterval"/>.
/// </summary>
/// <remarks>Not currently implemented; needs to be reworked in order to work.</remarks>
[DataField, AutoNetworkedField]
public float JointRepairDamage = 1f;

/// <summary>
/// Interval at which damage is calculated for each joint.
/// </summary>
/// <remarks>Not currently implemented; needs to be reworked in order to work.</remarks>
[DataField, AutoNetworkedField]
public TimeSpan DamageInterval = TimeSpan.FromMilliseconds(200);

/// <summary>
/// List of all joints and their respective pulled entities created by this leash.
/// </summary>
[DataField, AutoNetworkedField]
public List<LeashData> Leashed = new();

[DataDefinition, Serializable, NetSerializable]
public partial class LeashData
{
[DataField]
public string JointId = string.Empty;

[DataField]
public NetEntity Pulled = NetEntity.Invalid;

/// <summary>
/// Entity used to visualize the leash. Created dynamically.
/// </summary>
[DataField]
public NetEntity? LeashVisuals = null;

[DataField]
public float Damage = 0f;

[DataField]
public TimeSpan NextDamage = TimeSpan.Zero;

public LeashData(string jointId, NetEntity pulled)
{
JointId = jointId;
Pulled = pulled;
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Content.Shared.Floofstation.Leash.Components;

[RegisterComponent]
public sealed partial class LeashedComponent : Component
{
public const string VisualsContainerName = "leashed-visuals";

[DataField]
public string? JointId = null;

[NonSerialized]
public EntityUid? Puller = null, Anchor = null;
}
Mnemotechnician marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;

namespace Content.Shared.Floofstation.Leash.Events;

[Serializable, NetSerializable]
public sealed partial class LeashAttachDoAfterEvent : SimpleDoAfterEvent
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;

namespace Content.Shared.Floofstation.Leash.Events;

[Serializable, NetSerializable]
public sealed partial class LeashDetachDoAfterEvent : SimpleDoAfterEvent
{
}
Loading
Loading