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:
Hannah Giovanna Dawson
2025-10-27 19:53:04 +00:00
committed by GitHub
parent cf66dd7b35
commit cdbe92d37d
157 changed files with 1127 additions and 967 deletions

View File

@@ -1,5 +1,6 @@
using Content.Shared.Clothing.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Examine;
using Content.Shared.Inventory;
using Content.Shared.Silicons.Borgs;

View File

@@ -4,6 +4,7 @@ using Content.Shared.Buckle.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Events;
using Content.Shared.Damage.ForceSay;
using Content.Shared.Damage.Systems;
using Content.Shared.Emoting;
using Content.Shared.Examine;
using Content.Shared.Eye.Blinding.Systems;

View File

@@ -1,6 +1,6 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Robust.Shared.Audio;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
@@ -42,31 +42,31 @@ public sealed partial class BlockingSystem
private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component, DamageModifyEvent args)
{
if (TryComp<BlockingComponent>(component.BlockingItem, out var blocking))
if (component.BlockingItem is not { } item || !TryComp<BlockingComponent>(item, out var blocking))
return;
if (args.Damage.GetTotal() <= 0)
return;
// A shield should only block damage it can itself absorb. To determine that we need the Damageable component on it.
if (!TryComp<DamageableComponent>(item, out var dmgComp))
return;
var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction;
blockFraction = Math.Clamp(blockFraction, 0, 1);
_damageable.TryChangeDamage((item, dmgComp), blockFraction * args.OriginalDamage);
var modify = new DamageModifierSet();
foreach (var key in dmgComp.Damage.DamageDict.Keys)
{
if (args.Damage.GetTotal() <= 0)
return;
modify.Coefficients.TryAdd(key, 1 - blockFraction);
}
// A shield should only block damage it can itself absorb. To determine that we need the Damageable component on it.
if (!TryComp<DamageableComponent>(component.BlockingItem, out var dmgComp))
return;
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modify);
var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction;
blockFraction = Math.Clamp(blockFraction, 0, 1);
_damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage);
var modify = new DamageModifierSet();
foreach (var key in dmgComp.Damage.DamageDict.Keys)
{
modify.Coefficients.TryAdd(key, 1 - blockFraction);
}
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modify);
if (blocking.IsBlocking && !args.Damage.Equals(args.OriginalDamage))
{
_audio.PlayPvs(blocking.BlockSound, uid);
}
if (blocking.IsBlocking && !args.Damage.Equals(args.OriginalDamage))
{
_audio.PlayPvs(blocking.BlockSound, uid);
}
}

View File

@@ -6,8 +6,8 @@ using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reaction;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.EntityEffects.Effects.Solution;
using Content.Shared.EntityEffects.Effects.Transform;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids;
using Content.Shared.Forensics.Components;
@@ -99,8 +99,7 @@ public abstract class SharedBloodstreamSystem : EntitySystem
// bloodloss damage is based on the base value, and modified by how low your blood level is.
var amt = bloodstream.BloodlossDamage / (0.1f + bloodPercentage);
_damageableSystem.TryChangeDamage(uid, amt,
ignoreResistances: false, interruptsDoAfters: false);
_damageableSystem.TryChangeDamage(uid, amt, ignoreResistances: false, interruptsDoAfters: false);
// Apply dizziness as a symptom of bloodloss.
// The effect is applied in a way that it will never be cleared without being healthy.

View File

@@ -181,7 +181,7 @@ public partial class SharedBodySystem
{
// TODO BODY SYSTEM KILL : remove this when wounding and required parts are implemented properly
var damage = new DamageSpecifier(Prototypes.Index(BloodlossDamageType), 300);
Damageable.TryChangeDamage(bodyEnt, damage);
Damageable.ChangeDamage(bodyEnt.Owner, damage);
}
}

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Movement.Systems;
using Content.Shared.Standing;
using Robust.Shared.Containers;

View File

@@ -4,7 +4,8 @@ using Content.Shared.Armor;
using Content.Shared.Atmos.Rotting;
using Content.Shared.Body.Components;
using Content.Shared.Changeling.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Humanoid;
@@ -92,7 +93,7 @@ public sealed class ChangelingDevourSystem : EntitySystem
if (damage.Damage.DamageDict.TryGetValue(damagePoints.Key, out var val) && val > comp.DevourConsumeDamageCap)
return;
}
_damageable.TryChangeDamage(target, comp.DamagePerTick, true, true, damage, user);
_damageable.ChangeDamage((target.Value, damage), comp.DamagePerTick, true, true, user);
}
/// <summary>

View File

@@ -1,8 +1,10 @@
using System.Linq;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Damage.Systems;
using Content.Shared.Mobs.Components;
using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Shared.Chat;
@@ -40,7 +42,7 @@ public sealed class SharedSuicideSystem : EntitySystem
appliedDamageSpecifier.DamageDict[key] = Math.Ceiling((double) (value * lethalAmountOfDamage / totalDamage));
}
_damageableSystem.TryChangeDamage(target, appliedDamageSpecifier, true, origin: target);
_damageableSystem.ChangeDamage(target.AsNullable(), appliedDamageSpecifier, true, origin: target);
}
/// <summary>
@@ -64,6 +66,6 @@ public sealed class SharedSuicideSystem : EntitySystem
}
var damage = new DamageSpecifier(damagePrototype, lethalAmountOfDamage);
_damageableSystem.TryChangeDamage(target, damage, true, origin: target);
_damageableSystem.ChangeDamage(target.AsNullable(), damage, true, origin: target);
}
}

View File

@@ -2,7 +2,7 @@ using Content.Shared.ActionBlocker;
using Content.Shared.Buckle.Components;
using Content.Shared.Climbing.Components;
using Content.Shared.Climbing.Events;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.DoAfter;
using Content.Shared.DragDrop;
using Content.Shared.Hands.Components;

View File

@@ -1,5 +1,6 @@
using Content.Shared.Clothing.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Examine;
using Content.Shared.Inventory;
using Content.Shared.Movement.Systems;

View File

@@ -2,7 +2,7 @@ using Content.Shared.CCVar;
using Content.Shared.Chemistry.Hypospray.Events;
using Content.Shared.Climbing.Components;
using Content.Shared.Climbing.Events;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.IdentityManagement;
using Content.Shared.Medical;
using Content.Shared.Popups;
@@ -95,7 +95,7 @@ public sealed class ClumsySystem : EntitySystem
args.Cancelled = true; // fail to catch
if (ent.Comp.CatchingFailDamage != null)
_damageable.TryChangeDamage(ent, ent.Comp.CatchingFailDamage, origin: args.Item);
_damageable.ChangeDamage(ent.Owner, ent.Comp.CatchingFailDamage, origin: args.Item);
// Collisions don't work properly with PopupPredicted or PlayPredicted.
// So we make this server only.
@@ -127,7 +127,7 @@ public sealed class ClumsySystem : EntitySystem
return;
if (ent.Comp.GunShootFailDamage != null)
_damageable.TryChangeDamage(ent, ent.Comp.GunShootFailDamage, origin: ent);
_damageable.ChangeDamage(ent.Owner, ent.Comp.GunShootFailDamage, origin: ent);
_stun.TryUpdateParalyzeDuration(ent, ent.Comp.GunShootFailStunTime);
@@ -199,7 +199,7 @@ public sealed class ClumsySystem : EntitySystem
{
stunTime = bonkComp.BonkTime;
if (bonkComp.BonkDamage != null)
_damageable.TryChangeDamage(target, bonkComp.BonkDamage, true);
_damageable.ChangeDamage(target.Owner, bonkComp.BonkDamage, true);
}
_stun.TryUpdateParalyzeDuration(target, stunTime);

View File

@@ -1,3 +1,4 @@
using Content.Shared.Damage.Systems;
using Robust.Shared.GameStates;
namespace Content.Shared.Damage.Components;

View File

@@ -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;
}

View File

@@ -1,3 +1,4 @@
using Content.Shared.Damage.Systems;
using Robust.Shared.GameStates;
namespace Content.Shared.Damage.Components;

View File

@@ -1,3 +1,4 @@
using Content.Shared.Damage.Systems;
using Robust.Shared.GameStates;
namespace Content.Shared.Damage.Components;

View File

@@ -1,3 +1,4 @@
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;

View File

@@ -1,5 +1,6 @@
using System.Linq;
using System.Text.Json.Serialization;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;

View File

