fix infinite power gen bug (#12688)

This commit is contained in:
Nemanja
2022-11-20 21:50:43 -05:00
committed by GitHub
parent 8ab849aec9
commit d1b5630648

View File

@@ -71,23 +71,24 @@ public sealed class UpgradePowerSystem : EntitySystem
private void OnSupplierRefreshParts(EntityUid uid, UpgradePowerSupplierComponent component, RefreshPartsEvent args) private void OnSupplierRefreshParts(EntityUid uid, UpgradePowerSupplierComponent component, RefreshPartsEvent args)
{ {
if (!TryComp<PowerSupplierComponent>(uid, out var powa)) var supply = component.BaseSupplyRate;
return;
var rating = args.PartRatings[component.MachinePartPowerSupply]; var rating = args.PartRatings[component.MachinePartPowerSupply];
switch (component.Scaling) switch (component.Scaling)
{ {
case MachineUpgradeScalingType.Linear: case MachineUpgradeScalingType.Linear:
powa.MaxSupply += component.BaseSupplyRate * (rating - 1); supply += component.BaseSupplyRate * (rating - 1);
break; break;
case MachineUpgradeScalingType.Exponential: case MachineUpgradeScalingType.Exponential:
powa.MaxSupply *= MathF.Pow(component.PowerSupplyMultiplier, rating - 1); supply *= MathF.Pow(component.PowerSupplyMultiplier, rating - 1);
break; break;
default: default:
Logger.Error($"invalid power scaling type for {ToPrettyString(uid)}."); Logger.Error($"invalid power scaling type for {ToPrettyString(uid)}.");
powa.MaxSupply = component.BaseSupplyRate; supply = component.BaseSupplyRate;
break; break;
} }
if (TryComp<PowerSupplierComponent>(uid, out var powa))
powa.MaxSupply = supply;
} }
private void OnSupplierUpgradeExamine(EntityUid uid, UpgradePowerSupplierComponent component, UpgradeExamineEvent args) private void OnSupplierUpgradeExamine(EntityUid uid, UpgradePowerSupplierComponent component, UpgradeExamineEvent args)