diff --git a/Content.Shared/Floofstation/Leash/Components/LeashComponent.cs b/Content.Shared/Floofstation/Leash/Components/LeashComponent.cs
index 20ba744c0a4..7d17ecb8e81 100644
--- a/Content.Shared/Floofstation/Leash/Components/LeashComponent.cs
+++ b/Content.Shared/Floofstation/Leash/Components/LeashComponent.cs
@@ -46,27 +46,6 @@ public sealed partial class LeashComponent : Component
[DataField, AutoNetworkedField]
public TimeSpan PullInterval = TimeSpan.FromSeconds(1.5f);
- ///
- /// How much damage each leash joint can sustain before it breaks.
- ///
- /// Not currently implemented; needs to be reworked in order to work.
- [DataField, AutoNetworkedField]
- public float BreakDamage = 20f;
-
- ///
- /// How much damage each leash joint loses every .
- ///
- /// Not currently implemented; needs to be reworked in order to work.
- [DataField, AutoNetworkedField]
- public float JointRepairDamage = 1f;
-
- ///
- /// Interval at which damage is calculated for each joint.
- ///
- /// Not currently implemented; needs to be reworked in order to work.
- [DataField, AutoNetworkedField]
- public TimeSpan DamageInterval = TimeSpan.FromMilliseconds(200);
-
///
/// List of all joints and their respective pulled entities created by this leash.
///
@@ -88,12 +67,6 @@ public sealed partial class LeashData
[DataField]
public NetEntity? LeashVisuals = null;
- [DataField]
- public float Damage = 0f;
-
- [DataField]
- public TimeSpan NextDamage = TimeSpan.Zero;
-
public LeashData(string jointId, NetEntity pulled)
{
JointId = jointId;
diff --git a/Content.Shared/Floofstation/Leash/LeashSystem.cs b/Content.Shared/Floofstation/Leash/LeashSystem.cs
index fcd77a5994a..bb5356d6763 100644
--- a/Content.Shared/Floofstation/Leash/LeashSystem.cs
+++ b/Content.Shared/Floofstation/Leash/LeashSystem.cs
@@ -41,9 +41,8 @@ public override void Initialize()
UpdatesBefore.Add(typeof(SharedPhysicsSystem));
SubscribeLocalEvent(OnAnchorUnequipping);
- SubscribeLocalEvent(OnLeashedInserting);
- SubscribeLocalEvent(OnJointRemoved);
SubscribeLocalEvent>(OnGetEquipmentVerbs);
+ SubscribeLocalEvent(OnJointRemoved, after: [typeof(SharedJointSystem)]);
SubscribeLocalEvent>(OnGetLeashedVerbs);
SubscribeLocalEvent(OnAttachDoAfter);
@@ -73,30 +72,24 @@ public override void Update(float frameTime)
if (data.Pulled == NetEntity.Invalid || !TryGetEntity(data.Pulled, out var target))
continue;
+ // Client side only: set max distance to infinity to prevent the client from ever predicting leashes.
+ if (_net.IsClient
+ && TryComp(target, out var jointComp)
+ && jointComp.GetJoints.TryGetValue(data.JointId, out var joint)
+ && joint is DistanceJoint distanceJoint
+ )
+ distanceJoint.MaxLength = float.MaxValue;
+
+ if (_net.IsClient)
+ continue;
+
// Break each leash joint whose entities are on different maps or are too far apart
var targetXForm = Transform(target.Value);
if (targetXForm.MapUid != sourceXForm.MapUid
|| !sourceXForm.Coordinates.TryDistance(EntityManager, targetXForm.Coordinates, out var dst)
- || dst > leash.MaxDistance)
+ || dst > leash.MaxDistance
+ )
RemoveLeash(target.Value, (leashEnt, leash));
-
- // Calculate joint damage
- if (_timing.CurTime < data.NextDamage
- || !TryComp(target, out var jointComp)
- || !jointComp.GetJoints.TryGetValue(data.JointId, out var joint))
- continue;
-
- // TODO reaction force always returns 0 and thus damage doesn't work
- // TODO find another way to calculate how much force is being excerted to hold the two entities together
- // var damage = joint.GetReactionForce(1 / (float) leash.DamageInterval.TotalSeconds).Length() - leash.JointRepairDamage;
- // data.Damage = Math.Max(0f, data.Damage + damage);
- // data.NextDamage = _timing.CurTime + leash.DamageInterval;
- //
- // if (damage >= leash.BreakDamage && !_net.IsClient)
- // {
- // _popups.PopupPredicted(Loc.GetString("leash-snap-popup", ("leash", leashEnt)), target, null, PopupType.SmallCaution);
- // RemoveLeash(target, (leashEnt, leash), true);
- // }
}
}
@@ -115,33 +108,6 @@ private void OnAnchorUnequipping(Entity ent, ref BeingUneq
args.Cancel();
}
- private void OnLeashedInserting(Entity ent, ref ContainerGettingInsertedAttemptEvent args)
- {
- // Prevent the entity from entering crates and the like because that would instantly break all joints on it, including the leash
- if (!Exists(ent.Comp.Puller)
- || !Exists(ent.Comp.Anchor)
- || !TryComp(ent.Comp.Puller, out var leashPuller)
- || !TryComp(ent.Comp.Anchor, out var leashAnchor))
- return;
-
- args.Cancel();
- // This is hella unsafe to do, but we recreate the joint because dumb storage system removes it before raising the event.
- // We have to pray that OnJointRemoved already was called and that it deferred the removal of everything that used to exist
- // I HATE STORAGE
- DoLeash((ent.Comp.Anchor.Value, leashAnchor), (ent.Comp.Puller.Value, leashPuller), ent);
- }
-
- private void OnJointRemoved(Entity ent, ref JointRemovedEvent args)
- {
- var id = args.Joint.ID;
- if (!ent.Comp.Leashed.TryFirstOrDefault(it => it.JointId == id, out var data)
- || !TryGetEntity(data.Pulled, out var leashedEnt)
- || !TryComp(leashedEnt, out var leashed))
- return;
-
- RemoveLeash((leashedEnt.Value, leashed), ent!, false);
- }
-
private void OnGetEquipmentVerbs(Entity ent, ref GetVerbsEvent args)
{
if (!args.CanAccess
@@ -193,6 +159,26 @@ private void OnGetLeashedVerbs(Entity ent, ref GetVerbsEvent ent, ref JointRemovedEvent args)
+ {
+ var id = args.Joint.ID;
+ if (_timing.ApplyingState
+ || ent.Comp.LifeStage >= ComponentLifeStage.Removing
+ || ent.Comp.Puller is not { } puller
+ || !TryComp(ent.Comp.Anchor, out var anchor)
+ || !TryComp(puller, out var leash)
+ || !Transform(ent).Coordinates.TryDistance(EntityManager, Transform(puller).Coordinates, out var dst)
+ || dst > leash.MaxDistance
+ )
+ return;
+
+ // If the entity still has a leashed comp, and is on the same map, and is within the max distance of the leash
+ // Then the leash was likely broken due to some weird unforeseen fucking robust toolbox magic. We can try to recreate it.
+ // This is hella unsafe to do. It will crash in debug builds under certain conditions. Luckily, release builds are safe.
+ RemoveLeash(ent!, (puller, leash), false);
+ DoLeash((ent.Comp.Anchor.Value, anchor), (puller, leash), ent);
+ }
+
private void OnAttachDoAfter(Entity ent, ref LeashAttachDoAfterEvent args)
{
if (args.Cancelled || args.Handled
@@ -279,6 +265,7 @@ private DistanceJoint CreateLeashJoint(string jointId, Entity le
joint.MaxLength = leash.Comp.Length;
joint.Stiffness = 1f;
joint.CollideConnected = true; // This is just for performance reasons and doesn't actually make mobs collide.
+ joint.Damping = 1f;
return joint;
}
@@ -380,10 +367,7 @@ public void DoLeash(Entity anchor, Entity
// I'd like to use a chain joint or smth, but it's too hard and oftentimes buggy - lamia is a good bad example of that.
var joint = CreateLeashJoint(leashedComp.JointId, leash, leashTarget);
- var data = new LeashComponent.LeashData(leashedComp.JointId, netLeashTarget)
- {
- NextDamage = _timing.CurTime + leash.Comp.DamageInterval
- };
+ var data = new LeashComponent.LeashData(leashedComp.JointId, netLeashTarget);
if (leash.Comp.LeashSprite is { } sprite)
{
diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml b/Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml
index d01fc8b8de2..d91fc08e717 100644
--- a/Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml
+++ b/Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml
@@ -114,6 +114,7 @@
- GalacticCommon
- RobotTalk
- type: PsionicInsulation
+ - type: LeashAnchor # Floofstation
- type: entity
parent: MobSiliconBase
diff --git a/Resources/Prototypes/Floof/Entities/Objects/Tools/leash.yml b/Resources/Prototypes/Floof/Entities/Objects/Tools/leash.yml
index 45d080b601d..c674d92913b 100644
--- a/Resources/Prototypes/Floof/Entities/Objects/Tools/leash.yml
+++ b/Resources/Prototypes/Floof/Entities/Objects/Tools/leash.yml
@@ -2,7 +2,7 @@
id: BaseLeash
parent: BaseItem
name: leash
- description: Helps keep your animals close to you, as well as your friends. Attach to supported object or clothing (such as collars) to use. You can pull attached entities while holding the leash.
+ description: Helps keep your animals or friends close to you. Attach to supported objects or clothing (such as collars) to use. You can pull attached entities while holding the leash.
noSpawn: true
components:
- type: Sprite
@@ -10,6 +10,7 @@
layers:
- state: icon
- type: Leash
+ pullInterval: 0.75
leashSprite:
sprite: Floof/Objects/Tools/leash-rope.rsi
state: rope
@@ -19,9 +20,10 @@
parent: BaseLeash
components:
- type: Leash
- length: 3.5
- attachDelay: 4.5 # Gotta be at least as high as cuffs or antags may abuse it
- detachDelay: 3
+ length: 3
+ maxDistance: 6
+ attachDelay: 4
+ detachDelay: 4
selfDetachDelay: 10
- type: entity
@@ -31,6 +33,7 @@
components:
- type: Leash
length: 1.5
+ maxDistance: 3
attachDelay: 4.5
detachDelay: 3
selfDetachDelay: 10
@@ -54,6 +57,7 @@
suffix: DEBUG, DO NOT MAP
components:
- type: Leash
+ maxDistance: 100
maxJoints: 25
attachDelay: 0
detachDelay: 10000 # will still be instant for admin ghosts or whatever with instant doafters tag