From 292a61814129f6ba6c0cfdac0f63d5b70f1b0491 Mon Sep 17 00:00:00 2001 From: Alex Evgrashin Date: Tue, 16 Feb 2021 11:40:43 +0300 Subject: [PATCH] Breakable light (#3237) --- .../Behaviors/EmptyAllContainersBehaviour.cs | 30 +++++++++++++ .../PowerReceiverUsers/LightBulbComponent.cs | 15 ++++--- .../PoweredLightComponent.cs | 16 +++++++ .../Entities/Constructible/Walls/lighting.yml | 45 ++++++++++--------- 4 files changed, 79 insertions(+), 27 deletions(-) create mode 100644 Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs new file mode 100644 index 0000000000..30b295862c --- /dev/null +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs @@ -0,0 +1,30 @@ +#nullable enable +using Content.Server.GameObjects.EntitySystems; +using Robust.Server.GameObjects; +using Robust.Shared.Containers; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization; + + +namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors +{ + /// + /// Drop all items from all containers + /// + public class EmptyAllContainersBehaviour : IThresholdBehavior + { + void IExposeData.ExposeData(ObjectSerializer serializer) { } + + public void Execute(IEntity owner, DestructibleSystem system) + { + if (owner.Deleted || !owner.TryGetComponent(out var containerManager)) + return; + + foreach (var container in containerManager.GetAllContainers()) + { + container.EmptyContainer(true, owner.Transform.Coordinates); + } + } + + } +} diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/LightBulbComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/LightBulbComponent.cs index 53f5a34ed5..e09700dbf5 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/LightBulbComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/LightBulbComponent.cs @@ -120,12 +120,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece void ILand.Land(LandEventArgs eventArgs) { - - var soundCollection = _prototypeManager.Index("GlassBreak"); - var file = _random.Pick(soundCollection.PickFiles); - - EntitySystem.Get().PlayFromEntity(file, Owner); - + PlayBreakSound(); State = LightBulbState.Broken; } @@ -133,5 +128,13 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece { State = LightBulbState.Broken; } + + public void PlayBreakSound() + { + var soundCollection = _prototypeManager.Index("GlassBreak"); + var file = _random.Pick(soundCollection.PickFiles); + + EntitySystem.Get().PlayFromEntity(file, Owner); + } } } diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs index f469c9c834..5faa922a0d 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs @@ -221,9 +221,25 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece case PowerChangedMessage: UpdateLight(); break; + case DamageChangedMessage msg: + TryDestroyBulb(msg); + break; } } + private void TryDestroyBulb(DamageChangedMessage msg) + { + if (!msg.TookDamage) + return; + + if (LightBulb == null || LightBulb.State == LightBulbState.Broken) + return; + + LightBulb.State = LightBulbState.Broken; + LightBulb.PlayBreakSound(); + UpdateLight(); + } + void IMapInit.MapInit() { if (_hasLampOnSpawn) diff --git a/Resources/Prototypes/Entities/Constructible/Walls/lighting.yml b/Resources/Prototypes/Entities/Constructible/Walls/lighting.yml index 2d782dc299..b910ba4803 100644 --- a/Resources/Prototypes/Entities/Constructible/Walls/lighting.yml +++ b/Resources/Prototypes/Entities/Constructible/Walls/lighting.yml @@ -22,6 +22,22 @@ offset: "0.5, 0" color: "#DCDCC6" - type: SignalReceiver + - type: Damageable + resistances: metallicResistances + - type: Destructible + thresholds: + - trigger: + !type:DamageTrigger + damage: 50 + behaviors: + - !type:EmptyAllContainersBehaviour + - !type:SpawnEntitiesBehavior + spawn: + SteelSheet1: + min: 2 + max: 2 + - !type:DoActsBehavior + acts: ["Destruction"] placement: snap: - Wallmount @@ -39,16 +55,6 @@ - type: PoweredLight bulb: Tube - type: PowerReceiver - - type: Damageable - resistances: metallicResistances - - type: Destructible - thresholds: - - trigger: - !type:DamageTrigger - damage: 50 - behaviors: - - !type:DoActsBehavior - acts: ["Destruction"] - type: entity id: PoweredlightEmpty @@ -72,14 +78,21 @@ energy: 1.0 enabled: true offset: "0.5, 0" + - type: Damageable - type: Destructible thresholds: - trigger: !type:DamageTrigger damage: 25 behaviors: + - !type:EmptyAllContainersBehaviour + - !type:SpawnEntitiesBehavior + spawn: + SteelSheet1: + min: 1 + max: 1 - !type:DoActsBehavior - acts: [ "Destruction" ] + acts: ["Destruction"] - type: Construction graph: lightFixture node: bulbLight @@ -104,16 +117,6 @@ - type: PoweredLight bulb: Bulb - type: PowerReceiver - - type: Damageable - resistances: metallicResistances - - type: Destructible - thresholds: - - trigger: - !type:DamageTrigger - damage: 25 - behaviors: - - !type:DoActsBehavior - acts: ["Destruction"] - type: entity id: PoweredSmallLightEmpty