]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Rebalances electrocution damage to a log scale (#24829)
authorVaren <ychwack@hotmail.it>
Mon, 5 Feb 2024 18:47:52 +0000 (19:47 +0100)
committerGitHub <noreply@github.com>
Mon, 5 Feb 2024 18:47:52 +0000 (10:47 -0800)
Content.Server/Electrocution/ElectrocutionSystem.cs

index aac500f34f8b4e704857106921b437bd0db0a3fb..f71f8b69742eeec6cc35a216eaf97d29716e4ca0 100644 (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);