]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Reagent interactivity (pt. 1) (#15130)
authorKara <lunarautomaton6@gmail.com>
Thu, 6 Apr 2023 21:20:48 +0000 (14:20 -0700)
committerGitHub <noreply@github.com>
Thu, 6 Apr 2023 21:20:48 +0000 (16:20 -0500)
* Puddle slippy

* spillable melee

* splash spilling!

* splat melee sound

* p

17 files changed:
Content.Server/Destructible/Thresholds/Behaviors/SpillBehavior.cs
Content.Server/Fluids/Components/SpillableComponent.cs
Content.Server/Fluids/EntitySystems/PuddleSystem.cs
Content.Server/Fluids/EntitySystems/SpillableSystem.cs
Content.Server/Nutrition/EntitySystems/SmokingSystem.cs
Content.Shared/Chemistry/ReactiveSystem.cs
Resources/Locale/en-US/fluids/components/puddle-component.ftl
Resources/Locale/en-US/fluids/components/spillable-component.ftl
Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks.yml
Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cans.yml
Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_cups.yml
Resources/Prototypes/Entities/Objects/Consumable/Drinks/trash_drinks.yml
Resources/Prototypes/Entities/Objects/Consumable/Food/ingredients.yml
Resources/Prototypes/Entities/Objects/Consumable/Food/soup.yml
Resources/Prototypes/Entities/Objects/Specific/chemistry-bottles.yml
Resources/Prototypes/Entities/Objects/Specific/chemistry.yml
Resources/Prototypes/Entities/Objects/Tools/bucket.yml

index d751da911bc0a90ce0032e00603c6a480158827a..293e2e33538b3d13e1985fcbe917e06e3ea935d5 100644 (file)
@@ -31,12 +31,12 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
                 solutionContainerSystem.TryGetSolution(owner, spillableComponent.SolutionName,
                     out var compSolution))
             {
-                spillableSystem.SpillAt(compSolution, coordinates, "PuddleSmear", false);
+                spillableSystem.SplashSpillAt(owner, compSolution, coordinates, "PuddleSmear", false, user: cause);
             }
             else if (Solution != null &&
                      solutionContainerSystem.TryGetSolution(owner, Solution, out var behaviorSolution))
             {
-                spillableSystem.SpillAt(behaviorSolution, coordinates, "PuddleSmear");
+                spillableSystem.SplashSpillAt(owner, behaviorSolution, coordinates, "PuddleSmear", user: cause);
             }
         }
     }
index eb121215666803227bae1f8eebc40b3f031f3fbd..30a1bc66a05271fef3c300a622943087bad1f7ed 100644 (file)
@@ -1,3 +1,5 @@
+using Content.Shared.FixedPoint;
+
 namespace Content.Server.Fluids.Components;
 
 [RegisterComponent]
@@ -15,4 +17,10 @@ public sealed class SpillableComponent : Component
 
     [DataField("spillDelay")]
     public float? SpillDelay;
+
+    /// <summary>
+    ///     At most how much reagent can be splashed on someone at once?
+    /// </summary>
+    [DataField("maxMeleeSpillAmount")]
+    public FixedPoint2 MaxMeleeSpillAmount = FixedPoint2.New(20);
 }
index 0a9f8a8332c40697fae9f5d903f36b3581b8098f..dd0de51db19ca7bd0779bcaf41f8565b61907291 100644 (file)
@@ -1,8 +1,13 @@
 using Content.Server.Chemistry.EntitySystems;
 using Content.Server.Fluids.Components;
+using Content.Shared.Chemistry;
+using Content.Shared.Chemistry.Reaction;
+using Content.Shared.Chemistry.Reagent;
 using Content.Shared.Examine;
 using Content.Shared.FixedPoint;
 using Content.Shared.Fluids;
+using Content.Shared.Popups;
+using Content.Shared.Slippery;
 using Content.Shared.StepTrigger.Components;
 using Content.Shared.StepTrigger.Systems;
 using JetBrains.Annotations;
@@ -11,6 +16,7 @@ using Robust.Shared.Map;
 using Robust.Shared.Player;
 using Solution = Content.Shared.Chemistry.Components.Solution;
 using Robust.Shared.Prototypes;
