Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Lightning-Factor #543

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8960987
it works
WarMechanic Jul 12, 2024
e5c2f55
add initial weightings
WarMechanic Jul 12, 2024
4270666
tesla coils absorb lightning charge, reconsolidate lightning charge v…
WarMechanic Jul 13, 2024
aa37867
remove electrified component from lightning
WarMechanic Jul 13, 2024
cd93f05
allow parsing functions into lightning parameters
WarMechanic Jul 13, 2024
2064a49
add LightningContext constructor
WarMechanic Jul 13, 2024
a3e2b4c
fixes various Invalid Weight errors
WarMechanic Jul 13, 2024
51006c6
consolidations
WarMechanic Jul 13, 2024
adfe78b
reimplement lightning shock
WarMechanic Jul 13, 2024
f52115b
lightning damage scales with charge
WarMechanic Jul 13, 2024
907a689
fix lightning stacking
WarMechanic Jul 13, 2024
06a0132
another weighted pick fix
WarMechanic Jul 13, 2024
6df2db8
fix tesla being shaded
WarMechanic Jul 13, 2024
722cb4b
cull exploding behaviour from LightningTarget, use Explosive instead
WarMechanic Jul 13, 2024
89218fd
reimplement lightning resistance
WarMechanic Jul 13, 2024
fb470db
name consolidation + stacking options
WarMechanic Jul 13, 2024
37da556
fix LightningTarget not being able to influence LightningContext
WarMechanic Jul 13, 2024
ac5c8fe
adjusts prototypes, electrical devices are explosive again
WarMechanic Jul 13, 2024
f8d23b3
change system to use damage specifiers
WarMechanic Jul 13, 2024
c902785
oops
WarMechanic Jul 13, 2024
6cda0e0
increase odds of hitting mobs
WarMechanic Jul 13, 2024
af55fa7
uncrash
WarMechanic Jul 13, 2024
4e56c75
stopgap stuff
WarMechanic Jul 13, 2024
a9b7126
improves electrocution damage logic
WarMechanic Jul 14, 2024
de543cb
allow machines to take electrocution damage
WarMechanic Jul 14, 2024
40b32d4
stop giving a damage popup when 0 electrocute damage is dealt
WarMechanic Jul 14, 2024
b6b4b72
coils/rods no longer take shock damage, weighting buffs
WarMechanic Jul 14, 2024
02db056
consolidation
WarMechanic Jul 14, 2024
228590a
allow wall lights to be targeted by lightning
WarMechanic Jul 15, 2024
3584d28
update LightningArcShooter to use math
WarMechanic Jul 15, 2024
3eb4a4f
Merge branch 'master' into lightning
WarMechanic Jul 15, 2024
07fcfe3
migrate types to shared
WarMechanic Aug 24, 2024
71162d7
Merge branch 'master' of https://github.com/WarMechanic/Einstein-Engi…
WarMechanic Aug 24, 2024
301f951
fix LightningArcShooter fork chance being inverted
WarMechanic Aug 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Content.Server/Anomaly/Effects/ElectricityAnomalySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ private void OnPulse(Entity<ElectricityAnomalyComponent> anomaly, ref AnomalyPul

int boltCount = (int)MathF.Floor(MathHelper.Lerp((float)anomaly.Comp.MinBoltCount, (float)anomaly.Comp.MaxBoltCount, args.Severity));

_lightning.ShootRandomLightnings(anomaly, range, boltCount);
_lightning.ShootRandomLightnings(anomaly, range, boltCount, 50000f);
}

