Files
crystall-punk-14/Content.Server/Weapon/WeaponCapacitorChargerComponent.cs

50 lines
1.6 KiB
C#
Raw Normal View History

using Content.Server.Power.Components;
2021-06-09 22:19:39 +02:00
using Content.Server.PowerCell.Components;
using Content.Server.Weapon.Ranged.Barrels.Components;
using Content.Shared.Interaction;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Weapon
{
/// <summary>
/// Recharges the battery in a <see cref="ServerBatteryBarrelComponent"/>.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(BaseCharger))]
public sealed class WeaponCapacitorChargerComponent : BaseCharger
{
2021-12-08 17:32:32 +01:00
[Dependency] private readonly IEntityManager _entMan = default!;
public override string Name => "WeaponCapacitorCharger";
2021-12-05 18:09:01 +01:00
public override bool IsEntityCompatible(EntityUid entity)
{
2021-12-08 17:32:32 +01:00
return _entMan.TryGetComponent(entity, out ServerBatteryBarrelComponent? battery) && battery.PowerCell != null ||
_entMan.TryGetComponent(entity, out PowerCellSlotComponent? slot) && slot.HasCell;
}
2021-12-05 18:09:01 +01:00
protected override BatteryComponent? GetBatteryFrom(EntityUid entity)
{
2021-12-08 17:32:32 +01:00
if (_entMan.TryGetComponent(entity, out PowerCellSlotComponent? slot))
{
if (slot.Cell != null)
{
return slot.Cell;
}
}
2021-12-08 17:32:32 +01:00
if (_entMan.TryGetComponent(entity, out ServerBatteryBarrelComponent? battery))
{
if (battery.PowerCell != null)
{
return battery.PowerCell;
}
}
return null;
}
}
}