using Content.Server.Popups;
using Content.Server.Power.EntitySystems;
using Content.Server.Xenoarchaeology.Equipment.Components;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Placeable;
using Robust.Shared.Timing;
namespace Content.Server.Xenoarchaeology.Equipment.Systems;
public sealed class TraversalDistorterSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
///
public override void Initialize()
{
SubscribeLocalEvent(OnInit);
SubscribeLocalEvent(OnExamine);
SubscribeLocalEvent(OnItemPlaced);
SubscribeLocalEvent(OnItemRemoved);
}
private void OnInit(EntityUid uid, TraversalDistorterComponent component, MapInitEvent args)
{
component.NextActivation = _timing.CurTime;
}
///
/// Switches the state of the traversal distorter between up and down.
///
/// The distorter's entity
/// The component on the entity
/// If the distorter changed state
public bool SetState(EntityUid uid, TraversalDistorterComponent component, bool isDown)
{
if (!this.IsPowered(uid, EntityManager))
return false;
if (_timing.CurTime < component.NextActivation)
return false;
component.NextActivation = _timing.CurTime + component.ActivationDelay;
component.BiasDirection = isDown ? BiasDirection.Down : BiasDirection.Up;
return true;
}
private void OnExamine(EntityUid uid, TraversalDistorterComponent component, ExaminedEvent args)
{
string examine = string.Empty;
switch (component.BiasDirection)
{
case BiasDirection.Up:
examine = Loc.GetString("traversal-distorter-desc-up");
break;
case BiasDirection.Down:
examine = Loc.GetString("traversal-distorter-desc-down");
break;
}
args.PushMarkup(examine);
}
private void OnItemPlaced(EntityUid uid, TraversalDistorterComponent component, ref ItemPlacedEvent args)
{
var bias = EnsureComp(args.OtherEntity);
bias.Provider = uid;
}
private void OnItemRemoved(EntityUid uid, TraversalDistorterComponent component, ref ItemRemovedEvent args)
{
var otherEnt = args.OtherEntity;
if (TryComp(otherEnt, out var bias) && bias.Provider == uid)
RemComp(otherEnt, bias);
}
}