Add prediction for puddle and spillable examines (#25794)

Prediction for puddle and spillable examines
This commit is contained in:
Tayrtahn
2024-03-03 00:36:36 -05:00
committed by GitHub
parent a0b33def48
commit 4943151111
11 changed files with 96 additions and 74 deletions

View File

@@ -1,6 +1,4 @@
using Content.Server.Fluids.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids.Components;
@@ -10,11 +8,6 @@ public sealed partial class PuddleSystem
{
private static readonly TimeSpan EvaporationCooldown = TimeSpan.FromSeconds(1);
[ValidatePrototypeId<ReagentPrototype>]
private const string Water = "Water";
public static string[] EvaporationReagents = new[] { Water };
private void OnEvaporationMapInit(Entity<EvaporationComponent> entity, ref MapInitEvent args)
{
entity.Comp.NextTick = _timing.CurTime + EvaporationCooldown;
@@ -64,9 +57,4 @@ public sealed partial class PuddleSystem
}
}
}
public bool CanFullyEvaporate(Solution solution)
{
return solution.GetTotalPrototypeQuantity(EvaporationReagents) == solution.Volume;
}
}

View File

@@ -9,15 +9,14 @@ using Content.Shared.Clothing.Components;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory.Events;
using Content.Shared.Popups;
using Content.Shared.Spillable;
using Content.Shared.Throwing;
using Content.Shared.Verbs;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Player;
@@ -28,12 +27,13 @@ public sealed partial class PuddleSystem
[Dependency] private readonly OpenableSystem _openable = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private void InitializeSpillable()
protected override void InitializeSpillable()
{
SubscribeLocalEvent<SpillableComponent, ExaminedEvent>(OnExamined);
base.InitializeSpillable();
SubscribeLocalEvent<SpillableComponent, LandEvent>(SpillOnLand);
// openable handles the event if its closed
SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit, after: new[] { typeof(OpenableSystem) });
// Openable handles the event if it's closed
SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit, after: [typeof(OpenableSystem)]);
SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<SpillableComponent, SolutionContainerOverflowEvent>(OnOverflow);
@@ -41,17 +41,6 @@ public sealed partial class PuddleSystem
SubscribeLocalEvent<SpillableComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
}
private void OnExamined(Entity<SpillableComponent> entity, ref ExaminedEvent args)
{
using (args.PushGroup(nameof(SpillableComponent)))
{
args.PushMarkup(Loc.GetString("spill-examine-is-spillable"));
if (HasComp<MeleeWeaponComponent>(entity))
args.PushMarkup(Loc.GetString("spill-examine-spillable-weapon"));
}
}
private void OnOverflow(Entity<SpillableComponent> entity, ref SolutionContainerOverflowEvent args)
{
if (args.Handled)

View File

@@ -11,7 +11,6 @@ using Content.Shared.Chemistry.Reaction;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids;
using Content.Shared.Fluids.Components;
@@ -67,13 +66,13 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
[ValidatePrototypeId<ReagentPrototype>]
private const string CopperBlood = "CopperBlood";
private static string[] _standoutReagents = new[] { Blood, Slime, CopperBlood };
private static string[] _standoutReagents = [Blood, Slime, CopperBlood];
public static float PuddleVolume = 1000;
public static readonly float PuddleVolume = 1000;
// 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 = new();
private HashSet<EntityUid> _deletionQueue = [];
private EntityQuery<PuddleComponent> _puddleQuery;
@@ -91,7 +90,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
// Shouldn't need re-anchoring.
SubscribeLocalEvent<PuddleComponent, AnchorStateChangedEvent>(OnAnchorChanged);
SubscribeLocalEvent<PuddleComponent, ExaminedEvent>(HandlePuddleExamined);
SubscribeLocalEvent<PuddleComponent, SolutionContainerChangedEvent>(OnSolutionUpdate);
SubscribeLocalEvent<PuddleComponent, ComponentInit>(OnPuddleInit);
SubscribeLocalEvent<PuddleComponent, SpreadNeighborsEvent>(OnPuddleSpread);
@@ -99,7 +97,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
SubscribeLocalEvent<EvaporationComponent, MapInitEvent>(OnEvaporationMapInit);
InitializeSpillable();
InitializeTransfers();
}
@@ -448,31 +445,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
}
}
private void HandlePuddleExamined(Entity<PuddleComponent> entity, ref ExaminedEvent args)
{
using (args.PushGroup(nameof(PuddleComponent)))
{
if (TryComp<StepTriggerComponent>(entity, out var slippery) && slippery.Active)
{
args.PushMarkup(Loc.GetString("puddle-component-examine-is-slipper-text"));
}
if (HasComp<EvaporationComponent>(entity) &&
_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.SolutionName,
ref entity.Comp.Solution, out var solution))
{
if (CanFullyEvaporate(solution))
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating"));
else if (solution.GetTotalPrototypeQuantity(EvaporationReagents) > FixedPoint2.Zero)
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-partial"));
else
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-no"));
}
else
args.PushMarkup(Loc.GetString("puddle-component-examine-evaporating-no"));
}
}
private void OnAnchorChanged(Entity<PuddleComponent> entity, ref AnchorStateChangedEvent args)
{
if (!args.Anchored)