Rebalances electrocution damage to a log scale (#24829)

This commit is contained in:
Varen
2024-02-05 19:47:52 +01:00
committed by GitHub
parent 2ba1bd22dc
commit 1a4b96c2fc

View File

@@ -62,9 +62,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
[ValidatePrototypeId<DamageTypePrototype>]
private const string DamageType = "Shock";
// Yes, this is absurdly small for a reason.
private const float ElectrifiedScalePerWatt = 1E-6f;
// Multiply and shift the log scale for shock damage.
private const float RecursiveDamageMultiplier = 0.75f;
private const float RecursiveTimeMultiplier = 0.8f;
@@ -214,6 +212,16 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
TryDoElectrifiedAct(uid, args.User, siemens, electrified);
}
private float CalculateElectrifiedDamageScale(float power)
{
// A logarithm allows a curve of damage that grows quickly, but slows down dramatically past a value. This keeps the damage to a reasonable range.
const float DamageShift = 1.67f; // Shifts the curve for an overall higher or lower damage baseline
const float CeilingCoefficent = 1.35f; // Adjusts the approach to maximum damage, higher = Higher top damage
const float LogGrowth = 0.00001f; // Adjusts the growth speed of the curve
return DamageShift + MathF.Log(power * LogGrowth) * CeilingCoefficent;
}
public bool TryDoElectrifiedAct(EntityUid uid, EntityUid targetUid,
float siemens = 1,
ElectrifiedComponent? electrified = null,
@@ -264,7 +272,9 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
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 damageScale = CalculateElectrifiedDamageScale(supp);
if (damageScale <= 0f)
return false;
{
var lastRet = true;
@@ -275,7 +285,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
entity,
uid,
node,
(int) (electrified.ShockDamage * damageScale * MathF.Pow(RecursiveDamageMultiplier, depth)),
(int) MathF.Ceiling(electrified.ShockDamage * damageScale * MathF.Pow(RecursiveDamageMultiplier, depth)),
TimeSpan.FromSeconds(electrified.ShockTime * MathF.Min(1f + MathF.Log2(1f + damageScale), 3f) * MathF.Pow(RecursiveTimeMultiplier, depth)),
true,
electrified.SiemensCoefficient);