@@ -1,5 +1,5 @@
using Content.Shared.Damage.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Damage.Prototypes
{

View File

@@ -1,5 +1,5 @@
using Content.Shared.Damage.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Damage.Prototypes
{

View File

@@ -73,9 +73,9 @@ public sealed class DamageOnAttackedSystem : EntitySystem
}
}
totalDamage = _damageableSystem.TryChangeDamage(args.User, totalDamage, entity.Comp.IgnoreResistances, origin: entity);
totalDamage = _damageableSystem.ChangeDamage(args.User, totalDamage, entity.Comp.IgnoreResistances, origin: entity);
if (totalDamage != null && totalDamage.AnyPositive())
if (totalDamage.AnyPositive())
{
_adminLogger.Add(LogType.Damaged, $"{ToPrettyString(args.User):user} injured themselves by attacking {ToPrettyString(entity):target} and received {totalDamage.GetTotal():damage} damage");
_audioSystem.PlayPredicted(entity.Comp.InteractSound, entity, args.User);

View File

@@ -65,7 +65,7 @@ public sealed class DamageOnInteractSystem : EntitySystem
// or checking the entity for the comp itself if the inventory didn't work
if (protectiveEntity.Comp == null && TryComp<DamageOnInteractProtectionComponent>(args.User, out var protectiveComp))
protectiveEntity = (args.User, protectiveComp);
// if protectiveComp isn't null after all that, it means the user has protection,
// so let's calculate how much they resist
@@ -75,9 +75,9 @@ public sealed class DamageOnInteractSystem : EntitySystem
}
}
totalDamage = _damageableSystem.TryChangeDamage(args.User, totalDamage, origin: args.Target);
totalDamage = _damageableSystem.ChangeDamage(args.User, totalDamage, origin: args.Target);
if (totalDamage != null && totalDamage.AnyPositive())
if (totalDamage.AnyPositive())
{
// Record this interaction and determine when a user is allowed to interact with this entity again
entity.Comp.LastInteraction = _gameTiming.CurTime;

View File

@@ -0,0 +1,235 @@
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;
namespace Content.Shared.Damage.Systems;
public sealed partial class DamageableSystem
{
/// <summary>
/// Directly sets the damage specifier of a damageable component.
/// </summary>
/// <remarks>
/// Useful for some unfriendly folk. Also ensures that cached values are updated and that a damage changed
/// event is raised.
/// </remarks>
public void SetDamage(Entity<DamageableComponent?> ent, DamageSpecifier damage)
{
if (!_damageableQuery.Resolve(ent, ref ent.Comp, false))
return;
ent.Comp.Damage = damage;
OnEntityDamageChanged((ent, ent.Comp));
}
/// <summary>
/// Applies damage specified via a <see cref="DamageSpecifier"/>.
/// </summary>
/// <remarks>
/// <see cref="DamageSpecifier"/> is effectively just a dictionary of damage types and damage values. This
/// function just applies the container's resistances (unless otherwise specified) and then changes the
/// stored damage data. Division of group damage into types is managed by <see cref="DamageSpecifier"/>.
/// </remarks>
/// <returns>
/// If the attempt was successful or not.
/// </returns>
public bool TryChangeDamage(
Entity<DamageableComponent?> ent,
DamageSpecifier damage,
bool ignoreResistances = false,
bool interruptsDoAfters = true,
EntityUid? origin = null,
bool ignoreGlobalModifiers = false
)
{
//! Empty just checks if the DamageSpecifier is _literally_ empty, as in, is internal dictionary of damage types is empty.
// If you deal 0.0 of some damage type, Empty will be false!
return !TryChangeDamage(ent, damage, out _, ignoreResistances, interruptsDoAfters, origin, ignoreGlobalModifiers);
}
/// <summary>
/// Applies damage specified via a <see cref="DamageSpecifier"/>.
/// </summary>
/// <remarks>
/// <see cref="DamageSpecifier"/> is effectively just a dictionary of damage types and damage values. This
/// function just applies the container's resistances (unless otherwise specified) and then changes the
/// stored damage data. Division of group damage into types is managed by <see cref="DamageSpecifier"/>.
/// </remarks>
/// <returns>
/// If the attempt was successful or not.
/// </returns>
public bool TryChangeDamage(
Entity<DamageableComponent?> ent,
DamageSpecifier damage,
out DamageSpecifier newDamage,
bool ignoreResistances = false,
bool interruptsDoAfters = true,
EntityUid? origin = null,
bool ignoreGlobalModifiers = false
)
{
//! Empty just checks if the DamageSpecifier is _literally_ empty, as in, is internal dictionary of damage types is empty.
// If you deal 0.0 of some damage type, Empty will be false!
newDamage = ChangeDamage(ent, damage, ignoreResistances, interruptsDoAfters, origin, ignoreGlobalModifiers);
return !damage.Empty;
}
/// <summary>
/// Applies damage specified via a <see cref="DamageSpecifier"/>.
/// </summary>
/// <remarks>
/// <see cref="DamageSpecifier"/> is effectively just a dictionary of damage types and damage values. This
/// function just applies the container's resistances (unless otherwise specified) and then changes the
/// stored damage data. Division of group damage into types is managed by <see cref="DamageSpecifier"/>.
/// </remarks>
/// <returns>
/// The actual amount of damage taken, as a DamageSpecifier.
/// </returns>
public DamageSpecifier ChangeDamage(
Entity<DamageableComponent?> ent,
DamageSpecifier damage,
bool ignoreResistances = false,
bool interruptsDoAfters = true,
EntityUid? origin = null,
bool ignoreGlobalModifiers = false
)
{
var damageDone = new DamageSpecifier();
if (!_damageableQuery.Resolve(ent, ref ent.Comp, false))
return damageDone;
if (damage.Empty)
return damageDone;
var before = new BeforeDamageChangedEvent(damage, origin);
RaiseLocalEvent(ent, ref before);
if (before.Cancelled)
return damageDone;
// Apply resistances
if (!ignoreResistances)
{
if (
ent.Comp.DamageModifierSetId != null &&
_prototypeManager.Resolve(ent.Comp.DamageModifierSetId, out var modifierSet)
)
damage = DamageSpecifier.ApplyModifierSet(damage, modifierSet);
// TODO DAMAGE
// byref struct event.
var ev = new DamageModifyEvent(damage, origin);
RaiseLocalEvent(ent, ev);
damage = ev.Damage;
if (damage.Empty)
return damageDone;
}
if (!ignoreGlobalModifiers)
damage = ApplyUniversalAllModifiers(damage);
damageDone.DamageDict.EnsureCapacity(damage.DamageDict.Count);
var dict = ent.Comp.Damage.DamageDict;
foreach (var (type, value) in damage.DamageDict)
{
// CollectionsMarshal my beloved.
if (!dict.TryGetValue(type, out var oldValue))
continue;
var newValue = FixedPoint2.Max(FixedPoint2.Zero, oldValue + value);
if (newValue == oldValue)
continue;
dict[type] = newValue;
damageDone.DamageDict[type] = newValue - oldValue;
}
if (!damageDone.Empty)
OnEntityDamageChanged((ent, ent.Comp), damageDone, interruptsDoAfters, origin);
return damageDone;
}
/// <summary>
/// Applies the two universal "All" modifiers, if set.
/// Individual damage source modifiers are set in their respective code.
/// </summary>
/// <param name="damage">The damage to be changed.</param>
public DamageSpecifier ApplyUniversalAllModifiers(DamageSpecifier damage)
{
// Checks for changes first since they're unlikely in normal play.
if (
MathHelper.CloseToPercent(UniversalAllDamageModifier, 1f) &&
MathHelper.CloseToPercent(UniversalAllHealModifier, 1f)
)
return damage;
foreach (var (key, value) in damage.DamageDict)
{
if (value == 0)
continue;
if (value > 0)
{
damage.DamageDict[key] *= UniversalAllDamageModifier;
continue;
}
if (value < 0)
damage.DamageDict[key] *= UniversalAllHealModifier;
}
return damage;
}
public void ClearAllDamage(Entity<DamageableComponent?> ent)
{
SetAllDamage(ent, FixedPoint2.Zero);
}
/// <summary>
/// Sets all damage types supported by a <see cref="Components.DamageableComponent"/> to the specified value.
/// </summary>
/// <remarks>
/// Does nothing If the given damage value is negative.
/// </remarks>
public void SetAllDamage(Entity<DamageableComponent?> ent, FixedPoint2 newValue)
{
if (!_damageableQuery.Resolve(ent, ref ent.Comp, false))
return;
if (newValue < 0)
return;
foreach (var type in ent.Comp.Damage.DamageDict.Keys)
{
ent.Comp.Damage.DamageDict[type] = newValue;
}
// Setting damage does not count as 'dealing' damage, even if it is set to a larger value, so we pass an
// empty damage delta.
OnEntityDamageChanged((ent, ent.Comp), new DamageSpecifier());
}
/// <summary>
/// Set's the damage modifier set prototype for this entity.
/// </summary>
/// <param name="ent">The entity we're setting the modifier set of.</param>
/// <param name="damageModifierSetId">The prototype we're setting.</param>
public void SetDamageModifierSetId(Entity<DamageableComponent?> ent, ProtoId<DamageModifierSetPrototype>? damageModifierSetId)
{
if (!_damageableQuery.Resolve(ent, ref ent.Comp, false))
return;
ent.Comp.DamageModifierSetId = damageModifierSetId;
Dirty(ent);
}
}

View File

@@ -1,4 +1,6 @@
namespace Content.Shared.Damage;
using Content.Shared.Damage.Components;
namespace Content.Shared.Damage.Systems;
public sealed partial class DamageableSystem
{
@@ -9,7 +11,7 @@ public sealed partial class DamageableSystem
{
foreach (var (uid, damageable) in damageables)
{
TryChangeDamage(uid, damage, damageable: damageable);
TryChangeDamage((uid, damageable), damage);
}
}
}

View File

@@ -0,0 +1,290 @@
using Content.Shared.CCVar;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Content.Shared.Inventory;
using Content.Shared.Radiation.Events;
using Content.Shared.Rejuvenate;
using Robust.Shared.GameStates;
namespace Content.Shared.Damage.Systems;
public sealed partial class DamageableSystem
{
public override void Initialize()
{
SubscribeLocalEvent<DamageableComponent, ComponentInit>(DamageableInit);
SubscribeLocalEvent<DamageableComponent, ComponentHandleState>(DamageableHandleState);
SubscribeLocalEvent<DamageableComponent, ComponentGetState>(DamageableGetState);
SubscribeLocalEvent<DamageableComponent, OnIrradiatedEvent>(OnIrradiated);
SubscribeLocalEvent<DamageableComponent, RejuvenateEvent>(OnRejuvenate);
_appearanceQuery = GetEntityQuery<AppearanceComponent>();
_damageableQuery = GetEntityQuery<DamageableComponent>();
// Damage modifier CVars are updated and stored here to be queried in other systems.
// Note that certain modifiers requires reloading the guidebook.
Subs.CVar(
_config,
CCVars.PlaytestAllDamageModifier,
value =>
{
UniversalAllDamageModifier = value;
_chemistryGuideData.ReloadAllReagentPrototypes();
_explosion.ReloadMap();
},
true
);
Subs.CVar(
_config,
CCVars.PlaytestAllHealModifier,
value =>
{
UniversalAllHealModifier = value;
_chemistryGuideData.ReloadAllReagentPrototypes();
},
true
);
Subs.CVar(
_config,
CCVars.PlaytestProjectileDamageModifier,
value => UniversalProjectileDamageModifier = value,
true
);
Subs.CVar(
_config,
CCVars.PlaytestMeleeDamageModifier,
value => UniversalMeleeDamageModifier = value,
true
);
Subs.CVar(
_config,
CCVars.PlaytestProjectileDamageModifier,
value => UniversalProjectileDamageModifier = value,
true
);
Subs.CVar(
_config,
CCVars.PlaytestHitscanDamageModifier,
value => UniversalHitscanDamageModifier = value,
true
);
Subs.CVar(
_config,
CCVars.PlaytestReagentDamageModifier,
value =>
{
UniversalReagentDamageModifier = value;
_chemistryGuideData.ReloadAllReagentPrototypes();
},
true
);
Subs.CVar(
_config,
CCVars.PlaytestReagentHealModifier,
value =>
{
UniversalReagentHealModifier = value;
_chemistryGuideData.ReloadAllReagentPrototypes();
},
true
);
Subs.CVar(
_config,
CCVars.PlaytestExplosionDamageModifier,
value =>
{
UniversalExplosionDamageModifier = value;
_explosion.ReloadMap();
},
true
);
Subs.CVar(
_config,
CCVars.PlaytestThrownDamageModifier,
value => UniversalThrownDamageModifier = value,
true
);
Subs.CVar(
_config,
CCVars.PlaytestTopicalsHealModifier,
value => UniversalTopicalsHealModifier = value,
true
);
Subs.CVar(
_config,
CCVars.PlaytestMobDamageModifier,
value => UniversalMobDamageModifier = value,
true
);
}
/// <summary>
/// Initialize a damageable component
/// </summary>
private void DamageableInit(Entity<DamageableComponent> ent, ref ComponentInit _)
{
if (
ent.Comp.DamageContainerID is null ||
!_prototypeManager.Resolve(ent.Comp.DamageContainerID, out var damageContainerPrototype)
)
{
// No DamageContainerPrototype was given. So we will allow the container to support all damage types
foreach (var type in _prototypeManager.EnumeratePrototypes<DamageTypePrototype>())
{
ent.Comp.Damage.DamageDict.TryAdd(type.ID, FixedPoint2.Zero);
}
}
else
{
// Initialize damage dictionary, using the types and groups from the damage
// container prototype
foreach (var type in damageContainerPrototype.SupportedTypes)
{
ent.Comp.Damage.DamageDict.TryAdd(type, FixedPoint2.Zero);
}
foreach (var groupId in damageContainerPrototype.SupportedGroups)
{
var group = _prototypeManager.Index(groupId);
foreach (var type in group.DamageTypes)
{
ent.Comp.Damage.DamageDict.TryAdd(type, FixedPoint2.Zero);
}
}
}
ent.Comp.Damage.GetDamagePerGroup(_prototypeManager, ent.Comp.DamagePerGroup);
ent.Comp.TotalDamage = ent.Comp.Damage.GetTotal();
}
private void OnIrradiated(Entity<DamageableComponent> ent, ref OnIrradiatedEvent args)
{
var damageValue = FixedPoint2.New(args.TotalRads);
// Radiation should really just be a damage group instead of a list of types.
DamageSpecifier damage = new();
foreach (var typeId in ent.Comp.RadiationDamageTypeIDs)
{
damage.DamageDict.Add(typeId, damageValue);
}
ChangeDamage(ent.Owner, damage, interruptsDoAfters: false, origin: args.Origin);
}
private void OnRejuvenate(Entity<DamageableComponent> ent, ref RejuvenateEvent args)
{
// Do this so that the state changes when we set the damage
_mobThreshold.SetAllowRevives(ent, true);
ClearAllDamage(ent.AsNullable());
_mobThreshold.SetAllowRevives(ent, false);
}
private void DamageableHandleState(Entity<DamageableComponent> ent, ref ComponentHandleState args)
{
if (args.Current is not DamageableComponentState state)
return;
ent.Comp.DamageContainerID = state.DamageContainerId;
ent.Comp.DamageModifierSetId = state.ModifierSetId;
ent.Comp.HealthBarThreshold = state.HealthBarThreshold;
// Has the damage actually changed?
DamageSpecifier newDamage = new() { DamageDict = new Dictionary<string, FixedPoint2>(state.DamageDict) };
var delta = newDamage - ent.Comp.Damage;
delta.TrimZeros();
if (delta.Empty)
return;
ent.Comp.Damage = newDamage;
OnEntityDamageChanged(ent, delta);
}
}
/// <summary>
/// Raised before damage is done, so stuff can cancel it if necessary.
/// </summary>
[ByRefEvent]
public record struct BeforeDamageChangedEvent(DamageSpecifier Damage, EntityUid? Origin = null, bool Cancelled = false);
/// <summary>
/// Raised on an entity when damage is about to be dealt,
/// in case anything else needs to modify it other than the base
/// damageable component.
///
/// For example, armor.
/// </summary>
public sealed class DamageModifyEvent(DamageSpecifier damage, EntityUid? origin = null)
: EntityEventArgs, IInventoryRelayEvent
{
// Whenever locational damage is a thing, this should just check only that bit of armour.
public SlotFlags TargetSlots => ~SlotFlags.POCKET;
public readonly DamageSpecifier OriginalDamage = damage;
public DamageSpecifier Damage = damage;
}
public sealed class DamageChangedEvent : EntityEventArgs
{
/// <summary>
/// This is the component whose damage was changed.
/// </summary>
/// <remarks>
/// Given that nearly every component that cares about a change in the damage, needs to know the
/// current damage values, directly passing this information prevents a lot of duplicate
/// Owner.TryGetComponent() calls.
/// </remarks>
public readonly DamageableComponent Damageable;
/// <summary>
/// The amount by which the damage has changed. If the damage was set directly to some number, this will be
/// null.
/// </summary>
public readonly DamageSpecifier? DamageDelta;
/// <summary>
/// Was any of the damage change dealing damage, or was it all healing?
/// </summary>
public readonly bool DamageIncreased;
/// <summary>
/// Does this event interrupt DoAfters?
/// Note: As provided in the constructor, this *does not* account for DamageIncreased.
/// As written into the event, this *does* account for DamageIncreased.
/// </summary>
public readonly bool InterruptsDoAfters;
/// <summary>
/// Contains the entity which caused the change in damage, if any was responsible.
/// </summary>
public readonly EntityUid? Origin;
public DamageChangedEvent(
DamageableComponent damageable,
DamageSpecifier? damageDelta,
bool interruptsDoAfters,
EntityUid? origin
)
{
Damageable = damageable;
DamageDelta = damageDelta;
Origin = origin;
if (DamageDelta is null)
return;
foreach (var damageChange in DamageDelta.DamageDict.Values)
{
if (damageChange <= 0)
continue;
DamageIncreased = true;
break;
}
InterruptsDoAfters = interruptsDoAfters && DamageIncreased;
}
}

View File

@@ -1,469 +1,97 @@
using System.Linq;
using Content.Shared.CCVar;
using Content.Shared.Chemistry;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Damage.Components;
using Content.Shared.Explosion.EntitySystems;
using Content.Shared.FixedPoint;
using Content.Shared.Inventory;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Radiation.Events;
using Content.Shared.Rejuvenate;
using Robust.Shared.Configuration;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Damage
namespace Content.Shared.Damage.Systems;
public sealed partial class DamageableSystem : EntitySystem
{
public sealed partial class DamageableSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly SharedChemistryGuideDataSystem _chemistryGuideData = default!;
[Dependency] private readonly SharedExplosionSystem _explosion = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly SharedChemistryGuideDataSystem _chemistryGuideData = default!;
[Dependency] private readonly SharedExplosionSystem _explosion = default!;
private EntityQuery<AppearanceComponent> _appearanceQuery;
private EntityQuery<DamageableComponent> _damageableQuery;
private EntityQuery<AppearanceComponent> _appearanceQuery;
private EntityQuery<DamageableComponent> _damageableQuery;
public float UniversalAllDamageModifier { get; private set; } = 1f;
public float UniversalAllHealModifier { get; private set; } = 1f;
public float UniversalMeleeDamageModifier { get; private set; } = 1f;
public float UniversalProjectileDamageModifier { get; private set; } = 1f;
public float UniversalHitscanDamageModifier { get; private set; } = 1f;
public float UniversalReagentDamageModifier { get; private set; } = 1f;
public float UniversalReagentHealModifier { get; private set; } = 1f;
public float UniversalExplosionDamageModifier { get; private set; } = 1f;
public float UniversalThrownDamageModifier { get; private set; } = 1f;
public float UniversalTopicalsHealModifier { get; private set; } = 1f;
public float UniversalMobDamageModifier { get; private set; } = 1f;
public override void Initialize()
{
SubscribeLocalEvent<DamageableComponent, ComponentInit>(DamageableInit);
SubscribeLocalEvent<DamageableComponent, ComponentHandleState>(DamageableHandleState);
SubscribeLocalEvent<DamageableComponent, ComponentGetState>(DamageableGetState);
SubscribeLocalEvent<DamageableComponent, OnIrradiatedEvent>(OnIrradiated);
SubscribeLocalEvent<DamageableComponent, RejuvenateEvent>(OnRejuvenate);
_appearanceQuery = GetEntityQuery<AppearanceComponent>();
_damageableQuery = GetEntityQuery<DamageableComponent>();
// Damage modifier CVars are updated and stored here to be queried in other systems.
// Note that certain modifiers requires reloading the guidebook.
Subs.CVar(_config, CCVars.PlaytestAllDamageModifier, value =>
{
UniversalAllDamageModifier = value;
_chemistryGuideData.ReloadAllReagentPrototypes();
_explosion.ReloadMap();
}, true);
Subs.CVar(_config, CCVars.PlaytestAllHealModifier, value =>
{
UniversalAllHealModifier = value;
_chemistryGuideData.ReloadAllReagentPrototypes();
}, true);
Subs.CVar(_config, CCVars.PlaytestProjectileDamageModifier, value => UniversalProjectileDamageModifier = value, true);
Subs.CVar(_config, CCVars.PlaytestMeleeDamageModifier, value => UniversalMeleeDamageModifier = value, true);
Subs.CVar(_config, CCVars.PlaytestProjectileDamageModifier, value => UniversalProjectileDamageModifier = value, true);
Subs.CVar(_config, CCVars.PlaytestHitscanDamageModifier, value => UniversalHitscanDamageModifier = value, true);
Subs.CVar(_config, CCVars.PlaytestReagentDamageModifier, value =>
{
UniversalReagentDamageModifier = value;
_chemistryGuideData.ReloadAllReagentPrototypes();
}, true);
Subs.CVar(_config, CCVars.PlaytestReagentHealModifier, value =>
{
UniversalReagentHealModifier = value;
_chemistryGuideData.ReloadAllReagentPrototypes();
}, true);
Subs.CVar(_config, CCVars.PlaytestExplosionDamageModifier, value =>
{
UniversalExplosionDamageModifier = value;
_explosion.ReloadMap();
}, true);
Subs.CVar(_config, CCVars.PlaytestThrownDamageModifier, value => UniversalThrownDamageModifier = value, true);
Subs.CVar(_config, CCVars.PlaytestTopicalsHealModifier, value => UniversalTopicalsHealModifier = value, true);
Subs.CVar(_config, CCVars.PlaytestMobDamageModifier, value => UniversalMobDamageModifier = value, true);
}
/// <summary>
/// Initialize a damageable component
/// </summary>
private void DamageableInit(EntityUid uid, DamageableComponent component, ComponentInit _)
{
if (component.DamageContainerID != null &&
_prototypeManager.Resolve<DamageContainerPrototype>(component.DamageContainerID,
out var damageContainerPrototype))
{
// Initialize damage dictionary, using the types and groups from the damage
// container prototype
foreach (var type in damageContainerPrototype.SupportedTypes)
{
component.Damage.DamageDict.TryAdd(type, FixedPoint2.Zero);
}
foreach (var groupId in damageContainerPrototype.SupportedGroups)
{
var group = _prototypeManager.Index<DamageGroupPrototype>(groupId);
foreach (var type in group.DamageTypes)
{
component.Damage.DamageDict.TryAdd(type, FixedPoint2.Zero);
}
}
}
else
{
// No DamageContainerPrototype was given. So we will allow the container to support all damage types
foreach (var type in _prototypeManager.EnumeratePrototypes<DamageTypePrototype>())
{
component.Damage.DamageDict.TryAdd(type.ID, FixedPoint2.Zero);
}
}
component.Damage.GetDamagePerGroup(_prototypeManager, component.DamagePerGroup);
component.TotalDamage = component.Damage.GetTotal();
}
/// <summary>
/// Directly sets the damage specifier of a damageable component.
/// </summary>
/// <remarks>
/// Useful for some unfriendly folk. Also ensures that cached values are updated and that a damage changed
/// event is raised.
/// </remarks>
public void SetDamage(EntityUid uid, DamageableComponent damageable, DamageSpecifier damage)
{
damageable.Damage = damage;
DamageChanged(uid, damageable);
}
/// <summary>
/// If the damage in a DamageableComponent was changed, this function should be called.
/// </summary>
/// <remarks>
/// 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(EntityUid uid, DamageableComponent component, DamageSpecifier? damageDelta = null,
bool interruptsDoAfters = true, EntityUid? origin = null)
{
component.Damage.GetDamagePerGroup(_prototypeManager, component.DamagePerGroup);
component.TotalDamage = component.Damage.GetTotal();
Dirty(uid, component);
if (_appearanceQuery.TryGetComponent(uid, out var appearance) && damageDelta != null)
{
var data = new DamageVisualizerGroupData(component.DamagePerGroup.Keys.ToList());
_appearance.SetData(uid, DamageVisualizerKeys.DamageUpdateGroups, data, appearance);
}
// TODO DAMAGE
// byref struct event.
RaiseLocalEvent(uid, new DamageChangedEvent(component, damageDelta, interruptsDoAfters, origin));
}
/// <summary>
/// Applies damage specified via a <see cref="DamageSpecifier"/>.
/// </summary>
/// <remarks>
/// <see cref="DamageSpecifier"/> is effectively just a dictionary of damage types and damage values. This
/// function just applies the container's resistances (unless otherwise specified) and then changes the
/// stored damage data. Division of group damage into types is managed by <see cref="DamageSpecifier"/>.
/// </remarks>
/// <returns>
/// 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>
/// <param name="ignoreResistances">If true, this will ignore the entity's damage modifier (<see cref="DamageableComponent.DamageModifierSetId"/> and skip raising a <see cref="DamageModifyEvent"/>.</param>
/// <param name="interruptsDoAfters">Whether the damage should cancel any damage sensitive do-afters</param>
/// <param name="origin">The entity that is causing this damage</param>
/// <param name="ignoreGlobalModifiers">If true, this will skip over applying the universal damage modifiers (see <see cref="ApplyUniversalAllModifiers"/>).</param>
/// <returns></returns>
public DamageSpecifier? TryChangeDamage(
EntityUid? uid,
DamageSpecifier damage,
bool ignoreResistances = false,
bool interruptsDoAfters = true,
DamageableComponent? damageable = null,
EntityUid? origin = null,
bool ignoreGlobalModifiers = false)
{
if (!uid.HasValue || !_damageableQuery.Resolve(uid.Value, ref damageable, false))
{
// TODO BODY SYSTEM pass damage onto body system
// BOBBY WHEN?
return null;
}
if (damage.Empty)
{
return damage;
}
var before = new BeforeDamageChangedEvent(damage, origin);
RaiseLocalEvent(uid.Value, ref before);
if (before.Cancelled)
return null;
// Apply resistances
if (!ignoreResistances)
{
if (damageable.DamageModifierSetId != null &&
_prototypeManager.Resolve(damageable.DamageModifierSetId, out var modifierSet))
{
damage = DamageSpecifier.ApplyModifierSet(damage, modifierSet);
}
// TODO DAMAGE
// byref struct event.
var ev = new DamageModifyEvent(damage, origin);
RaiseLocalEvent(uid.Value, ev);
damage = ev.Damage;
if (damage.Empty)
{
return damage;
}
}
if (!ignoreGlobalModifiers)
damage = ApplyUniversalAllModifiers(damage);
var delta = new DamageSpecifier();
delta.DamageDict.EnsureCapacity(damage.DamageDict.Count);
var dict = damageable.Damage.DamageDict;
foreach (var (type, value) in damage.DamageDict)
{
// CollectionsMarshal my beloved.
if (!dict.TryGetValue(type, out var oldValue))
continue;
var newValue = FixedPoint2.Max(FixedPoint2.Zero, oldValue + value);
if (newValue == oldValue)
continue;
dict[type] = newValue;
delta.DamageDict[type] = newValue - oldValue;
}
if (delta.DamageDict.Count > 0)
DamageChanged(uid.Value, damageable, delta, interruptsDoAfters, origin);
return delta;
}
/// <summary>
/// Applies the two univeral "All" modifiers, if set.
/// Individual damage source modifiers are set in their respective code.
/// </summary>
/// <param name="damage">The damage to be changed.</param>
public DamageSpecifier ApplyUniversalAllModifiers(DamageSpecifier damage)
{
// Checks for changes first since they're unlikely in normal play.
if (UniversalAllDamageModifier == 1f && UniversalAllHealModifier == 1f)
return damage;
foreach (var (key, value) in damage.DamageDict)
{
if (value == 0)
continue;
if (value > 0)
{
damage.DamageDict[key] *= UniversalAllDamageModifier;
continue;
}
if (value < 0)
{
damage.DamageDict[key] *= UniversalAllHealModifier;
}
}
return damage;
}
/// <summary>
/// Sets all damage types supported by a <see cref="DamageableComponent"/> to the specified value.
/// </summary>
/// <remakrs>
/// Does nothing If the given damage value is negative.
/// </remakrs>
public void SetAllDamage(EntityUid uid, DamageableComponent component, FixedPoint2 newValue)
{
if (newValue < 0)
{
// invalid value
return;
}
foreach (var type in component.Damage.DamageDict.Keys)
{
component.Damage.DamageDict[type] = newValue;
}
// 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(uid, component, new DamageSpecifier());
}
public void SetDamageModifierSetId(EntityUid uid, string? damageModifierSetId, DamageableComponent? comp = null)
{
if (!_damageableQuery.Resolve(uid, ref comp))
return;
comp.DamageModifierSetId = damageModifierSetId;
Dirty(uid, comp);
}
private void DamageableGetState(EntityUid uid, DamageableComponent component, ref ComponentGetState args)
{
if (_netMan.IsServer)
{
args.State = new DamageableComponentState(component.Damage.DamageDict, component.DamageContainerID, component.DamageModifierSetId, component.HealthBarThreshold);
}
else
{
// avoid mispredicting damage on newly spawned entities.
args.State = new DamageableComponentState(component.Damage.DamageDict.ShallowClone(), component.DamageContainerID, component.DamageModifierSetId, component.HealthBarThreshold);
}
}
private void OnIrradiated(EntityUid uid, DamageableComponent component, OnIrradiatedEvent args)
{
var damageValue = FixedPoint2.New(args.TotalRads);
// Radiation should really just be a damage group instead of a list of types.
DamageSpecifier damage = new();
foreach (var typeId in component.RadiationDamageTypeIDs)
{
damage.DamageDict.Add(typeId, damageValue);
}
TryChangeDamage(uid, damage, interruptsDoAfters: false, origin: args.Origin);
}
private void OnRejuvenate(EntityUid uid, DamageableComponent component, RejuvenateEvent args)
{
TryComp<MobThresholdsComponent>(uid, out var thresholds);
_mobThreshold.SetAllowRevives(uid, true, thresholds); // do this so that the state changes when we set the damage
SetAllDamage(uid, component, 0);
_mobThreshold.SetAllowRevives(uid, false, thresholds);
}
private void DamageableHandleState(EntityUid uid, DamageableComponent component, ref ComponentHandleState args)
{
if (args.Current is not DamageableComponentState state)
{
return;
}
component.DamageContainerID = state.DamageContainerId;
component.DamageModifierSetId = state.ModifierSetId;
component.HealthBarThreshold = state.HealthBarThreshold;
// Has the damage actually changed?
DamageSpecifier newDamage = new() { DamageDict = new(state.DamageDict) };
var delta = newDamage - component.Damage;
delta.TrimZeros();
if (!delta.Empty)
{
component.Damage = newDamage;
DamageChanged(uid, component, delta);
}
}
}
public float UniversalAllDamageModifier { get; private set; } = 1f;
public float UniversalAllHealModifier { get; private set; } = 1f;
public float UniversalMeleeDamageModifier { get; private set; } = 1f;
public float UniversalProjectileDamageModifier { get; private set; } = 1f;
public float UniversalHitscanDamageModifier { get; private set; } = 1f;
public float UniversalReagentDamageModifier { get; private set; } = 1f;
public float UniversalReagentHealModifier { get; private set; } = 1f;
public float UniversalExplosionDamageModifier { get; private set; } = 1f;
public float UniversalThrownDamageModifier { get; private set; } = 1f;
public float UniversalTopicalsHealModifier { get; private set; } = 1f;
public float UniversalMobDamageModifier { get; private set; } = 1f;
/// <summary>
/// Raised before damage is done, so stuff can cancel it if necessary.
/// If the damage in a DamageableComponent was changed this function should be called.
/// </summary>
[ByRefEvent]
public record struct BeforeDamageChangedEvent(DamageSpecifier Damage, EntityUid? Origin = null, bool Cancelled = false);
/// <summary>
/// Raised on an entity when damage is about to be dealt,
/// in case anything else needs to modify it other than the base
/// damageable component.
///
/// For example, armor.
/// </summary>
public sealed class DamageModifyEvent : EntityEventArgs, IInventoryRelayEvent
/// <remarks>
/// 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>
private void OnEntityDamageChanged(
Entity<DamageableComponent> ent,
DamageSpecifier? damageDelta = null,
bool interruptsDoAfters = true,
EntityUid? origin = null
)
{
// Whenever locational damage is a thing, this should just check only that bit of armour.
public SlotFlags TargetSlots { get; } = ~SlotFlags.POCKET;
ent.Comp.Damage.GetDamagePerGroup(_prototypeManager, ent.Comp.DamagePerGroup);
ent.Comp.TotalDamage = ent.Comp.Damage.GetTotal();
Dirty(ent);
public readonly DamageSpecifier OriginalDamage;
public DamageSpecifier Damage;
public EntityUid? Origin;
public DamageModifyEvent(DamageSpecifier damage, EntityUid? origin = null)
if (damageDelta != null && _appearanceQuery.TryGetComponent(ent, out var appearance))
{
OriginalDamage = damage;
Damage = damage;
Origin = origin;
_appearance.SetData(
ent,
DamageVisualizerKeys.DamageUpdateGroups,
new DamageVisualizerGroupData(ent.Comp.DamagePerGroup.Keys.ToList()),
appearance
);
}
// TODO DAMAGE
// byref struct event.
RaiseLocalEvent(ent, new DamageChangedEvent(ent.Comp, damageDelta, interruptsDoAfters, origin));
}
public sealed class DamageChangedEvent : EntityEventArgs
private void DamageableGetState(Entity<DamageableComponent> ent, ref ComponentGetState args)
{
/// <summary>
/// This is the component whose damage was changed.
/// </summary>
/// <remarks>
/// Given that nearly every component that cares about a change in the damage, needs to know the
/// current damage values, directly passing this information prevents a lot of duplicate
/// Owner.TryGetComponent() calls.
/// </remarks>
public readonly DamageableComponent Damageable;
/// <summary>
/// The amount by which the damage has changed. If the damage was set directly to some number, this will be
/// null.
/// </summary>
public readonly DamageSpecifier? DamageDelta;
/// <summary>
/// Was any of the damage change dealing damage, or was it all healing?
/// </summary>
public readonly bool DamageIncreased;
/// <summary>
/// Does this event interrupt DoAfters?
/// Note: As provided in the constructor, this *does not* account for DamageIncreased.
/// As written into the event, this *does* account for DamageIncreased.
/// </summary>
public readonly bool InterruptsDoAfters;
/// <summary>
/// Contains the entity which caused the change in damage, if any was responsible.
/// </summary>
public readonly EntityUid? Origin;
public DamageChangedEvent(DamageableComponent damageable, DamageSpecifier? damageDelta, bool interruptsDoAfters, EntityUid? origin)
if (_netMan.IsServer)
{
Damageable = damageable;
DamageDelta = damageDelta;
Origin = origin;
args.State = new DamageableComponentState(
ent.Comp.Damage.DamageDict,
ent.Comp.DamageContainerID,
ent.Comp.DamageModifierSetId,
ent.Comp.HealthBarThreshold
);
// TODO BODY SYSTEM pass damage onto body system
// BOBBY WHEN? 😭
// BOBBY SOON 🫡
if (DamageDelta == null)
return;
foreach (var damageChange in DamageDelta.DamageDict.Values)
{
if (damageChange > 0)
{
DamageIncreased = true;
break;
}
}
InterruptsDoAfters = interruptsDoAfters && DamageIncreased;
return;
}
// avoid mispredicting damage on newly spawned entities.
args.State = new DamageableComponentState(
ent.Comp.Damage.DamageDict.ShallowClone(),
ent.Comp.DamageContainerID,
ent.Comp.DamageModifierSetId,
ent.Comp.HealthBarThreshold
);
}
}

