Make holofans use power cells (#8813)
This commit is contained in:
@@ -6,28 +6,14 @@ 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.
|
||||
/// How much charge a single use expends.
|
||||
/// </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);
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("chargeUse")]
|
||||
public float ChargeUse = 50f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Server.Coordinates.Helpers;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.PowerCell;
|
||||
using Content.Shared.PowerCell.Components;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Holosign
|
||||
{
|
||||
public sealed class HolosignSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly PowerCellSystem _cellSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -16,42 +19,51 @@ namespace Content.Server.Holosign
|
||||
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);
|
||||
_cellSystem.TryGetBatteryFromSlot(uid, out var battery);
|
||||
var charges = UsesRemaining(component, battery);
|
||||
var maxCharges = MaxUses(component, battery);
|
||||
|
||||
args.PushMarkup(Loc.GetString("emag-charges-remaining", ("charges", charges)));
|
||||
if (charges == component.MaxCharges)
|
||||
|
||||
if (charges > 0 && charges == 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)
|
||||
if (args.Handled ||
|
||||
!_cellSystem.TryGetBatteryFromSlot(uid, out var battery) ||
|
||||
!battery.TryUseCharge(component.ChargeUse))
|
||||
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;
|
||||
}
|
||||
|
||||
private int UsesRemaining(HolosignProjectorComponent component, BatteryComponent? battery = null)
|
||||
{
|
||||
if (battery == null ||
|
||||
component.ChargeUse == 0f) return 0;
|
||||
|
||||
return (int) (battery.CurrentCharge / component.ChargeUse);
|
||||
}
|
||||
|
||||
private int MaxUses(HolosignProjectorComponent component, BatteryComponent? battery = null)
|
||||
{
|
||||
if (battery == null ||
|
||||
component.ChargeUse == 0f) return 0;
|
||||
|
||||
return (int) (battery.MaxCharge / component.ChargeUse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,16 @@
|
||||
description: A handy-dandy holographic projector that displays a janitorial sign.
|
||||
components:
|
||||
- type: HolosignProjector
|
||||
- type: ItemCooldown
|
||||
- type: UseDelay
|
||||
delay: 1.0
|
||||
- type: PowerCellSlot
|
||||
cellSlot:
|
||||
startingItem: PowerCellSmallHigh
|
||||
- type: Sprite
|
||||
sprite: Objects/Devices/Holoprojectors/custodial.rsi
|
||||
state: icon
|
||||
netsync: false
|
||||
|
||||
- type: entity
|
||||
parent: Holoprojector
|
||||
@@ -17,7 +24,8 @@
|
||||
components:
|
||||
- type: HolosignProjector
|
||||
signProto: HoloFan
|
||||
rechargeTime: 120
|
||||
chargeUse: 120
|
||||
- type: Sprite
|
||||
sprite: Objects/Devices/Holoprojectors/atmos.rsi
|
||||
state: icon
|
||||
netsync: false
|
||||
|
||||
Reference in New Issue
Block a user