diff --git a/Content.Shared/Damage/Systems/DamageableSystem.API.cs b/Content.Shared/Damage/Systems/DamageableSystem.API.cs index c2a1374901..c5452eda7c 100644 --- a/Content.Shared/Damage/Systems/DamageableSystem.API.cs +++ b/Content.Shared/Damage/Systems/DamageableSystem.API.cs @@ -8,13 +8,41 @@ namespace Content.Shared.Damage.Systems; public sealed partial class DamageableSystem { /// - /// Directly sets the damage specifier of a damageable component. + /// Directly sets the damage in a damageable component. + /// This method keeps the damage types supported by the DamageContainerPrototype in the component. + /// If a type is given in , but not supported then it will not be set. + /// If a type is supported but not given in then it will be set to 0. /// /// /// Useful for some unfriendly folk. Also ensures that cached values are updated and that a damage changed /// event is raised. /// public void SetDamage(Entity ent, DamageSpecifier damage) + { + if (!_damageableQuery.Resolve(ent, ref ent.Comp, false)) + return; + + foreach (var type in ent.Comp.Damage.DamageDict.Keys) + { + if (damage.DamageDict.TryGetValue(type, out var value)) + ent.Comp.Damage.DamageDict[type] = value; + else + ent.Comp.Damage.DamageDict[type] = 0; + } + + OnEntityDamageChanged((ent, ent.Comp)); + } + + /// + /// Directly sets the damage specifier of a damageable component. + /// This will overwrite the complete damage dict, meaning it will bulldoze the supported damage types. + /// + /// + /// This may break persistance as the supported types are reset in case the component is initialized again. + /// So this only makes sense if you also change the DamageContainerPrototype in the component at the same time. + /// Only use this method if you know what you are doing. + /// + public void SetDamageSpecifier(Entity ent, DamageSpecifier damage) { if (!_damageableQuery.Resolve(ent, ref ent.Comp, false)) return;