Update DamageableSystem to modern standards (#39417)
* Update DamageableSystem to modern standards * DamageContainerId -> DamageContainerID with lint flag * Replace strings with protoids * Make CVar subscription declarations all consistently whitespaced * ChangeDamage -> TryChangeDamage, cope with C# jank * Revert event signature changes * Restore a comment * Re-add two queries * Init the queries * Use appearanceQuery in DamageChanged * Use damageableQuery in TryChangeDamage * Use damageableQuery in SetDamageModifierSetId * Final cleanup, fix sandboxing * Rectify ExplosionSystem:::ProcessEntity's call to TryChangeDamage * Re-organize DamageableSystem * first big fuck you breaking change. * THATS A LOT OF DAMAGE!!! * Fix test fails * test fixes 2 * push it --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
cf66dd7b35
commit
cdbe92d37d
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Mobs;
|
||||
using Content.Shared.StatusIcon;
|
||||
@@ -6,105 +7,100 @@ using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Damage
|
||||
namespace Content.Shared.Damage.Components;
|
||||
|
||||
/// <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]
|
||||
[Access(typeof(DamageableSystem), Other = AccessPermissions.ReadExecute)]
|
||||
public sealed partial class DamageableComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that allows entities to take damage.
|
||||
/// This <see cref="DamageContainerPrototype"/> specifies what damage types are supported by this component.
|
||||
/// If null, all damage types will be supported.
|
||||
/// </summary>
|
||||
[DataField("damageContainer")]
|
||||
// ReSharper disable once InconsistentNaming - This is wrong but fixing it is potentially annoying for downstreams.
|
||||
public ProtoId<DamageContainerPrototype>? 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>
|
||||
/// 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"/>.
|
||||
/// Though DamageModifierSets can be deserialized directly, we only want to use the prototype version here
|
||||
/// to reduce duplication.
|
||||
/// </remarks>
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent]
|
||||
[Access(typeof(DamageableSystem), Other = AccessPermissions.ReadExecute)]
|
||||
public sealed partial class DamageableComponent : Component
|
||||
[DataField("damageModifierSet")]
|
||||
public ProtoId<DamageModifierSetPrototype>? 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(readOnly: true)] //TODO FULL GAME SAVE
|
||||
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;
|
||||
|
||||
[DataField("radiationDamageTypes")]
|
||||
// ReSharper disable once UseCollectionExpression - Cannot refactor this as it's a potential sandbox violation.
|
||||
public List<ProtoId<DamageTypePrototype>> RadiationDamageTypeIDs = new() { "Radiation" };
|
||||
|
||||
/// <summary>
|
||||
/// Group types that affect the pain overlay.
|
||||
/// </summary>
|
||||
/// TODO: Add support for adding damage types specifically rather than whole damage groups
|
||||
[DataField]
|
||||
// ReSharper disable once UseCollectionExpression - Cannot refactor this as it's a potential sandbox volation.
|
||||
public List<ProtoId<DamageGroupPrototype>> PainDamageGroups = new() { "Brute", "Burn" };
|
||||
|
||||
[DataField]
|
||||
public Dictionary<MobState, ProtoId<HealthIconPrototype>> HealthIcons = new()
|
||||
{
|
||||
/// <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")]
|
||||
public ProtoId<DamageContainerPrototype>? DamageContainerID;
|
||||
{ MobState.Alive, "HealthIconFine" },
|
||||
{ MobState.Critical, "HealthIconCritical" },
|
||||
{ MobState.Dead, "HealthIconDead" },
|
||||
};
|
||||
|
||||
/// <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>
|
||||
[DataField("damageModifierSet")]
|
||||
public ProtoId<DamageModifierSetPrototype>? DamageModifierSetId;
|
||||
[DataField]
|
||||
public ProtoId<HealthIconPrototype> RottingIcon = "HealthIconRotting";
|
||||
|
||||
/// <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(readOnly: true)] // TODO FULL GAME SAVE
|
||||
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;
|
||||
|
||||
[DataField("radiationDamageTypes")]
|
||||
public List<ProtoId<DamageTypePrototype>> RadiationDamageTypeIDs = new() { "Radiation" };
|
||||
|
||||
/// <summary>
|
||||
/// Group types that affect the pain overlay.
|
||||
/// </summary>
|
||||
/// TODO: Add support for adding damage types specifically rather than whole damage groups
|
||||
[DataField]
|
||||
public List<ProtoId<DamageGroupPrototype>> PainDamageGroups = new() { "Brute", "Burn" };
|
||||
|
||||
[DataField]
|
||||
public Dictionary<MobState, ProtoId<HealthIconPrototype>> HealthIcons = new()
|
||||
{
|
||||
{ MobState.Alive, "HealthIconFine" },
|
||||
{ MobState.Critical, "HealthIconCritical" },
|
||||
{ MobState.Dead, "HealthIconDead" },
|
||||
};
|
||||
|
||||
[DataField]
|
||||
public ProtoId<HealthIconPrototype> RottingIcon = "HealthIconRotting";
|
||||
|
||||
[DataField]
|
||||
public FixedPoint2? HealthBarThreshold;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DamageableComponentState : ComponentState
|
||||
{
|
||||
public readonly Dictionary<string, FixedPoint2> DamageDict;
|
||||
public readonly string? DamageContainerId;
|
||||
public readonly string? ModifierSetId;
|
||||
public readonly FixedPoint2? HealthBarThreshold;
|
||||
|
||||
public DamageableComponentState(
|
||||
Dictionary<string, FixedPoint2> damageDict,
|
||||
string? damageContainerId,
|
||||
string? modifierSetId,
|
||||
FixedPoint2? healthBarThreshold)
|
||||
{
|
||||
DamageDict = damageDict;
|
||||
DamageContainerId = damageContainerId;
|
||||
ModifierSetId = modifierSetId;
|
||||
HealthBarThreshold = healthBarThreshold;
|
||||
}
|
||||
}
|
||||
[DataField]
|
||||
public FixedPoint2? HealthBarThreshold;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DamageableComponentState(
|
||||
Dictionary<string, FixedPoint2> damageDict,
|
||||
ProtoId<DamageContainerPrototype>? damageContainerId,
|
||||
ProtoId<DamageModifierSetPrototype>? modifierSetId,
|
||||
FixedPoint2? healthBarThreshold)
|
||||
: ComponentState
|
||||
{
|
||||
public readonly Dictionary<string, FixedPoint2> DamageDict = damageDict;
|
||||
public readonly ProtoId<DamageContainerPrototype>? DamageContainerId = damageContainerId;
|
||||
public readonly ProtoId<DamageModifierSetPrototype>? ModifierSetId = modifierSetId;
|
||||
public readonly FixedPoint2? HealthBarThreshold = healthBarThreshold;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user