generator machine upgrading (#12145)
This commit is contained in:
@@ -13,4 +13,13 @@ namespace Content.Server.Construction.Components
|
|||||||
public Container BoardContainer = default!;
|
public Container BoardContainer = default!;
|
||||||
public Container PartContainer = default!;
|
public Container PartContainer = default!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The different types of scaling that are available for machine upgrades
|
||||||
|
/// </summary>
|
||||||
|
public enum MachineUpgradeScalingType : byte
|
||||||
|
{
|
||||||
|
Linear,
|
||||||
|
Exponential
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||||
|
|
||||||
namespace Content.Server.Power.Components;
|
namespace Content.Server.Power.Components;
|
||||||
@@ -34,14 +35,7 @@ public sealed class UpgradePowerDrawComponent : Component
|
|||||||
/// What type of scaling is being used?
|
/// What type of scaling is being used?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("scaling", required: true), ViewVariables(VVAccess.ReadWrite)]
|
[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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ using Content.Server.Construction;
|
|||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace Content.Server.Power.SMES
|
namespace Content.Server.Power.EntitySystems
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class UpgradeBatterySystem : EntitySystem
|
public sealed class UpgradeBatterySystem : EntitySystem
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
using Content.Server.Construction;
|
using Content.Server.Construction;
|
||||||
|
using Content.Server.Construction.Components;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
|
|
||||||
namespace Content.Server.Power.EntitySystems;
|
namespace Content.Server.Power.EntitySystems;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This handles using upgraded machine parts
|
/// This handles using upgraded machine parts
|
||||||
/// to modify the power load of a machine.
|
/// to modify the power supply/generation of a machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class UpgradePowerDrawSystem : EntitySystem
|
public sealed class UpgradePowerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<UpgradePowerDrawComponent, MapInitEvent>(OnMapInit);
|
SubscribeLocalEvent<UpgradePowerDrawComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<UpgradePowerDrawComponent, RefreshPartsEvent>(OnRefreshParts);
|
SubscribeLocalEvent<UpgradePowerDrawComponent, RefreshPartsEvent>(OnRefreshParts);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<UpgradePowerSupplierComponent, MapInitEvent>(OnSupplierMapInit);
|
||||||
|
SubscribeLocalEvent<UpgradePowerSupplierComponent, RefreshPartsEvent>(OnSupplierRefreshParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMapInit(EntityUid uid, UpgradePowerDrawComponent component, MapInitEvent args)
|
private void OnMapInit(EntityUid uid, UpgradePowerDrawComponent component, MapInitEvent args)
|
||||||
@@ -30,10 +34,10 @@ public sealed class UpgradePowerDrawSystem : EntitySystem
|
|||||||
var rating = args.PartRatings[component.MachinePartPowerDraw];
|
var rating = args.PartRatings[component.MachinePartPowerDraw];
|
||||||
switch (component.Scaling)
|
switch (component.Scaling)
|
||||||
{
|
{
|
||||||
case PowerDrawScalingType.Linear:
|
case MachineUpgradeScalingType.Linear:
|
||||||
load += component.PowerDrawMultiplier * (rating - 1);
|
load += component.PowerDrawMultiplier * (rating - 1);
|
||||||
break;
|
break;
|
||||||
case PowerDrawScalingType.Exponential:
|
case MachineUpgradeScalingType.Exponential:
|
||||||
load *= MathF.Pow(component.PowerDrawMultiplier, rating - 1);
|
load *= MathF.Pow(component.PowerDrawMultiplier, rating - 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -46,4 +50,31 @@ public sealed class UpgradePowerDrawSystem : EntitySystem
|
|||||||
if (TryComp<PowerConsumerComponent>(uid, out var powa2))
|
if (TryComp<PowerConsumerComponent>(uid, out var powa2))
|
||||||
powa2.DrawRate = load;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +169,9 @@
|
|||||||
LayoutId: GeneratorPlasma
|
LayoutId: GeneratorPlasma
|
||||||
- type: Machine
|
- type: Machine
|
||||||
board: GeneratorPlasmaMachineCircuitboard
|
board: GeneratorPlasmaMachineCircuitboard
|
||||||
|
- type: UpgradePowerSupplier
|
||||||
|
powerSupplyMultiplier: 1.25
|
||||||
|
scaling: Exponential
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: [ BaseGenerator, ConstructibleMachine ]
|
parent: [ BaseGenerator, ConstructibleMachine ]
|
||||||
@@ -185,6 +188,9 @@
|
|||||||
LayoutId: GeneratorUranium
|
LayoutId: GeneratorUranium
|
||||||
- type: Machine
|
- type: Machine
|
||||||
board: GeneratorUraniumMachineCircuitboard
|
board: GeneratorUraniumMachineCircuitboard
|
||||||
|
- type: UpgradePowerSupplier
|
||||||
|
powerSupplyMultiplier: 1.25
|
||||||
|
scaling: Exponential
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseGeneratorWallmount
|
parent: BaseGeneratorWallmount
|
||||||
|
|||||||
Reference in New Issue
Block a user