using Content.Shared.Armor; using Content.Shared.Damage.Components; using Content.Shared.Inventory; using Robust.Shared.Audio; namespace Content.Shared.Damage.Systems; public sealed partial class StaminaSystem { [Dependency] private readonly InventorySystem _inventory = default!; /// /// Gets the combined stamina protection coefficients from all armor worn by an entity /// private float GetMeleeCoefficient(EntityUid target) { var coefficient = 1.0f; if (!_inventory.TryGetSlots(target, out var slots)) return coefficient; foreach (var slot in slots) { if (!_inventory.TryGetSlotEntity(target, slot.Name, out var equipped)) continue; if (TryComp(equipped, out var armor)) { coefficient *= armor.StaminaMeleeDamageCoefficient; } } return coefficient; } /// /// Gets the combined stamina protection coefficients from all armor worn by an entity /// private float GetProjectileCoefficient(EntityUid target) { var coefficient = 1.0f; if (!_inventory.TryGetSlots(target, out var slots)) return coefficient; foreach (var slot in slots) { if (!_inventory.TryGetSlotEntity(target, slot.Name, out var equipped)) continue; if (TryComp(equipped, out var armor)) { coefficient *= armor.StaminaDamageCoefficient; } } return coefficient; } /// /// Applies stamina damage from melee attacks with armor resistance calculations /// public void TakeMeleeStaminaDamage(EntityUid target, float damage, StaminaComponent? stamina = null, EntityUid? source = null, EntityUid? with = null, bool visual = true, SoundSpecifier? sound = null) { if (!Resolve(target, ref stamina)) return; var coefficient = GetMeleeCoefficient(target); var finalDamage = damage * coefficient; TakeStaminaDamage(target, finalDamage, stamina, source, with, visual, sound); } /// /// Applies stamina damage from projectiles with armor resistance calculations /// public void TakeProjectileStaminaDamage(EntityUid target, float damage, StaminaComponent? stamina = null, EntityUid? source = null, EntityUid? with = null, bool visual = true, SoundSpecifier? sound = null) { if (!Resolve(target, ref stamina)) return; var coefficient = GetProjectileCoefficient(target); var finalDamage = damage * coefficient; TakeStaminaDamage(target, finalDamage, stamina, source, with, visual, sound); } }