+using Robust.Shared.Random;
 
 namespace Content.Server.Fluids.EntitySystems
 {
@@ -21,7 +27,10 @@ namespace Content.Server.Fluids.EntitySystems
         [Dependency] private readonly FluidSpreaderSystem _fluidSpreaderSystem = default!;
         [Dependency] private readonly StepTriggerSystem _stepTrigger = default!;
         [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+        [Dependency] private readonly ReactiveSystem _reactive = default!;
+        [Dependency] private readonly SharedPopupSystem _popup = default!;
         [Dependency] private readonly IPrototypeManager _protoMan = default!;
+        [Dependency] private readonly IRobustRandom _random = default!;
 
         public static float PuddleVolume = 1000;
 
@@ -38,6 +47,7 @@ namespace Content.Server.Fluids.EntitySystems
             SubscribeLocalEvent<PuddleComponent, ExaminedEvent>(HandlePuddleExamined);
             SubscribeLocalEvent<PuddleComponent, SolutionChangedEvent>(OnSolutionUpdate);
             SubscribeLocalEvent<PuddleComponent, ComponentInit>(OnPuddleInit);
+            SubscribeLocalEvent<PuddleComponent, SlipEvent>(OnPuddleSlip);
         }
 
         public override void Update(float frameTime)
@@ -55,6 +65,29 @@ namespace Content.Server.Fluids.EntitySystems
             _solutionContainerSystem.EnsureSolution(uid, component.SolutionName, FixedPoint2.New(PuddleVolume), out _);
         }
 
+        private void OnPuddleSlip(EntityUid uid, PuddleComponent component, ref SlipEvent args)
+        {
+            // Reactive entities have a chance to get a touch reaction from slipping on a puddle
+            // (i.e. it is implied they fell face first onto it or something)
+            if (!HasComp<ReactiveComponent>(args.Slipped))
+                return;
+
+            // Eventually probably have some system of 'body coverage' to tweak the probability but for now just 0.5
+            // (implying that spacemen have a 50% chance to either land on their ass or their face)
+            if (!_random.Prob(0.5f))
+                return;
+
+            if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solution))
+                return;
+
+            _popup.PopupEntity(Loc.GetString("puddle-component-slipped-touch-reaction", ("puddle", uid)),
+                args.Slipped, args.Slipped, PopupType.SmallCaution);
+
+            // Take 15% of the puddle solution
+            var splitSol = _solutionContainerSystem.SplitSolution(uid, solution, solution.Volume * 0.15f);
+            _reactive.DoEntityReaction(args.Slipped, splitSol, ReactionMethod.Touch);
+        }
+
         private void OnSolutionUpdate(EntityUid uid, PuddleComponent component, SolutionChangedEvent args)
         {
             if (args.Solution.Name != component.SolutionName)
index f98656e291f1d9d9f25aff5fd5742deb51a4eda5..54d3691c76adaa6824d9244d9652cb51f19b3994 100644 (file)
@@ -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.
 
index a6e274627a1272a8edfb9856ddacbc5248936667..a985f39315ae2e659db1bafa0e0637a2f01fbe5e 100644 (file)
@@ -136,7 +136,7 @@ namespace Content.Server.Nutrition.EntitySystems
                     continue;
                 }
 
-                _reactiveSystem.ReactionEntity(containerManager.Owner, ReactionMethod.Ingestion, inhaledSolution);
+                _reactiveSystem.DoEntityReaction(containerManager.Owner, inhaledSolution, ReactionMethod.Ingestion);
                 _bloodstreamSystem.TryAddToChemicals(containerManager.Owner, inhaledSolution, bloodstream);
             }
 
