* Add admin logging, models, migrations * Add logging damage changes * Add Log admin flag, LogFilter, Logs admin menu tab, message Refactor admin logging API * Change admin log get method names * Fix the name again * Minute amount of reorganization * Reset Postgres db snapshot * Reset Sqlite db snapshot * Make AdminLog have a composite primary key of round, id * Minute cleanup * Change admin system to do a type check instead of index check * Make admin logs use C# 10 interpolated string handlers * Implement UI on its own window Custom controls Searching Add admin log converters * Implement limits into the query * Change logs to be put into an OutputPanel instead for text wrapping * Add log <-> player m2m relationship back * UI improvements, make text wrap, add separators * Remove entity prefix from damaged log * Add explicit m2m model, fix any players filter * Add debug command to test bulk adding logs * Admin logs now just kinda go * Add histogram for database update time * Make admin log system update run every 5 seconds * Add a cap to the log queue and a metric for how many times it has been reached * Add metric for logs sent in a round * Make cvars out of admin logs queue send delay and cap * Merge fixes * Reset some changes * Add test for adding and getting a single log * Add tests for bulk adding logs * Add test for querying logs * Add CallerArgumentExpression to LogStringHandler methods and test * Improve UI, fix SQLite, add searching by round * Add entities to admin logs * Move distinct after orderby * Add migrations * ef core eat my ass * Add cvar for client logs batch size * Sort logs from newest to oldest by default * Merge fixes * Reorganize tests and add one for date ordering * Add note to log types to not change their numeric values * Add impacts to logs, better UI filtering * Make log add callable from shared for convenience * Get current round id directly from game ticker * Revert namespace change for DamageableSystem
136 lines
5.6 KiB
C#
136 lines
5.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Content.Shared.Acts;
|
|
using Content.Shared.Damage.Prototypes;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.Radiation;
|
|
using Robust.Shared.Analyzers;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Serialization;
|
|
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;
|
|
|
|
namespace Content.Shared.Damage
|
|
{
|
|
/// <summary>
|
|
/// Component that allows entities to take damage.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The supported damage types are specified using a <see cref="DamageContainerPrototype"/>s. DamageContainers
|
|
/// may also have resistances to certain damage types, defined via a <see cref="DamageModifierSetPrototype"/>.
|
|
/// </remarks>
|
|
[RegisterComponent]
|
|
[NetworkedComponent()]
|
|
[Friend(typeof(DamageableSystem))]
|
|
public class DamageableComponent : Component, IRadiationAct, IExAct
|
|
{
|
|
public override string Name => "Damageable";
|
|
|
|
/// <summary>
|
|
/// This <see cref="DamageContainerPrototype"/> specifies what damage types are supported by this component.
|
|
/// If null, all damage types will be supported.
|
|
/// </summary>
|
|
[DataField("damageContainer", customTypeSerializer: typeof(PrototypeIdSerializer<DamageContainerPrototype>))]
|
|
public string? DamageContainerID;
|
|
|
|
/// <summary>
|
|
/// This <see cref="DamageModifierSetPrototype"/> will be applied to any damage that is dealt to this container,
|
|
/// unless the damage explicitly ignores resistances.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Though DamageModifierSets can be deserialized directly, we only want to use the prototype version here
|
|
/// to reduce duplication.
|
|
/// </remarks>
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
[DataField("damageModifierSet", customTypeSerializer: typeof(PrototypeIdSerializer<DamageModifierSetPrototype>))]
|
|
public string? DamageModifierSetId;
|
|
|
|
/// <summary>
|
|
/// All the damage information is stored in this <see cref="DamageSpecifier"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If this data-field is specified, this allows damageable components to be initialized with non-zero damage.
|
|
/// </remarks>
|
|
[DataField("damage")]
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public DamageSpecifier Damage = new();
|
|
|
|
/// <summary>
|
|
/// Damage, indexed by <see cref="DamageGroupPrototype"/> ID keys.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Groups which have no members that are supported by this component will not be present in this
|
|
/// dictionary.
|
|
/// </remarks>
|
|
[ViewVariables] public Dictionary<string, FixedPoint2> DamagePerGroup = new();
|
|
|
|
/// <summary>
|
|
/// The sum of all damages in the DamageableComponent.
|
|
/// </summary>
|
|
[ViewVariables] public FixedPoint2 TotalDamage;
|
|
|
|
// Really these shouldn't be here. OnExplosion() and RadiationAct() should be handled elsewhere.
|
|
[ViewVariables]
|
|
[DataField("radiationDamageTypes", customTypeSerializer: typeof(PrototypeIdListSerializer<DamageTypePrototype>))]
|
|
public List<string> RadiationDamageTypeIDs = new() {"Radiation"};
|
|
[ViewVariables]
|
|
[DataField("explosionDamageTypes", customTypeSerializer: typeof(PrototypeIdListSerializer<DamageTypePrototype>))]
|
|
public List<string> ExplosionDamageTypeIDs = new() { "Piercing", "Heat" };
|
|
|
|
// TODO RADIATION Remove this.
|
|
void IRadiationAct.RadiationAct(float frameTime, SharedRadiationPulseComponent radiation)
|
|
{
|
|
var damageValue = FixedPoint2.New(MathF.Max((frameTime * radiation.RadsPerSecond), 1));
|
|
|
|
// Radiation should really just be a damage group instead of a list of types.
|
|
DamageSpecifier damage = new();
|
|
foreach (var typeID in RadiationDamageTypeIDs)
|
|
{
|
|
damage.DamageDict.Add(typeID, damageValue);
|
|
}
|
|
|
|
EntitySystem.Get<DamageableSystem>().TryChangeDamage(OwnerUid, damage);
|
|
}
|
|
|
|
// TODO EXPLOSION Remove this.
|
|
void IExAct.OnExplosion(ExplosionEventArgs eventArgs)
|
|
{
|
|
var damageValue = eventArgs.Severity switch
|
|
{
|
|
ExplosionSeverity.Light => FixedPoint2.New(20),
|
|
ExplosionSeverity.Heavy => FixedPoint2.New(60),
|
|
ExplosionSeverity.Destruction => FixedPoint2.New(250),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
|
|
// Explosion should really just be a damage group instead of a list of types.
|
|
DamageSpecifier damage = new();
|
|
foreach (var typeID in ExplosionDamageTypeIDs)
|
|
{
|
|
damage.DamageDict.Add(typeID, damageValue);
|
|
}
|
|
|
|
EntitySystem.Get<DamageableSystem>().TryChangeDamage(OwnerUid, damage);
|
|
}
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public class DamageableComponentState : ComponentState
|
|
{
|
|
public readonly Dictionary<string, FixedPoint2> DamageDict;
|
|
public readonly string? ModifierSetId;
|
|
|
|
public DamageableComponentState(
|
|
Dictionary<string, FixedPoint2> damageDict,
|
|
string? modifierSetId)
|
|
{
|
|
DamageDict = damageDict;
|
|
ModifierSetId = modifierSetId;
|
|
}
|
|
}
|
|
}
|