private void OnSupercritical(Entity<ElectricityAnomalyComponent> anomaly, ref AnomalySupercriticalEvent args)
{
var range = anomaly.Comp.MaxElectrocuteRange * 3;

_emp.EmpPulse(_transform.GetMapCoordinates(anomaly), range, anomaly.Comp.EmpEnergyConsumption, anomaly.Comp.EmpDisabledDuration);
_lightning.ShootRandomLightnings(anomaly, range, anomaly.Comp.MaxBoltCount * 3, arcDepth: 3);
_lightning.ShootRandomLightnings(anomaly, range, anomaly.Comp.MaxBoltCount * 3, 100000f,
maxArcs: 3
Comment on lines +43 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_lightning.ShootRandomLightnings(anomaly, range, anomaly.Comp.MaxBoltCount * 3, 100000f,
maxArcs: 3
_lightning.ShootRandomLightnings(anomaly, range, anomaly.Comp.MaxBoltCount * 3, 100000f, maxArcs: 3

);
}

public override void Update(float frameTime)
Expand Down
78 changes: 49 additions & 29 deletions Content.Server/Electrocution/ElectrocutionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Damage.Prototypes;
using Content.Shared.Database;
using Content.Shared.Electrocution;
using Content.Shared.FixedPoint;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Inventory;
Expand Down Expand Up @@ -213,7 +214,7 @@ private void OnElectrifiedInteractUsing(EntityUid uid, ElectrifiedComponent elec
TryDoElectrifiedAct(uid, args.User, siemens, electrified);
}

private float CalculateElectrifiedDamageScale(float power)
public 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
Expand Down Expand Up @@ -314,13 +315,26 @@ public bool TryDoElectrifiedAct(EntityUid uid, EntityUid targetUid,
}
}

public bool TryDoElectrocution(
EntityUid uid, EntityUid? sourceUid, FixedPoint2 shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
{
var damage = new DamageSpecifier();
damage.DamageDict.Add("Shock", shockDamage.Value);

return TryDoElectrocution(
uid, sourceUid, damage, time, refresh, siemensCoefficient,
statusEffects, ignoreInsulation
);
}

/// <inheritdoc/>
public override bool TryDoElectrocution(
EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
EntityUid uid, EntityUid? sourceUid, DamageSpecifier damageSpecifier, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
{
if (!DoCommonElectrocutionAttempt(uid, sourceUid, ref siemensCoefficient, ignoreInsulation)
|| !DoCommonElectrocution(uid, sourceUid, shockDamage, time, refresh, siemensCoefficient, statusEffects))
|| !DoCommonElectrocution(uid, sourceUid, damageSpecifier, time, refresh, siemensCoefficient, statusEffects))
return false;

RaiseLocalEvent(uid, new ElectrocutedEvent(uid, sourceUid, siemensCoefficient), true);
Expand Down Expand Up @@ -394,48 +408,54 @@ private bool DoCommonElectrocutionAttempt(EntityUid uid, EntityUid? sourceUid, r
}

private bool DoCommonElectrocution(EntityUid uid, EntityUid? sourceUid,
int? shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
FixedPoint2? shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null)
{
var damage = new DamageSpecifier();
if (shockDamage.HasValue)
damage.DamageDict.Add("Shock", shockDamage.Value);

return DoCommonElectrocution(uid, sourceUid, damage, time, refresh, siemensCoefficient, statusEffects);
}

private bool DoCommonElectrocution(EntityUid uid, EntityUid? sourceUid,
DamageSpecifier? damageSpecifier, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null)
{
if (siemensCoefficient <= 0)
return false;

if (shockDamage != null)
var checkDamage = false;
if (damageSpecifier != null)
{
shockDamage = (int) (shockDamage * siemensCoefficient);
damageSpecifier *= siemensCoefficient;
var actual = _damageable.TryChangeDamage(uid, damageSpecifier, origin: sourceUid);

if (shockDamage.Value <= 0)
return false;
if (actual != null && actual.DamageDict.Values.Sum() > FixedPoint2.Zero)
{
_adminLogger.Add(LogType.Electrocution,
$"{ToPrettyString(uid):entity} received {actual.GetTotal():damage} powered electrocution damage{(sourceUid != null ? " from " + ToPrettyString(sourceUid.Value) : ""):source}");

checkDamage = true;
}
}

if (!Resolve(uid, ref statusEffects, false) ||
!_statusEffects.CanApplyEffect(uid, StatusEffectKey, statusEffects))
var checkStun = false;
if (siemensCoefficient > 0.5f
&& Resolve(uid, ref statusEffects, false)
&& _statusEffects.CanApplyEffect(uid, StatusEffectKey, statusEffects)
&& _statusEffects.TryAddStatusEffect<ElectrocutedComponent>(uid, StatusEffectKey, time, refresh, statusEffects))
{
return false;
_stun.TryParalyze(uid, time * ParalyzeTimeMultiplier, refresh, statusEffects);

checkStun = true;
}

if (!_statusEffects.TryAddStatusEffect<ElectrocutedComponent>(uid, StatusEffectKey, time, refresh, statusEffects))
if (!checkDamage && !checkStun)
return false;

var shouldStun = siemensCoefficient > 0.5f;

if (shouldStun)
_stun.TryParalyze(uid, time * ParalyzeTimeMultiplier, refresh, statusEffects);

// TODO: Sparks here.

if (shockDamage is { } dmg)
{
var actual = _damageable.TryChangeDamage(uid,
new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>(DamageType), dmg), origin: sourceUid);

if (actual != null)
{
_adminLogger.Add(LogType.Electrocution,
$"{ToPrettyString(uid):entity} received {actual.GetTotal():damage} powered electrocution damage{(sourceUid != null ? " from " + ToPrettyString(sourceUid.Value) : ""):source}");
}
}

_stuttering.DoStutter(uid, time * StutteringTimeMultiplier, refresh, statusEffects);
_jittering.DoJitter(uid, time * JitterTimeMultiplier, refresh, JitterAmplitude, JitterFrequency, true, statusEffects);

Expand Down
6 changes: 5 additions & 1 deletion Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ private void RollMalfunction(Entity<ActiveMicrowaveComponent, MicrowaveComponent
}

if (_random.Prob(ent.Comp2.LightningChance))
_lightning.ShootRandomLightnings(ent, 1.0f, 2, MalfunctionSpark, triggerLightningEvents: false);
_lightning.ShootRandomLightnings(ent, 1.0f, 2, 5000f,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_lightning.ShootRandomLightnings(ent, 1.0f, 2, 5000f,
_lightning.ShootRandomLightnings(
ent,
1.0f,
2,
5000f,

lightningPrototype: MalfunctionSpark,
electrocute: false,
explode: false
);
}

/// <summary>
Expand Down
55 changes: 13 additions & 42 deletions Content.Server/Lightning/Components/LightningTargetComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,31 @@ namespace Content.Server.Lightning.Components;
public sealed partial class LightningTargetComponent : Component
{
/// <summary>
/// The probability that this target will not be ignored by a lightning strike. This is necessary for Tesla's balance.
/// The probability weighting of being stuck by lightning, compared against other nearby lightning targets.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The probability weighting of being stuck by lightning, compared against other nearby lightning targets.
/// The probability weighting of being struck by lightning, compared against other nearby lightning targets.

/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float HitProbability = 1f;

/// <summary>
/// Priority level for selecting a lightning target.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int Priority;
[DataField]
public float Weighting = 1f;

/// <summary>
/// Lightning has a number of bounces into neighboring targets.
/// This number controls how many bounces the lightning bolt has left after hitting that target.
/// At high values, the lightning will not travel farther than that entity.
/// For the love of god, do not make this number negative.
/// </summary>
Comment on lines +25 to 26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// For the love of god, do not make this number negative.
/// </summary>
/// </summary>
/// <remarks>For the love of god, do not make this number negative.</remarks>

[DataField, ViewVariables(VVAccess.ReadWrite)]
public int LightningResistance = 1; //by default, reduces the number of bounces from this target by 1

// BOOM PART

/// <summary>
/// Will the entity explode after being struck by lightning?
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool LightningExplode = true;

/// <summary>
/// The explosion prototype to spawn
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public ProtoId<ExplosionPrototype> ExplosionPrototype = "Default";

/// <summary>
/// The total amount of intensity an explosion can achieve
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float TotalIntensity = 25f;

/// <summary>
/// How quickly does the explosion's power slope? Higher = smaller area and more concentrated damage, lower = larger area and more spread out damage
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float Dropoff = 2f;
[DataField]
public int LightningArcReduction = 0;

/// <summary>
/// How much intensity can be applied per tile?
/// Lightning has a charge that gauges its energy.
/// This number subtracts residual charge after absorption.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float MaxTileIntensity = 5f;
[DataField]
public float LightningChargeReduction = 0f;

/// <summary>
/// how much structural damage the object takes from a lightning strike
/// Lightning has a charge that gauges its energy.
/// This number multiplies residual charge after absorption.
/// </summary>
[DataField]
public FixedPoint2 DamageFromLightning = 1;
public float LightningChargeMultiplier = 1f;
}
Loading
Loading