generator machine upgrading (#12145)

This commit is contained in:
Nemanja
2022-10-22 18:38:57 -04:00
committed by GitHub
parent cc3f9d631f
commit cfab87b3d7
6 changed files with 85 additions and 15 deletions

View File

@@ -13,4 +13,13 @@ namespace Content.Server.Construction.Components
public Container BoardContainer = default!;
public Container PartContainer = default!;
}
/// <summary>
/// The different types of scaling that are available for machine upgrades
/// </summary>
public enum MachineUpgradeScalingType : byte
{
Linear,
Exponential
}
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Construction.Prototypes;
using Content.Server.Construction.Components;
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Power.Components;
@@ -34,14 +35,7 @@ public sealed class UpgradePowerDrawComponent : Component
/// What type of scaling is being used?
/// </summary>
[DataField("scaling", required: true), ViewVariables(VVAccess.ReadWrite)]
public PowerDrawScalingType Scaling;
public MachineUpgradeScalingType Scaling;
}
/// <summary>
/// The different types of scaling that are available
/// </summary>
public enum PowerDrawScalingType : byte
{
Linear,
Exponential
}

View File

@@ -0,0 +1,30 @@
using Content.Server.Construction.Components;
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Power.Components;
[RegisterComponent]
public sealed class UpgradePowerSupplierComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
public float BaseSupplyRate;
/// <summary>
/// The machine part that affects the power supplu.
/// </summary>
[DataField("machinePartPowerSupply", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public string MachinePartPowerSupply = "Capacitor";
/// <summary>
/// The multiplier used for scaling the power supply.
/// </summary>
[DataField("powerSupplyMultiplier", required: true), ViewVariables(VVAccess.ReadWrite)]
public float PowerSupplyMultiplier = 1f;
/// <summary>
/// What type of scaling is being used?
/// </summary>
[DataField("scaling", required: true), ViewVariables(VVAccess.ReadWrite)]
public MachineUpgradeScalingType Scaling;
}

View File

@@ -2,7 +2,7 @@ using Content.Server.Construction;
using Content.Server.Power.Components;
using JetBrains.Annotations;
namespace Content.Server.Power.SMES
namespace Content.Server.Power.EntitySystems
{
[UsedImplicitly]
public sealed class UpgradeBatterySystem : EntitySystem

View File

@@ -1,19 +1,23 @@
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Server.Power.Components;
namespace Content.Server.Power.EntitySystems;
/// <summary>
/// This handles using upgraded machine parts
/// to modify the power load of a machine.
/// to modify the power supply/generation of a machine.
/// </summary>
public sealed class UpgradePowerDrawSystem : EntitySystem
public sealed class UpgradePowerSystem : EntitySystem
{
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<UpgradePowerDrawComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<UpgradePowerDrawComponent, RefreshPartsEvent>(OnRefreshParts);
SubscribeLocalEvent<UpgradePowerSupplierComponent, MapInitEvent>(OnSupplierMapInit);
SubscribeLocalEvent<UpgradePowerSupplierComponent, RefreshPartsEvent>(OnSupplierRefreshParts);
}
private void OnMapInit(EntityUid uid, UpgradePowerDrawComponent component, MapInitEvent args)
@@ -30,10 +34,10 @@ public sealed class UpgradePowerDrawSystem : EntitySystem
var rating = args.PartRatings[component.MachinePartPowerDraw];
switch (component.Scaling)
{
case PowerDrawScalingType.Linear:
case MachineUpgradeScalingType.Linear:
load += component.PowerDrawMultiplier * (rating - 1);
break;
case PowerDrawScalingType.Exponential:
case MachineUpgradeScalingType.Exponential:
load *= MathF.Pow(component.PowerDrawMultiplier, rating - 1);
break;
default:
@@ -46,4 +50,31 @@ public sealed class UpgradePowerDrawSystem : EntitySystem
if (TryComp<PowerConsumerComponent>(uid, out var powa2))
powa2.DrawRate = load;
}
private void OnSupplierMapInit(EntityUid uid, UpgradePowerSupplierComponent component, MapInitEvent args)
{
if (TryComp<PowerSupplierComponent>(uid, out var supplier))
component.BaseSupplyRate = supplier.MaxSupply;
}
private void OnSupplierRefreshParts(EntityUid uid, UpgradePowerSupplierComponent component, RefreshPartsEvent args)
{
if (!TryComp<PowerSupplierComponent>(uid, out var powa))
return;
var rating = args.PartRatings[component.MachinePartPowerSupply];
switch (component.Scaling)
{
case MachineUpgradeScalingType.Linear:
powa.MaxSupply += component.BaseSupplyRate * (rating - 1);
break;
case MachineUpgradeScalingType.Exponential:
powa.MaxSupply *= MathF.Pow(component.PowerSupplyMultiplier, rating - 1);
break;
default:
Logger.Error($"invalid power scaling type for {ToPrettyString(uid)}.");
powa.MaxSupply = component.BaseSupplyRate;
break;
}
}
}

View File

@@ -169,6 +169,9 @@
LayoutId: GeneratorPlasma
- type: Machine
board: GeneratorPlasmaMachineCircuitboard
- type: UpgradePowerSupplier
powerSupplyMultiplier: 1.25
scaling: Exponential
- type: entity
parent: [ BaseGenerator, ConstructibleMachine ]
@@ -185,6 +188,9 @@
LayoutId: GeneratorUranium
- type: Machine
board: GeneratorUraniumMachineCircuitboard
- type: UpgradePowerSupplier
powerSupplyMultiplier: 1.25
scaling: Exponential
- type: entity
parent: BaseGeneratorWallmount