Make a lot more puddle stuff predicted (#38871)
* feat: predict evaporation * refactor: move puddle update logic to shared * refactor: move more puddle stuff to Shared Still can't do stuff that creates puddles :( * refactor: move puddle transfers to shared * fix: various style fixes + switch to predicted variants * style: make some puddle stuff private instead of protected * refactor: move solution dumping to its own system * docs: clarify Drainable/Dumpable/Refillable docs Also whacks unneeded VVAccess's. * fix: audit usages of drainable+refillable I'm leaving spear and arrow for now... but I don't love it. * Added an item query I guess * Review changes * You can pour out waterguns * Review changes * oops --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
This commit is contained in:
@@ -1,38 +1,25 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Chemistry.TileReactions;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Server.Spreader;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Effects;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Fluids;
|
||||
using Content.Shared.Fluids.Components;
|
||||
using Content.Shared.Friction;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Slippery;
|
||||
using Content.Shared.StepTrigger.Components;
|
||||
using Content.Shared.StepTrigger.Systems;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Fluids.EntitySystems;
|
||||
|
||||
@@ -41,28 +28,15 @@ namespace Content.Server.Fluids.EntitySystems;
|
||||
/// </summary>
|
||||
public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly SharedMapSystem _map = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly AudioSystem _audio = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly ReactiveSystem _reactive = default!;
|
||||
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popups = default!;
|
||||
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly StepTriggerSystem _stepTrigger = default!;
|
||||
[Dependency] private readonly SpeedModifierContactsSystem _speedModContacts = default!;
|
||||
[Dependency] private readonly TileFrictionController _tile = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly TurfSystem _turf = default!;
|
||||
|
||||
// Using local deletion queue instead of the standard queue so that we can easily "undelete" if a puddle
|
||||
// loses & then gains reagents in a single tick.
|
||||
private HashSet<EntityUid> _deletionQueue = [];
|
||||
|
||||
private EntityQuery<PuddleComponent> _puddleQuery;
|
||||
|
||||
/*
|
||||
@@ -77,16 +51,11 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
|
||||
_puddleQuery = GetEntityQuery<PuddleComponent>();
|
||||
|
||||
// Shouldn't need re-anchoring.
|
||||
SubscribeLocalEvent<PuddleComponent, AnchorStateChangedEvent>(OnAnchorChanged);
|
||||
SubscribeLocalEvent<PuddleComponent, SpreadNeighborsEvent>(OnPuddleSpread);
|
||||
SubscribeLocalEvent<PuddleComponent, SlipEvent>(OnPuddleSlip);
|
||||
|
||||
SubscribeLocalEvent<EvaporationComponent, MapInitEvent>(OnEvaporationMapInit);
|
||||
|
||||
InitializeTransfers();
|
||||
}
|
||||
|
||||
// TODO: This can be predicted once https://github.com/space-wizards/RobustToolbox/pull/5849 is merged
|
||||
private void OnPuddleSpread(Entity<PuddleComponent> entity, ref SpreadNeighborsEvent args)
|
||||
{
|
||||
// Overflow is the source of the overflowing liquid. This contains the excess fluid above overflow limit (20u)
|
||||
@@ -273,6 +242,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This can be predicted once https://github.com/space-wizards/RobustToolbox/pull/5849 is merged
|
||||
private void OnPuddleSlip(Entity<PuddleComponent> entity, ref SlipEvent args)
|
||||
{
|
||||
// Reactive entities have a chance to get a touch reaction from slipping on a puddle
|
||||
@@ -289,168 +259,12 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
out var solution))
|
||||
return;
|
||||
|
||||
_popups.PopupEntity(Loc.GetString("puddle-component-slipped-touch-reaction", ("puddle", entity.Owner)),
|
||||
Popups.PopupEntity(Loc.GetString("puddle-component-slipped-touch-reaction", ("puddle", entity.Owner)),
|
||||
args.Slipped, args.Slipped, PopupType.SmallCaution);
|
||||
|
||||
// Take 15% of the puddle solution
|
||||
var splitSol = _solutionContainerSystem.SplitSolution(entity.Comp.Solution.Value, solution.Volume * 0.15f);
|
||||
_reactive.DoEntityReaction(args.Slipped, splitSol, ReactionMethod.Touch);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
foreach (var ent in _deletionQueue)
|
||||
{
|
||||
Del(ent);
|
||||
}
|
||||
|
||||
_deletionQueue.Clear();
|
||||
|
||||
TickEvaporation();
|
||||
}
|
||||
|
||||
protected override void OnSolutionUpdate(Entity<PuddleComponent> entity, ref SolutionContainerChangedEvent args)
|
||||
{
|
||||
if (args.SolutionId != entity.Comp.SolutionName)
|
||||
return;
|
||||
|
||||
base.OnSolutionUpdate(entity, ref args);
|
||||
|
||||
if (args.Solution.Volume <= 0)
|
||||
{
|
||||
_deletionQueue.Add(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
_deletionQueue.Remove(entity);
|
||||
UpdateSlip((entity, entity.Comp), args.Solution);
|
||||
UpdateSlow(entity, args.Solution);
|
||||
UpdateEvaporation(entity, args.Solution);
|
||||
}
|
||||
|
||||
private void UpdateSlip(Entity<PuddleComponent> entity, Solution solution)
|
||||
{
|
||||
if (!TryComp<StepTriggerComponent>(entity, out var comp))
|
||||
return;
|
||||
|
||||
// Ensure we actually have the component
|
||||
EnsureComp<TileFrictionModifierComponent>(entity);
|
||||
|
||||
EnsureComp<SlipperyComponent>(entity, out var slipComp);
|
||||
|
||||
// This is the base amount of reagent needed before a puddle can be considered slippery. Is defined based on
|
||||
// the sprite threshold for a puddle larger than 5 pixels.
|
||||
var smallPuddleThreshold = FixedPoint2.New(entity.Comp.OverflowVolume.Float() * LowThreshold);
|
||||
|
||||
// Stores how many units of slippery reagents a puddle has
|
||||
var slipperyUnits = FixedPoint2.Zero;
|
||||
// Stores how many units of super slippery reagents a puddle has
|
||||
var superSlipperyUnits = FixedPoint2.Zero;
|
||||
|
||||
// These three values will be averaged later and all start at zero so the calculations work
|
||||
// A cumulative weighted amount of minimum speed to slip values
|
||||
var puddleFriction = FixedPoint2.Zero;
|
||||
// A cumulative weighted amount of minimum speed to slip values
|
||||
var slipStepTrigger = FixedPoint2.Zero;
|
||||
// A cumulative weighted amount of launch multipliers from slippery reagents
|
||||
var launchMult = FixedPoint2.Zero;
|
||||
// A cumulative weighted amount of stun times from slippery reagents
|
||||
var stunTimer = TimeSpan.Zero;
|
||||
// A cumulative weighted amount of knockdown times from slippery reagents
|
||||
var knockdownTimer = TimeSpan.Zero;
|
||||
|
||||
// Check if the puddle is big enough to slip in to avoid doing unnecessary logic
|
||||
if (solution.Volume <= smallPuddleThreshold)
|
||||
{
|
||||
_stepTrigger.SetActive(entity, false, comp);
|
||||
_tile.SetModifier(entity, 1f);
|
||||
slipComp.SlipData.SlipFriction = 1f;
|
||||
slipComp.AffectsSliding = false;
|
||||
Dirty(entity, slipComp);
|
||||
return;
|
||||
}
|
||||
|
||||
slipComp.AffectsSliding = true;
|
||||
|
||||
foreach (var (reagent, quantity) in solution.Contents)
|
||||
{
|
||||
var reagentProto = _prototypeManager.Index<ReagentPrototype>(reagent.Prototype);
|
||||
|
||||
// Calculate the minimum speed needed to slip in the puddle. Average the overall slip thresholds for all reagents
|
||||
var deltaSlipTrigger = reagentProto.SlipData?.RequiredSlipSpeed ?? entity.Comp.DefaultSlippery;
|
||||
slipStepTrigger += quantity * deltaSlipTrigger;
|
||||
|
||||
// Aggregate Friction based on quantity
|
||||
puddleFriction += reagentProto.Friction * quantity;
|
||||
|
||||
if (reagentProto.SlipData == null)
|
||||
continue;
|
||||
|
||||
slipperyUnits += quantity;
|
||||
// Aggregate launch speed based on quantity
|
||||
launchMult += reagentProto.SlipData.LaunchForwardsMultiplier * quantity;
|
||||
// Aggregate stun times based on quantity
|
||||
stunTimer += reagentProto.SlipData.StunTime * (float)quantity;
|
||||
knockdownTimer += reagentProto.SlipData.KnockdownTime * (float)quantity;
|
||||
|
||||
if (reagentProto.SlipData.SuperSlippery)
|
||||
superSlipperyUnits += quantity;
|
||||
}
|
||||
|
||||
// Turn on the step trigger if it's slippery
|
||||
_stepTrigger.SetActive(entity, slipperyUnits > smallPuddleThreshold, comp);
|
||||
|
||||
// This is based of the total volume and not just the slippery volume because there is a default
|
||||
// slippery for all reagents even if they aren't technically slippery.
|
||||
slipComp.SlipData.RequiredSlipSpeed = (float)(slipStepTrigger / solution.Volume);
|
||||
_stepTrigger.SetRequiredTriggerSpeed(entity, slipComp.SlipData.RequiredSlipSpeed);
|
||||
|
||||
// Divide these both by only total amount of slippery reagents.
|
||||
// A puddle with 10 units of lube vs a puddle with 10 of lube and 20 catchup should stun and launch forward the same amount.
|
||||
if (slipperyUnits > 0)
|
||||
{
|
||||
slipComp.SlipData.LaunchForwardsMultiplier = (float)(launchMult/slipperyUnits);
|
||||
slipComp.SlipData.StunTime = (stunTimer/(float)slipperyUnits);
|
||||
slipComp.SlipData.KnockdownTime = (knockdownTimer/(float)slipperyUnits);
|
||||
}
|
||||
|
||||
// Only make it super slippery if there is enough super slippery units for its own puddle
|
||||
slipComp.SlipData.SuperSlippery = superSlipperyUnits >= smallPuddleThreshold;
|
||||
|
||||
// Lower tile friction based on how slippery it is, lets items slide across a puddle of lube
|
||||
slipComp.SlipData.SlipFriction = (float)(puddleFriction / solution.Volume);
|
||||
_tile.SetModifier(entity, slipComp.SlipData.SlipFriction);
|
||||
|
||||
Dirty(entity, slipComp);
|
||||
}
|
||||
|
||||
private void UpdateSlow(EntityUid uid, Solution solution)
|
||||
{
|
||||
var maxViscosity = 0f;
|
||||
foreach (var (reagent, _) in solution.Contents)
|
||||
{
|
||||
var reagentProto = _prototypeManager.Index<ReagentPrototype>(reagent.Prototype);
|
||||
maxViscosity = Math.Max(maxViscosity, reagentProto.Viscosity);
|
||||
}
|
||||
|
||||
if (maxViscosity > 0)
|
||||
{
|
||||
var comp = EnsureComp<SpeedModifierContactsComponent>(uid);
|
||||
var speed = 1 - maxViscosity;
|
||||
_speedModContacts.ChangeSpeedModifiers(uid, speed, comp);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemComp<SpeedModifierContactsComponent>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnchorChanged(Entity<PuddleComponent> entity, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (!args.Anchored)
|
||||
QueueDel(entity);
|
||||
Reactive.DoEntityReaction(args.Slipped, splitSol, ReactionMethod.Touch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -507,7 +321,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
return true;
|
||||
}
|
||||
|
||||
_audio.PlayPvs(puddleComponent.SpillSound, puddleUid);
|
||||
Audio.PlayPvs(puddleComponent.SpillSound, puddleUid);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -553,6 +367,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
|
||||
#region Spill
|
||||
|
||||
// TODO: This can be predicted once https://github.com/space-wizards/RobustToolbox/pull/5849 is merged
|
||||
/// <inheritdoc/>
|
||||
public override bool TrySplashSpillAt(EntityUid uid,
|
||||
EntityCoordinates coordinates,
|
||||
@@ -582,13 +397,13 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
_adminLogger.Add(LogType.Landed,
|
||||
AdminLogger.Add(LogType.Landed,
|
||||
$"{ToPrettyString(user.Value):user} threw {ToPrettyString(uid):entity} which splashed a solution {SharedSolutionContainerSystem.ToPrettyString(solution):solution} onto {ToPrettyString(owner):target}");
|
||||
}
|
||||
|
||||
targets.Add(owner);
|
||||
_reactive.DoEntityReaction(owner, splitSolution, ReactionMethod.Touch);
|
||||
_popups.PopupEntity(
|
||||
Reactive.DoEntityReaction(owner, splitSolution, ReactionMethod.Touch);
|
||||
Popups.PopupEntity(
|
||||
Loc.GetString("spill-land-spilled-on-other", ("spillable", uid),
|
||||
("target", Identity.Entity(owner, EntityManager))), owner, PopupType.SmallCaution);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user