Machine Battery Scaling (SMES/Substation) (#11662)

Co-authored-by: CommieFlowers <rasmus.cedergren@hotmail.com>
This commit is contained in:
rolfero
2022-10-04 02:59:39 +02:00
committed by GitHub
parent 0c24f8b69b
commit f8c4c2d449
4 changed files with 67 additions and 8 deletions

View File

@@ -0,0 +1,28 @@
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Power.Components
{
[RegisterComponent]
public sealed class UpgradeBatteryComponent : Component
{
/// <summary>
/// The machine part that affects the power capacity.
/// </summary>
[DataField("machinePartPowerCapacity", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartPowerCapacity = "Capacitor";
/// <summary>
/// The machine part rating is raised to this power when calculating power gain
/// </summary>
[DataField("maxChargeMultiplier")]
public float MaxChargeMultiplier = 2f;
/// <summary>
/// Power gain scaling
/// </summary>
[DataField("baseMaxCharge")]
public float BaseMaxCharge = 8000000;
}
}

View File

@@ -0,0 +1,27 @@
using Content.Server.Construction;
using Content.Server.Power.Components;
using JetBrains.Annotations;
namespace Content.Server.Power.SMES
{
[UsedImplicitly]
public sealed class UpgradeBatterySystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<UpgradeBatteryComponent, RefreshPartsEvent>(OnRefreshParts);
}
public void OnRefreshParts(EntityUid uid, UpgradeBatteryComponent component, RefreshPartsEvent args)
{
var capacitorRating = args.PartRatings[component.MachinePartPowerCapacity];
if (TryComp<BatteryComponent>(uid, out var batteryComp))
{
batteryComp.MaxCharge = MathF.Pow(component.MaxChargeMultiplier, capacitorRating - 1) * component.BaseMaxCharge;
}
}
}
}

View File

@@ -20,11 +20,13 @@
layers: layers:
- state: smes - state: smes
- type: Smes - type: Smes
- type: UpgradeBattery
maxChargeMultiplier: 2
baseMaxCharge: 8000000
- type: Appearance - type: Appearance
visuals: visuals:
- type: SmesVisualizer - type: SmesVisualizer
- type: Battery - type: Battery
maxCharge: 10000000
startingCharge: 0 startingCharge: 0
- type: ExaminableBattery - type: ExaminableBattery
- type: NodeContainer - type: NodeContainer
@@ -66,11 +68,11 @@
- type: entity - type: entity
parent: BaseSMES parent: BaseSMES
id: SMESBasic id: SMESBasic
suffix: Basic, 10MW suffix: Basic, 8MW
components: components:
- type: Battery - type: Battery
maxCharge: 10000000 maxCharge: 8000000
startingCharge: 10000000 startingCharge: 8000000
- type: entity - type: entity
parent: SMESBasic parent: SMESBasic

View File

@@ -17,8 +17,10 @@
shader: unshaded shader: unshaded
- state: full - state: full
shader: unshaded shader: unshaded
- type: UpgradeBattery
maxChargeMultiplier: 2
baseMaxCharge: 2500000
- type: Battery - type: Battery
maxCharge: 4000000
startingCharge: 0 startingCharge: 0
- type: ExaminableBattery - type: ExaminableBattery
- type: PointLight - type: PointLight
@@ -163,11 +165,11 @@
- type: entity - type: entity
parent: BaseSubstation parent: BaseSubstation
id: SubstationBasic id: SubstationBasic
suffix: Basic, 4MW suffix: Basic, 2.5MW
components: components:
- type: Battery - type: Battery
maxCharge: 4000000 maxCharge: 2500000
startingCharge: 4000000 startingCharge: 2500000
- type: entity - type: entity
parent: SubstationBasic parent: SubstationBasic