Reagent interactivity (pt. 1) (#15130)
* Puddle slippy * spillable melee * splash spilling! * splat melee sound * p
This commit is contained in:
@@ -15,8 +15,17 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Spillable;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Fluids.EntitySystems;
|
||||
|
||||
@@ -28,19 +37,32 @@ public sealed class SpillableSystem : EntitySystem
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly ReactiveSystem _reactive = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SpillableComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<SpillableComponent, LandEvent>(SpillOnLand);
|
||||
SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit);
|
||||
SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
|
||||
SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
|
||||
SubscribeLocalEvent<SpillableComponent, SolutionSpikeOverflowEvent>(OnSpikeOverflow);
|
||||
SubscribeLocalEvent<SpillableComponent, SpillDoAfterEvent>(OnDoAfter);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, SpillableComponent component, ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("spill-examine-is-spillable"));
|
||||
|
||||
if (HasComp<MeleeWeaponComponent>(uid))
|
||||
args.PushMarkup(Loc.GetString("spill-examine-spillable-weapon"));
|
||||
}
|
||||
|
||||
private void OnSpikeOverflow(EntityUid uid, SpillableComponent component, SolutionSpikeOverflowEvent args)
|
||||
{
|
||||
if (!args.Handled)
|
||||
@@ -104,11 +126,61 @@ public sealed class SpillableSystem : EntitySystem
|
||||
if (args.User != null)
|
||||
{
|
||||
_adminLogger.Add(LogType.Landed,
|
||||
$"{ToPrettyString(uid):entity} spilled a solution {SolutionContainerSystem.ToPrettyString(solution):solution} on landing");
|
||||
$"{ToPrettyString(args.User.Value):user} threw {ToPrettyString(uid):entity} which spilled a solution {SolutionContainerSystem.ToPrettyString(solution):solution} on landing");
|
||||
}
|
||||
|
||||
var drainedSolution = _solutionContainerSystem.Drain(uid, solution, solution.Volume);
|
||||
SpillAt(drainedSolution, EntityManager.GetComponent<TransformComponent>(uid).Coordinates, "PuddleSmear");
|
||||
SplashSpillAt(uid, drainedSolution, Transform(uid).Coordinates, "PuddleSmear");
|
||||
}
|
||||
|
||||
private void SplashOnMeleeHit(EntityUid uid, SpillableComponent component, MeleeHitEvent args)
|
||||
{
|
||||
// When attacking someone reactive with a spillable entity,
|
||||
// splash a little on them (touch react)
|
||||
// If this also has solution transfer, then assume the transfer amount is how much we want to spill.
|
||||
// Otherwise let's say they want to spill a quarter of its max volume.
|
||||
|
||||
if (!_solutionContainerSystem.TryGetDrainableSolution(uid, out var solution))
|
||||
return;
|
||||
|
||||
if (TryComp<DrinkComponent>(uid, out var drink) && !drink.Opened)
|
||||
return;
|
||||
|
||||
var hitCount = args.HitEntities.Count;
|
||||
|
||||
var totalSplit = FixedPoint2.Min(solution.MaxVolume * 0.25, solution.Volume);
|
||||
if (TryComp<SolutionTransferComponent>(uid, out var transfer))
|
||||
{
|
||||
totalSplit = FixedPoint2.Min(transfer.TransferAmount, solution.Volume);
|
||||
}
|
||||
|
||||
// a little lame, but reagent quantity is not very balanced and we don't want people
|
||||
// spilling like 100u of reagent on someone at once!
|
||||
totalSplit = FixedPoint2.Min(totalSplit, component.MaxMeleeSpillAmount);
|
||||
|
||||
foreach (var hit in args.HitEntities)
|
||||
{
|
||||
if (!HasComp<ReactiveComponent>(hit))
|
||||
{
|
||||
hitCount -= 1; // so we don't undershoot solution calculation for actual reactive entities
|
||||
continue;
|
||||
}
|
||||
|
||||
var splitSolution = _solutionContainerSystem.SplitSolution(uid, solution, totalSplit / hitCount);
|
||||
|
||||
_adminLogger.Add(LogType.MeleeHit, $"{ToPrettyString(args.User)} splashed {SolutionContainerSystem.ToPrettyString(splitSolution):solution} from {ToPrettyString(uid):entity} onto {ToPrettyString(hit):target}");
|
||||
_reactive.DoEntityReaction(hit, splitSolution, ReactionMethod.Touch);
|
||||
|
||||
_popup.PopupEntity(
|
||||
Loc.GetString("spill-melee-hit-attacker", ("amount", totalSplit / hitCount), ("spillable", uid),
|
||||
("target", Identity.Entity(hit, EntityManager))),
|
||||
hit, args.User);
|
||||
|
||||
_popup.PopupEntity(
|
||||
Loc.GetString("spill-melee-hit-others", ("attacker", args.User), ("spillable", uid),
|
||||
("target", Identity.Entity(hit, EntityManager))),
|
||||
hit, Filter.PvsExcept(args.User), true, PopupType.SmallCaution);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSpillVerb(EntityUid uid, SpillableComponent component, GetVerbsEvent<Verb> args)
|
||||
@@ -144,6 +216,39 @@ public sealed class SpillableSystem : EntitySystem
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// First splashes reagent on reactive entities near the spilling entity, then spills the rest regularly to a
|
||||
/// puddle. This is intended for 'destructive' spills, like when entities are destroyed or thrown.
|
||||
/// </summary>
|
||||
public PuddleComponent? SplashSpillAt(EntityUid uid, Solution solution, EntityCoordinates coordinates, string prototype,
|
||||
bool overflow = true, bool sound = true, bool combine = true, EntityUid? user=null)
|
||||
{
|
||||
if (solution.Volume == 0)
|
||||
return null;
|
||||
|
||||
// Get reactive entities nearby--if there are some, it'll spill a bit on them instead.
|
||||
foreach (var ent in _entityLookup.GetComponentsInRange<ReactiveComponent>(coordinates, 1.0f))
|
||||
{
|
||||
// sorry! no overload for returning uid, so .owner must be used
|
||||
var owner = ent.Owner;
|
||||
|
||||
// between 5 and 30%
|
||||
var splitAmount = solution.Volume * _random.NextFloat(0.05f, 0.30f);
|
||||
var splitSolution = solution.SplitSolution(splitAmount);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
_adminLogger.Add(LogType.Landed,
|
||||
$"{ToPrettyString(user.Value):user} threw {ToPrettyString(uid):entity} which splashed a solution {SolutionContainerSystem.ToPrettyString(solution):solution} onto {ToPrettyString(owner):target}");
|
||||
}
|
||||
|
||||
_reactive.DoEntityReaction(owner, splitSolution, ReactionMethod.Touch);
|
||||
_popup.PopupEntity(Loc.GetString("spill-land-spilled-on-other", ("spillable", uid), ("target", owner)), owner, PopupType.SmallCaution);
|
||||
}
|
||||
|
||||
return SpillAt(solution, coordinates, prototype, overflow, sound, combine: combine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spills solution at the specified grid coordinates.
|
||||
/// </summary>
|
||||
@@ -159,7 +264,6 @@ public sealed class SpillableSystem : EntitySystem
|
||||
{
|
||||
if (solution.Volume == 0) return null;
|
||||
|
||||
|
||||
if (!_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid))
|
||||
return null; // Let's not spill to space.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user