Skip to content

Commit

Permalink
god himself couldn't fix this shit
Browse files Browse the repository at this point in the history
  • Loading branch information
MilonPL committed Nov 14, 2024
1 parent fefb1a3 commit 00e63e4
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 52 deletions.
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.TakeStaminaDamageWithProjectileCoefficient(hitEntity, hitscan.StaminaDamage, source: user); // DeltaV - Cope with hitscan not being an entity

var dmg = hitscan.Damage;

Expand Down
55 changes: 4 additions & 51 deletions Content.Shared/Damage/Systems/StaminaSystem.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System.Linq;
using Content.Shared.Administration.Logs;
using Content.Shared.Alert;
using Content.Shared.Armor; // DeltaV
using Content.Shared.CombatMode;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory; // DeltaV
using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Rejuvenate;
Expand Down Expand Up @@ -36,7 +34,6 @@ public sealed partial class StaminaSystem : EntitySystem
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly InventorySystem _inventory = default!; // DeltaV

/// <summary>
/// How much of a buffer is there between the stun duration and when stuns can be re-applied.
Expand Down Expand Up @@ -171,28 +168,8 @@ private void OnMeleeHit(EntityUid uid, StaminaDamageOnHitComponent component, Me

foreach (var (ent, comp) in toHit)
{
// Begin DeltaV code - melee stamina resistance from armor
var finalDamage = damage / toHit.Count;

if (_inventory.TryGetSlots(ent, out var slots))
{
var coefficient = 1.0f;

foreach (var slot in slots)
{
if (!_inventory.TryGetSlotEntity(ent, slot.Name, out var equipped))
continue;

if (TryComp<ArmorComponent>(equipped, out var armor))
{
coefficient *= armor.StaminaMeleeDamageCoefficient;
}
}

finalDamage *= coefficient;
}
TakeStaminaDamage(ent, finalDamage, comp, source: args.User, with: args.Weapon, sound: component.Sound);
// End DeltaV code
// DeltaV - Stamina damage coefficient
TakeStaminaDamageWithMeleeCoefficient(ent, damage, comp, source: args.User, with: args.Weapon, sound: component.Sound);
}
}

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

// Begin DeltaV code
var damage = component.Damage;

// Check for armor on the target that might reduce stamina damage
if (_inventory.TryGetSlots(target, out var slots))
{
var coefficient = 1.0f;

// Check each equipped item for armor
foreach (var slot in slots)
{
if (!_inventory.TryGetSlotEntity(target, slot.Name, out var equipped))
continue;

// If equipped item has armor component, multiply the coefficient
if (TryComp<ArmorComponent>(equipped, out var armor))
{
coefficient *= armor.StaminaDamageCoefficient;
}
}

damage *= coefficient;
}

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

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

0 comments on commit 00e63e4

Please sign in to comment.