2020-06-28 09:23:26 -06:00
|
|
|
|
using Content.Shared.GameObjects.Components.Power;
|
2020-10-29 20:17:03 +02:00
|
|
|
|
using Content.Shared.GameObjects.EntitySystems;
|
2020-11-01 07:56:46 +11:00
|
|
|
|
using Content.Shared.Utility;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Server.GameObjects;
|
2019-07-31 15:02:36 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-10-29 20:17:03 +02:00
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
2018-09-21 08:21:40 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Power
|
|
|
|
|
|
{
|
2020-06-28 09:23:26 -06:00
|
|
|
|
/// <summary>
|
2020-10-29 20:17:03 +02:00
|
|
|
|
/// Batteries that can update an <see cref="AppearanceComponent"/> based on their charge percent
|
|
|
|
|
|
/// and fit into a <see cref="PowerCellSlotComponent"/> of the appropriate size.
|
2020-06-28 09:23:26 -06:00
|
|
|
|
/// </summary>
|
2019-07-31 15:02:36 +02:00
|
|
|
|
[RegisterComponent]
|
2020-06-28 09:23:26 -06:00
|
|
|
|
[ComponentReference(typeof(BatteryComponent))]
|
2020-10-29 20:17:03 +02:00
|
|
|
|
public class PowerCellComponent : BatteryComponent, IExamine
|
2018-09-21 08:21:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
public override string Name => "PowerCell";
|
|
|
|
|
|
|
2020-10-29 20:17:03 +02:00
|
|
|
|
[ViewVariables] public PowerCellSize CellSize => _cellSize;
|
|
|
|
|
|
private PowerCellSize _cellSize = PowerCellSize.Small;
|
|
|
|
|
|
|
|
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ExposeData(serializer);
|
|
|
|
|
|
serializer.DataField(ref _cellSize, "cellSize", PowerCellSize.Small);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-21 08:21:40 +02:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
2020-06-28 09:23:26 -06:00
|
|
|
|
CurrentCharge = MaxCharge;
|
|
|
|
|
|
UpdateVisuals();
|
2018-09-21 08:21:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-28 09:23:26 -06:00
|
|
|
|
protected override void OnChargeChanged()
|
2018-09-21 08:21:40 +02:00
|
|
|
|
{
|
2020-06-28 09:23:26 -06:00
|
|
|
|
base.OnChargeChanged();
|
|
|
|
|
|
UpdateVisuals();
|
2018-09-21 08:21:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-28 09:23:26 -06:00
|
|
|
|
private void UpdateVisuals()
|
2018-09-21 08:21:40 +02:00
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
|
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
|
|
|
|
|
{
|
2020-11-01 07:56:46 +11:00
|
|
|
|
appearance.SetData(PowerCellVisuals.ChargeLevel, GetLevel(CurrentCharge / MaxCharge));
|
2020-08-22 22:29:20 +02:00
|
|
|
|
}
|
2018-09-21 08:21:40 +02:00
|
|
|
|
}
|
2020-10-29 20:17:03 +02:00
|
|
|
|
|
2020-11-01 07:56:46 +11:00
|
|
|
|
private byte GetLevel(float fraction)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (byte) ContentHelpers.RoundToNearestLevels(fraction, 1, SharedPowerCell.PowerCellVisualsLevels);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-29 20:17:03 +02:00
|
|
|
|
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(inDetailsRange)
|
|
|
|
|
|
{
|
|
|
|
|
|
message.AddMarkup(Loc.GetString($"The charge indicator reads {CurrentCharge / MaxCharge * 100:F0} %."));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum PowerCellSize
|
|
|
|
|
|
{
|
|
|
|
|
|
Small,
|
|
|
|
|
|
Medium,
|
|
|
|
|
|
Large
|
2018-09-21 08:21:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|