- add: Time beacon. (#254)
This commit is contained in:
104
Content.Server/_White/TimeBeacon/TimeBeaconSystem.cs
Normal file
104
Content.Server/_White/TimeBeacon/TimeBeaconSystem.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Pulling;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server._White.TimeBeacon;
|
||||
|
||||
public sealed class TimeBeaconSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly AudioSystem _audio = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
[Dependency] private readonly PullingSystem _pulling = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<TimeBeaconComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<TimeBeaconComponent, ExaminedEvent>(OnExamine);
|
||||
SubscribeLocalEvent<TimeBeaconAnchorComponent, MapInitEvent>(OnMapInit);
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<TimeBeaconAnchorComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
Timer.Spawn(ent.Comp.Duration, () =>
|
||||
{
|
||||
var entity = ent.Comp.Entity;
|
||||
|
||||
if (entity == EntityUid.Invalid)
|
||||
return;
|
||||
|
||||
if (EntityManager.Deleted(ent) || EntityManager.Deleted(entity))
|
||||
return;
|
||||
|
||||
if (!TryComp(ent, out TransformComponent? xform) || !TryComp(entity, out TransformComponent? entXform))
|
||||
return;
|
||||
|
||||
if (xform.MapID != entXform.MapID)
|
||||
return;
|
||||
|
||||
// break pulls before portal enter so we dont break shit
|
||||
if (TryComp<SharedPullableComponent>(entity, out var pullable) && pullable.BeingPulled)
|
||||
{
|
||||
_pulling.TryStopPull(pullable);
|
||||
}
|
||||
|
||||
if (TryComp<SharedPullerComponent>(entity, out var pulling)
|
||||
&& pulling.Pulling != null &&
|
||||
TryComp<SharedPullableComponent>(pulling.Pulling.Value, out var subjectPulling))
|
||||
{
|
||||
_pulling.TryStopPull(subjectPulling);
|
||||
}
|
||||
|
||||
_transform.SetCoordinates(entity, entXform, xform.Coordinates);
|
||||
QueueDel(ent);
|
||||
});
|
||||
}
|
||||
|
||||
private void OnExamine(Entity<TimeBeaconComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
if (ent.Comp.NextUse <= _timing.CurTime)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("time-beacon-component-charged"));
|
||||
return;
|
||||
}
|
||||
|
||||
var message = Loc.GetString("time-beacon-component-charging",
|
||||
("cooldown", (int) (ent.Comp.NextUse - _timing.CurTime).TotalSeconds));
|
||||
args.PushMarkup(message);
|
||||
}
|
||||
|
||||
private void OnUseInHand(Entity<TimeBeaconComponent> ent, ref UseInHandEvent args)
|
||||
{
|
||||
var coords = CompOrNull<TransformComponent>(args.User)?.Coordinates;
|
||||
|
||||
if (coords == null)
|
||||
return;
|
||||
|
||||
if (ent.Comp.NextUse > _timing.CurTime)
|
||||
{
|
||||
var message = Loc.GetString("time-beacon-component-cooldown",
|
||||
("cooldown", (int) (ent.Comp.NextUse - _timing.CurTime).TotalSeconds));
|
||||
_popup.PopupEntity(message, args.User, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
var anchor = Spawn(ent.Comp.AnchorEntity, coords.Value);
|
||||
_transform.AttachToGridOrMap(anchor);
|
||||
var anchorComp = EnsureComp<TimeBeaconAnchorComponent>(anchor);
|
||||
anchorComp.Entity = args.User;
|
||||
|
||||
_popup.PopupEntity(Loc.GetString("time-beacon-component-anchor-set"), args.User, args.User, PopupType.Medium);
|
||||
_audio.PlayEntity(ent.Comp.Sound, args.User, ent);
|
||||
|
||||
ent.Comp.NextUse = _timing.CurTime + ent.Comp.Cooldown;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user