2020-08-14 06:52:17 +10:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Radiation;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2020-08-14 06:52:17 +10:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2020-08-14 06:52:17 +10:00
|
|
|
using Robust.Shared.Random;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-03-16 15:50:20 +01:00
|
|
|
using Robust.Shared.Timing;
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Radiation
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2020-09-21 01:49:40 +02:00
|
|
|
[ComponentReference(typeof(SharedRadiationPulseComponent))]
|
2020-08-14 06:52:17 +10:00
|
|
|
public sealed class RadiationPulseComponent : SharedRadiationPulseComponent
|
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
2020-09-02 01:30:03 +02:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
|
2020-09-21 01:49:40 +02:00
|
|
|
private float _duration;
|
2021-03-05 01:08:38 +01:00
|
|
|
private float _range = 5f;
|
2021-12-01 20:21:17 +00:00
|
|
|
private TimeSpan _startTime;
|
2020-09-21 01:49:40 +02:00
|
|
|
private TimeSpan _endTime;
|
2021-03-05 01:08:38 +01:00
|
|
|
private bool _draw = true;
|
|
|
|
|
private bool _decay = true;
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2020-09-21 01:49:40 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the entity will delete itself after a certain duration defined by
|
|
|
|
|
/// <see cref="MinPulseLifespan"/> and <see cref="MaxPulseLifespan"/>
|
|
|
|
|
/// </summary>
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("decay")]
|
2020-09-21 01:49:40 +02:00
|
|
|
public override bool Decay
|
|
|
|
|
{
|
|
|
|
|
get => _decay;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_decay = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-02 01:30:03 +02:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("minPulseLifespan")]
|
|
|
|
|
public float MinPulseLifespan { get; set; } = 0.8f;
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("maxPulseLifespan")]
|
|
|
|
|
public float MaxPulseLifespan { get; set; } = 2.5f;
|
2020-09-21 01:49:40 +02:00
|
|
|
|
2021-12-01 20:21:17 +00:00
|
|
|
[DataField("sound")] public SoundSpecifier Sound { get; set; } = new SoundCollectionSpecifier("RadiationPulse");
|
2020-09-21 01:49:40 +02:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("range")]
|
2020-09-21 01:49:40 +02:00
|
|
|
public override float Range
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
2020-09-21 01:49:40 +02:00
|
|
|
get => _range;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_range = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("draw")]
|
2020-09-21 01:49:40 +02:00
|
|
|
public override bool Draw
|
|
|
|
|
{
|
|
|
|
|
get => _draw;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_draw = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-14 06:52:17 +10:00
|
|
|
|
2021-12-01 20:21:17 +00:00
|
|
|
public override TimeSpan StartTime => _startTime;
|
2020-09-21 01:49:40 +02:00
|
|
|
public override TimeSpan EndTime => _endTime;
|
2020-09-02 01:30:03 +02:00
|
|
|
|
2020-09-21 01:49:40 +02:00
|
|
|
public void DoPulse()
|
|
|
|
|
{
|
|
|
|
|
if (Decay)
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
2020-09-21 01:49:40 +02:00
|
|
|
var currentTime = _gameTiming.CurTime;
|
2021-12-01 20:21:17 +00:00
|
|
|
_startTime = currentTime;
|
2020-09-21 01:49:40 +02:00
|
|
|
_duration = _random.NextFloat() * (MaxPulseLifespan - MinPulseLifespan) + MinPulseLifespan;
|
|
|
|
|
_endTime = currentTime + TimeSpan.FromSeconds(_duration);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 23:36:57 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), Sound.GetSound(), Owner);
|
2020-08-14 06:52:17 +10:00
|
|
|
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2020-08-14 06:52:17 +10:00
|
|
|
{
|
2022-01-10 22:30:17 -08:00
|
|
|
return new RadiationPulseState(_range, Draw, Decay, _startTime, _endTime);
|
2020-09-21 01:49:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(float frameTime)
|
|
|
|
|
{
|
2021-12-09 12:29:27 +01:00
|
|
|
if (!Decay || _entMan.Deleted(Owner))
|
2020-09-21 01:49:40 +02:00
|
|
|
return;
|
|
|
|
|
|
2021-07-31 19:52:33 +02:00
|
|
|
if (_duration <= 0f)
|
2021-12-08 17:32:32 +01:00
|
|
|
_entMan.QueueDeleteEntity(Owner);
|
2020-09-21 01:49:40 +02:00
|
|
|
|
|
|
|
|
_duration -= frameTime;
|
2020-08-14 06:52:17 +10:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-02 01:30:03 +02:00
|
|
|
}
|