constructable rechargers (#16367)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Content.Shared.Power;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Power.Components
|
||||
{
|
||||
@@ -8,8 +10,32 @@ namespace Content.Server.Power.Components
|
||||
[ViewVariables]
|
||||
public CellChargerStatus Status;
|
||||
|
||||
/// <summary>
|
||||
/// The charge rate of the charger, in watts
|
||||
/// </summary>
|
||||
|
||||
[DataField("chargeRate")]
|
||||
public int ChargeRate = 20;
|
||||
public float ChargeRate = 20.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The charge rate with no machine upgrades
|
||||
/// </summary>
|
||||
|
||||
[DataField("baseChargeRate")]
|
||||
public float BaseChargeRate = 20.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The machine part that affects the charge rate multiplier of the charger
|
||||
/// </summary>
|
||||
[DataField("machinePartChargeRateModifier", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
|
||||
public string MachinePartChargeRateModifier = "Capacitor";
|
||||
|
||||
/// <summary>
|
||||
/// A value used to scale the charge rate multiplier
|
||||
/// with the corresponding part rating.
|
||||
/// </summary>
|
||||
[DataField("partRatingChargeRateModifier")]
|
||||
public float PartRatingChargeRateModifier = 1.5f;
|
||||
|
||||
[DataField("slotId", required: true)]
|
||||
public string SlotId = string.Empty;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using Content.Server.Construction;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.PowerCell;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Power;
|
||||
using Content.Shared.PowerCell.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Content.Shared.Power;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Server.Power.EntitySystems;
|
||||
@@ -20,6 +21,8 @@ internal sealed class ChargerSystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<ChargerComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<ChargerComponent, RefreshPartsEvent>(OnRefreshParts);
|
||||
SubscribeLocalEvent<ChargerComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
||||
SubscribeLocalEvent<ChargerComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<ChargerComponent, EntInsertedIntoContainerMessage>(OnInserted);
|
||||
SubscribeLocalEvent<ChargerComponent, EntRemovedFromContainerMessage>(OnRemoved);
|
||||
@@ -51,6 +54,17 @@ internal sealed class ChargerSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRefreshParts(EntityUid uid, ChargerComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var modifierRating = args.PartRatings[component.MachinePartChargeRateModifier];
|
||||
component.ChargeRate = component.BaseChargeRate * MathF.Pow(component.PartRatingChargeRateModifier, modifierRating - 1);
|
||||
}
|
||||
|
||||
private void OnUpgradeExamine(EntityUid uid, ChargerComponent component, UpgradeExamineEvent args)
|
||||
{
|
||||
args.AddPercentageUpgrade("charger-component-charge-rate", component.ChargeRate / component.BaseChargeRate);
|
||||
}
|
||||
|
||||
private void OnPowerChanged(EntityUid uid, ChargerComponent component, ref PowerChangedEvent args)
|
||||
{
|
||||
UpdateStatus(uid, component);
|
||||
|
||||
Reference in New Issue
Block a user