Swaps HV/MV/LV scaling to supply power scaling (#20880)
This commit is contained in:
@@ -41,18 +41,6 @@ public sealed partial class ElectrifiedComponent : Component
|
|||||||
[DataField("lowVoltageNode")]
|
[DataField("lowVoltageNode")]
|
||||||
public string? LowVoltageNode;
|
public string? LowVoltageNode;
|
||||||
|
|
||||||
[DataField("highVoltageDamageMultiplier")]
|
|
||||||
public float HighVoltageDamageMultiplier = 3f;
|
|
||||||
|
|
||||||
[DataField("highVoltageTimeMultiplier")]
|
|
||||||
public float HighVoltageTimeMultiplier = 1.5f;
|
|
||||||
|
|
||||||
[DataField("mediumVoltageDamageMultiplier")]
|
|
||||||
public float MediumVoltageDamageMultiplier = 2f;
|
|
||||||
|
|
||||||
[DataField("mediumVoltageTimeMultiplier")]
|
|
||||||
public float MediumVoltageTimeMultiplier = 1.25f;
|
|
||||||
|
|
||||||
[DataField("shockDamage")]
|
[DataField("shockDamage")]
|
||||||
public int ShockDamage = 20;
|
public int ShockDamage = 20;
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,18 @@
|
|||||||
[Access(typeof(ElectrocutionSystem))]
|
[Access(typeof(ElectrocutionSystem))]
|
||||||
public sealed partial class ElectrocutionComponent : Component
|
public sealed partial class ElectrocutionComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("timeLeft")]
|
|
||||||
public float TimeLeft;
|
|
||||||
|
|
||||||
[DataField("electrocuting")]
|
[DataField("electrocuting")]
|
||||||
public EntityUid Electrocuting;
|
public EntityUid Electrocuting;
|
||||||
|
|
||||||
|
[DataField("source")]
|
||||||
|
public EntityUid Source;
|
||||||
|
|
||||||
|
[DataField("timeLeft")]
|
||||||
|
public float TimeLeft;
|
||||||
|
|
||||||
[DataField("accumDamage")]
|
[DataField("accumDamage")]
|
||||||
public float AccumulatedDamage;
|
public float AccumulatedDamage;
|
||||||
|
|
||||||
[DataField("source")]
|
[DataField("baseDamage")]
|
||||||
public EntityUid Source;
|
public float BaseDamage = 20f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ using Content.Shared.Interaction;
|
|||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Jittering;
|
using Content.Shared.Jittering;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
|
using Content.Shared.Mobs;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Pulling.Components;
|
using Content.Shared.Pulling.Components;
|
||||||
using Content.Shared.Speech.EntitySystems;
|
using Content.Shared.Speech.EntitySystems;
|
||||||
@@ -61,7 +62,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
|||||||
private const string DamageType = "Shock";
|
private const string DamageType = "Shock";
|
||||||
|
|
||||||
// Yes, this is absurdly small for a reason.
|
// Yes, this is absurdly small for a reason.
|
||||||
private const float ElectrifiedDamagePerWatt = 0.0015f;
|
private const float ElectrifiedScalePerWatt = 1E-6f;
|
||||||
|
|
||||||
private const float RecursiveDamageMultiplier = 0.75f;
|
private const float RecursiveDamageMultiplier = 0.75f;
|
||||||
private const float RecursiveTimeMultiplier = 0.8f;
|
private const float RecursiveTimeMultiplier = 0.8f;
|
||||||
@@ -102,7 +103,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
|||||||
var timePassed = Math.Min(frameTime, electrocution.TimeLeft);
|
var timePassed = Math.Min(frameTime, electrocution.TimeLeft);
|
||||||
|
|
||||||
electrocution.TimeLeft -= timePassed;
|
electrocution.TimeLeft -= timePassed;
|
||||||
electrocution.AccumulatedDamage += consumer.ReceivedPower * ElectrifiedDamagePerWatt * timePassed;
|
electrocution.AccumulatedDamage += electrocution.BaseDamage * (consumer.ReceivedPower / consumer.DrawRate) * timePassed;
|
||||||
|
|
||||||
if (!MathHelper.CloseTo(electrocution.TimeLeft, 0))
|
if (!MathHelper.CloseTo(electrocution.TimeLeft, 0))
|
||||||
continue;
|
continue;
|
||||||
@@ -117,7 +118,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
|||||||
if (actual != null)
|
if (actual != null)
|
||||||
{
|
{
|
||||||
_adminLogger.Add(LogType.Electrocution,
|
_adminLogger.Add(LogType.Electrocution,
|
||||||
$"{ToPrettyString(electrocution.Electrocuting):entity} received {actual.Total:damage} powered electrocution damage from {ToPrettyString(electrocution.Source):source}");
|
$"{ToPrettyString(electrocution.Electrocuting):entity} received {actual.GetTotal():damage} powered electrocution damage from {ToPrettyString(electrocution.Source):source}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QueueDel(uid);
|
QueueDel(uid);
|
||||||
@@ -257,15 +258,17 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
var node = PoweredNode(uid, electrified, nodeContainer);
|
var node = PoweredNode(uid, electrified, nodeContainer);
|
||||||
if (node == null)
|
if (node?.NodeGroup is not IBasePowerNet powerNet)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var (damageMult, timeMult) = node.NodeGroupID switch
|
var net = powerNet.NetworkNode;
|
||||||
{
|
var supp = net.LastCombinedSupply;
|
||||||
NodeGroupID.HVPower => (electrified.HighVoltageDamageMultiplier, electrified.HighVoltageTimeMultiplier),
|
|
||||||
NodeGroupID.MVPower => (electrified.MediumVoltageDamageMultiplier, electrified.MediumVoltageTimeMultiplier),
|
if (supp <= 0f)
|
||||||
_ => (1f, 1f)
|
return false;
|
||||||
};
|
|
||||||
|
// Initial damage scales off of the available supply on the principle that the victim has shorted the entire powernet through their body.
|
||||||
|
var damageScale = supp * ElectrifiedScalePerWatt;
|
||||||
|
|
||||||
{
|
{
|
||||||
var lastRet = true;
|
var lastRet = true;
|
||||||
@@ -276,8 +279,8 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
|||||||
entity,
|
entity,
|
||||||
uid,
|
uid,
|
||||||
node,
|
node,
|
||||||
(int) (electrified.ShockDamage * MathF.Pow(RecursiveDamageMultiplier, depth) * damageMult),
|
(int) (electrified.ShockDamage * damageScale * MathF.Pow(RecursiveDamageMultiplier, depth)),
|
||||||
TimeSpan.FromSeconds(electrified.ShockTime * MathF.Pow(RecursiveTimeMultiplier, depth) * timeMult),
|
TimeSpan.FromSeconds(electrified.ShockTime * MathF.Min(1f + MathF.Log2(1f + damageScale), 3f) * MathF.Pow(RecursiveTimeMultiplier, depth)),
|
||||||
true,
|
true,
|
||||||
electrified.SiemensCoefficient);
|
electrified.SiemensCoefficient);
|
||||||
}
|
}
|
||||||
@@ -304,18 +307,18 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool TryDoElectrocution(
|
public override bool TryDoElectrocution(
|
||||||
EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
|
EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
|
||||||
StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
|
StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
|
||||||
{
|
{
|
||||||
if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient, ignoreInsulation)
|
if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient, ignoreInsulation)
|
||||||
|| !DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
|
|| !DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient), true);
|
RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient), true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryDoElectrocutionPowered(
|
private bool TryDoElectrocutionPowered(
|
||||||
EntityUid uid,
|
EntityUid uid,
|
||||||
@@ -331,12 +334,12 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
|||||||
if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient))
|
if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
|
||||||
|
return false;
|
||||||
|
|
||||||
// Coefficient needs to be higher than this to do a powered electrocution!
|
// Coefficient needs to be higher than this to do a powered electrocution!
|
||||||
if (siemensCoefficient <= 0.5f)
|
if (siemensCoefficient <= 0.5f)
|
||||||
return DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects);
|
return true;
|
||||||
|
|
||||||
if (!DoCommonElectrocution(uid, sourceUid, null, time, refresh, siemensCoefficient, statusEffects))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!Resolve(sourceUid, ref sourceTransform)) // This shouldn't really happen, but just in case...
|
if (!Resolve(sourceUid, ref sourceTransform)) // This shouldn't really happen, but just in case...
|
||||||
return true;
|
return true;
|
||||||
@@ -422,7 +425,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
|
|||||||
if (actual != null)
|
if (actual != null)
|
||||||
{
|
{
|
||||||
_adminLogger.Add(LogType.Electrocution,
|
_adminLogger.Add(LogType.Electrocution,
|
||||||
$"{ToPrettyString(uid):entity} received {actual.Total:damage} powered electrocution damage{(sourceUid != null ? " from " + ToPrettyString(sourceUid.Value) : ""):source}");
|
$"{ToPrettyString(uid):entity} received {actual.GetTotal():damage} powered electrocution damage{(sourceUid != null ? " from " + ToPrettyString(sourceUid.Value) : ""):source}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ namespace Content.Server.Power.Pow3r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network.LastCombinedLoad = demand;
|
||||||
network.LastCombinedSupply = totalSupply + totalBatterySupply;
|
network.LastCombinedSupply = totalSupply + totalBatterySupply;
|
||||||
network.LastCombinedMaxSupply = totalMaxSupply + totalMaxBatterySupply;
|
network.LastCombinedMaxSupply = totalMaxSupply + totalMaxBatterySupply;
|
||||||
|
|
||||||
|
|||||||
@@ -488,6 +488,11 @@ namespace Content.Server.Power.Pow3r
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables] public List<NodeId> BatterySupplies = new();
|
[ViewVariables] public List<NodeId> BatterySupplies = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The total load on the power network as of last tick.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables] public float LastCombinedLoad = 0f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Available supply, including both normal supplies and batteries.
|
/// Available supply, including both normal supplies and batteries.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user