View File

@@ -1,10 +1,8 @@
using Content.Shared.Damage.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Mobs.Components;
using Content.Shared.FixedPoint;
using Robust.Shared.Timing;
namespace Content.Shared.Damage;
namespace Content.Shared.Damage.Systems;
public sealed class PassiveDamageSystem : EntitySystem
{
@@ -47,7 +45,7 @@ public sealed class PassiveDamageSystem : EntitySystem
foreach (var allowedState in comp.AllowedStates)
{
if(allowedState == mobState.CurrentState)
_damageable.TryChangeDamage(uid, comp.Damage, true, false, damage);
_damageable.ChangeDamage((uid, damage), comp.Damage, true, false);
}
}
}

View File

@@ -1,10 +1,11 @@
using Content.Shared.Damage.Components;
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Standing;
using Robust.Shared.Physics.Events;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Containers;
using Robust.Shared.Physics.Events;
namespace Content.Shared.Damage.Components;
namespace Content.Shared.Damage.Systems;
public sealed class RequireProjectileTargetSystem : EntitySystem
{

View File

@@ -85,9 +85,9 @@ public abstract class SharedGodmodeSystem : EntitySystem
if (!Resolve(uid, ref godmode, false))
return;
if (TryComp<DamageableComponent>(uid, out var damageable) && godmode.OldDamage != null)
if (godmode.OldDamage != null)
{
_damageable.SetDamage(uid, damageable, godmode.OldDamage);
_damageable.SetDamage(uid, godmode.OldDamage);
}
RemComp<GodmodeComponent>(uid);

View File

@@ -5,109 +5,108 @@ using Content.Shared.FixedPoint;
using Content.Shared.Inventory;
using Content.Shared.Movement.Systems;
namespace Content.Shared.Damage
namespace Content.Shared.Damage.Systems;
public sealed class SlowOnDamageSystem : EntitySystem
{
public sealed class SlowOnDamageSystem : EntitySystem
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!;
public override void Initialize()
{
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!;
base.Initialize();
public override void Initialize()
SubscribeLocalEvent<SlowOnDamageComponent, DamageChangedEvent>(OnDamageChanged);
SubscribeLocalEvent<SlowOnDamageComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<ClothingSlowOnDamageModifierComponent, InventoryRelayedEvent<ModifySlowOnDamageSpeedEvent>>(OnModifySpeed);
SubscribeLocalEvent<ClothingSlowOnDamageModifierComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<ClothingSlowOnDamageModifierComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<ClothingSlowOnDamageModifierComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<IgnoreSlowOnDamageComponent, ComponentStartup>(OnIgnoreStartup);
SubscribeLocalEvent<IgnoreSlowOnDamageComponent, ComponentShutdown>(OnIgnoreShutdown);
SubscribeLocalEvent<IgnoreSlowOnDamageComponent, ModifySlowOnDamageSpeedEvent>(OnIgnoreModifySpeed);
}
private void OnRefreshMovespeed(EntityUid uid, SlowOnDamageComponent component, RefreshMovementSpeedModifiersEvent args)
{
if (!TryComp<DamageableComponent>(uid, out var damage))
return;
if (damage.TotalDamage == FixedPoint2.Zero)
return;
// Get closest threshold
FixedPoint2 closest = FixedPoint2.Zero;
var total = damage.TotalDamage;
foreach (var thres in component.SpeedModifierThresholds)
{
base.Initialize();
SubscribeLocalEvent<SlowOnDamageComponent, DamageChangedEvent>(OnDamageChanged);
SubscribeLocalEvent<SlowOnDamageComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<ClothingSlowOnDamageModifierComponent, InventoryRelayedEvent<ModifySlowOnDamageSpeedEvent>>(OnModifySpeed);
SubscribeLocalEvent<ClothingSlowOnDamageModifierComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<ClothingSlowOnDamageModifierComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<ClothingSlowOnDamageModifierComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<IgnoreSlowOnDamageComponent, ComponentStartup>(OnIgnoreStartup);
SubscribeLocalEvent<IgnoreSlowOnDamageComponent, ComponentShutdown>(OnIgnoreShutdown);
SubscribeLocalEvent<IgnoreSlowOnDamageComponent, ModifySlowOnDamageSpeedEvent>(OnIgnoreModifySpeed);
if (total >= thres.Key && thres.Key > closest)
closest = thres.Key;
}
private void OnRefreshMovespeed(EntityUid uid, SlowOnDamageComponent component, RefreshMovementSpeedModifiersEvent args)
if (closest != FixedPoint2.Zero)
{
if (!TryComp<DamageableComponent>(uid, out var damage))
return;
var speed = component.SpeedModifierThresholds[closest];
if (damage.TotalDamage == FixedPoint2.Zero)
return;
// Get closest threshold
FixedPoint2 closest = FixedPoint2.Zero;
var total = damage.TotalDamage;
foreach (var thres in component.SpeedModifierThresholds)
{
if (total >= thres.Key && thres.Key > closest)
closest = thres.Key;
}
if (closest != FixedPoint2.Zero)
{
var speed = component.SpeedModifierThresholds[closest];
var ev = new ModifySlowOnDamageSpeedEvent(speed);
RaiseLocalEvent(uid, ref ev);
args.ModifySpeed(ev.Speed, ev.Speed);
}
}
private void OnDamageChanged(EntityUid uid, SlowOnDamageComponent component, DamageChangedEvent args)
{
// We -could- only refresh if it crossed a threshold but that would kind of be a lot of duplicated
// code and this isn't a super hot path anyway since basically only humans have this
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(uid);
}
private void OnModifySpeed(Entity<ClothingSlowOnDamageModifierComponent> ent, ref InventoryRelayedEvent<ModifySlowOnDamageSpeedEvent> args)
{
var dif = 1 - args.Args.Speed;
if (dif <= 0)
return;
// reduces the slowness modifier by the given coefficient
args.Args.Speed += dif * ent.Comp.Modifier;
}
private void OnExamined(Entity<ClothingSlowOnDamageModifierComponent> ent, ref ExaminedEvent args)
{
var msg = Loc.GetString("slow-on-damage-modifier-examine", ("mod", (1 - ent.Comp.Modifier) * 100));
args.PushMarkup(msg);
}
private void OnGotEquipped(Entity<ClothingSlowOnDamageModifierComponent> ent, ref ClothingGotEquippedEvent args)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(args.Wearer);
}
private void OnGotUnequipped(Entity<ClothingSlowOnDamageModifierComponent> ent, ref ClothingGotUnequippedEvent args)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(args.Wearer);
}
private void OnIgnoreStartup(Entity<IgnoreSlowOnDamageComponent> ent, ref ComponentStartup args)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(ent);
}
private void OnIgnoreShutdown(Entity<IgnoreSlowOnDamageComponent> ent, ref ComponentShutdown args)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(ent);
}
private void OnIgnoreModifySpeed(Entity<IgnoreSlowOnDamageComponent> ent, ref ModifySlowOnDamageSpeedEvent args)
{
args.Speed = 1f;
var ev = new ModifySlowOnDamageSpeedEvent(speed);
RaiseLocalEvent(uid, ref ev);
args.ModifySpeed(ev.Speed, ev.Speed);
}
}
[ByRefEvent]
public record struct ModifySlowOnDamageSpeedEvent(float Speed) : IInventoryRelayEvent
private void OnDamageChanged(EntityUid uid, SlowOnDamageComponent component, DamageChangedEvent args)
{
public SlotFlags TargetSlots => SlotFlags.WITHOUT_POCKET;
// We -could- only refresh if it crossed a threshold but that would kind of be a lot of duplicated
// code and this isn't a super hot path anyway since basically only humans have this
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(uid);
}
private void OnModifySpeed(Entity<ClothingSlowOnDamageModifierComponent> ent, ref InventoryRelayedEvent<ModifySlowOnDamageSpeedEvent> args)
{
var dif = 1 - args.Args.Speed;
if (dif <= 0)
return;
// reduces the slowness modifier by the given coefficient
args.Args.Speed += dif * ent.Comp.Modifier;
}
private void OnExamined(Entity<ClothingSlowOnDamageModifierComponent> ent, ref ExaminedEvent args)
{
var msg = Loc.GetString("slow-on-damage-modifier-examine", ("mod", (1 - ent.Comp.Modifier) * 100));
args.PushMarkup(msg);
}
private void OnGotEquipped(Entity<ClothingSlowOnDamageModifierComponent> ent, ref ClothingGotEquippedEvent args)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(args.Wearer);
}
private void OnGotUnequipped(Entity<ClothingSlowOnDamageModifierComponent> ent, ref ClothingGotUnequippedEvent args)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(args.Wearer);
}
private void OnIgnoreStartup(Entity<IgnoreSlowOnDamageComponent> ent, ref ComponentStartup args)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(ent);
}
private void OnIgnoreShutdown(Entity<IgnoreSlowOnDamageComponent> ent, ref ComponentShutdown args)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(ent);
}
private void OnIgnoreModifySpeed(Entity<IgnoreSlowOnDamageComponent> ent, ref ModifySlowOnDamageSpeedEvent args)
{
args.Speed = 1f;
}
}
[ByRefEvent]
public record struct ModifySlowOnDamageSpeedEvent(float Speed) : IInventoryRelayEvent
{
public SlotFlags TargetSlots => SlotFlags.WITHOUT_POCKET;
}

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Destructible.Thresholds.Triggers;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.FixedPoint;
using Content.Shared.Damage.Prototypes;
using Robust.Shared.Prototypes;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.FixedPoint;
using Robust.Shared.Serialization;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
namespace Content.Shared.Destructible.Thresholds.Triggers;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Destructible.Thresholds.Triggers;

