From 13b84870ecc079301c1e619a90e3a18e9113ec32 Mon Sep 17 00:00:00 2001 From: Verm <32827189+Vermidia@users.noreply.github.com> Date: Sun, 7 Jul 2024 09:21:53 -0500 Subject: [PATCH] Bartending+: Shaking and Stirring (#29243) * 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 --- .../EntitySystems/ReactionMixerSystem.cs | 57 +++++++++++++++---- .../Reaction/ReactionMixerComponent.cs | 21 +++++++ .../chemistry/components/mixing-component.ftl | 3 + .../Prototypes/Chemistry/mixing_types.yml | 14 +++++ .../Consumable/Drinks/drinks_special.yml | 6 +- .../Entities/Objects/Misc/utensils.yml | 15 +++++ .../Prototypes/Recipes/Reactions/drinks.yml | 54 ++++++++++++++++++ 7 files changed, 159 insertions(+), 11 deletions(-) diff --git a/Content.Server/Chemistry/EntitySystems/ReactionMixerSystem.cs b/Content.Server/Chemistry/EntitySystems/ReactionMixerSystem.cs index d5f7655f88..a81f38a21d 100644 --- a/Content.Server/Chemistry/EntitySystems/ReactionMixerSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ReactionMixerSystem.cs @@ -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(OnAfterInteract); + SubscribeLocalEvent(OnShake); + SubscribeLocalEvent(OnDoAfter); } private void OnAfterInteract(Entity 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 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 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? 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; + } } diff --git a/Content.Shared/Chemistry/Reaction/ReactionMixerComponent.cs b/Content.Shared/Chemistry/Reaction/ReactionMixerComponent.cs index 118f224061..8edfa44ce8 100644 --- a/Content.Shared/Chemistry/Reaction/ReactionMixerComponent.cs +++ b/Content.Shared/Chemistry/Reaction/ReactionMixerComponent.cs @@ -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"; + + /// + /// Defines if interacting is enough to mix with this component + /// + [ViewVariables] + [DataField] + public bool MixOnInteract = true; + + /// + /// How long it takes to mix with this + /// + [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 +{ +} diff --git a/Resources/Locale/en-US/chemistry/components/mixing-component.ftl b/Resources/Locale/en-US/chemistry/components/mixing-component.ftl index a486ed8ede..c434246fab 100644 --- a/Resources/Locale/en-US/chemistry/components/mixing-component.ftl +++ b/Resources/Locale/en-US/chemistry/components/mixing-component.ftl @@ -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} diff --git a/Resources/Prototypes/Chemistry/mixing_types.yml b/Resources/Prototypes/Chemistry/mixing_types.yml index 20d58e70ab..fd73256410 100644 --- a/Resources/Prototypes/Chemistry/mixing_types.yml +++ b/Resources/Prototypes/Chemistry/mixing_types.yml @@ -51,3 +51,17 @@ 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 diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_special.yml b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_special.yml index d2c1249740..604ae28fb3 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_special.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Drinks/drinks_special.yml @@ -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 @@ -34,6 +34,10 @@ - type: PhysicalComposition materialComposition: Steel: 50 + - type: ReactionMixer + mixOnInteract: false + reactionTypes: + - Shake - type: entity parent: DrinkGlassBase diff --git a/Resources/Prototypes/Entities/Objects/Misc/utensils.yml b/Resources/Prototypes/Entities/Objects/Misc/utensils.yml index 86667f094f..e735b2dcdd 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/utensils.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/utensils.yml @@ -87,6 +87,11 @@ 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 @@ -103,6 +108,11 @@ - Spoon - type: Shovel speedModifier: 0.1 # you can try + - type: ReactionMixer + mixMessage: "spoon-mixing-success" + timeToMix: 0.5 + reactionTypes: + - Stir - type: entity parent: UtensilBasePlastic @@ -137,6 +147,11 @@ - type: Utensil types: - Spoon + - type: ReactionMixer + mixMessage: "spoon-mixing-success" + timeToMix: 0.5 + reactionTypes: + - Stir - type: MeleeWeapon wideAnimationRotation: 180 attackRate: 2 diff --git a/Resources/Prototypes/Recipes/Reactions/drinks.yml b/Resources/Prototypes/Recipes/Reactions/drinks.yml index 2a14c0ecd2..96cc5b6aaa 100644 --- a/Resources/Prototypes/Recipes/Reactions/drinks.yml +++ b/Resources/Prototypes/Recipes/Reactions/drinks.yml @@ -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 @@ -98,6 +104,8 @@ - type: reaction id: BlueHawaiian + requiredMixerCategories: + - Shake reactants: CoconutRum: amount: 2 @@ -126,6 +134,8 @@ - type: reaction id: BahamaMama + requiredMixerCategories: + - Shake reactants: Ice: amount: 1 @@ -168,6 +178,8 @@ - type: reaction id: BeepskySmash + requiredMixerCategories: + - Shake reactants: Iron: amount: 1 @@ -190,6 +202,8 @@ - type: reaction id: BloodyMary + requiredMixerCategories: + - Stir reactants: JuiceLime: amount: 1 @@ -280,6 +294,8 @@ - type: reaction id: DemonsBlood + requiredMixerCategories: + - Stir reactants: Rum: amount: 1 @@ -294,6 +310,8 @@ - type: reaction id: DevilsKiss + requiredMixerCategories: + - Stir reactants: Rum: amount: 1 @@ -306,6 +324,8 @@ - type: reaction id: DoctorsDelight + requiredMixerCategories: + - Stir reactants: Cream: amount: 2 @@ -322,6 +342,8 @@ - type: reaction id: DriestMartini + requiredMixerCategories: + - Shake reactants: Gin: amount: 1 @@ -332,6 +354,8 @@ - type: reaction id: ErikaSurprise + requiredMixerCategories: + - Shake reactants: Ale: amount: 2 @@ -373,6 +397,8 @@ - type: reaction id: GargleBlaster + requiredMixerCategories: + - Shake reactants: Cognac: amount: 1 @@ -411,6 +437,8 @@ - type: reaction id: Gildlager + requiredMixerCategories: + - Shake reactants: Gold: amount: 1 @@ -548,6 +576,8 @@ - type: reaction id: IrishCoffee + requiredMixerCategories: + - Stir reactants: Coffee: amount: 1 @@ -568,6 +598,8 @@ - type: reaction id: KiraSpecial + requiredMixerCategories: + - Stir reactants: JuiceLime: amount: 1 @@ -580,6 +612,8 @@ - type: reaction id: Lemonade + requiredMixerCategories: + - Stir reactants: JuiceLemon: amount: 1 @@ -592,6 +626,8 @@ - type: reaction id: LemonLime + requiredMixerCategories: + - Stir reactants: JuiceLemon: amount: 1 @@ -604,6 +640,8 @@ - type: reaction id: LongIslandIcedTea + requiredMixerCategories: + - Stir reactants: CubaLibre: amount: 3 @@ -618,6 +656,8 @@ - type: reaction id: Manhattan + requiredMixerCategories: + - Shake reactants: Whiskey: amount: 2 @@ -658,6 +698,8 @@ - type: reaction id: Martini + requiredMixerCategories: + - Shake reactants: Gin: amount: 2 @@ -679,6 +721,8 @@ - type: reaction id: Mojito + requiredMixerCategories: + - Shake reactants: JuiceLime: amount: 1 @@ -726,6 +770,8 @@ - type: reaction id: Patron + requiredMixerCategories: + - Shake reactants: Tequila: amount: 10 @@ -736,6 +782,8 @@ - type: reaction id: Painkiller + requiredMixerCategories: + - Shake reactants: JuicePineapple: amount: 3 @@ -838,6 +886,8 @@ - type: reaction id: ScrewdriverCocktail + requiredMixerCategories: + - Shake reactants: JuiceOrange: amount: 2 @@ -955,6 +1005,8 @@ - type: reaction id: ToxinsSpecial + requiredMixerCategories: + - Shake reactants: Rum: amount: 2 @@ -967,6 +1019,8 @@ - type: reaction id: VodkaMartini + requiredMixerCategories: + - Shake reactants: Vermouth: amount: 1 -- 2.51.2