Prettier window breaking (#2368)
* Put the damage in the windows * add crack overlays * Window cracking * glass related sounds * let's use a valid state * run optipng on these for posterity * Examine damage descriptions * add "Constructible" to dictionary * Downmix stereo effects to mono * breaking and knocking * Add shard etc. sprites * shard inhands * more sprite wrangling * Expand destructiblecomponent drop system + implement it for windows * Shard descriptions * Random sprite component * no nullbabby * Random destroysounds * random offset on destructible drops * fix fucked yaml * sound collections * random pitch for knocking * Localization * hascomponent * better spawnondestroy * missed one
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
@@ -7,6 +8,7 @@ using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Damage
|
||||
@@ -65,11 +67,6 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
protected override void DestructionBehavior()
|
||||
{
|
||||
_actSystem.HandleBreakage(Owner);
|
||||
if (!Owner.Deleted && DestroySound != string.Empty)
|
||||
{
|
||||
var pos = Owner.Transform.Coordinates;
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(DestroySound, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Damage
|
||||
@@ -17,6 +20,8 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
public class DestructibleComponent : RuinableComponent, IDestroyAct
|
||||
{
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
protected ActSystem ActSystem;
|
||||
|
||||
@@ -24,22 +29,51 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
public override string Name => "Destructible";
|
||||
|
||||
/// <summary>
|
||||
/// Entity spawned upon destruction.
|
||||
/// Entities spawned on destruction plus the min and max amount spawned.
|
||||
/// </summary>
|
||||
public string SpawnOnDestroy { get; private set; }
|
||||
public Dictionary<string, MinMax> SpawnOnDestroy { get; private set; }
|
||||
|
||||
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(SpawnOnDestroy) && eventArgs.IsSpawnWreck)
|
||||
if (SpawnOnDestroy == null || !eventArgs.IsSpawnWreck) return;
|
||||
foreach (var (key, value) in SpawnOnDestroy)
|
||||
{
|
||||
Owner.EntityManager.SpawnEntity(SpawnOnDestroy, Owner.Transform.Coordinates);
|
||||
int count;
|
||||
if (value.Min >= value.Max)
|
||||
{
|
||||
count = value.Min;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = _random.Next(value.Min, value.Max + 1);
|
||||
}
|
||||
|
||||
if (count == 0) continue;
|
||||
|
||||
if (EntityPrototypeHelpers.HasComponent<StackComponent>(key))
|
||||
{
|
||||
var spawned = Owner.EntityManager.SpawnEntity(key, Owner.Transform.Coordinates);
|
||||
var stack = spawned.GetComponent<StackComponent>();
|
||||
stack.Count = count;
|
||||
spawned.RandomOffset(0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var spawned = Owner.EntityManager.SpawnEntity(key, Owner.Transform.Coordinates);
|
||||
spawned.RandomOffset(0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(this, d => d.SpawnOnDestroy, "spawnOnDestroy", string.Empty);
|
||||
|
||||
|
||||
serializer.DataField(this, d => d.SpawnOnDestroy, "spawnOnDestroy", null);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@@ -56,11 +90,13 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
var pos = Owner.Transform.Coordinates;
|
||||
ActSystem.HandleDestruction(Owner,
|
||||
true); //This will call IDestroyAct.OnDestroy on this component (and all other components on this entity)
|
||||
if (DestroySound != string.Empty)
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(DestroySound, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct MinMax
|
||||
{
|
||||
public int Min;
|
||||
public int Max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Logger = Robust.Shared.Log.Logger;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Damage
|
||||
{
|
||||
@@ -16,12 +20,19 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
[ComponentReference(typeof(IDamageableComponent))]
|
||||
public abstract class RuinableComponent : DamageableComponent
|
||||
{
|
||||
[Dependency] private IRobustRandom _random = default!;
|
||||
/// <summary>
|
||||
/// Sound played upon destruction.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
protected string DestroySound { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used instead of <see cref="DestroySound"/> if specified.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
protected string DestroySoundCollection { get; private set; }
|
||||
|
||||
public override List<DamageState> SupportedDamageStates =>
|
||||
new List<DamageState> {DamageState.Alive, DamageState.Dead};
|
||||
|
||||
@@ -44,6 +55,7 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
() => Thresholds.TryGetValue(DamageState.Dead, out var value) ? value : (int?) null);
|
||||
|
||||
serializer.DataField(this, ruinable => ruinable.DestroySound, "destroySound", string.Empty);
|
||||
serializer.DataField(this, ruinable => ruinable.DestroySoundCollection, "destroySoundCollection", string.Empty);
|
||||
}
|
||||
|
||||
protected override void EnterState(DamageState state)
|
||||
@@ -65,10 +77,24 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
{
|
||||
CurrentState = DamageState.Dead;
|
||||
|
||||
if (!Owner.Deleted && DestroySound != string.Empty)
|
||||
if (!Owner.Deleted)
|
||||
{
|
||||
var pos = Owner.Transform.Coordinates;
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(DestroySound, pos);
|
||||
string sound = string.Empty;
|
||||
if (DestroySoundCollection != string.Empty)
|
||||
{
|
||||
sound = AudioHelpers.GetRandomFileFromSoundCollection(DestroySoundCollection);
|
||||
|
||||
}
|
||||
else if (DestroySound != string.Empty)
|
||||
{
|
||||
sound = DestroySound;
|
||||
}
|
||||
if (sound != string.Empty)
|
||||
{
|
||||
Logger.Debug("Playing destruction sound");
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(sound, pos, AudioHelpers.WithVariation(0.125f));
|
||||
}
|
||||
}
|
||||
|
||||
DestructionBehavior();
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class RandomSpriteStateComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
public override string Name => "RandomSpriteState";
|
||||
|
||||
private List<string> _spriteStates;
|
||||
|
||||
private int _spriteLayer;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _spriteStates, "spriteStates", null);
|
||||
serializer.DataField(ref _spriteLayer, "spriteLayer", 0);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if (_spriteStates == null) return;
|
||||
if (!Owner.TryGetComponent(out SpriteComponent spriteComponent)) return;
|
||||
spriteComponent.LayerSetState(_spriteLayer, _random.Pick(_spriteStates));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,104 @@
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using System;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedWindowComponent))]
|
||||
public class WindowComponent : SharedWindowComponent
|
||||
public class WindowComponent : SharedWindowComponent, IExamine, IInteractHand
|
||||
{
|
||||
private int? Damage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Owner.TryGetComponent(out IDamageableComponent damageableComponent)) return null;
|
||||
return damageableComponent.TotalDamage;
|
||||
}
|
||||
}
|
||||
|
||||
private int? MaxDamage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Owner.TryGetComponent(out IDamageableComponent damageableComponent)) return null;
|
||||
return damageableComponent.Thresholds[DamageState.Dead];
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if (Owner.TryGetComponent(out IDamageableComponent damageableComponent))
|
||||
{
|
||||
damageableComponent.HealthChangedEvent += OnDamage;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDamage(HealthChangedEventArgs eventArgs)
|
||||
{
|
||||
int current = eventArgs.Damageable.TotalDamage;
|
||||
int max = eventArgs.Damageable.Thresholds[DamageState.Dead];
|
||||
if (eventArgs.Damageable.CurrentState == DamageState.Dead) return;
|
||||
UpdateVisuals(current, max);
|
||||
}
|
||||
|
||||
private void UpdateVisuals(int currentDamage, int maxDamage)
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
appearance.SetData(WindowVisuals.Damage, (float) currentDamage / maxDamage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
int? damage = Damage;
|
||||
int? maxDamage = MaxDamage;
|
||||
if (damage == null || maxDamage == null) return;
|
||||
float fraction = ((damage == 0 || maxDamage == 0) ? 0f : (float) damage / maxDamage) ?? 0f;
|
||||
int level = Math.Min(ContentHelpers.RoundToLevels(fraction, 1, 7), 5);
|
||||
switch (level)
|
||||
{
|
||||
case 0:
|
||||
message.AddText(Loc.GetString("It looks fully intact."));
|
||||
break;
|
||||
case 1:
|
||||
message.AddText(Loc.GetString("It has a few scratches."));
|
||||
break;
|
||||
case 2:
|
||||
message.AddText(Loc.GetString("It has a few small cracks."));
|
||||
break;
|
||||
case 3:
|
||||
message.AddText(Loc.GetString("It has several big cracks running along its surface."));
|
||||
break;
|
||||
case 4:
|
||||
message.AddText(Loc.GetString("It has deep cracks across multiple layers."));
|
||||
break;
|
||||
case 5:
|
||||
message.AddText(Loc.GetString("It is extremely badly cracked and on the verge of shattering."));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>()
|
||||
.PlayAtCoords("/Audio/Effects/glass_knock.ogg", eventArgs.Target.Transform.Coordinates, AudioHelpers.WithVariation(0.05f));
|
||||
eventArgs.Target.PopupMessageEveryone(Loc.GetString("*knock knock*"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user