index dc629bc8e9c8e9557702b517a9a74c99ffd44682..ca372e940bd755f8a28af3e1a0f983cd320fcb48 100644 (file)
@@ -17,14 +17,6 @@ namespace Content.Shared.Chemistry
         [Dependency] private readonly IRobustRandom _robustRandom = default!;
         [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
 
-        public void ReactionEntity(EntityUid uid, ReactionMethod method, Solution solution)
-        {
-            foreach (var (id, quantity) in solution)
-            {
-                ReactionEntity(uid, method, id, quantity, solution);
-            }
-        }
-
         public void DoEntityReaction(EntityUid uid, Solution solution, ReactionMethod method)
         {
             foreach (var (reagentId, quantity) in solution.Contents.ToArray())
index eaed045d8d00a2448de010991bc4c578fbdf8816..4114733e897aaf38cde5b96d7fb4ef8c47d3ba40 100644 (file)
@@ -1 +1,2 @@
-puddle-component-examine-is-slipper-text = It looks slippery.
\ No newline at end of file
+puddle-component-examine-is-slipper-text = It looks slippery.
+puddle-component-slipped-touch-reaction = The chemicals in {THE($puddle)} get on your skin!
index 4c00b7b459bdb963ba83ff3e76738a58bb585e8f..cfcdf86a90922c585ef195040bee0d771241dac7 100644 (file)
@@ -2,4 +2,12 @@
 
 spill-target-verb-get-data-text = Spill liquid
 spill-target-verb-activate-cannot-drain-message = You can't pour anything from {$owner}!
-spill-target-verb-activate-is-empty-message = {$owner} is empty!
\ No newline at end of file
+spill-target-verb-activate-is-empty-message = {$owner} is empty!
+
+spill-melee-hit-attacker = You spill {$amount}u of {THE($spillable)} onto {THE($target)}!
+spill-melee-hit-others = {CAPITALIZE(THE($attacker))} spills some of {THE($spillable)} onto {THE($target)}!
+
+spill-land-spilled-on-other = {CAPITALIZE(THE($spillable))} spills some of its solution onto {THE($target)}!
+
+spill-examine-is-spillable = This container looks spillable.
+spill-examine-spillable-weapon = You could splash this onto someone with a melee attack.
index 43b9a64e7ae8fa94ce95f4e9d386cfaa05e6d93f..6e2d74a8550ac2211c3e4c86433a6b055f55d1b7 100644 (file)
   - type: Drink
   - type: Sprite
     state: icon
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: Spillable
     solution: drink
   - type: FitsInDispenser
index 93843b36e7135620ae4b736e92ebf9d24a6b88f4..4a40578fd4cb6b234611f01e80e693308ddb22d6 100644 (file)
           False: {state: "icon"}
   - type: Spillable
     solution: drink
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: ItemCooldown
   - type: Recyclable
   - type: SpaceGarbage
     sprite: Objects/Consumable/Drinks/shamblersjuice.rsi
   - type: Item
     sprite: Objects/Consumable/Drinks/shamblersjuice.rsi
-    
+
 - type: entity
   parent: DrinkCanBaseFull
   id: DrinkPwrGameCan
index 5ef3ad01e0e35addf3a06960ac687c5d6ea56f3b..1d15533407bb2d15b25605309eadc08224772810 100644 (file)
     state: icon
   - type: Spillable
     solution: drink
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: ItemCooldown
 
 - type: entity
index f879ee78ccb907b9a378b5ed12aa17c280e95bfb..03b04d7e555307a80762c3d1f616274170d050d0 100644 (file)
     maxTransferAmount: 5
   - type: Drink
     isOpen: true
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: Spillable
     solution: drink
   - type: FitsInDispenser
index 040af2e4cb54cbc5edb9d568667c5b139cf85474..8839b4be89919300f7bec3664169c50e8c47d29d 100644 (file)
       path: /Audio/Items/eating_1.ogg
   - type: Spillable
     solution: food
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: TrashOnEmpty
     solution: food
 
index 91f3dac564f291859becae0bb69b12993cefc021..c3b1b8b605379932945f74c158f2898cd42d342e 100644 (file)
         Blunt: 5
   - type: Spillable
     solution: food
+  # soup weapon!
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: Damageable
     damageContainer: Inorganic
   - type: Destructible
index 8bc21bc44cef50f64d09e43a450fb96f69f2e628..42408dd180c106b89b608893761b1bb57be82e59 100644 (file)
     sprite: Objects/Specific/Chemistry/beaker.rsi
   - type: Spillable
     solution: drink
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: TrashOnEmpty
     solution: drink
   - type: StaticPrice
index c27ceb7f8a44d58630b7d6d5f8880b163d18a86b..1eeae258a3fe722373aa804b3274c0d5582bd4b5 100644 (file)
         visible: false
   - type: Item
     sprite: Objects/Specific/Chemistry/beaker.rsi
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: SolutionContainerManager
     solutions:
       beaker:
index cbcd4851a2f0d92ee8c3b1cbea738896a54cdf23..a61b6efb4e28ba6a10d5f498f2e805b809a92384 100644 (file)
     interfaces:
     - key: enum.TransferAmountUiKey.Key
       type: TransferAmountBoundUserInterface
+  - type: MeleeWeapon
+    soundNoDamage:
+      path: "/Audio/Effects/Fluids/splat.ogg"
+    damage:
+      types:
+        Blunt: 0
   - type: Spillable
     solution: bucket
   - type: DrawableSolution