Breakable light (#3237)

This commit is contained in:
Alex Evgrashin
2021-02-16 11:40:43 +03:00
committed by GitHub
parent 1e0da06488
commit 292a618141
4 changed files with 79 additions and 27 deletions

View File

@@ -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
{
/// <summary>
/// Drop all items from all containers
/// </summary>
public class EmptyAllContainersBehaviour : IThresholdBehavior
{
void IExposeData.ExposeData(ObjectSerializer serializer) { }
public void Execute(IEntity owner, DestructibleSystem system)
{
if (owner.Deleted || !owner.TryGetComponent<ContainerManagerComponent>(out var containerManager))
return;
foreach (var container in containerManager.GetAllContainers())
{
container.EmptyContainer(true, owner.Transform.Coordinates);
}
}
}
}

View File

@@ -120,12 +120,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
void ILand.Land(LandEventArgs eventArgs) void ILand.Land(LandEventArgs eventArgs)
{ {
PlayBreakSound();
var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>("GlassBreak");
var file = _random.Pick(soundCollection.PickFiles);
EntitySystem.Get<AudioSystem>().PlayFromEntity(file, Owner);
State = LightBulbState.Broken; State = LightBulbState.Broken;
} }
@@ -133,5 +128,13 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
{ {
State = LightBulbState.Broken; State = LightBulbState.Broken;
} }
public void PlayBreakSound()
{
var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>("GlassBreak");
var file = _random.Pick(soundCollection.PickFiles);
EntitySystem.Get<AudioSystem>().PlayFromEntity(file, Owner);
}
} }
} }

View File

@@ -221,9 +221,25 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
case PowerChangedMessage: case PowerChangedMessage:
UpdateLight(); UpdateLight();
break; 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() void IMapInit.MapInit()
{ {
if (_hasLampOnSpawn) if (_hasLampOnSpawn)

View File

@@ -22,6 +22,22 @@
offset: "0.5, 0" offset: "0.5, 0"
color: "#DCDCC6" color: "#DCDCC6"
- type: SignalReceiver - 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: placement:
snap: snap:
- Wallmount - Wallmount
@@ -39,16 +55,6 @@
- type: PoweredLight - type: PoweredLight
bulb: Tube bulb: Tube
- type: PowerReceiver - type: PowerReceiver
- type: Damageable
resistances: metallicResistances
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 50
behaviors:
- !type:DoActsBehavior
acts: ["Destruction"]
- type: entity - type: entity
id: PoweredlightEmpty id: PoweredlightEmpty
@@ -72,14 +78,21 @@
energy: 1.0 energy: 1.0
enabled: true enabled: true
offset: "0.5, 0" offset: "0.5, 0"
- type: Damageable
- type: Destructible - type: Destructible
thresholds: thresholds:
- trigger: - trigger:
!type:DamageTrigger !type:DamageTrigger
damage: 25 damage: 25
behaviors: behaviors:
- !type:EmptyAllContainersBehaviour
- !type:SpawnEntitiesBehavior
spawn:
SteelSheet1:
min: 1
max: 1
- !type:DoActsBehavior - !type:DoActsBehavior
acts: [ "Destruction" ] acts: ["Destruction"]
- type: Construction - type: Construction
graph: lightFixture graph: lightFixture
node: bulbLight node: bulbLight
@@ -104,16 +117,6 @@
- type: PoweredLight - type: PoweredLight
bulb: Bulb bulb: Bulb
- type: PowerReceiver - type: PowerReceiver
- type: Damageable
resistances: metallicResistances
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 25
behaviors:
- !type:DoActsBehavior
acts: ["Destruction"]
- type: entity - type: entity
id: PoweredSmallLightEmpty id: PoweredSmallLightEmpty