Modify damage logging. (#5579)
This commit is contained in:
@@ -40,5 +40,17 @@ public enum LogType
|
||||
Pickup = 36,
|
||||
Drop = 37,
|
||||
BulletHit = 38,
|
||||
MeleeHit = 41,
|
||||
HitScanHit = 42,
|
||||
Suicide = 43,
|
||||
Explosion = 44,
|
||||
Radiation = 45,
|
||||
Barotrauma = 46,
|
||||
Flammable = 47,
|
||||
Asphyxiation = 48,
|
||||
Temperature = 49,
|
||||
Hunger = 50,
|
||||
Thirst = 51,
|
||||
Electrocution = 52,
|
||||
CrayonDraw = 39,
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Content.Shared.Administration.Logs;
|
||||
|
||||
namespace Content.Shared.Damage
|
||||
{
|
||||
@@ -93,7 +94,11 @@ namespace Content.Shared.Damage
|
||||
damage.DamageDict.Add(typeID, damageValue);
|
||||
}
|
||||
|
||||
EntitySystem.Get<DamageableSystem>().TryChangeDamage(OwnerUid, damage);
|
||||
var actual = EntitySystem.Get<DamageableSystem>().TryChangeDamage(OwnerUid, damage);
|
||||
|
||||
// should logging be disabled during rad storms? a lot of entities are going to be damaged.
|
||||
if (actual != null)
|
||||
EntitySystem.Get<SharedAdminLogSystem>().Add(LogType.Radiation, $"{Owner} took {actual.Total} radiation damage");
|
||||
}
|
||||
|
||||
// TODO EXPLOSION Remove this.
|
||||
@@ -114,7 +119,11 @@ namespace Content.Shared.Damage
|
||||
damage.DamageDict.Add(typeID, damageValue);
|
||||
}
|
||||
|
||||
EntitySystem.Get<DamageableSystem>().TryChangeDamage(OwnerUid, damage);
|
||||
var actual = EntitySystem.Get<DamageableSystem>().TryChangeDamage(OwnerUid, damage);
|
||||
|
||||
// will logging handle nukes?
|
||||
if (actual != null)
|
||||
EntitySystem.Get<SharedAdminLogSystem>().Add(LogType.Explosion, $"{Owner} took {actual.Total} explosion damage");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,10 @@ namespace Content.Shared.Damage
|
||||
SubscribeLocalEvent<DamageableComponent, ComponentGetState>(DamageableGetState);
|
||||
}
|
||||
|
||||
protected virtual void SetTotalDamage(DamageableComponent damageable, FixedPoint2 @new)
|
||||
/// <summary>
|
||||
/// Update the total damage value and optionally add to admin logs
|
||||
/// </summary>
|
||||
protected virtual void SetTotalDamage(DamageableComponent damageable, FixedPoint2 @new, bool logChange)
|
||||
{
|
||||
var owner = damageable.Owner;
|
||||
var old = damageable.TotalDamage;
|
||||
@@ -33,6 +36,11 @@ namespace Content.Shared.Damage
|
||||
return;
|
||||
}
|
||||
|
||||
damageable.TotalDamage = @new;
|
||||
|
||||
if (!logChange)
|
||||
return;
|
||||
|
||||
LogType logType;
|
||||
string type;
|
||||
FixedPoint2 change;
|
||||
@@ -52,7 +60,6 @@ namespace Content.Shared.Damage
|
||||
|
||||
_logs.Add(logType, $"{owner} {type} {change} damage. Old: {old} | New: {@new}");
|
||||
|
||||
damageable.TotalDamage = @new;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,7 +110,7 @@ namespace Content.Shared.Damage
|
||||
public void SetDamage(DamageableComponent damageable, DamageSpecifier damage)
|
||||
{
|
||||
damageable.Damage = damage;
|
||||
DamageChanged(damageable);
|
||||
DamageChanged(damageable, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -113,10 +120,11 @@ namespace Content.Shared.Damage
|
||||
/// This updates cached damage information, flags the component as dirty, and raises a damage changed event.
|
||||
/// The damage changed event is used by other systems, such as damage thresholds.
|
||||
/// </remarks>
|
||||
public void DamageChanged(DamageableComponent component, DamageSpecifier? damageDelta = null, bool interruptsDoAfters = true)
|
||||
public void DamageChanged(DamageableComponent component, bool logChange, DamageSpecifier? damageDelta = null,
|
||||
bool interruptsDoAfters = true)
|
||||
{
|
||||
component.DamagePerGroup = component.Damage.GetDamagePerGroup();
|
||||
SetTotalDamage(component, component.Damage.Total);
|
||||
SetTotalDamage(component, component.Damage.Total, logChange);
|
||||
component.Dirty();
|
||||
|
||||
if (EntityManager.TryGetComponent<AppearanceComponent>(component.OwnerUid, out var appearance) && damageDelta != null)
|
||||
@@ -136,7 +144,8 @@ namespace Content.Shared.Damage
|
||||
/// Returns a <see cref="DamageSpecifier"/> with information about the actual damage changes. This will be
|
||||
/// null if the user had no applicable components that can take damage.
|
||||
/// </returns>
|
||||
public DamageSpecifier? TryChangeDamage(EntityUid uid, DamageSpecifier damage, bool ignoreResistances = false, bool interruptsDoAfters = true)
|
||||
public DamageSpecifier? TryChangeDamage(EntityUid uid, DamageSpecifier damage, bool ignoreResistances = false,
|
||||
bool interruptsDoAfters = true, bool logChange = false)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent<DamageableComponent>(uid, out var damageable))
|
||||
{
|
||||
@@ -185,7 +194,7 @@ namespace Content.Shared.Damage
|
||||
|
||||
if (!delta.Empty)
|
||||
{
|
||||
DamageChanged(damageable, delta, interruptsDoAfters);
|
||||
DamageChanged(damageable, logChange, delta, interruptsDoAfters);
|
||||
}
|
||||
|
||||
return delta;
|
||||
@@ -212,7 +221,7 @@ namespace Content.Shared.Damage
|
||||
|
||||
// Setting damage does not count as 'dealing' damage, even if it is set to a larger value, so we pass an
|
||||
// empty damage delta.
|
||||
DamageChanged(component, new DamageSpecifier());
|
||||
DamageChanged(component, false, new DamageSpecifier());
|
||||
}
|
||||
|
||||
private void DamageableGetState(EntityUid uid, DamageableComponent component, ref ComponentGetState args)
|
||||
@@ -237,7 +246,7 @@ namespace Content.Shared.Damage
|
||||
if (!delta.Empty)
|
||||
{
|
||||
component.Damage = newDamage;
|
||||
DamageChanged(component, delta);
|
||||
DamageChanged(component, false, delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,18 +543,6 @@ namespace Content.Shared.Interaction
|
||||
#endregion
|
||||
|
||||
#region Throw
|
||||
/// <summary>
|
||||
/// Activates the Throw behavior of an object
|
||||
/// Verifies that the user is capable of doing the throw interaction first
|
||||
/// </summary>
|
||||
public bool TryThrowInteraction(IEntity user, IEntity item)
|
||||
{
|
||||
if (user == null || item == null || !_actionBlockerSystem.CanThrow(user.Uid)) return false;
|
||||
|
||||
ThrownInteraction(user, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls Thrown on all components that implement the IThrown interface
|
||||
/// on an entity that has been thrown.
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
@@ -128,13 +123,12 @@ namespace Content.Shared.Throwing
|
||||
return;
|
||||
}
|
||||
|
||||
var landMsg = new LandEvent {User = thrownItem.Thrower?.Uid};
|
||||
RaiseLocalEvent(landing.Uid, landMsg, false);
|
||||
|
||||
// Assume it's uninteresting if it has no thrower. For now anyway.
|
||||
if (thrownItem.Thrower is not null)
|
||||
_adminLogSystem.Add(LogType.Landed, LogImpact.Low, $"{landing} thrown by {thrownItem.Thrower:thrower} landed.");
|
||||
|
||||
var landMsg = new LandEvent {User = thrownItem.Thrower?.Uid};
|
||||
RaiseLocalEvent(landing.Uid, landMsg, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -142,11 +136,12 @@ namespace Content.Shared.Throwing
|
||||
/// </summary>
|
||||
public void ThrowCollideInteraction(IEntity? user, IPhysBody thrown, IPhysBody target)
|
||||
{
|
||||
if (user is not null)
|
||||
_adminLogSystem.Add(LogType.ThrowHit, LogImpact.Low,
|
||||
$"{thrown.Owner:thrown} thrown by {user:thrower} hit {target.Owner:target}.");
|
||||
// TODO: Just pass in the bodies directly
|
||||
RaiseLocalEvent(target.Owner.Uid, new ThrowHitByEvent(user, thrown.Owner, target.Owner));
|
||||
RaiseLocalEvent(thrown.Owner.Uid, new ThrowDoHitEvent(user, thrown.Owner, target.Owner));
|
||||
if (user is not null)
|
||||
_adminLogSystem.Add(LogType.ThrowHit, LogImpact.Low, $"{thrown.Owner:thrown} thrown by {user:thrower} hit {target.Owner:target}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,18 +73,27 @@ namespace Content.Shared.Verbs
|
||||
}
|
||||
}
|
||||
|
||||
public void LogVerb(Verb verb, EntityUid user, EntityUid target, bool forced)
|
||||
public void LogVerb(Verb verb, EntityUid userUid, EntityUid targetUid, bool forced)
|
||||
{
|
||||
// first get the held item. again.
|
||||
EntityUid? used = null;
|
||||
if (EntityManager.TryGetComponent(user, out SharedHandsComponent? hands))
|
||||
EntityUid? usedUid = null;
|
||||
if (EntityManager.TryGetComponent(userUid, out SharedHandsComponent? hands))
|
||||
{
|
||||
hands.TryGetActiveHeldEntity(out var useEntityd);
|
||||
used = useEntityd?.Uid;
|
||||
if (used != null && EntityManager.TryGetComponent(used.Value, out HandVirtualItemComponent? pull))
|
||||
used = pull.BlockingEntity;
|
||||
usedUid = useEntityd?.Uid;
|
||||
if (usedUid != null && EntityManager.TryGetComponent(usedUid.Value, out HandVirtualItemComponent? pull))
|
||||
usedUid = pull.BlockingEntity;
|
||||
}
|
||||
|
||||
// get all the entities
|
||||
if (!EntityManager.TryGetEntity(userUid, out var user) ||
|
||||
!EntityManager.TryGetEntity(targetUid, out var target))
|
||||
return;
|
||||
|
||||
IEntity? used = null;
|
||||
if (usedUid != null)
|
||||
EntityManager.TryGetEntity(usedUid.Value, out used);
|
||||
|
||||
// then prepare the basic log message body
|
||||
var verbText = $"{verb.Category?.Text} {verb.Text}".Trim();
|
||||
var logText = forced
|
||||
|
||||
Reference in New Issue
Block a user