Update puddle stickiness (#16597)
This commit is contained in:
@@ -4,6 +4,7 @@ using Content.Shared.Chemistry.Reaction;
|
|||||||
using Content.Shared.Chemistry.Reagent;
|
using Content.Shared.Chemistry.Reagent;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.Systems;
|
||||||
using Content.Shared.Slippery;
|
using Content.Shared.Slippery;
|
||||||
using Content.Shared.StepTrigger.Components;
|
using Content.Shared.StepTrigger.Components;
|
||||||
using Content.Shared.StepTrigger.Systems;
|
using Content.Shared.StepTrigger.Systems;
|
||||||
@@ -39,9 +40,7 @@ namespace Content.Server.Chemistry.TileReactions
|
|||||||
|
|
||||||
var slow = entityManager.EnsureComponent<SlowContactsComponent>(puddleUid);
|
var slow = entityManager.EnsureComponent<SlowContactsComponent>(puddleUid);
|
||||||
var speedModifier = 1 - reagent.Viscosity;
|
var speedModifier = 1 - reagent.Viscosity;
|
||||||
slow.WalkSpeedModifier = speedModifier;
|
entityManager.EntitySysManager.GetEntitySystem<SlowContactsSystem>().ChangeModifiers(puddleUid, speedModifier, slow);
|
||||||
slow.SprintSpeedModifier = speedModifier;
|
|
||||||
entityManager.Dirty(slow);
|
|
||||||
|
|
||||||
return reactVolume;
|
return reactVolume;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ using Solution = Content.Shared.Chemistry.Components.Solution;
|
|||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.Systems;
|
||||||
|
|
||||||
namespace Content.Server.Fluids.EntitySystems;
|
namespace Content.Server.Fluids.EntitySystems;
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
|||||||
[Dependency] private readonly StepTriggerSystem _stepTrigger = default!;
|
[Dependency] private readonly StepTriggerSystem _stepTrigger = default!;
|
||||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||||
[Dependency] private readonly TileFrictionController _tile = default!;
|
[Dependency] private readonly TileFrictionController _tile = default!;
|
||||||
|
[Dependency] private readonly SlowContactsSystem _slowContacts = default!;
|
||||||
|
|
||||||
public static float PuddleVolume = 1000;
|
public static float PuddleVolume = 1000;
|
||||||
|
|
||||||
@@ -242,6 +245,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
|||||||
|
|
||||||
_deletionQueue.Remove(uid);
|
_deletionQueue.Remove(uid);
|
||||||
UpdateSlip(uid, component, args.Solution);
|
UpdateSlip(uid, component, args.Solution);
|
||||||
|
UpdateSlow(uid, args.Solution);
|
||||||
UpdateEvaporation(uid, args.Solution);
|
UpdateEvaporation(uid, args.Solution);
|
||||||
UpdateAppearance(uid, component);
|
UpdateAppearance(uid, component);
|
||||||
}
|
}
|
||||||
@@ -319,6 +323,26 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateSlow(EntityUid uid, Solution solution)
|
||||||
|
{
|
||||||
|
var maxViscosity = 0f;
|
||||||
|
foreach (var reagent in solution.Contents)
|
||||||
|
{
|
||||||
|
var reagentProto = _prototypeManager.Index<ReagentPrototype>(reagent.ReagentId);
|
||||||
|
maxViscosity = Math.Max(maxViscosity, reagentProto.Viscosity);
|
||||||
|
}
|
||||||
|
if (maxViscosity > 0)
|
||||||
|
{
|
||||||
|
var comp = EnsureComp<SlowContactsComponent>(uid);
|
||||||
|
var speed = 1 - maxViscosity;
|
||||||
|
_slowContacts.ChangeModifiers(uid, speed, comp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RemComp<SlowContactsComponent>(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void HandlePuddleExamined(EntityUid uid, PuddleComponent component, ExaminedEvent args)
|
private void HandlePuddleExamined(EntityUid uid, PuddleComponent component, ExaminedEvent args)
|
||||||
{
|
{
|
||||||
if (TryComp<StepTriggerComponent>(uid, out var slippery) && slippery.Active)
|
if (TryComp<StepTriggerComponent>(uid, out var slippery) && slippery.Active)
|
||||||
|
|||||||
@@ -1,32 +1,22 @@
|
|||||||
|
using Content.Shared.Movement.Systems;
|
||||||
using Content.Shared.Whitelist;
|
using Content.Shared.Whitelist;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
|
|
||||||
namespace Content.Shared.Movement.Components;
|
namespace Content.Shared.Movement.Components;
|
||||||
|
|
||||||
[NetworkedComponent, RegisterComponent]
|
[NetworkedComponent, RegisterComponent]
|
||||||
public sealed class SlowContactsComponent : Component
|
[AutoGenerateComponentState]
|
||||||
|
[Access(typeof(SlowContactsSystem))]
|
||||||
|
public sealed partial class SlowContactsComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("walkSpeedModifier")]
|
[DataField("walkSpeedModifier"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float WalkSpeedModifier { get; set; } = 1.0f;
|
[AutoNetworkedField]
|
||||||
|
public float WalkSpeedModifier = 1.0f;
|
||||||
|
|
||||||
[DataField("sprintSpeedModifier")]
|
[AutoNetworkedField]
|
||||||
public float SprintSpeedModifier { get; set; } = 1.0f;
|
[DataField("sprintSpeedModifier"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float SprintSpeedModifier = 1.0f;
|
||||||
|
|
||||||
[DataField("ignoreWhitelist")]
|
[DataField("ignoreWhitelist")]
|
||||||
public EntityWhitelist? IgnoreWhitelist;
|
public EntityWhitelist? IgnoreWhitelist;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public sealed class SlowContactsComponentState : ComponentState
|
|
||||||
{
|
|
||||||
public readonly float WalkSpeedModifier;
|
|
||||||
|
|
||||||
public readonly float SprintSpeedModifier;
|
|
||||||
|
|
||||||
public SlowContactsComponentState(float walkSpeedModifier, float sprintSpeedModifier)
|
|
||||||
{
|
|
||||||
WalkSpeedModifier = walkSpeedModifier;
|
|
||||||
SprintSpeedModifier = sprintSpeedModifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
using Robust.Shared.GameStates;
|
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Physics.Events;
|
using Robust.Shared.Physics.Events;
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
@@ -21,9 +20,6 @@ public sealed class SlowContactsSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<SlowContactsComponent, EndCollideEvent>(OnEntityExit);
|
SubscribeLocalEvent<SlowContactsComponent, EndCollideEvent>(OnEntityExit);
|
||||||
SubscribeLocalEvent<SlowedByContactComponent, RefreshMovementSpeedModifiersEvent>(MovementSpeedCheck);
|
SubscribeLocalEvent<SlowedByContactComponent, RefreshMovementSpeedModifiersEvent>(MovementSpeedCheck);
|
||||||
|
|
||||||
SubscribeLocalEvent<SlowContactsComponent, ComponentHandleState>(OnHandleState);
|
|
||||||
SubscribeLocalEvent<SlowContactsComponent, ComponentGetState>(OnGetState);
|
|
||||||
|
|
||||||
UpdatesAfter.Add(typeof(SharedPhysicsSystem));
|
UpdatesAfter.Add(typeof(SharedPhysicsSystem));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,18 +42,20 @@ public sealed class SlowContactsSystem : EntitySystem
|
|||||||
_toUpdate.Clear();
|
_toUpdate.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGetState(EntityUid uid, SlowContactsComponent component, ref ComponentGetState args)
|
public void ChangeModifiers(EntityUid uid, float speed, SlowContactsComponent? component = null)
|
||||||
{
|
{
|
||||||
args.State = new SlowContactsComponentState(component.WalkSpeedModifier, component.SprintSpeedModifier);
|
ChangeModifiers(uid, speed, speed, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHandleState(EntityUid uid, SlowContactsComponent component, ref ComponentHandleState args)
|
public void ChangeModifiers(EntityUid uid, float walkSpeed, float sprintSpeed, SlowContactsComponent? component = null)
|
||||||
{
|
{
|
||||||
if (args.Current is not SlowContactsComponentState state)
|
if (!Resolve(uid, ref component))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
component.WalkSpeedModifier = state.WalkSpeedModifier;
|
component.WalkSpeedModifier = walkSpeed;
|
||||||
component.SprintSpeedModifier = state.SprintSpeedModifier;
|
component.SprintSpeedModifier = sprintSpeed;
|
||||||
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MovementSpeedCheck(EntityUid uid, SlowedByContactComponent component, RefreshMovementSpeedModifiersEvent args)
|
private void MovementSpeedCheck(EntityUid uid, SlowedByContactComponent component, RefreshMovementSpeedModifiersEvent args)
|
||||||
|
|||||||
Reference in New Issue
Block a user