Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stamina damage resist #2190

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Server/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid?
{
var hitEntity = lastHit.Value;
if (hitscan.StaminaDamage > 0f)
_stamina.TakeStaminaDamage(hitEntity, hitscan.StaminaDamage, source: user);
_stamina.TakeProjectileStaminaDamage(hitEntity, hitscan.StaminaDamage, source: user); // DeltaV - Cope with hitscan not being an entity

var dmg = hitscan.Damage;

Expand Down
31 changes: 31 additions & 0 deletions Content.Shared/Armor/ArmorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@ public sealed partial class ArmorComponent : Component
/// </summary>
[DataField]
public float PriceMultiplier = 1;

/// <summary>
/// DeltaV: The incoming stamina projectile damage will get multiplied by this value.
/// </summary>
[DataField]
public float StaminaDamageCoefficient = 1;

/// <summary>
/// DeltaV: The configured stamina melee damage coefficient. The actual value used
/// will be this or the blunt damage coefficient, whichever provides better protection.
/// </summary>
[DataField]
private float _staminaMeleeDamageCoefficient = 1;

/// <summary>
/// DeltaV: Gets or sets the effective stamina melee damage coefficient, using either the configured
/// value or the blunt damage coefficient, whichever provides better protection (lower value).
/// </summary>
[Access(typeof(SharedArmorSystem))]
public float StaminaMeleeDamageCoefficient
{
get
{
// Try to get the blunt damage coefficient from modifiers
var bluntCoefficient = Modifiers.Coefficients.GetValueOrDefault("Blunt", 1.0f);

// Return whichever provides better protection (lower coefficient)
return Math.Min(bluntCoefficient, _staminaMeleeDamageCoefficient);
}
set => _staminaMeleeDamageCoefficient = value;
}
}

/// <summary>
Expand Down
29 changes: 25 additions & 4 deletions Content.Shared/Armor/SharedArmorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void OnArmorVerbExamine(EntityUid uid, ArmorComponent component, GetVerb
if (!args.CanInteract || !args.CanAccess)
return;

var examineMarkup = GetArmorExamine(component.Modifiers);
var examineMarkup = GetArmorExamine(component); // DeltaV - Changed argument type to ArmorComponent

var ev = new ArmorExamineEvent(examineMarkup);
RaiseLocalEvent(uid, ref ev);
Expand All @@ -50,12 +50,13 @@ private void OnArmorVerbExamine(EntityUid uid, ArmorComponent component, GetVerb
Loc.GetString("armor-examinable-verb-message"));
}

private FormattedMessage GetArmorExamine(DamageModifierSet armorModifiers)
// DeltaV - Changed to take ArmorComponent instead of DamageModifierSet
private FormattedMessage GetArmorExamine(ArmorComponent component)
{
var msg = new FormattedMessage();
msg.AddMarkupOrThrow(Loc.GetString("armor-examine"));

foreach (var coefficientArmor in armorModifiers.Coefficients)
foreach (var coefficientArmor in component.Modifiers.Coefficients) // DeltaV
{
msg.PushNewline();

Expand All @@ -66,7 +67,7 @@ private FormattedMessage GetArmorExamine(DamageModifierSet armorModifiers)
));
}

foreach (var flatArmor in armorModifiers.FlatReduction)
foreach (var flatArmor in component.Modifiers.FlatReduction) // DeltaV
{
msg.PushNewline();

Expand All @@ -77,6 +78,26 @@ private FormattedMessage GetArmorExamine(DamageModifierSet armorModifiers)
));
}

// DeltaV - Add stamina resistance information if it differs from default
if (!MathHelper.CloseTo(component.StaminaDamageCoefficient, 1.0f))
{
msg.PushNewline();
var reduction = (1 - component.StaminaDamageCoefficient) * 100;
msg.AddMarkupOrThrow(Loc.GetString("armor-stamina-projectile-coefficient-value",
("value", MathF.Round(reduction, 1))
));
}

if (!MathHelper.CloseTo(component.StaminaMeleeDamageCoefficient, 1.0f))
{
msg.PushNewline();
var reduction = (1 - component.StaminaMeleeDamageCoefficient) * 100;
msg.AddMarkupOrThrow(Loc.GetString("armor-stamina-melee-coefficient-value",
("value", MathF.Round(reduction, 1))
));
}
// End DeltaV

return msg;
}
}
6 changes: 4 additions & 2 deletions Content.Shared/Damage/Systems/StaminaSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ private void OnMeleeHit(EntityUid uid, StaminaDamageOnHitComponent component, Me

foreach (var (ent, comp) in toHit)
{
TakeStaminaDamage(ent, damage / toHit.Count, comp, source: args.User, with: args.Weapon, sound: component.Sound);
// DeltaV - Stamina damage coefficient
TakeMeleeStaminaDamage(ent, damage, comp, source: args.User, with: args.Weapon, sound: component.Sound);
}
}

