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

@@ -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;
}
}
}