Plays rustle sound when inserting or opening a backpack. (#2890)
* SoundCollection * Works * Applied review * Waah * Working * e * Adjust sound collection serialization Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Items;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
@@ -13,16 +14,22 @@ using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.GameObjects.EntitySystemMessages;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -46,6 +53,8 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
private int _storageCapacityMax;
|
||||
public readonly HashSet<IPlayerSession> SubscribedSessions = new();
|
||||
|
||||
public string? StorageSoundCollection { get; set; }
|
||||
|
||||
[ViewVariables]
|
||||
public override IReadOnlyList<IEntity>? StoredEntities => _storage?.ContainedEntities;
|
||||
|
||||
@@ -135,6 +144,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
return;
|
||||
}
|
||||
|
||||
PlaySoundCollection(StorageSoundCollection);
|
||||
EnsureInitialCalculated();
|
||||
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner.Uid}) had entity (UID {message.Entity.Uid}) inserted into it.");
|
||||
@@ -207,6 +217,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
/// <param name="entity">The entity to open the UI for</param>
|
||||
public void OpenStorageUI(IEntity entity)
|
||||
{
|
||||
PlaySoundCollection(StorageSoundCollection);
|
||||
EnsureInitialCalculated();
|
||||
|
||||
var userSession = entity.GetComponent<BasicActorComponent>().playerSession;
|
||||
@@ -331,6 +342,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
|
||||
serializer.DataField(ref _storageCapacityMax, "capacity", 10000);
|
||||
serializer.DataField(ref _occludesLight, "occludesLight", true);
|
||||
serializer.DataField(this, x => x.StorageSoundCollection, "storageSoundCollection", string.Empty);
|
||||
//serializer.DataField(ref StorageUsed, "used", 0);
|
||||
}
|
||||
|
||||
@@ -494,5 +506,17 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void PlaySoundCollection(string? name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var file = AudioHelpers.GetRandomFileFromSoundCollection(name);
|
||||
EntitySystem.Get<AudioSystem>()
|
||||
.PlayFromEntity(file, Owner, AudioParams.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user