]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Bartending+: Shaking and Stirring (#29243)
authorVerm <32827189+Vermidia@users.noreply.github.com>
Sun, 7 Jul 2024 14:21:53 +0000 (09:21 -0500)
committerGitHub <noreply@github.com>
Sun, 7 Jul 2024 14:21:53 +0000 (00:21 +1000)
* Shaking and Stirring

* Remove shake message

* Switch if order a bit

* Add doafter supprot for reactionmixer

* Fix nullability

* Timespan zero

* Forgot to remove loc string

* Reorganize usings

* Remove unneeded usings, fix b52 needing to be shaken

Content.Server/Chemistry/EntitySystems/ReactionMixerSystem.cs
Content.Shared/Chemistry/Reaction/ReactionMixerComponent.cs
Resources/Locale/en-US/chemistry/components/mixing-component.ftl
Resources/Prototypes/Chemistry/mixing_types.yml
Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_special.yml
Resources/Prototypes/Entities/Objects/Misc/utensils.yml
Resources/Prototypes/Recipes/Reactions/drinks.yml

index d5f7655f884cb1f337ad29307d16830318b3502b..a81f38a21d4081688fe93ba11941ca409a6e5de2 100644 (file)
@@ -1,6 +1,9 @@
+using Content.Shared.Chemistry.Components;
 using Content.Shared.Chemistry.Reaction;
+using Content.Shared.DoAfter;
 using Content.Shared.IdentityManagement;
 using Content.Shared.Interaction;
+using Content.Shared.Nutrition.EntitySystems;
 using Content.Server.Chemistry.Containers.EntitySystems;
 using Content.Server.Popups;
 
@@ -10,34 +13,68 @@ public sealed partial class ReactionMixerSystem : EntitySystem
 {
     [Dependency] private readonly PopupSystem _popup = default!;
     [Dependency] private readonly SolutionContainerSystem _solutionContainers = default!;
+    [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
 
     public override void Initialize()
     {
         base.Initialize();
 
         SubscribeLocalEvent<ReactionMixerComponent, AfterInteractEvent>(OnAfterInteract);
+        SubscribeLocalEvent<ReactionMixerComponent, ShakeEvent>(OnShake);
+        SubscribeLocalEvent<ReactionMixerComponent, ReactionMixDoAfterEvent>(OnDoAfter);
     }
 
     private void OnAfterInteract(Entity<ReactionMixerComponent> entity, ref AfterInteractEvent args)
     {
-        if (!args.Target.HasValue || !args.CanReach)
+        if (!args.Target.HasValue || !args.CanReach || !entity.Comp.MixOnInteract)
             return;
 
-        var mixAttemptEvent = new MixingAttemptEvent(entity);
-        RaiseLocalEvent(entity, ref mixAttemptEvent);
-        if (mixAttemptEvent.Cancelled)
-        {
+        if (!MixAttempt(entity, args.Target.Value, out var solution))
             return;
-        }
 
-        if (!_solutionContainers.TryGetMixableSolution(args.Target.Value, out var solution, out _))
+        var doAfterArgs = new DoAfterArgs(EntityManager, args.User, entity.Comp.TimeToMix, new ReactionMixDoAfterEvent(), entity, args.Target.Value, entity);
+
+        _doAfterSystem.TryStartDoAfter(doAfterArgs);
+    }
+
+    private void OnDoAfter(Entity<ReactionMixerComponent> entity, ref ReactionMixDoAfterEvent args)
+    {
+        //Do again to get the solution again
+        if (!MixAttempt(entity, args.Target!.Value, out var solution))
             return;
 
-        _popup.PopupEntity(Loc.GetString(entity.Comp.MixMessage, ("mixed", Identity.Entity(args.Target.Value, EntityManager)), ("mixer", Identity.Entity(entity.Owner, EntityManager))), args.User, args.User);
+        _popup.PopupEntity(Loc.GetString(entity.Comp.MixMessage, ("mixed", Identity.Entity(args.Target!.Value, EntityManager)), ("mixer", Identity.Entity(entity.Owner, EntityManager))), args.User, args.User);
+
+        _solutionContainers.UpdateChemicals(solution!.Value, true, entity.Comp);
+
+        var afterMixingEvent = new AfterMixingEvent(entity, args.Target!.Value);
+        RaiseLocalEvent(entity, afterMixingEvent);
+    }
+
+    private void OnShake(Entity<ReactionMixerComponent> entity, ref ShakeEvent args)
+    {
+        if (!MixAttempt(entity, entity, out var solution))
+            return;
 
-        _solutionContainers.UpdateChemicals(solution.Value, true, entity.Comp);
+        _solutionContainers.UpdateChemicals(solution!.Value, true, entity.Comp);
 
-        var afterMixingEvent = new AfterMixingEvent(entity, args.Target.Value);
+        var afterMixingEvent = new AfterMixingEvent(entity, entity);
         RaiseLocalEvent(entity, afterMixingEvent);
     }
+
+    private bool MixAttempt(EntityUid ent, EntityUid target, out Entity<SolutionComponent>? solution)
+    {
+        solution = null;
+        var mixAttemptEvent = new MixingAttemptEvent(ent);
+        RaiseLocalEvent(ent, ref mixAttemptEvent);
+        if (mixAttemptEvent.Cancelled)
+        {
+            return false;
+        }
+
+        if (!_solutionContainers.TryGetMixableSolution(target, out solution, out _))
+            return false;
+
+        return true;
+    }
 }
index 118f224061094bb66cd84b7ee920623b3b4f7a67..8edfa44ce850ebb4328b0c1969a8da817665146b 100644 (file)
@@ -1,5 +1,7 @@
 using Content.Shared.Chemistry.Components;
+using Content.Shared.DoAfter;
 using Robust.Shared.Prototypes;
+using Robust.Shared.Serialization;
 
 namespace Content.Shared.Chemistry.Reaction;
 
@@ -19,9 +21,28 @@ public sealed partial class ReactionMixerComponent : Component
     [ViewVariables]
     [DataField]
     public LocId MixMessage = "default-mixing-success";
+
+    /// <summary>
+    ///     Defines if interacting is enough to mix with this component
+    /// </summary>
+    [ViewVariables]
+    [DataField]
+    public bool MixOnInteract = true;
+
+    /// <summary>
+    ///     How long it takes to mix with this
+    /// </summary>
+    [ViewVariables]
+    [DataField]
+    public TimeSpan TimeToMix = TimeSpan.Zero;
 }
 
 [ByRefEvent]
 public record struct MixingAttemptEvent(EntityUid Mixed, bool Cancelled = false);
 
 public readonly record struct AfterMixingEvent(EntityUid Mixed, EntityUid Mixer);
+
+[Serializable, NetSerializable]
+public sealed partial class ReactionMixDoAfterEvent : SimpleDoAfterEvent
+{
+}
index a486ed8ede3dbdabd8c1bb28c4b155e38eeb36a3..c434246fab78605a110eec6fb8d5c65cc81838a7 100644 (file)
@@ -6,9 +6,12 @@ mixing-verb-default-condense = condense
 mixing-verb-centrifuge = centrifugation
 mixing-verb-electrolysis = electrolyze
 mixing-verb-holy = bless
+mixing-verb-stir = stir
+mixing-verb-shake = shake
 
 ## Entity
 
 default-mixing-success = You mix the {$mixed} with the {$mixer}
 bible-mixing-success = You bless the {$mixed} with the {$mixer}
+spoon-mixing-success = You stir the {$mixed} with the {$mixer}
 
index 20d58e70abd9ac23d75f4b42f7176e86327be7b7..fd73256410830c929a2237ad78cdb30a072734e3 100644 (file)
   icon:
     sprite: Objects/Specific/Chapel/bible.rsi
     state: icon
+
+- type: mixingCategory
+  id: Shake
+  verbText: mixing-verb-shake
+  icon:
+    sprite: Objects/Consumable/Drinks/shaker.rsi
+    state: icon
+
+- type: mixingCategory
+  id: Stir
+  verbText: mixing-verb-stir
+  icon:
+    sprite: Objects/Misc/utensils.rsi
+    state: spoon
index d2c1249740e009fb16dcf60e0c2a1a1ba3659e4f..604ae28fb300cb8a41ee44647ca5af43e6e1fc0b 100644 (file)
@@ -11,7 +11,7 @@
   - type: MixableSolution
     solution: drink
   - type: Drink
-  - type: Shakeable # Doesn't do anything, but I mean...
+  - type: Shakeable
   - type: FitsInDispenser
     solution: drink
   - type: DrawableSolution
   - type: PhysicalComposition
     materialComposition:
       Steel: 50
+  - type: ReactionMixer
+    mixOnInteract: false
+    reactionTypes:
+    - Shake
 
 - type: entity
   parent: DrinkGlassBase
index 86667f094fdbb74863897e288db13fd0a5f19bd3..e735b2dcddce97bc2f91fb33623d4a4191416dba 100644 (file)
         Blunt: 1
   - type: Shovel
     speedModifier: 0.1 # you can try
+  - type: ReactionMixer
+    mixMessage: "spoon-mixing-success"
+    timeToMix: 0.5
+    reactionTypes:
+    - Stir
 
 - type: entity
   parent: UtensilBasePlastic
     - Spoon
   - type: Shovel
     speedModifier: 0.1 # you can try
+  - type: ReactionMixer
+    mixMessage: "spoon-mixing-success"
+    timeToMix: 0.5
+    reactionTypes:
+    - Stir
 
 - type: entity
   parent: UtensilBasePlastic
   - type: Utensil
     types:
     - Spoon
+  - type: ReactionMixer
+    mixMessage: "spoon-mixing-success"
+    timeToMix: 0.5
+    reactionTypes:
+    - Stir
   - type: MeleeWeapon
     wideAnimationRotation: 180
     attackRate: 2
index 2a14c0ecd29c4bdf9415f75015538235388c410a..96cc5b6aaa44985bebc13f1c1b38878bf29b0f88 100644 (file)
@@ -10,6 +10,8 @@
 
 - type: reaction
   id: AlliesCocktail
+  requiredMixerCategories:
+  - Shake
   reactants:
     Martini:
       amount: 2
@@ -20,6 +22,8 @@
 
 - type: reaction
   id: Amasec
+  requiredMixerCategories:
+  - Shake
   reactants:
     Wine:
       amount: 2
@@ -32,6 +36,8 @@
 
 - type: reaction
   id: Andalusia
+  requiredMixerCategories:
+  - Stir
   reactants:
     Rum:
       amount: 1
 
 - type: reaction
   id: BlueHawaiian
+  requiredMixerCategories:
+  - Shake
   reactants:
     CoconutRum:
       amount: 2
 
 - type: reaction
   id: BahamaMama
+  requiredMixerCategories:
+  - Shake
   reactants:
     Ice:
       amount: 1
 
 - type: reaction
   id: BeepskySmash
+  requiredMixerCategories:
+  - Shake
   reactants:
     Iron:
       amount: 1
 
 - type: reaction
   id: BloodyMary
+  requiredMixerCategories:
+  - Stir
   reactants:
     JuiceLime:
       amount: 1
 
 - type: reaction
   id: DemonsBlood
+  requiredMixerCategories:
+  - Stir
   reactants:
     Rum:
       amount: 1
 
 - type: reaction
   id: DevilsKiss
+  requiredMixerCategories:
+  - Stir
   reactants:
     Rum:
       amount: 1
 
 - type: reaction
   id: DoctorsDelight
+  requiredMixerCategories:
+  - Stir
   reactants:
     Cream:
       amount: 2
 
 - type: reaction
   id: DriestMartini
+  requiredMixerCategories:
+  - Shake
   reactants:
     Gin:
       amount: 1
 
 - type: reaction
   id: ErikaSurprise
+  requiredMixerCategories:
+  - Shake
   reactants:
     Ale:
       amount: 2
 
 - type: reaction
   id: GargleBlaster
+  requiredMixerCategories:
+  - Shake
   reactants:
     Cognac:
       amount: 1
 
 - type: reaction
   id: Gildlager
+  requiredMixerCategories:
+  - Shake
   reactants:
     Gold:
       amount: 1
 
 - type: reaction
   id: IrishCoffee
+  requiredMixerCategories:
+  - Stir
   reactants:
     Coffee:
       amount: 1
 
 - type: reaction
   id: KiraSpecial
+  requiredMixerCategories:
+  - Stir
   reactants:
     JuiceLime:
       amount: 1
 
 - type: reaction
   id: Lemonade
+  requiredMixerCategories:
+  - Stir
   reactants:
     JuiceLemon:
       amount: 1
 
 - type: reaction
   id: LemonLime
+  requiredMixerCategories:
+  - Stir
   reactants:
     JuiceLemon:
       amount: 1
 
 - type: reaction
   id: LongIslandIcedTea
+  requiredMixerCategories:
+  - Stir
   reactants:
     CubaLibre:
       amount: 3
 
 - type: reaction
   id: Manhattan
+  requiredMixerCategories:
+  - Shake
   reactants:
     Whiskey:
       amount: 2
 
 - type: reaction
   id: Martini
+  requiredMixerCategories:
+  - Shake
   reactants:
     Gin:
       amount: 2
 
 - type: reaction
   id: Mojito
+  requiredMixerCategories:
+  - Shake
   reactants:
     JuiceLime:
       amount: 1
 
 - type: reaction
   id: Patron
+  requiredMixerCategories:
+  - Shake
   reactants:
     Tequila:
       amount: 10
 
 - type: reaction
   id: Painkiller
+  requiredMixerCategories:
+  - Shake
   reactants:
     JuicePineapple:
       amount: 3
 
 - type: reaction
   id: ScrewdriverCocktail
+  requiredMixerCategories:
+  - Shake
   reactants:
     JuiceOrange:
       amount: 2
 
 - type: reaction
   id: ToxinsSpecial
+  requiredMixerCategories:
+  - Shake
   reactants:
     Rum:
       amount: 2
 
 - type: reaction
   id: VodkaMartini
+  requiredMixerCategories:
+  - Shake
   reactants:
     Vermouth:
       amount: 1