using Content.Shared._NF.Skrungler.Components;
using Content.Shared.Audio;
using Content.Shared.Construction.Components;
using Content.Shared.Examine;
using Content.Shared.Jittering;
using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
namespace Content.Shared._NF.Skrungler;
///
/// Lets you turn other mobs into plasma fuel.
///
///
public abstract class SharedSkrunglerSystem : EntitySystem
{
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedJitteringSystem _jittering = default!;
///
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnExamined);
SubscribeLocalEvent(OnUnanchorAttempt);
SubscribeLocalEvent(OnStorageOpenAttempt);
}
private void OnExamined(Entity ent, ref ExaminedEvent args)
{
if (!TryComp(ent, out var appearance))
return;
using (args.PushGroup(nameof(SkrunglerComponent)))
{
if (_appearance.TryGetData(ent, SkrunglerVisuals.Skrungling, out var isSkrungling, appearance) &&
isSkrungling)
{
args.PushMarkup(Loc.GetString("skrungler-entity-storage-component-on-examine-details-is-running",
("owner", ent)));
}
if (_appearance.TryGetData(ent, StorageVisuals.HasContents, out var hasContents, appearance) &&
hasContents)
{
args.PushMarkup(Loc.GetString("skrungler-entity-storage-component-on-examine-details-has-contents"));
}
else
{
args.PushMarkup(Loc.GetString("skrungler-entity-storage-component-on-examine-details-empty"));
}
}
}
private void OnStorageOpenAttempt(Entity ent, ref StorageOpenAttemptEvent args)
{
if (ent.Comp.Active)
args.Cancelled = true;
}
private void OnUnanchorAttempt(Entity ent, ref UnanchorAttemptEvent args)
{
if (ent.Comp.Active)
args.Cancel();
}
protected virtual void StartProcessing(EntityUid uid, Entity skrungler)
{
if (!TryComp(uid, out PhysicsComponent? physics))
return;
var curTime = Timing.CurTime;
var expectedYield = physics.FixturesMass * skrungler.Comp.YieldPerUnitMass;
skrungler.Comp.CurrentExpectedYield += expectedYield;
skrungler.Comp.FinishProcessingTime = curTime + physics.FixturesMass * skrungler.Comp.ProcessingTimePerUnitMass;
skrungler.Comp.Active = true;
skrungler.Comp.NextMessTime = curTime + skrungler.Comp.MessInterval;
Dirty(skrungler);
StartProcessingVisuals(skrungler);
QueueDel(uid);
}
private void StartProcessingVisuals(Entity ent)
{
_appearance.SetData(ent, SkrunglerVisuals.SkrunglingBase, true);
_appearance.SetData(ent, SkrunglerVisuals.Skrungling, true);
_jittering.AddJitter(ent, -85, 0); // High frequency, low amplitude jitter.
_audio.PlayPvs(ent.Comp.SkrungStartSound, ent);
_audio.PlayPvs(ent.Comp.SkrunglerSound, ent);
_ambientSound.SetAmbience(ent, true);
}
protected void EndProcessingVisuals(Entity ent)
{
_appearance.SetData(ent, SkrunglerVisuals.SkrunglingBase, false);
_appearance.SetData(ent, SkrunglerVisuals.Skrungling, false);
RemCompDeferred(ent);
_audio.PlayPvs(ent.Comp.SkrungFinishSound, ent);
_ambientSound.SetAmbience(ent, false);
}
}