Solution Entities (#21916)
* Creates Content.Shared.Chemistry.Solutions Copies Solution class to new namespace Obsoletes old Solution class * Switches over to the Solutions.Solution Solution * Creates Content.Shared.Chemistry.Containers Copies relevant components/systems to the new namespace Obsoletes old versions * Switches over to the Containers.XYZ namespace * Creates SolutionSystem and obsoletes old SolutionContainerSystem methods * Start using SolutionSystem for Solution manipulation * EnumerateSolutions * Move TryGetMixableSolution * Move EnsureSolution to Server * Create Solution Entities * Stop using obsolete solution system methods * Fix prototype component tests * Add using ..Audio.Systems; back * Wrap solution container slots in ContainerSlots * Actually add the slot to the solution container map * Dirty SolutionContainerComponent when ensuring solutions * Revert namespace changes * Remerge SolutionSystem and SolutionContainerSystem * SolutionContainerManagerComponent refactor * Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release * Readd examine reagent sorting * Fix errors * Poke tests * Fix solution names not being applied * Fix WoolyComponent including statement * Fix merge skew * Fix compile errors * Make reactions use solntities * Reindent solution class namespace * Field attribute changes * AutoGenerateComponentState for SolutionContainerComponent * SolutionContainerComponent -> ContainedSolutionComponent * ref ReactionAttemptEvent * Denetwork preinit solutions * Misc 1 * Nullable TryGetSolution out vars * Cache associated solutions * Fix merge skew * Use explicit regions in SharedSolutionContainerSystem.Capabilities * Add debug assert * Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent * ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName * SolutionComponent doc comments * Implicit DataField names and property purge * ReagentEffect DataField names * Local variables for readability * Sort using statements + Entity<T> event handlers * Fix compile erros * Fix compile errors --------- Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
@@ -36,29 +36,29 @@ public sealed partial class PuddleSystem
|
||||
SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit, after: new[] { typeof(OpenableSystem) });
|
||||
SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
|
||||
SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
|
||||
SubscribeLocalEvent<SpillableComponent, SolutionOverflowEvent>(OnOverflow);
|
||||
SubscribeLocalEvent<SpillableComponent, SolutionContainerOverflowEvent>(OnOverflow);
|
||||
SubscribeLocalEvent<SpillableComponent, SpillDoAfterEvent>(OnDoAfter);
|
||||
SubscribeLocalEvent<SpillableComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, SpillableComponent component, ExaminedEvent args)
|
||||
private void OnExamined(Entity<SpillableComponent> entity, ref ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("spill-examine-is-spillable"));
|
||||
|
||||
if (HasComp<MeleeWeaponComponent>(uid))
|
||||
if (HasComp<MeleeWeaponComponent>(entity))
|
||||
args.PushMarkup(Loc.GetString("spill-examine-spillable-weapon"));
|
||||
}
|
||||
|
||||
private void OnOverflow(EntityUid uid, SpillableComponent component, ref SolutionOverflowEvent args)
|
||||
private void OnOverflow(Entity<SpillableComponent> entity, ref SolutionContainerOverflowEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
TrySpillAt(Transform(uid).Coordinates, args.Overflow, out _);
|
||||
TrySpillAt(Transform(entity).Coordinates, args.Overflow, out _);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void SplashOnMeleeHit(EntityUid uid, SpillableComponent component, MeleeHitEvent args)
|
||||
private void SplashOnMeleeHit(Entity<SpillableComponent> entity, ref MeleeHitEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
@@ -68,20 +68,20 @@ public sealed partial class PuddleSystem
|
||||
// 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))
|
||||
if (!_solutionContainerSystem.TryGetDrainableSolution(entity.Owner, out var soln, out var solution))
|
||||
return;
|
||||
|
||||
var hitCount = args.HitEntities.Count;
|
||||
|
||||
var totalSplit = FixedPoint2.Min(solution.MaxVolume * 0.25, solution.Volume);
|
||||
if (TryComp<SolutionTransferComponent>(uid, out var transfer))
|
||||
if (TryComp<SolutionTransferComponent>(entity, 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);
|
||||
totalSplit = FixedPoint2.Min(totalSplit, entity.Comp.MaxMeleeSpillAmount);
|
||||
|
||||
if (totalSplit == 0)
|
||||
return;
|
||||
@@ -95,29 +95,29 @@ public sealed partial class PuddleSystem
|
||||
continue;
|
||||
}
|
||||
|
||||
var splitSolution = _solutionContainerSystem.SplitSolution(uid, solution, totalSplit / hitCount);
|
||||
var splitSolution = _solutionContainerSystem.SplitSolution(soln.Value, totalSplit / hitCount);
|
||||
|
||||
_adminLogger.Add(LogType.MeleeHit, $"{ToPrettyString(args.User)} splashed {SolutionContainerSystem.ToPrettyString(splitSolution):solution} from {ToPrettyString(uid):entity} onto {ToPrettyString(hit):target}");
|
||||
_adminLogger.Add(LogType.MeleeHit, $"{ToPrettyString(args.User)} splashed {SolutionContainerSystem.ToPrettyString(splitSolution):solution} from {ToPrettyString(entity.Owner):entity} onto {ToPrettyString(hit):target}");
|
||||
_reactive.DoEntityReaction(hit, splitSolution, ReactionMethod.Touch);
|
||||
|
||||
_popups.PopupEntity(
|
||||
Loc.GetString("spill-melee-hit-attacker", ("amount", totalSplit / hitCount), ("spillable", uid),
|
||||
Loc.GetString("spill-melee-hit-attacker", ("amount", totalSplit / hitCount), ("spillable", entity.Owner),
|
||||
("target", Identity.Entity(hit, EntityManager))),
|
||||
hit, args.User);
|
||||
|
||||
_popups.PopupEntity(
|
||||
Loc.GetString("spill-melee-hit-others", ("attacker", args.User), ("spillable", uid),
|
||||
Loc.GetString("spill-melee-hit-others", ("attacker", args.User), ("spillable", entity.Owner),
|
||||
("target", Identity.Entity(hit, EntityManager))),
|
||||
hit, Filter.PvsExcept(args.User), true, PopupType.SmallCaution);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGotEquipped(EntityUid uid, SpillableComponent component, GotEquippedEvent args)
|
||||
private void OnGotEquipped(Entity<SpillableComponent> entity, ref GotEquippedEvent args)
|
||||
{
|
||||
if (!component.SpillWorn)
|
||||
if (!entity.Comp.SpillWorn)
|
||||
return;
|
||||
|
||||
if (!TryComp(uid, out ClothingComponent? clothing))
|
||||
if (!TryComp(entity, out ClothingComponent? clothing))
|
||||
return;
|
||||
|
||||
// check if entity was actually used as clothing
|
||||
@@ -126,33 +126,33 @@ public sealed partial class PuddleSystem
|
||||
if (!isCorrectSlot)
|
||||
return;
|
||||
|
||||
if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solution))
|
||||
if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution))
|
||||
return;
|
||||
|
||||
if (solution.Volume == 0)
|
||||
return;
|
||||
|
||||
// spill all solution on the player
|
||||
var drainedSolution = _solutionContainerSystem.Drain(uid, solution, solution.Volume);
|
||||
TrySplashSpillAt(uid, Transform(args.Equipee).Coordinates, drainedSolution, out _);
|
||||
var drainedSolution = _solutionContainerSystem.Drain(entity.Owner, soln.Value, solution.Volume);
|
||||
TrySplashSpillAt(entity.Owner, Transform(args.Equipee).Coordinates, drainedSolution, out _);
|
||||
}
|
||||
|
||||
private void SpillOnLand(EntityUid uid, SpillableComponent component, ref LandEvent args)
|
||||
private void SpillOnLand(Entity<SpillableComponent> entity, ref LandEvent args)
|
||||
{
|
||||
if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solution))
|
||||
if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution))
|
||||
return;
|
||||
|
||||
if (_openable.IsClosed(uid))
|
||||
if (_openable.IsClosed(entity.Owner))
|
||||
return;
|
||||
|
||||
if (args.User != null)
|
||||
{
|
||||
_adminLogger.Add(LogType.Landed,
|
||||
$"{ToPrettyString(uid):entity} spilled a solution {SolutionContainerSystem.ToPrettyString(solution):solution} on landing");
|
||||
$"{ToPrettyString(entity.Owner):entity} spilled a solution {SolutionContainerSystem.ToPrettyString(solution):solution} on landing");
|
||||
}
|
||||
|
||||
var drainedSolution = _solutionContainerSystem.Drain(uid, solution, solution.Volume);
|
||||
TrySplashSpillAt(uid, Transform(uid).Coordinates, drainedSolution, out _);
|
||||
var drainedSolution = _solutionContainerSystem.Drain(entity.Owner, soln.Value, solution.Volume);
|
||||
TrySplashSpillAt(entity.Owner, Transform(entity).Coordinates, drainedSolution, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,18 +165,18 @@ public sealed partial class PuddleSystem
|
||||
return;
|
||||
|
||||
// Don’t care about empty containers.
|
||||
if (!_solutionContainerSystem.TryGetSolution(ent, ent.Comp.SolutionName, out var solution))
|
||||
if (!_solutionContainerSystem.TryGetSolution(ent.Owner, ent.Comp.SolutionName, out _, out var solution) || solution.Volume <= 0)
|
||||
return;
|
||||
|
||||
args.Cancel("pacified-cannot-throw-spill");
|
||||
}
|
||||
|
||||
private void AddSpillVerb(EntityUid uid, SpillableComponent component, GetVerbsEvent<Verb> args)
|
||||
private void AddSpillVerb(Entity<SpillableComponent> entity, ref GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
if (!_solutionContainerSystem.TryGetSolution(args.Target, component.SolutionName, out var solution))
|
||||
if (!_solutionContainerSystem.TryGetSolution(args.Target, entity.Comp.SolutionName, out var soln, out var solution))
|
||||
return;
|
||||
|
||||
if (_openable.IsClosed(args.Target))
|
||||
@@ -195,20 +195,21 @@ public sealed partial class PuddleSystem
|
||||
};
|
||||
|
||||
// TODO VERB ICONS spill icon? pouring out a glass/beaker?
|
||||
if (component.SpillDelay == null)
|
||||
if (entity.Comp.SpillDelay == null)
|
||||
{
|
||||
var target = args.Target;
|
||||
verb.Act = () =>
|
||||
{
|
||||
var puddleSolution = _solutionContainerSystem.SplitSolution(args.Target,
|
||||
solution, solution.Volume);
|
||||
TrySpillAt(Transform(args.Target).Coordinates, puddleSolution, out _);
|
||||
var puddleSolution = _solutionContainerSystem.SplitSolution(soln.Value, solution.Volume);
|
||||
TrySpillAt(Transform(target).Coordinates, puddleSolution, out _);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
var user = args.User;
|
||||
verb.Act = () =>
|
||||
{
|
||||
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, component.SpillDelay ?? 0, new SpillDoAfterEvent(), uid, target: uid)
|
||||
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, user, entity.Comp.SpillDelay ?? 0, new SpillDoAfterEvent(), entity.Owner, target: entity.Owner)
|
||||
{
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
@@ -222,17 +223,17 @@ public sealed partial class PuddleSystem
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void OnDoAfter(EntityUid uid, SpillableComponent component, DoAfterEvent args)
|
||||
private void OnDoAfter(Entity<SpillableComponent> entity, ref SpillDoAfterEvent args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled || args.Args.Target == null)
|
||||
return;
|
||||
|
||||
//solution gone by other means before doafter completes
|
||||
if (!_solutionContainerSystem.TryGetDrainableSolution(uid, out var solution) || solution.Volume == 0)
|
||||
if (!_solutionContainerSystem.TryGetDrainableSolution(entity.Owner, out var soln, out var solution) || solution.Volume == 0)
|
||||
return;
|
||||
|
||||
var puddleSolution = _solutionContainerSystem.SplitSolution(uid, solution, solution.Volume);
|
||||
TrySpillAt(Transform(uid).Coordinates, puddleSolution, out _);
|
||||
var puddleSolution = _solutionContainerSystem.SplitSolution(soln.Value, solution.Volume);
|
||||
TrySpillAt(Transform(entity).Coordinates, puddleSolution, out _);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user