From 989025b222830b3a16886e78a135520dcdd5c654 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Thu, 23 Jul 2020 01:42:09 +0200 Subject: [PATCH] Add drink atmos (#1434) --- .../Components/Nutrition/DrinkComponent.cs | 37 ++++++++++++++----- .../Objects/Consumable/drinks_cans.yml | 1 + 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs b/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs index cdeba574f4..0f919c7228 100644 --- a/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs @@ -1,4 +1,5 @@ using Content.Server.GameObjects.Components.Chemistry; +using Content.Server.GameObjects.Components.Fluids; using Content.Server.GameObjects.EntitySystems.Click; using Content.Server.Interfaces.GameObjects.Components.Interaction; using Content.Shared.Audio; @@ -25,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Nutrition { [RegisterComponent] [ComponentReference(typeof(IAfterInteract))] - public class DrinkComponent : Component, IUse, IAfterInteract, ISolutionChange,IExamine + public class DrinkComponent : Component, IUse, IAfterInteract, ISolutionChange,IExamine, ILand { #pragma warning disable 649 [Dependency] private readonly IPrototypeManager _prototypeManager; @@ -41,16 +42,15 @@ namespace Content.Server.GameObjects.Components.Nutrition private bool _defaultToOpened; [ViewVariables] public ReagentUnit TransferAmount { get; private set; } = ReagentUnit.New(2); - [ViewVariables] - public bool Opened => _opened; - + protected bool Opened { get; set; } [ViewVariables] public bool Empty => _contents.CurrentVolume.Float() <= 0; private AppearanceComponent _appearanceComponent; - private bool _opened = false; private string _soundCollection; + private bool _pressurized; + private string _burstSound; public override void ExposeData(ObjectSerializer serializer) { @@ -58,6 +58,8 @@ namespace Content.Server.GameObjects.Components.Nutrition serializer.DataField(ref _useSound, "useSound", "/Audio/Items/drink.ogg"); serializer.DataField(ref _defaultToOpened, "isOpen", false); //For things like cups of coffee. serializer.DataField(ref _soundCollection, "openSounds","canOpenSounds"); + serializer.DataField(ref _pressurized, "pressurized",false); + serializer.DataField(ref _burstSound, "burstSound", "/Audio/Effects/flash_bang.ogg"); } public override void Initialize() @@ -72,7 +74,7 @@ namespace Content.Server.GameObjects.Components.Nutrition _contents.Capabilities = SolutionCaps.PourIn | SolutionCaps.PourOut | SolutionCaps.Injectable; - _opened = _defaultToOpened; + Opened = _defaultToOpened; UpdateAppearance(); } @@ -88,14 +90,14 @@ namespace Content.Server.GameObjects.Components.Nutrition } bool IUse.UseEntity(UseEntityEventArgs args) { - if (!_opened) + if (!Opened) { //Do the opening stuff like playing the sounds. var soundCollection = _prototypeManager.Index(_soundCollection); var file = _random.Pick(soundCollection.PickFiles); EntitySystem.Get().PlayFromEntity(file, args.User, AudioParams.Default); - _opened = true; + Opened = true; return false; } return TryUseDrink(args.User); @@ -126,7 +128,7 @@ namespace Content.Server.GameObjects.Components.Nutrition return false; } - if (!_opened) + if (!Opened) { target.PopupMessage(target, Loc.GetString("Open it first!")); return false; @@ -159,5 +161,22 @@ namespace Content.Server.GameObjects.Components.Nutrition target.PopupMessage(target, Loc.GetString("You've had enough {0}!", Owner.Name)); return false; } + + void ILand.Land(LandEventArgs eventArgs) + { + if (_pressurized && + !Opened && + _random.Prob(0.25f) && + Owner.TryGetComponent(out SolutionComponent component)) + { + Opened = true; + + var solution = component.SplitSolution(component.CurrentVolume); + SpillHelper.SpillAt(Owner, solution, "PuddleSmear"); + + EntitySystem.Get().PlayFromEntity(_burstSound, Owner, + AudioParams.Default.WithVolume(-4)); + } + } } } diff --git a/Resources/Prototypes/Entities/Objects/Consumable/drinks_cans.yml b/Resources/Prototypes/Entities/Objects/Consumable/drinks_cans.yml index e148996027..98efe1543c 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/drinks_cans.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/drinks_cans.yml @@ -5,6 +5,7 @@ components: - type: Drink openSounds: canOpenSounds + pressurized: true - type: Solution maxVol: 20 contents: