Skip to content

Commit

Permalink
fix lightning stacking
Browse files Browse the repository at this point in the history
  • Loading branch information
WarMechanic committed Jul 13, 2024
1 parent f52115b commit 907a689
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions Content.Server/Lightning/LightningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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))
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<LightningArc>(Arcs);
other.History = new List<EntityUid>(History);

return other;
}
};

/// <summary>
Expand Down

0 comments on commit 907a689

Please sign in to comment.