2020-12-07 14:52:55 +01:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Destructible;
|
|
|
|
|
using Content.Server.Destructible.Thresholds.Triggers;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Server.Popups;
|
2020-10-29 21:42:11 +02:00
|
|
|
using Content.Shared.Audio;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Damage;
|
|
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Rounding;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Window;
|
2020-10-29 21:42:11 +02:00
|
|
|
using Robust.Server.GameObjects;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2020-10-08 17:41:23 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-02-16 02:56:46 +01:00
|
|
|
using Robust.Shared.IoC;
|
2020-10-29 21:42:11 +02:00
|
|
|
using Robust.Shared.Localization;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Robust.Shared.Timing;
|
2020-10-29 21:42:11 +02:00
|
|
|
using Robust.Shared.Utility;
|
2021-02-16 02:56:46 +01:00
|
|
|
using Robust.Shared.ViewVariables;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Window
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(SharedWindowComponent))]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2020-10-29 21:42:11 +02:00
|
|
|
public class WindowComponent : SharedWindowComponent, IExamine, IInteractHand
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
2021-02-16 02:56:46 +01:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] private TimeSpan _lastKnockTime;
|
|
|
|
|
|
2021-07-31 19:52:33 +02:00
|
|
|
[DataField("knockDelay")]
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
private TimeSpan _knockDelay = TimeSpan.FromSeconds(0.5);
|
2021-02-16 02:56:46 +01:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("rateLimitedKnocking")]
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] private bool _rateLimitedKnocking = true;
|
2021-02-16 02:56:46 +01:00
|
|
|
|
2021-07-10 17:35:33 +02:00
|
|
|
[DataField("knockSound")]
|
|
|
|
|
private SoundSpecifier _knockSound = new SoundPathSpecifier("/Audio/Effects/glass_knock.ogg");
|
|
|
|
|
|
2020-10-29 21:42:11 +02:00
|
|
|
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
|
|
|
|
{
|
2021-09-15 03:07:37 +10:00
|
|
|
if (!Owner.TryGetComponent(out DamageableComponent? damageable) ||
|
2021-02-05 13:41:05 +01:00
|
|
|
!Owner.TryGetComponent(out DestructibleComponent? destructible))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var damage = damageable.TotalDamage;
|
2021-02-09 12:57:21 +01:00
|
|
|
DamageTrigger? trigger = null;
|
2021-02-05 13:41:05 +01:00
|
|
|
|
|
|
|
|
// TODO: Pretend this does not exist until https://github.com/space-wizards/space-station-14/pull/2783 is merged
|
|
|
|
|
foreach (var threshold in destructible.Thresholds)
|
|
|
|
|
{
|
2021-02-09 12:57:21 +01:00
|
|
|
if ((trigger = threshold.Trigger as DamageTrigger) != null)
|
2021-02-05 13:41:05 +01:00
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trigger == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var damageThreshold = trigger.Damage;
|
|
|
|
|
var fraction = damage == 0 || damageThreshold == 0
|
2020-12-07 14:52:55 +01:00
|
|
|
? 0f
|
2021-02-05 13:41:05 +01:00
|
|
|
: (float) damage / damageThreshold;
|
2021-02-01 11:22:50 -05:00
|
|
|
var level = Math.Min(ContentHelpers.RoundToLevels((double) fraction, 1, 7), 5);
|
2021-02-05 13:41:05 +01:00
|
|
|
|
2020-10-29 21:42:11 +02:00
|
|
|
switch (level)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2021-02-26 05:19:12 -04:00
|
|
|
message.AddText(Loc.GetString("comp-window-damaged-1"));
|
2020-10-29 21:42:11 +02:00
|
|
|
break;
|
|
|
|
|
case 1:
|
2021-02-26 05:19:12 -04:00
|
|
|
message.AddText(Loc.GetString("comp-window-damaged-2"));
|
2020-10-29 21:42:11 +02:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2021-02-26 05:19:12 -04:00
|
|
|
message.AddText(Loc.GetString("comp-window-damaged-3"));
|
2020-10-29 21:42:11 +02:00
|
|
|
break;
|
|
|
|
|
case 3:
|
2021-02-26 05:19:12 -04:00
|
|
|
message.AddText(Loc.GetString("comp-window-damaged-4"));
|
2020-10-29 21:42:11 +02:00
|
|
|
break;
|
|
|
|
|
case 4:
|
2021-02-26 05:19:12 -04:00
|
|
|
message.AddText(Loc.GetString("comp-window-damaged-5"));
|
2020-10-29 21:42:11 +02:00
|
|
|
break;
|
|
|
|
|
case 5:
|
2021-02-26 05:19:12 -04:00
|
|
|
message.AddText(Loc.GetString("comp-window-damaged-6"));
|
2020-10-29 21:42:11 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
|
|
|
|
{
|
2021-02-16 02:56:46 +01:00
|
|
|
if (_rateLimitedKnocking && _gameTiming.CurTime < _lastKnockTime + _knockDelay)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(
|
|
|
|
|
Filter.Pvs(eventArgs.Target), _knockSound.GetSound(),
|
|
|
|
|
eventArgs.Target.Transform.Coordinates, AudioHelpers.WithVariation(0.05f));
|
2021-02-26 05:19:12 -04:00
|
|
|
eventArgs.Target.PopupMessageEveryone(Loc.GetString("comp-window-knock"));
|
2021-02-16 02:56:46 +01:00
|
|
|
|
|
|
|
|
_lastKnockTime = _gameTiming.CurTime;
|
|
|
|
|
|
2020-10-29 21:42:11 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-10-08 17:41:23 +02:00
|
|
|
}
|
|
|
|
|
}
|