diff --git a/Content.Server/Lightning/LightningSystem.cs b/Content.Server/Lightning/LightningSystem.cs index 769360f6f90..7d943f4aea9 100644 --- a/Content.Server/Lightning/LightningSystem.cs +++ b/Content.Server/Lightning/LightningSystem.cs @@ -149,9 +149,12 @@ public void ShootRandomLightnings(EntityUid user, float lightningRadius, int lig for (int i = 0; i < lightningCount; i++) { - EntityUid target = EntityUid.Parse(_random.Pick(weights)); + string stringTarget = _random.Pick(weights); + weights.Remove(stringTarget); + EntityUid target = EntityUid.Parse(stringTarget); - ShootLightning(user, target, context); + LightningContext clone = context.Clone(); + ShootLightning(user, target, clone); } } @@ -194,6 +197,9 @@ private void StageLightningArc(LightningArc lightningArc, int arcDepth = 0) // add this arc to the pool of arcs context.Arcs.Add(lightningArc); + if (!context.History.Contains(user)) + context.History.Add(user); + // check for any more targets if (!TryGetLightningTargets(Transform(target).Coordinates, context.ArcRange(context), out var weights)) { @@ -202,9 +208,6 @@ private void StageLightningArc(LightningArc lightningArc, int arcDepth = 0) return; } - if (!context.History.Contains(user)) - context.History.Add(user); - // depending on AllowLooping, remove previously visited entities from the targeting list if (!context.AllowLooping(context)) { @@ -280,7 +283,7 @@ public record struct LightningArc( int ContextId, int ArcDepth ); -public record struct LightningContext +public struct LightningContext { // These are not parameters, and are handled by the LightningSystem public int Id; @@ -322,6 +325,15 @@ public LightningContext() ElectrocuteIgnoreInsulation = (float discharge, LightningContext context) => false; Explode = (float discharge, LightningContext context) => true; } + + public LightningContext Clone() + { + LightningContext other = (LightningContext) MemberwiseClone(); + other.Arcs = new List(Arcs); + other.History = new List(History); + + return other; + } }; ///