Skip to content

Commit

Permalink
Log enrichment: Explosion damage to players (#29762)
Browse files Browse the repository at this point in the history
* Log enrichment: Explosion damage to players

* Update Content.Server/Explosion/EntitySystems/ExplosionSystem.Processing.cs

Co-authored-by: Chief-Engineer <[email protected]>

* Revert to total damage variant only, currently serialised as string.

* Make this its own log type.

---------

Co-authored-by: Chief-Engineer <[email protected]>
  • Loading branch information
TsjipTsjip and Chief-Engineer authored Aug 9, 2024
1 parent e05df5d commit 736325a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Content.Server/Administration/Commands/ExplosionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
}

var sysMan = IoCManager.Resolve<IEntitySystemManager>();
sysMan.GetEntitySystem<ExplosionSystem>().QueueExplosion(coords, type.ID, intensity, slope, maxIntensity);
sysMan.GetEntitySystem<ExplosionSystem>().QueueExplosion(coords, type.ID, intensity, slope, maxIntensity, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void AddSmiteVerbs(GetVerbsEvent<Verb> args)
var coords = _transformSystem.GetMapCoordinates(args.Target);
Timer.Spawn(_gameTiming.TickPeriod,
() => _explosionSystem.QueueExplosion(coords, ExplosionSystem.DefaultExplosionPrototypeId,
4, 1, 2, maxTileBreak: 0), // it gibs, damage doesn't need to be high.
4, 1, 2, args.Target, maxTileBreak: 0), // it gibs, damage doesn't need to be high.
CancellationToken.None);

_bodySystem.GibBody(args.Target);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Linq;
using System.Numerics;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Explosion.Components;
using Content.Shared.CCVar;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Explosion;
using Content.Shared.Explosion.Components;
using Content.Shared.Explosion.EntitySystems;
Expand All @@ -14,6 +17,7 @@
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
Expand Down Expand Up @@ -205,7 +209,8 @@ internal bool ExplodeTile(BroadphaseComponent lookup,
MapCoordinates epicenter,
HashSet<EntityUid> processed,
string id,
float? fireStacks)
float? fireStacks,
EntityUid? cause)
{
var size = grid.Comp.TileSize;
var gridBox = new Box2(tile * size, (tile + 1) * size);
Expand All @@ -224,7 +229,7 @@ internal bool ExplodeTile(BroadphaseComponent lookup,
// process those entities
foreach (var (uid, xform) in list)
{
ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks);
ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks, cause);
}

// process anchored entities
Expand All @@ -234,7 +239,7 @@ internal bool ExplodeTile(BroadphaseComponent lookup,
foreach (var entity in _anchored)
{
processed.Add(entity);
ProcessEntity(entity, epicenter, damage, throwForce, id, null, fireStacks);
ProcessEntity(entity, epicenter, damage, throwForce, id, null, fireStacks, cause);
}

// Walls and reinforced walls will break into girders. These girders will also be considered turf-blocking for
Expand Down Expand Up @@ -270,7 +275,7 @@ internal bool ExplodeTile(BroadphaseComponent lookup,
{
// Here we only throw, no dealing damage. Containers n such might drop their entities after being destroyed, but
// they should handle their own damage pass-through, with their own damage reduction calculation.
ProcessEntity(uid, epicenter, null, throwForce, id, xform, null);
ProcessEntity(uid, epicenter, null, throwForce, id, xform, null, cause);
}

return !tileBlocked;
Expand Down Expand Up @@ -306,7 +311,8 @@ internal void ExplodeSpace(BroadphaseComponent lookup,
MapCoordinates epicenter,
HashSet<EntityUid> processed,
string id,
float? fireStacks)
float? fireStacks,
EntityUid? cause)
{
var gridBox = Box2.FromDimensions(tile * DefaultTileSize, new Vector2(DefaultTileSize, DefaultTileSize));
var worldBox = spaceMatrix.TransformBox(gridBox);
Expand All @@ -322,7 +328,7 @@ internal void ExplodeSpace(BroadphaseComponent lookup,
foreach (var (uid, xform) in state.Item1)
{
processed.Add(uid);
ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks);
ProcessEntity(uid, epicenter, damage, throwForce, id, xform, fireStacks, cause);
}

if (throwForce <= 0)
Expand All @@ -336,7 +342,7 @@ internal void ExplodeSpace(BroadphaseComponent lookup,

foreach (var (uid, xform) in list)
{
ProcessEntity(uid, epicenter, null, throwForce, id, xform, fireStacks);
ProcessEntity(uid, epicenter, null, throwForce, id, xform, fireStacks, cause);
}
}

Expand Down Expand Up @@ -434,13 +440,28 @@ private void ProcessEntity(
float throwForce,
string id,
TransformComponent? xform,
float? fireStacksOnIgnite)
float? fireStacksOnIgnite,
EntityUid? cause)
{
if (originalDamage != null)
{
GetEntitiesToDamage(uid, originalDamage, id);
foreach (var (entity, damage) in _toDamage)
{
if (damage.GetTotal() > 0 && TryComp<ActorComponent>(entity, out var actorComponent))
{
// Log damage to player entities only, cause this will create a massive amount of log spam otherwise.
if (cause != null)
{
_adminLogger.Add(LogType.ExplosionHit, LogImpact.Medium, $"Explosion of {ToPrettyString(cause):actor} dealt {damage.GetTotal()} damage to {ToPrettyString(entity):subject}");
}
else
{
_adminLogger.Add(LogType.ExplosionHit, LogImpact.Medium, $"Explosion at {epicenter:epicenter} dealt {damage.GetTotal()} damage to {ToPrettyString(entity):subject}");
}

}

// TODO EXPLOSIONS turn explosions into entities, and pass the the entity in as the damage origin.
_damageableSystem.TryChangeDamage(entity, damage, ignoreResistances: true);

Expand Down Expand Up @@ -647,6 +668,8 @@ struct ExplosionData

public readonly EntityUid VisualEnt;

public readonly EntityUid? Cause;

/// <summary>
/// Initialize a new instance for processing
/// </summary>
Expand All @@ -663,9 +686,11 @@ public Explosion(ExplosionSystem system,
bool canCreateVacuum,
IEntityManager entMan,
IMapManager mapMan,
EntityUid visualEnt)
EntityUid visualEnt,
EntityUid? cause)
{
VisualEnt = visualEnt;
Cause = cause;
_system = system;
ExplosionType = explosionType;
_tileSetIntensity = tileSetIntensity;
Expand Down Expand Up @@ -829,7 +854,8 @@ public int Process(int processingTarget)
Epicenter,
ProcessedEntities,
ExplosionType.ID,
ExplosionType.FireStacks);
ExplosionType.FireStacks,
Cause);

// If the floor is not blocked by some dense object, damage the floor tiles.
if (canDamageFloor)
Expand All @@ -847,7 +873,8 @@ public int Process(int processingTarget)
Epicenter,
ProcessedEntities,
ExplosionType.ID,
ExplosionType.FireStacks);
ExplosionType.FireStacks,
Cause);
}

