Skip to content

Commit

Permalink
Merge pull request Simple-Station#120 from Mnemotechnician/feat/leash
Browse files Browse the repository at this point in the history
Leashes
  • Loading branch information
FoxxoTrystan authored Aug 23, 2024
2 parents 858fd60 + 984a93c commit a850f03
Show file tree
Hide file tree
Showing 20 changed files with 724 additions and 11 deletions.
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 sealed 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;
}
};
}
13 changes: 13 additions & 0 deletions Content.Shared/Floofstation/Leash/Components/LeashedComponent.cs
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;
}
14 changes: 14 additions & 0 deletions Content.Shared/Floofstation/Leash/LeashDoAfterEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;

namespace Content.Shared.Floofstation.Leash;

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

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

0 comments on commit a850f03

Please sign in to comment.