Expand Down Expand Up @@ -202,7 +203,8 @@ private void OnCollide(EntityUid uid, StaminaDamageOnCollideComponent component,
if (ev.Cancelled)
return;

TakeStaminaDamage(target, component.Damage, source: uid, sound: component.Sound);
// DeltaV - Stamina damage coefficient
TakeProjectileStaminaDamage(target, component.Damage, source: uid, sound: component.Sound);
}

private void SetStaminaAlert(EntityUid uid, StaminaComponent? component = null)
Expand Down
99 changes: 99 additions & 0 deletions Content.Shared/DeltaV/Damage/StaminaSystem.Resist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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!;

/// <summary>
/// Gets the combined stamina protection coefficients from all armor worn by an entity
/// </summary>
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<ArmorComponent>(equipped, out var armor))
{
coefficient *= armor.StaminaMeleeDamageCoefficient;
}
}

return coefficient;
}

/// <summary>
/// Gets the combined stamina protection coefficients from all armor worn by an entity
/// </summary>
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<ArmorComponent>(equipped, out var armor))
{
coefficient *= armor.StaminaDamageCoefficient;
}
}

return coefficient;
}

/// <summary>
/// Applies stamina damage from melee attacks with armor resistance calculations
/// </summary>
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);
}

/// <summary>
/// Applies stamina damage from projectiles with armor resistance calculations
/// </summary>
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);
}
}
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/deltav/armor/armor-examine.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
armor-stamina-projectile-coefficient-value = - [color=yellow]Stamina projectile[/color] damage reduced by [color=lightblue]{$value}%[/color].
armor-stamina-melee-coefficient-value = - [color=yellow]Stamina melee[/color] damage reduced by [color=lightblue]{$value}%[/color].
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Slash: 0.80
Piercing: 0.50
Heat: 0.80
staminaDamageCoefficient: 0.6 # Decent at stopping disablers
- type: ClothingSpeedModifier
walkModifier: 0.90
sprintModifier: 0.90
Expand Down Expand Up @@ -44,6 +45,7 @@
Slash: 0.60
Piercing: 0.90
Heat: 0.90
staminaDamageCoefficient: 0.9
- type: ExplosionResistance # Better than nothing against a blast or shockwave.
damageCoefficient: 0.90
- type: AllowSuitStorage
Expand All @@ -68,6 +70,7 @@
Slash: 0.40
Piercing: 0.70
Heat: 0.70
staminaDamageCoefficient: 0.5
- type: ClothingSpeedModifier
walkModifier: 0.75
sprintModifier: 0.75
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Radiation: 0.75
Caustic: 0.75
Heat: 0.75
staminaDamageCoefficient: 0.3 # It's a hardsuit, duh
- type: ClothingSpeedModifier
walkModifier: 0.75
sprintModifier: 0.75
Expand Down Expand Up @@ -68,6 +69,7 @@
Radiation: 0.80
Caustic: 0.80
Heat: 0.80
staminaDamageCoefficient: 0.3 # still a hardsuit
- type: ClothingSpeedModifier
walkModifier: 0.85
sprintModifier: 0.85
Expand Down Expand Up @@ -113,6 +115,7 @@
Radiation: 0.70
Caustic: 0.70
Heat: 0.70
staminaDamageCoefficient: 0.2
- type: ClothingSpeedModifier
walkModifier: 0.65
sprintModifier: 0.65
Expand Down Expand Up @@ -158,6 +161,7 @@
Radiation: 0.75
Caustic: 0.75
Heat: 0.75
staminaDamageCoefficient: 0.2
- type: ClothingSpeedModifier
walkModifier: 0.80
sprintModifier: 0.80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
Piercing: 0.5
Shock: 0.8
Heat: 0.7
staminaDamageCoefficient: 0.6
- type: ClothingSpeedModifier
walkModifier: 1.0
sprintModifier: 0.85
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Slash: 0.70
Piercing: 0.70 #Can save you, but bullets will still hurt. Will take about 10 shots from a Viper before critting, as opposed to 7 while unarmored and 16~ with a bulletproof vest.
Heat: 0.80
staminaDamageCoefficient: 0.75 # DeltaV - Decent at stopping disablers
- type: ExplosionResistance
damageCoefficient: 0.90

Expand Down Expand Up @@ -122,6 +123,7 @@
Piercing: 0.35
Heat: 0.35
Caustic: 0.5
staminaDamageCoefficient: 0.35 # DeltaV
- type: ExplosionResistance
damageCoefficient: 0.35
- type: ClothingSpeedModifier
Expand Down Expand Up @@ -209,6 +211,7 @@
Heat: 0.5
Radiation: 0
Caustic: 0.75
staminaDamageCoefficient: 0.1 # DeltaV
- type: GroupExamine
- type: ProtectedFromStepTriggers
slots: WITHOUT_POCKET
Expand Down Expand Up @@ -275,6 +278,7 @@
Piercing: 0.6
Heat: 0.5
Caustic: 0.9
staminaDamageCoefficient: 0.7 # DeltaV - Some protection against disablers, but you're better off with a vest
- type: ClothingSpeedModifier
walkModifier: 1.0
sprintModifier: 1.0
Expand Down
Loading
Loading