if (!MoveNext())
Expand Down Expand Up @@ -888,4 +915,5 @@ public sealed class QueuedExplosion
public float TotalIntensity, Slope, MaxTileIntensity, TileBreakScale;
public int MaxTileBreak;
public bool CanCreateVacuum;
public EntityUid? Cause; // The entity that exploded, for logging purposes.
}
9 changes: 6 additions & 3 deletions Content.Server/Explosion/EntitySystems/ExplosionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void QueueExplosion(EntityUid uid,

var posFound = _transformSystem.TryGetMapOrGridCoordinates(uid, out var gridPos, pos);

QueueExplosion(mapPos, typeId, totalIntensity, slope, maxTileIntensity, tileBreakScale, maxTileBreak, canCreateVacuum, addLog: false);
QueueExplosion(mapPos, typeId, totalIntensity, slope, maxTileIntensity, uid, tileBreakScale, maxTileBreak, canCreateVacuum, addLog: false);

if (!addLog)
return;
Expand Down Expand Up @@ -281,6 +281,7 @@ public void QueueExplosion(MapCoordinates epicenter,
float totalIntensity,
float slope,
float maxTileIntensity,
EntityUid? cause,
float tileBreakScale = 1f,
int maxTileBreak = int.MaxValue,
bool canCreateVacuum = true,
Expand Down Expand Up @@ -324,7 +325,8 @@ public void QueueExplosion(MapCoordinates epicenter,
MaxTileIntensity = maxTileIntensity,
TileBreakScale = tileBreakScale,
MaxTileBreak = maxTileBreak,
CanCreateVacuum = canCreateVacuum
CanCreateVacuum = canCreateVacuum,
Cause = cause
};
_explosionQueue.Enqueue(boom);
_queuedExplosions.Add(boom);
Expand Down Expand Up @@ -393,7 +395,8 @@ public void QueueExplosion(MapCoordinates epicenter,
queued.CanCreateVacuum,
EntityManager,
_mapManager,
visualEnt);
visualEnt,
queued.Cause);
}

private void CameraShake(float range, MapCoordinates epicenter, float totalIntensity)
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Lightning/LightningTargetSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private void OnHitByLightning(Entity<LightningTargetComponent> uid, ref HitByLig
uid.Comp.ExplosionPrototype,
uid.Comp.TotalIntensity, uid.Comp.Dropoff,
uid.Comp.MaxTileIntensity,
uid,
canCreateVacuum: false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private void DestroyAfterLimit(EntityUid uid, BluespaceLockerComponent component
{
case BluespaceLockerDestroyType.Explode:
_explosionSystem.QueueExplosion(uid.ToCoordinates().ToMap(EntityManager, _transformSystem),
ExplosionSystem.DefaultExplosionPrototypeId, 4, 1, 2, maxTileBreak: 0);
ExplosionSystem.DefaultExplosionPrototypeId, 4, 1, 2, uid, maxTileBreak: 0);
goto case BluespaceLockerDestroyType.Delete;
case BluespaceLockerDestroyType.Delete:
QueueDel(uid);
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared.Database/LogType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,10 @@ public enum LogType
/// Storage & entity-storage related interactions
/// </summary>
Storage = 93,

/// <summary>
/// A player got hit by an explosion and was dealt damage.
/// </summary>
ExplosionHit = 94,

}

0 comments on commit 736325a

Please sign in to comment.