View File

@@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Content.Shared.ActionBlocker;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Hands.Components;
using Content.Shared.Tag;
using Robust.Shared.GameStates;

View File

@@ -2,7 +2,7 @@ using System.Linq;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Administration.Logs;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.Doors.Components;
using Content.Shared.Emag.Systems;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;

View File

@@ -1,4 +1,5 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;

View File

@@ -1,5 +1,7 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Damage.Systems;
using Content.Shared.FixedPoint;
using Content.Shared.Localizations;
using Robust.Shared.Prototypes;
@@ -43,11 +45,10 @@ public sealed partial class EvenHealthChangeEntityEffectSystem : EntityEffectSys
damageSpec *= args.Scale;
_damageable.TryChangeDamage(
entity,
entity.AsNullable(),
damageSpec,
args.Effect.IgnoreResistances,
interruptsDoAfters: false,
damageable: entity.Comp);
interruptsDoAfters: false);
}
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Content.Shared.Localizations;
@@ -13,7 +14,7 @@ namespace Content.Shared.EntityEffects.Effects;
/// <inheritdoc cref="EntityEffectSystem{T,TEffect}"/>
public sealed partial class HealthChangeEntityEffectSystem : EntityEffectSystem<DamageableComponent, HealthChange>
{
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly Damage.Systems.DamageableSystem _damageable = default!;
protected override void Effect(Entity<DamageableComponent> entity, ref EntityEffectEvent<HealthChange> args)
{
@@ -22,7 +23,7 @@ public sealed partial class HealthChangeEntityEffectSystem : EntityEffectSystem<
damageSpec *= args.Scale;
_damageable.TryChangeDamage(
entity,
entity.AsNullable(),
damageSpec,
args.Effect.IgnoreResistances,
interruptsDoAfters: false);
@@ -49,10 +50,10 @@ public sealed partial class HealthChange : EntityEffectBase<HealthChange>
var damageSpec = new DamageSpecifier(Damage);
var universalReagentDamageModifier = entSys.GetEntitySystem<DamageableSystem>().UniversalReagentDamageModifier;
var universalReagentHealModifier = entSys.GetEntitySystem<DamageableSystem>().UniversalReagentHealModifier;
var universalReagentDamageModifier = entSys.GetEntitySystem<Damage.Systems.DamageableSystem>().UniversalReagentDamageModifier;
var universalReagentHealModifier = entSys.GetEntitySystem<Damage.Systems.DamageableSystem>().UniversalReagentHealModifier;
damageSpec = entSys.GetEntitySystem<DamageableSystem>().ApplyUniversalAllModifiers(damageSpec);
damageSpec = entSys.GetEntitySystem<Damage.Systems.DamageableSystem>().ApplyUniversalAllModifiers(damageSpec);
foreach (var (kind, amount) in damageSpec.DamageDict)
{

View File

@@ -1,7 +1,7 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Chat;
using Content.Shared.CombatMode;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.IdentityManagement;
@@ -12,7 +12,6 @@ using Content.Shared.Verbs;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Interaction.Events;
using Content.Shared.Mind;
using Robust.Shared.Player;
using Robust.Shared.Audio.Systems;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Popups;
using Content.Shared.Fax.Components;
@@ -26,7 +26,7 @@ public sealed class FaxecuteSystem : EntitySystem
return;
var damageSpec = faxecute.Damage;
_damageable.TryChangeDamage(sendEntity, damageSpec);
_damageable.ChangeDamage(sendEntity.Value, damageSpec);
_popupSystem.PopupEntity(Loc.GetString("fax-machine-popup-error", ("target", uid)), uid, PopupType.LargeCaution);
return;

View File

@@ -1,5 +1,5 @@
using Content.Shared.Flash.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
namespace Content.Shared.Flash;
@@ -18,7 +18,7 @@ public sealed class DamagedByFlashingSystem : EntitySystem
// Best wait for Ed's status effect system rewrite.
private void OnFlashAttempt(Entity<DamagedByFlashingComponent> ent, ref FlashAttemptEvent args)
{
_damageable.TryChangeDamage(ent, ent.Comp.FlashDamage);
_damageable.ChangeDamage(ent.Owner, ent.Comp.FlashDamage);
// TODO: It would be more logical if different flashes had different power,
// and the damage would be inflicted depending on the strength of the flash.

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.IdentityManagement;

View File

@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Forensics;

View File

@@ -7,6 +7,7 @@ using Content.Shared.Climbing.Events;
using Content.Shared.Contraband;
using Content.Shared.Damage;
using Content.Shared.Damage.Events;
using Content.Shared.Damage.Systems;
using Content.Shared.Electrocution;
using Content.Shared.Explosion;
using Content.Shared.Eye.Blinding.Systems;

View File

@@ -1,6 +1,6 @@
using Content.Shared.Administration.Logs;
using Content.Shared.Body.Systems;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.Destructible;
using Content.Shared.DoAfter;
@@ -330,7 +330,7 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
{
EnsureComp<KitchenSpikeVictimComponent>(args.Target.Value);
_damageableSystem.TryChangeDamage(args.Target, ent.Comp.ButcherDamage, true);
_damageableSystem.ChangeDamage(args.Target.Value, ent.Comp.ButcherDamage, true);
// Log severity for damaging other entities is normally medium.
_logger.Add(LogType.Action,
@@ -428,7 +428,7 @@ public sealed class SharedKitchenSpikeSystem : EntitySystem
kitchenSpike.NextDamage += kitchenSpike.DamageInterval;
Dirty(uid, kitchenSpike);
_damageableSystem.TryChangeDamage(contained, kitchenSpike.TimeDamage, true);
_damageableSystem.ChangeDamage(contained.Value, kitchenSpike.TimeDamage, true);
}
}

View File

@@ -2,7 +2,8 @@ using Content.Shared.Administration.Logs;
using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.FixedPoint;
@@ -76,12 +77,10 @@ public sealed class HealingSystem : EntitySystem
if (healing.ModifyBloodLevel != 0 && bloodstream != null)
_bloodstreamSystem.TryModifyBloodLevel((target.Owner, bloodstream), healing.ModifyBloodLevel);
var healed = _damageable.TryChangeDamage(target.Owner, healing.Damage * _damageable.UniversalTopicalsHealModifier, true, origin: args.Args.User);
if (healed == null && healing.BloodlossModifier != 0)
if (!_damageable.TryChangeDamage(target.Owner, healing.Damage * _damageable.UniversalTopicalsHealModifier, out var healed, true, origin: args.Args.User) && healing.BloodlossModifier != 0)
return;
var total = healed?.GetTotal() ?? FixedPoint2.Zero;
var total = healed.GetTotal();
// Re-verify that we can heal the damage.
var dontRepeat = false;

View File

@@ -1,5 +1,5 @@
using Content.Shared.Actions;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.DoAfter;
using Content.Shared.FixedPoint;
using Content.Shared.Inventory;

View File

@@ -2,7 +2,7 @@ using System.Numerics;
using Content.Shared.Access.Systems;
using Content.Shared.ActionBlocker;
using Content.Shared.Clothing;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.DoAfter;
using Content.Shared.Emp;

View File

@@ -1,7 +1,6 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Mobs.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Mobs.Components
{

View File

@@ -3,6 +3,7 @@ using Content.Shared.Buckle.Components;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Damage;
using Content.Shared.Damage.ForceSay;
using Content.Shared.Damage.Systems;
using Content.Shared.Emoting;
using Content.Shared.Hands;
using Content.Shared.Interaction;

View File

@@ -1,9 +1,8 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Mobs.Components;
using Content.Shared.Standing;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Timing;
namespace Content.Shared.Mobs.Systems;

View File

@@ -2,6 +2,8 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.FixedPoint;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Events;

View File

@@ -1,16 +1,14 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Systems;
using Content.Shared.Nutrition.Components;
using Content.Shared.Rejuvenate;
using Content.Shared.StatusIcon;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Shared.Nutrition.EntitySystems;

View File

@@ -1,6 +1,5 @@
using Content.Shared.Actions;
using Content.Shared.Coordinates;
using Content.Shared.Damage;
using Content.Shared.Hands;
using Content.Shared.Interaction;
using Content.Shared.Item;
@@ -14,6 +13,7 @@ using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Damage.Systems;
namespace Content.Shared.Polymorph.Systems;

View File

@@ -1,5 +1,6 @@
using Content.Shared.Administration.Logs;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
@@ -32,14 +33,14 @@ public sealed partial class RepairableSystem : EntitySystem
if (ent.Comp.Damage != null)
{
var damageChanged = _damageableSystem.TryChangeDamage(ent.Owner, ent.Comp.Damage, true, false, origin: args.User);
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(ent.Owner):target} by {damageChanged?.GetTotal()}");
var damageChanged = _damageableSystem.ChangeDamage(ent.Owner, ent.Comp.Damage, true, false, origin: args.User);
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(ent.Owner):target} by {damageChanged.GetTotal()}");
}
else
{
// Repair all damage
_damageableSystem.SetAllDamage(ent.Owner, damageable, 0);
_damageableSystem.SetAllDamage((ent.Owner, damageable), 0);
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(ent.Owner):target} back to full health");
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Silicons.Borgs.Components;
namespace Content.Shared.Silicons.Borgs;

View File

@@ -1,5 +1,8 @@
using Robust.Shared.Audio.Systems;
using Robust.Shared.Serialization;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.DoAfter;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
@@ -8,9 +11,6 @@ using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.NPC.Components;
using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Serialization;
using System.Diagnostics.CodeAnalysis;
namespace Content.Shared.Silicons.Bots;

View File

@@ -1,5 +1,5 @@
using Content.Shared.Construction.EntitySystems;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Destructible;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;

View File

@@ -3,6 +3,7 @@ using Content.Shared.Buckle.Components;
using Content.Shared.CCVar;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Gravity;

View File

@@ -5,7 +5,7 @@ namespace Content.Shared.Trigger.Systems;
public sealed class DamageOnTriggerSystem : XOnTriggerSystem<DamageOnTriggerComponent>
{
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly Damage.Systems.DamageableSystem _damageableSystem = default!;
protected override void OnTrigger(Entity<DamageOnTriggerComponent> ent, EntityUid target, ref TriggerEvent args)
{
@@ -13,7 +13,7 @@ public sealed class DamageOnTriggerSystem : XOnTriggerSystem<DamageOnTriggerComp
var ev = new BeforeDamageOnTriggerEvent(damage, target);
RaiseLocalEvent(ent.Owner, ref ev);
args.Handled |= _damageableSystem.TryChangeDamage(target, ev.Damage, ent.Comp.IgnoreResistances, origin: ent.Owner) is not null;
args.Handled |= _damageableSystem.TryChangeDamage(target, ev.Damage, ent.Comp.IgnoreResistances, origin: ent.Owner);
}
}

View File

@@ -1,6 +1,6 @@
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Popups;
@@ -137,7 +137,7 @@ public abstract partial class SharedDeployableTurretSystem : EntitySystem
if (TryComp<DamageableComponent>(ent, out var damageable))
{
var damageSetID = enabled ? ent.Comp.DeployedDamageModifierSetId : ent.Comp.RetractedDamageModifierSetId;
_damageable.SetDamageModifierSetId(ent, damageSetID, damageable);
_damageable.SetDamageModifierSetId((ent, damageable), damageSetID);
}
// Change the turret's fixtures

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Weapons.Hitscan.Components;
using Content.Shared.Weapons.Hitscan.Events;
@@ -22,9 +22,7 @@ public sealed class HitscanBasicDamageSystem : EntitySystem
var dmg = ent.Comp.Damage * _damage.UniversalHitscanDamageModifier;
var damageDealt = _damage.TryChangeDamage(args.Data.HitEntity, dmg, origin: args.Data.Gun);
if (damageDealt == null)
if(!_damage.TryChangeDamage(args.Data.HitEntity.Value, dmg, out var damageDealt, origin: args.Data.Gun))
return;
var damageEvent = new HitscanDamageDealtEvent

View File

@@ -1,8 +1,8 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
using Robust.Shared.Physics.Events;

View File

@@ -7,6 +7,7 @@ using Content.Shared.Administration.Components;
using Content.Shared.Administration.Logs;
using Content.Shared.CombatMode;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
@@ -541,9 +542,8 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
RaiseLocalEvent(target.Value, attackedEvent);
var modifiedDamage = DamageSpecifier.ApplyModifierSets(damage + hitEvent.BonusDamage + attackedEvent.BonusDamage, hitEvent.ModifiersList);
var damageResult = Damageable.TryChangeDamage(target, modifiedDamage, origin:user, ignoreResistances:resistanceBypass);
if (damageResult is {Empty: false})
if (!Damageable.TryChangeDamage(target.Value, modifiedDamage, out var damageResult, origin:user, ignoreResistances:resistanceBypass))
{
// If the target has stamina and is taking blunt damage, they should also take stamina damage based on their blunt to stamina factor
if (damageResult.DamageDict.TryGetValue("Blunt", out var bluntDamage))
@@ -568,7 +568,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
_meleeSound.PlayHitSound(target.Value, user, GetHighestDamageSound(modifiedDamage, _protoManager), hitEvent.HitSoundOverride, component);
if (damageResult?.GetTotal() > FixedPoint2.Zero)
if (damageResult.GetTotal() > FixedPoint2.Zero)
{
DoDamageEffect(targets, user, targetXform);
}
@@ -697,9 +697,9 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
RaiseLocalEvent(entity, attackedEvent);
var modifiedDamage = DamageSpecifier.ApplyModifierSets(damage + hitEvent.BonusDamage + attackedEvent.BonusDamage, hitEvent.ModifiersList);
var damageResult = Damageable.TryChangeDamage(entity, modifiedDamage, origin: user, ignoreResistances: resistanceBypass);
var damageResult = Damageable.ChangeDamage(entity, modifiedDamage, origin: user, ignoreResistances: resistanceBypass);
if (damageResult != null && damageResult.GetTotal() > FixedPoint2.Zero)
if (damageResult.GetTotal() > FixedPoint2.Zero)
{
// If the target has stamina and is taking blunt damage, they should also take stamina damage based on their blunt to stamina factor
if (damageResult.DamageDict.TryGetValue("Blunt", out var bluntDamage))

View File

@@ -7,6 +7,7 @@ using Content.Shared.Audio;
using Content.Shared.CombatMode;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Examine;
using Content.Shared.Hands;
using Content.Shared.Hands.EntitySystems;

View File

@@ -1,6 +1,7 @@
using System.Linq;
using Content.Shared.Chemistry;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Movement.Pulling.Events;

View File

@@ -1,4 +1,5 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Whitelist;
using Content.Shared.Xenoarchaeology.Artifact.XAE.Components;
using Robust.Shared.Random;

View File

@@ -1,4 +1,5 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Xenoarchaeology.Artifact.Components;
using Content.Shared.Xenoarchaeology.Artifact.XAT.Components;
using Robust.Shared.Prototypes;

View File

@@ -1,4 +1,4 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Emag.Systems;
using Content.Shared.Examine;
using Content.Shared.Popups;