From e35d5390db6b7587dd5818f9b0f708c94d7a8620 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Sun, 5 May 2019 18:52:06 +0200 Subject: [PATCH] Storage system refactor & map init. * Demonstrated map init working with guns, toolboxes, tool lockers. * Refactored EntityStorage and ServerStorage to have a common interface. * EntityStorage no longer uses ServerStorage PURELY for visuals. Use an appearance visualizer instead. --- Content.Client/Content.Client.csproj | 1 + .../Storage/ClientStorageComponent.cs | 48 -- .../Components/Storage/StorageVisualizer2D.cs | 47 ++ Content.Server/Content.Server.csproj | 5 +- Content.Server/EntryPoint.cs | 7 + .../Interactable/HandheldLightComponent.cs | 19 +- .../Storage}/EntityStorageComponent.cs | 73 +- .../Storage/Fill/ToolLockerFillComponent.cs | 92 ++ .../Fill/ToolboxElectricalFillComponent.cs | 38 + .../Items/Storage/IStorageComponent.cs | 11 + .../Items/Storage/ServerStorageComponent.cs | 28 +- .../Projectile/BallisticMagazineComponent.cs | 39 +- .../BallisticMagazineWeaponComponent.cs | 34 +- .../Storage/SharedStorageComponent.cs | 30 +- Resources/Maps/stationstation.yml | 785 +----------------- Resources/Prototypes/Entities/Items.yml | 9 +- Resources/Prototypes/Entities/closet.yml | 68 +- 17 files changed, 384 insertions(+), 950 deletions(-) create mode 100644 Content.Client/GameObjects/Components/Storage/StorageVisualizer2D.cs rename Content.Server/GameObjects/Components/{ => Items/Storage}/EntityStorageComponent.cs (76%) create mode 100644 Content.Server/GameObjects/Components/Items/Storage/Fill/ToolLockerFillComponent.cs create mode 100644 Content.Server/GameObjects/Components/Items/Storage/Fill/ToolboxElectricalFillComponent.cs create mode 100644 Content.Server/GameObjects/Components/Items/Storage/IStorageComponent.cs diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index 0c937fa2d0..68385e7420 100644 --- a/Content.Client/Content.Client.csproj +++ b/Content.Client/Content.Client.csproj @@ -91,6 +91,7 @@ + diff --git a/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs b/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs index e2c9d7b021..daf6efcaf2 100644 --- a/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs +++ b/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs @@ -26,19 +26,6 @@ namespace Content.Client.GameObjects.Components.Storage private int StorageCapacityMax; private StorageWindow Window; - [ViewVariables] private string _closedState; - [ViewVariables] private string _openState; - - public bool Open - { - get => _open; - set - { - _open = value; - SetDoorSprite(_open); - } - } - public override void OnAdd() { base.OnAdd(); @@ -56,20 +43,6 @@ namespace Content.Client.GameObjects.Components.Storage public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); - - serializer.DataField(ref _closedState, "state_door_closed", null); - serializer.DataField(ref _openState, "state_door_open", null); - } - - /// - public override void HandleComponentState(ComponentState curState, ComponentState nextState) - { - base.HandleComponentState(curState, nextState); - - if (!(curState is StorageComponentState storageState)) - return; - - Open = storageState.Open; } public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null) @@ -125,27 +98,6 @@ namespace Content.Client.GameObjects.Components.Storage SendNetworkMessage(new RemoveEntityMessage(entityuid)); } - private void SetDoorSprite(bool open) - { - if(!Owner.TryGetComponent(out var spriteComp)) - return; - - if(!spriteComp.Running) - return; - - if (spriteComp.BaseRSI == null) - { - return; - } - - var baseName = spriteComp.LayerGetState(0).Name; - - var stateId = open ? _openState ?? $"{baseName}_open" : _closedState ?? $"{baseName}_door"; - - if (spriteComp.BaseRSI.TryGetState(stateId, out _)) - spriteComp.LayerSetState(1, stateId); - } - /// /// GUI class for client storage component /// diff --git a/Content.Client/GameObjects/Components/Storage/StorageVisualizer2D.cs b/Content.Client/GameObjects/Components/Storage/StorageVisualizer2D.cs new file mode 100644 index 0000000000..16269d4357 --- /dev/null +++ b/Content.Client/GameObjects/Components/Storage/StorageVisualizer2D.cs @@ -0,0 +1,47 @@ +using Content.Shared.GameObjects.Components.Storage; +using Robust.Client.GameObjects; +using Robust.Client.Interfaces.GameObjects.Components; +using Robust.Shared.Utility; +using YamlDotNet.RepresentationModel; + +namespace Content.Client.GameObjects.Components.Storage +{ + public sealed class StorageVisualizer2D : AppearanceVisualizer + { + private string _stateOpen; + private string _stateClosed; + + public override void LoadData(YamlMappingNode node) + { + base.LoadData(node); + + if (node.TryGetNode("state_open", out var child)) + { + _stateOpen = child.AsString(); + } + + if (node.TryGetNode("state_closed", out child)) + { + _stateClosed = child.AsString(); + } + } + + public override void OnChangeData(AppearanceComponent component) + { + base.OnChangeData(component); + + if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) + { + return; + } + + component.TryGetData(StorageVisuals.Open, out bool open); + sprite.LayerSetState(StorageVisualLayers.Door, open ? _stateOpen : _stateClosed); + } + } + + public enum StorageVisualLayers + { + Door + } +} diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index b08832352c..f7ebce47ec 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -72,7 +72,10 @@ - + + + + diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index a4ab7fccd8..a2ab36f3e9 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -47,6 +47,8 @@ using Content.Shared.Interfaces; using Robust.Server.Interfaces.ServerStatus; using Robust.Shared.Timing; using Content.Server.GameObjects.Components.Destructible; +using Content.Server.GameObjects.Components.Items.Storage; +using Content.Server.GameObjects.Components.Items.Storage.Fill; using Content.Server.GameObjects.Components.Movement; using Content.Server.Interfaces.Chat; using Content.Server.Interfaces.GameObjects.Components.Movement; @@ -120,8 +122,13 @@ namespace Content.Server factory.Register(); factory.Register(); + factory.RegisterReference(); factory.RegisterReference(); factory.Register(); + factory.RegisterReference(); + + factory.Register(); + factory.Register(); factory.Register(); factory.Register(); diff --git a/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs index 31594f589d..0ab01e8c81 100644 --- a/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs @@ -4,6 +4,7 @@ using Content.Server.Interfaces.GameObjects; using Content.Shared.GameObjects; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.Container; +using Robust.Server.Interfaces.GameObjects; using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; @@ -15,7 +16,7 @@ namespace Content.Server.GameObjects.Components.Interactable /// /// Component that represents a handheld lightsource which can be toggled on and off. /// - internal class HandheldLightComponent : Component, IUse, IExamine, IAttackBy + internal class HandheldLightComponent : Component, IUse, IExamine, IAttackBy, IMapInit { public const float Wattage = 10; [ViewVariables] private ContainerSlot _cellContainer; @@ -76,12 +77,6 @@ namespace Content.Server.GameObjects.Components.Interactable Owner.TryGetComponent(out _clothingComponent); _cellContainer = ContainerManagerComponent.Ensure("flashlight_cell_container", Owner, out var existed); - - if (!existed) - { - var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallHyper"); - _cellContainer.Insert(cell); - } } /// @@ -179,5 +174,15 @@ namespace Content.Server.GameObjects.Components.Interactable component.EjectCell(user); } } + + void IMapInit.MapInit() + { + if (_cellContainer.ContainedEntity != null) + { + return; + } + var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallHyper"); + _cellContainer.Insert(cell); + } } } diff --git a/Content.Server/GameObjects/Components/EntityStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs similarity index 76% rename from Content.Server/GameObjects/Components/EntityStorageComponent.cs rename to Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs index 28c22739cf..783ecdd774 100644 --- a/Content.Server/GameObjects/Components/EntityStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs @@ -8,14 +8,16 @@ using Robust.Shared.Maths; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; using System.Linq; +using Content.Server.GameObjects.Components.Items.Storage; +using Content.Shared.GameObjects.Components.Storage; +using Robust.Server.GameObjects; namespace Content.Server.GameObjects.Components { - public class EntityStorageComponent : Component, IAttackHand + public class EntityStorageComponent : Component, IAttackHand, IStorageComponent { public override string Name => "EntityStorage"; - private ServerStorageComponent StorageComponent; private int StorageCapacityMax; private bool IsCollidableWhenOpen; private Container Contents; @@ -24,14 +26,7 @@ namespace Content.Server.GameObjects.Components public override void Initialize() { base.Initialize(); - Contents = ContainerManagerComponent.Ensure($"{typeof(EntityStorageComponent).FullName}{Owner.Uid.ToString()}", Owner); - if (!Owner.TryGetComponent(out StorageComponent)) - { - StorageComponent = Owner.AddComponent(); - // TODO: This is a terrible hack. - // Components should not need to be manually initialized in Initialize(). - StorageComponent.Initialize(); - } + Contents = ContainerManagerComponent.Ensure(nameof(EntityStorageComponent), Owner); entityQuery = new IntersectingEntityQuery(Owner); } @@ -43,12 +38,8 @@ namespace Content.Server.GameObjects.Components serializer.DataField(ref IsCollidableWhenOpen, "IsCollidableWhenOpen", false); } - [ViewVariables(VVAccess.ReadWrite)] - public bool Open - { - get => StorageComponent.Open; - set => StorageComponent.Open = value; - } + [ViewVariables] + public bool Open { get; private set; } public bool AttackHand(AttackHandEventArgs eventArgs) { @@ -67,7 +58,7 @@ namespace Content.Server.GameObjects.Components { Open = false; var entities = Owner.EntityManager.GetEntities(entityQuery); - int count = 0; + var count = 0; foreach (var entity in entities) { if (!AddToContents(entity)) @@ -96,13 +87,19 @@ namespace Content.Server.GameObjects.Components { collidableComponent.CollisionEnabled = IsCollidableWhenOpen || !Open; } + if (Owner.TryGetComponent(out var placeableSurfaceComponent)) { placeableSurfaceComponent.IsPlaceable = Open; } + + if (Owner.TryGetComponent(out AppearanceComponent appearance)) + { + appearance.SetData(StorageVisuals.Open, Open); + } } - private bool AddToContents(IEntity entity) + private bool AddToContents(IEntity entity) { var collidableComponent = Owner.GetComponent(); if(entity.TryGetComponent(out var entityCollidableComponent)) @@ -140,10 +137,10 @@ namespace Content.Server.GameObjects.Components private void EmptyContents() { - while (Contents.ContainedEntities.Count > 0 ) + foreach (var contained in Contents.ContainedEntities.ToArray()) { - var containedEntity = Contents.ContainedEntities.First(); - Contents.Remove(containedEntity); + Contents.Remove(contained); + contained.Transform.WorldPosition = Owner.Transform.WorldPosition; } } @@ -154,12 +151,44 @@ namespace Content.Server.GameObjects.Components switch (message) { case RelayMovementEntityMessage msg: - if(msg.Entity.TryGetComponent(out var handsComponent)) + if (msg.Entity.HasComponent()) { OpenStorage(); } break; } } + + public bool Remove(IEntity entity) + { + return Contents.CanRemove(entity); + } + + public bool Insert(IEntity entity) + { + // Trying to add while open just dumps it on the ground below us. + if (Open) + { + entity.Transform.WorldPosition = Owner.Transform.WorldPosition; + return true; + } + + return Contents.Insert(entity); + } + + public bool CanInsert(IEntity entity) + { + if (Open) + { + return true; + } + + if (Contents.ContainedEntities.Count >= StorageCapacityMax) + { + return false; + } + + return Contents.CanInsert(entity); + } } } diff --git a/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolLockerFillComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolLockerFillComponent.cs new file mode 100644 index 0000000000..7071481fa1 --- /dev/null +++ b/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolLockerFillComponent.cs @@ -0,0 +1,92 @@ +using System; +using Robust.Server.Interfaces.GameObjects; +using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Maths; + +namespace Content.Server.GameObjects.Components.Items.Storage.Fill +{ + internal sealed class ToolLockerFillComponent : Component, IMapInit + { + public override string Name => "ToolLockerFill"; + +#pragma warning disable 649 + [Dependency] private readonly IEntityManager _entityManager; +#pragma warning restore 649 + + void IMapInit.MapInit() + { + var storage = Owner.GetComponent(); + var random = new Random(DateTime.Now.GetHashCode() ^ Owner.Uid.GetHashCode()); + + void Spawn(string prototype) + { + storage.Insert(_entityManager.SpawnEntity(prototype)); + } + + if (random.Prob(0.4f)) + { + Spawn("HazardVestClothing"); + } + + if (random.Prob(0.7f)) + { + Spawn("FlashlightLantern"); + } + + if (random.Prob(0.7f)) + { + Spawn("Screwdriver"); + } + + if (random.Prob(0.7f)) + { + Spawn("Wrench"); + } + + if (random.Prob(0.7f)) + { + Spawn("Welder"); + } + + if (random.Prob(0.7f)) + { + Spawn("Crowbar"); + } + + if (random.Prob(0.7f)) + { + Spawn("Wirecutter"); + } + + if (random.Prob(0.2f)) + { + Spawn("Multitool"); + } + + if (random.Prob(0.2f)) + { + Spawn("UtilityBeltClothing"); + } + + if (random.Prob(0.05f)) + { + Spawn("YellowGloves"); + } + + if (random.Prob(0.4f)) + { + Spawn("HelmetEngineering"); + } + + for (var i = 0; i < 3; i++) + { + if (random.Prob(0.3f)) + { + Spawn("CableStack"); + } + } + } + } +} diff --git a/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolboxElectricalFillComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolboxElectricalFillComponent.cs new file mode 100644 index 0000000000..40161e7c88 --- /dev/null +++ b/Content.Server/GameObjects/Components/Items/Storage/Fill/ToolboxElectricalFillComponent.cs @@ -0,0 +1,38 @@ +using System; +using Robust.Server.Interfaces.GameObjects; +using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Maths; + +namespace Content.Server.GameObjects.Components.Items.Storage.Fill +{ + internal sealed class ToolboxElectricalFillComponent : Component, IMapInit + { + public override string Name => "ToolboxElectricalFill"; + +#pragma warning disable 649 + [Dependency] private readonly IEntityManager _entityManager; +#pragma warning restore 649 + + void IMapInit.MapInit() + { + var storage = Owner.GetComponent(); + var random = new Random(DateTime.Now.GetHashCode() ^ Owner.Uid.GetHashCode()); + + void Spawn(string prototype) + { + storage.Insert(_entityManager.SpawnEntity(prototype)); + } + + Spawn("Screwdriver"); + Spawn("Crowbar"); + Spawn("Wirecutter"); + Spawn("CableStack"); + Spawn("CableStack"); + + // 5% chance for a pair of fancy insulated gloves, else just a third cable coil. + Spawn(random.Prob(0.05f) ? "YellowGloves" : "CableStack"); + } + } +} diff --git a/Content.Server/GameObjects/Components/Items/Storage/IStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/IStorageComponent.cs new file mode 100644 index 0000000000..b46ea0e1de --- /dev/null +++ b/Content.Server/GameObjects/Components/Items/Storage/IStorageComponent.cs @@ -0,0 +1,11 @@ +using Robust.Shared.Interfaces.GameObjects; + +namespace Content.Server.GameObjects.Components.Items.Storage +{ + public interface IStorageComponent + { + bool Remove(IEntity entity); + bool Insert(IEntity entity); + bool CanInsert(IEntity entity); + } +} diff --git a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs index 1f6e50afa5..33886c053d 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs @@ -18,6 +18,7 @@ using Robust.Shared.GameObjects.EntitySystemMessages; using Robust.Shared.Interfaces.Map; using Robust.Shared.ViewVariables; using Content.Server.GameObjects.Components; +using Content.Server.GameObjects.Components.Items.Storage; using Robust.Server.GameObjects.EntitySystemMessages; namespace Content.Server.GameObjects @@ -25,7 +26,7 @@ namespace Content.Server.GameObjects /// /// Storage component for containing entities within this one, matches a UI on the client which shows stored entities /// - public class ServerStorageComponent : SharedStorageComponent, IAttackBy, IUse, IActivate + public class ServerStorageComponent : SharedStorageComponent, IAttackBy, IUse, IActivate, IStorageComponent { #pragma warning disable 649 [Dependency] private readonly IMapManager _mapManager; @@ -40,20 +41,6 @@ namespace Content.Server.GameObjects private int StorageCapacityMax = 10000; public HashSet SubscribedSessions = new HashSet(); - [ViewVariables(VVAccess.ReadWrite)] - public bool Open - { - get => _open; - set - { - if (_open == value) - return; - - _open = value; - Dirty(); - } - } - public override void Initialize() { base.Initialize(); @@ -61,12 +48,6 @@ namespace Content.Server.GameObjects storage = ContainerManagerComponent.Ensure("storagebase", Owner); } - /// - public override ComponentState GetComponentState() - { - return new StorageComponentState(_open); - } - public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); @@ -243,7 +224,10 @@ namespace Content.Server.GameObjects private void UpdateDoorState() { - Open = SubscribedSessions.Count != 0; + if (Owner.TryGetComponent(out AppearanceComponent appearance)) + { + appearance.SetData(StorageVisuals.Open, SubscribedSessions.Count != 0); + } } public void HandlePlayerSessionChangeEvent(object obj, SessionStatusEventArgs SSEA) diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineComponent.cs index 4d7e4c07a9..4ee7e2a16a 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineComponent.cs @@ -3,31 +3,41 @@ using System.Collections.Generic; using Content.Shared.GameObjects.Components.Weapons.Ranged; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.Container; +using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile { - public class BallisticMagazineComponent : Component + public class BallisticMagazineComponent : Component, IMapInit { public override string Name => "BallisticMagazine"; // Stack of loaded bullets. + [ViewVariables] private readonly Stack _loadedBullets = new Stack(); + [ViewVariables] private string _fillType; + [ViewVariables] private Container _bulletContainer; + [ViewVariables] private AppearanceComponent _appearance; private BallisticMagazineType _magazineType; private BallisticCaliber _caliber; private int _capacity; + [ViewVariables] public BallisticMagazineType MagazineType => _magazineType; + [ViewVariables] public BallisticCaliber Caliber => _caliber; + [ViewVariables] public int Capacity => _capacity; + [ViewVariables] public int CountLoaded => _loadedBullets.Count; public event Action OnAmmoCountChanged; @@ -62,18 +72,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile { _loadedBullets.Push(entity); } - _updateAppearance(); - } - else if (_fillType != null) - { - // Load up bullets from fill. - for (var i = 0; i < Capacity; i++) - { - var bullet = Owner.EntityManager.SpawnEntity(_fillType); - AddBullet(bullet); - } } + _updateAppearance(); + OnAmmoCountChanged?.Invoke(); _appearance.SetData(BallisticMagazineVisuals.AmmoCapacity, Capacity); } @@ -113,6 +115,21 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile { _appearance.SetData(BallisticMagazineVisuals.AmmoLeft, CountLoaded); } + + void IMapInit.MapInit() + { + if (_fillType == null) + { + return; + } + + // Load up bullets from fill. + for (var i = 0; i < Capacity; i++) + { + var bullet = Owner.EntityManager.SpawnEntity(_fillType); + AddBullet(bullet); + } + } } public enum BallisticMagazineType diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs index 14b82815a2..6f577bfd8b 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs @@ -6,31 +6,43 @@ using Content.Shared.GameObjects.Components.Weapons.Ranged; using Content.Shared.Interfaces; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.Container; +using Robust.Server.Interfaces.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Maths; using Robust.Shared.Serialization; using Robust.Shared.Utility; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile { - public class BallisticMagazineWeaponComponent : BallisticWeaponComponent, IUse, IAttackBy + public class BallisticMagazineWeaponComponent : BallisticWeaponComponent, IUse, IAttackBy, IMapInit { public override string Name => "BallisticMagazineWeapon"; + [ViewVariables] private string _defaultMagazine; + [ViewVariables] private ContainerSlot _magazineSlot; private BallisticMagazineType _magazineType; + [ViewVariables] public BallisticMagazineType MagazineType => _magazineType; + [ViewVariables] private IEntity Magazine => _magazineSlot.ContainedEntity; + [ViewVariables] private Random _bulletDropRandom; + [ViewVariables] private string _magInSound; + [ViewVariables] private string _magOutSound; + [ViewVariables] private string _autoEjectSound; + [ViewVariables] private bool _autoEjectMagazine; + [ViewVariables] private AppearanceComponent _appearance; private static readonly Direction[] _randomBulletDirs = @@ -67,16 +79,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile { base.Startup(); - _magazineSlot = - ContainerManagerComponent.Ensure("ballistic_gun_magazine", Owner, - out var alreadyExisted); + _magazineSlot = ContainerManagerComponent.Ensure("ballistic_gun_magazine", Owner); - if (!alreadyExisted && _defaultMagazine != null) - { - var magazine = Owner.EntityManager.SpawnEntity(_defaultMagazine); - InsertMagazine(magazine, false); - } - else if (Magazine != null) + if (Magazine != null) { // Already got magazine from loading a container. Magazine.GetComponent().OnAmmoCountChanged += _magazineAmmoCountChanged; @@ -262,5 +267,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile component.EjectMagazine(); } } + + void IMapInit.MapInit() + { + if (_defaultMagazine != null) + { + var magazine = Owner.EntityManager.SpawnEntity(_defaultMagazine); + InsertMagazine(magazine, false); + } + } } } diff --git a/Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs b/Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs index b987fc761e..db850840a1 100644 --- a/Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs +++ b/Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs @@ -9,29 +9,6 @@ namespace Content.Shared.GameObjects.Components.Storage { public override string Name => "Storage"; public override uint? NetID => ContentNetIDs.INVENTORY; - public override Type StateType => typeof(StorageComponentState); - - protected bool _open; - - /// - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _open, "open", false); - } - } - - [Serializable, NetSerializable] - public class StorageComponentState : ComponentState - { - public bool Open { get; } - - public StorageComponentState(bool open) - : base(ContentNetIDs.INVENTORY) - { - Open = open; - } } /// @@ -92,4 +69,11 @@ namespace Content.Shared.GameObjects.Components.Storage Directed = true; } } + + [NetSerializable] + [Serializable] + public enum StorageVisuals + { + Open + } } diff --git a/Resources/Maps/stationstation.yml b/Resources/Maps/stationstation.yml index 81cf3a8cdd..69bf08f6c3 100644 --- a/Resources/Maps/stationstation.yml +++ b/Resources/Maps/stationstation.yml @@ -2,7 +2,7 @@ meta: format: 2 name: DemoStation author: Space-Wizards - postmapinit: true + postmapinit: false tilemap: 0: space 1: floor @@ -1075,12 +1075,6 @@ entities: pos: -7.5,-4.5 rot: -1.5707963267949 rad type: Transform -- type: ammo_casing_12mm - uid: 144 - components: - - parent: 379 - grid: 0 - type: Transform - type: spawn_point_latejoin uid: 145 components: @@ -1153,30 +1147,6 @@ entities: entities: [] type: Robust.Server.GameObjects.Components.Container.Container type: ContainerContainer -- type: ammo_casing_12mm - uid: 153 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 154 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 155 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 156 - components: - - parent: 380 - grid: 0 - type: Transform - type: fire_extinguisher uid: 157 components: @@ -1184,54 +1154,6 @@ entities: pos: -1.297692,-5.396082 rot: -1.5707963267949 rad type: Transform -- type: ammo_casing_12mm - uid: 158 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 159 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 160 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 161 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 162 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 163 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 164 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 165 - components: - - parent: 380 - grid: 0 - type: Transform - type: spawn_point_latejoin uid: 166 components: @@ -1246,12 +1168,6 @@ entities: pos: -5.5,-0.5 rot: -1.5707963267949 rad type: Transform -- type: ammo_casing_12mm - uid: 168 - components: - - parent: 380 - grid: 0 - type: Transform - type: poweredsmalllight uid: 169 components: @@ -1281,24 +1197,6 @@ entities: - parent: 169 grid: 0 type: Transform -- type: ammo_casing_12mm - uid: 172 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 173 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 174 - components: - - parent: 380 - grid: 0 - type: Transform - type: table uid: 175 components: @@ -1709,18 +1607,6 @@ entities: pos: -10.5,0.5 rot: -1.5707963267949 rad type: Transform -- type: ammo_casing_12mm - uid: 231 - components: - - parent: 380 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 232 - components: - - parent: 380 - grid: 0 - type: Transform - type: airlock uid: 233 components: @@ -2104,7 +1990,7 @@ entities: pos: 7.5,-7.5 rot: -1.5707963267949 rad type: Transform -- type: YellowToolboxItem +- type: YellowToolboxItemFilled uid: 278 components: - grid: 0 @@ -2116,7 +2002,7 @@ entities: entities: [] type: Robust.Server.GameObjects.Components.Container.Container type: ContainerContainer -- type: YellowToolboxItem +- type: YellowToolboxItemFilled uid: 279 components: - grid: 0 @@ -2135,18 +2021,6 @@ entities: pos: -1.934832,-5.154238 rot: -1.5707963267949 rad type: Transform - - containers: - flashlight_cell_container: - entities: - - 281 - type: Content.Server.GameObjects.ContainerSlot - type: ContainerContainer -- type: PowerCellSmallHyper - uid: 281 - components: - - parent: 280 - grid: 0 - type: Transform - type: FlashlightLantern uid: 282 components: @@ -2154,24 +2028,6 @@ entities: pos: -2.017696,-5.71715 rot: -1.5707963267949 rad type: Transform - - containers: - flashlight_cell_container: - entities: - - 283 - type: Content.Server.GameObjects.ContainerSlot - type: ContainerContainer -- type: PowerCellSmallHyper - uid: 283 - components: - - parent: 282 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 284 - components: - - parent: 380 - grid: 0 - type: Transform - type: Crowbar uid: 285 components: @@ -2231,151 +2087,6 @@ entities: pos: -6.605512,7.638151 rot: -1.5707963267949 rad type: Transform - - containers: - magazine_bullet_container: - entities: - - 292 - - 293 - - 294 - - 295 - - 296 - - 297 - - 298 - - 299 - - 300 - - 301 - - 302 - - 303 - - 304 - - 305 - - 306 - - 307 - - 308 - - 309 - - 310 - - 311 - type: Robust.Server.GameObjects.Components.Container.Container - type: ContainerContainer -- type: ammo_casing_12mm - uid: 292 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 293 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 294 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 295 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 296 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 297 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 298 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 299 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 300 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 301 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 302 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 303 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 304 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 305 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 306 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 307 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 308 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 309 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 310 - components: - - parent: 291 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 311 - components: - - parent: 291 - grid: 0 - type: Transform - type: magazine_12mm_filled uid: 312 components: @@ -2383,151 +2094,6 @@ entities: pos: -6.339887,7.669401 rot: -1.5707963267949 rad type: Transform - - containers: - magazine_bullet_container: - entities: - - 313 - - 314 - - 315 - - 316 - - 317 - - 318 - - 319 - - 320 - - 321 - - 322 - - 323 - - 324 - - 325 - - 326 - - 327 - - 328 - - 329 - - 330 - - 331 - - 332 - type: Robust.Server.GameObjects.Components.Container.Container - type: ContainerContainer -- type: ammo_casing_12mm - uid: 313 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 314 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 315 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 316 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 317 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 318 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 319 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 320 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 321 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 322 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 323 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 324 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 325 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 326 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 327 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 328 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 329 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 330 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 331 - components: - - parent: 312 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 332 - components: - - parent: 312 - grid: 0 - type: Transform - type: magazine_12mm_filled uid: 333 components: @@ -2535,151 +2101,6 @@ entities: pos: -6.027387,7.622526 rot: -1.5707963267949 rad type: Transform - - containers: - magazine_bullet_container: - entities: - - 334 - - 335 - - 336 - - 337 - - 338 - - 339 - - 340 - - 341 - - 342 - - 343 - - 344 - - 345 - - 346 - - 347 - - 348 - - 349 - - 350 - - 351 - - 352 - - 353 - type: Robust.Server.GameObjects.Components.Container.Container - type: ContainerContainer -- type: ammo_casing_12mm - uid: 334 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 335 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 336 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 337 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 338 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 339 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 340 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 341 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 342 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 343 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 344 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 345 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 346 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 347 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 348 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 349 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 350 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 351 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 352 - components: - - parent: 333 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 353 - components: - - parent: 333 - grid: 0 - type: Transform - type: BackpackClothing uid: 354 components: @@ -2718,166 +2139,6 @@ entities: pos: -2.524035,7.579326 rot: -1.5707963267949 rad type: Transform - - containers: - ballistics_chamber_0: - entities: - - 378 - type: Content.Server.GameObjects.ContainerSlot - ballistic_gun_magazine: - entities: - - 358 - type: Content.Server.GameObjects.ContainerSlot - type: ContainerContainer -- type: magazine_12mm_filled - uid: 358 - components: - - parent: 357 - grid: 0 - type: Transform - - containers: - magazine_bullet_container: - entities: - - 359 - - 360 - - 361 - - 362 - - 363 - - 364 - - 365 - - 366 - - 367 - - 368 - - 369 - - 370 - - 371 - - 372 - - 373 - - 374 - - 375 - - 376 - - 377 - type: Robust.Server.GameObjects.Components.Container.Container - type: ContainerContainer -- type: ammo_casing_12mm - uid: 359 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 360 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 361 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 362 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 363 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 364 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 365 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 366 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 367 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 368 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 369 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 370 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 371 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 372 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 373 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 374 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 375 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 376 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 377 - components: - - parent: 358 - grid: 0 - type: Transform -- type: ammo_casing_12mm - uid: 378 - components: - - parent: 357 - grid: 0 - type: Transform - type: smg_c20r uid: 379 components: @@ -2885,46 +2146,6 @@ entities: pos: -1.94591,7.485576 rot: -1.5707963267949 rad type: Transform - - containers: - ballistics_chamber_0: - entities: - - 144 - type: Content.Server.GameObjects.ContainerSlot - ballistic_gun_magazine: - entities: - - 380 - type: Content.Server.GameObjects.ContainerSlot - type: ContainerContainer -- type: magazine_12mm_filled - uid: 380 - components: - - parent: 379 - grid: 0 - type: Transform - - containers: - magazine_bullet_container: - entities: - - 231 - - 232 - - 174 - - 173 - - 172 - - 153 - - 154 - - 155 - - 156 - - 284 - - 158 - - 159 - - 160 - - 161 - - 162 - - 163 - - 164 - - 165 - - 168 - type: Robust.Server.GameObjects.Components.Container.Container - type: ContainerContainer - type: wall uid: 381 components: diff --git a/Resources/Prototypes/Entities/Items.yml b/Resources/Prototypes/Entities/Items.yml index 1ebd8abe2a..d4874e8adf 100644 --- a/Resources/Prototypes/Entities/Items.yml +++ b/Resources/Prototypes/Entities/Items.yml @@ -47,7 +47,7 @@ Size: 9999 - type: entity - name: "Electrical Toolbox With Handle" + name: Electrical Toolbox parent: BaseItem id: YellowToolboxItem description: A toolbox typically stocked with electrical gear @@ -61,6 +61,13 @@ - type: Item Size: 9999 +- type: entity + id: YellowToolboxItemFilled + name: Electrical Toolbox (Filled) + parent: YellowToolboxItem + components: + - type: ToolboxElectricalFill + - type: entity name: "Extra-Grip™ Mop" parent: BaseItem diff --git a/Resources/Prototypes/Entities/closet.yml b/Resources/Prototypes/Entities/closet.yml index ba5323d54a..4ef562074a 100644 --- a/Resources/Prototypes/Entities/closet.yml +++ b/Resources/Prototypes/Entities/closet.yml @@ -8,6 +8,7 @@ layers: - state: generic - state: generic_door + map: ["enum.StorageVisualLayers.Door"] - type: Icon sprite: Buildings/closet.rsi @@ -23,10 +24,12 @@ mass: 25 Anchored: false - type: EntityStorage - - type: Storage - state_door_open: generic_open - state_door_closed: generic_door - type: PlaceableSurface + - type: Appearance + visuals: + - type: StorageVisualizer2D + state_open: generic_open + state_closed: generic_door placement: snap: @@ -40,16 +43,26 @@ - type: Sprite sprite: Buildings/closet.rsi layers: - - state: eng - - state: eng_tool_door + - state: eng + - state: eng_tool_door + map: ["enum.StorageVisualLayers.Door"] - - type: Storage - state_door_closed: eng_tool_door - state_door_open: eng_open + - type: Appearance + visuals: + - type: StorageVisualizer2D + state_open: eng_open + state_closed: eng_tool_door - type: Icon state: eng_tool_door +- type: entity + id: locker_tool_filled + name: Tool Locker (Filled) + parent: locker_tool + components: + - type: ToolLockerFill + - type: entity id: locker_electrical_supplies name: Electrical Supplies Locker @@ -58,12 +71,15 @@ - type: Sprite sprite: Buildings/closet.rsi layers: - - state: eng - - state: eng_elec_door + - state: eng + - state: eng_elec_door + map: ["enum.StorageVisualLayers.Door"] - - type: Storage - state_door_closed: eng_elec_door - state_door_open: eng_open + - type: Appearance + visuals: + - type: StorageVisualizer2D + state_open: eng_open + state_closed: eng_elec_door - type: Icon state: eng_elec_door @@ -76,12 +92,15 @@ - type: Sprite sprite: Buildings/closet.rsi layers: - - state: eng - - state: eng_weld_door + - state: eng + - state: eng_weld_door + map: ["enum.StorageVisualLayers.Door"] - - type: Storage - state_door_closed: eng_weld_door - state_door_open: eng_open + - type: Appearance + visuals: + - type: StorageVisualizer2D + state_open: eng_open + state_closed: eng_weld_door - type: Icon state: eng_weld_door @@ -94,12 +113,15 @@ - type: Sprite sprite: Buildings/closet.rsi layers: - - state: eng - - state: eng_rad_door + - state: eng + - state: eng_rad_door + map: ["enum.StorageVisualLayers.Door"] - - type: Storage - state_door_closed: eng_rad_door - state_door_open: eng_open + - type: Appearance + visuals: + - type: StorageVisualizer2D + state_open: eng_open + state_closed: eng_rad_door - type: Icon state: eng_rad_door