Holofan Projector Upstream from Nyano (#8352)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Emisse
2022-06-03 05:58:18 -06:00
committed by GitHub
parent 9c6b55c0e7
commit c87f4ab65c
14 changed files with 252 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Holosign
{
[RegisterComponent]
public sealed class HolosignProjectorComponent : Component
{
[ViewVariables]
[DataField("maxCharges")]
public int MaxCharges = 6;
[ViewVariables(VVAccess.ReadWrite), DataField("charges")]
public int CurrentCharges = 6;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("signProto", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
public string SignProto = "HolosignWetFloor";
/// <summary>
/// When the holosign was last used.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("lastUse")]
public TimeSpan LastUsed = TimeSpan.Zero;
/// <summary>
/// How long it takes for 1 charge to accumulate.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("rechargeTime")]
public TimeSpan RechargeTime = TimeSpan.FromSeconds(30);
}
}

View File

@@ -0,0 +1,57 @@
using Content.Shared.Interaction.Events;
using Content.Shared.Examine;
using Content.Server.Coordinates.Helpers;
using Robust.Shared.Timing;
namespace Content.Server.Holosign
{
public sealed class HolosignSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HolosignProjectorComponent, UseInHandEvent>(OnUse);
SubscribeLocalEvent<HolosignProjectorComponent, ExaminedEvent>(OnExamine);
}
private int GetCharges(HolosignProjectorComponent component)
{
return component.CurrentCharges + (int) ((_timing.CurTime - component.LastUsed).TotalSeconds / component.RechargeTime.TotalSeconds);
}
private void OnExamine(EntityUid uid, HolosignProjectorComponent component, ExaminedEvent args)
{
// TODO: This should probably be using an itemstatus
// TODO: I'm too lazy to do this rn but it's literally copy-paste from emag.
var timeRemaining = (component.LastUsed + component.RechargeTime * (component.MaxCharges - component.CurrentCharges) - _timing.CurTime).TotalSeconds % component.RechargeTime.TotalSeconds;
var charges = GetCharges(component);
args.PushMarkup(Loc.GetString("emag-charges-remaining", ("charges", charges)));
if (charges == component.MaxCharges)
{
args.PushMarkup(Loc.GetString("emag-max-charges"));
return;
}
args.PushMarkup(Loc.GetString("emag-recharging", ("seconds", Math.Round(timeRemaining))));
}
private void OnUse(EntityUid uid, HolosignProjectorComponent component, UseInHandEvent args)
{
if (component.CurrentCharges == 0 || args.Handled)
return;
// TODO: Too tired to deal
var holo = EntityManager.SpawnEntity(component.SignProto, Transform(args.User).Coordinates.SnapToGrid(EntityManager));
Transform(holo).Anchored = true;
// Don't reset last use time if it's already accumulating.
if (component.CurrentCharges == component.MaxCharges)
component.LastUsed = _timing.CurTime;
component.CurrentCharges--;
args.Handled = true;
}
}
}