Add drink atmos (#1434)

This commit is contained in:
DrSmugleaf
2020-07-23 01:42:09 +02:00
committed by GitHub
parent 327b3b610f
commit 989025b222
2 changed files with 29 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.Components.Fluids;
using Content.Server.GameObjects.EntitySystems.Click; using Content.Server.GameObjects.EntitySystems.Click;
using Content.Server.Interfaces.GameObjects.Components.Interaction; using Content.Server.Interfaces.GameObjects.Components.Interaction;
using Content.Shared.Audio; using Content.Shared.Audio;
@@ -25,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(IAfterInteract))] [ComponentReference(typeof(IAfterInteract))]
public class DrinkComponent : Component, IUse, IAfterInteract, ISolutionChange,IExamine public class DrinkComponent : Component, IUse, IAfterInteract, ISolutionChange,IExamine, ILand
{ {
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IPrototypeManager _prototypeManager; [Dependency] private readonly IPrototypeManager _prototypeManager;
@@ -41,16 +42,15 @@ namespace Content.Server.GameObjects.Components.Nutrition
private bool _defaultToOpened; private bool _defaultToOpened;
[ViewVariables] [ViewVariables]
public ReagentUnit TransferAmount { get; private set; } = ReagentUnit.New(2); public ReagentUnit TransferAmount { get; private set; } = ReagentUnit.New(2);
[ViewVariables] [ViewVariables]
public bool Opened => _opened; protected bool Opened { get; set; }
[ViewVariables] [ViewVariables]
public bool Empty => _contents.CurrentVolume.Float() <= 0; public bool Empty => _contents.CurrentVolume.Float() <= 0;
private AppearanceComponent _appearanceComponent; private AppearanceComponent _appearanceComponent;
private bool _opened = false;
private string _soundCollection; private string _soundCollection;
private bool _pressurized;
private string _burstSound;
public override void ExposeData(ObjectSerializer serializer) 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 _useSound, "useSound", "/Audio/Items/drink.ogg");
serializer.DataField(ref _defaultToOpened, "isOpen", false); //For things like cups of coffee. serializer.DataField(ref _defaultToOpened, "isOpen", false); //For things like cups of coffee.
serializer.DataField(ref _soundCollection, "openSounds","canOpenSounds"); 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() public override void Initialize()
@@ -72,7 +74,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
_contents.Capabilities = SolutionCaps.PourIn _contents.Capabilities = SolutionCaps.PourIn
| SolutionCaps.PourOut | SolutionCaps.PourOut
| SolutionCaps.Injectable; | SolutionCaps.Injectable;
_opened = _defaultToOpened; Opened = _defaultToOpened;
UpdateAppearance(); UpdateAppearance();
} }
@@ -88,14 +90,14 @@ namespace Content.Server.GameObjects.Components.Nutrition
} }
bool IUse.UseEntity(UseEntityEventArgs args) bool IUse.UseEntity(UseEntityEventArgs args)
{ {
if (!_opened) if (!Opened)
{ {
//Do the opening stuff like playing the sounds. //Do the opening stuff like playing the sounds.
var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>(_soundCollection); var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>(_soundCollection);
var file = _random.Pick(soundCollection.PickFiles); var file = _random.Pick(soundCollection.PickFiles);
EntitySystem.Get<AudioSystem>().PlayFromEntity(file, args.User, AudioParams.Default); EntitySystem.Get<AudioSystem>().PlayFromEntity(file, args.User, AudioParams.Default);
_opened = true; Opened = true;
return false; return false;
} }
return TryUseDrink(args.User); return TryUseDrink(args.User);
@@ -126,7 +128,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
return false; return false;
} }
if (!_opened) if (!Opened)
{ {
target.PopupMessage(target, Loc.GetString("Open it first!")); target.PopupMessage(target, Loc.GetString("Open it first!"));
return false; return false;
@@ -159,5 +161,22 @@ namespace Content.Server.GameObjects.Components.Nutrition
target.PopupMessage(target, Loc.GetString("You've had enough {0}!", Owner.Name)); target.PopupMessage(target, Loc.GetString("You've had enough {0}!", Owner.Name));
return false; 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<AudioSystem>().PlayFromEntity(_burstSound, Owner,
AudioParams.Default.WithVolume(-4));
}
}
} }
} }

View File

@@ -5,6 +5,7 @@
components: components:
- type: Drink - type: Drink
openSounds: canOpenSounds openSounds: canOpenSounds
pressurized: true
- type: Solution - type: Solution
maxVol: 20 maxVol: 20
contents: contents: