Skip to content

Commit

Permalink
Stamina Damage Resistance Real (#679)
Browse files Browse the repository at this point in the history
# Description
Added stamina damage resistance, acts the same way as armor does.
Call this shock resistance if you wish :trollface:
Just attach StaminaDamageResistance component to an entity with a set
multiplier and have fun.

Made all hardsuits 25% stun resistant by default.
With some variety, e.g. nukie, ERT, captain, HoS suits are 50%, DS are
90%, etc. etc.

This will not remove stuneta but it will make it more difficult to
stamcrit a traitor or such.

Some armor/batong ratios that you need to hit before the target is
stamcritted:
0% - 3 batong hits
25% - 4 batong hits
50% - 6 batong hits
75% - 12 batong hits
90% - 28 batong hits :trollface:
100% - 

![image](https://github.com/user-attachments/assets/da147676-520b-4e3c-b027-ef9dc6a7394b)


# Changelog

:cl:
- add: Added different stamina damage resistance to hardsuits.

---------

Co-authored-by: whateverusername0 <whateveremail>
  • Loading branch information
whateverusername0 authored Aug 6, 2024
1 parent cb3ddd4 commit 55aa822
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Content.Server/Nyanotrasen/Abilities/Boxer/BoxingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<BoxerComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<BoxerComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<BoxingGlovesComponent, StaminaMeleeHitEvent>(OnStamHit);
SubscribeLocalEvent<BoxingGlovesComponent, TakeStaminaDamageEvent>(OnStamHit);
}

private void OnInit(EntityUid uid, BoxerComponent component, ComponentInit args)
Expand All @@ -27,7 +27,7 @@ private void OnMeleeHit(EntityUid uid, BoxerComponent component, MeleeHitEvent a
args.ModifiersList.Add(component.UnarmedModifiers);
}

private void OnStamHit(EntityUid uid, BoxingGlovesComponent component, StaminaMeleeHitEvent args)
private void OnStamHit(EntityUid uid, BoxingGlovesComponent component, TakeStaminaDamageEvent args)
{
if (!_containerSystem.TryGetContainingContainer(uid, out var equipee))
return;
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Nyanotrasen/Abilities/Oni/OniSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override void Initialize()
SubscribeLocalEvent<OniComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
SubscribeLocalEvent<OniComponent, MeleeHitEvent>(OnOniMeleeHit);
SubscribeLocalEvent<HeldByOniComponent, MeleeHitEvent>(OnHeldMeleeHit);
SubscribeLocalEvent<HeldByOniComponent, StaminaMeleeHitEvent>(OnStamHit);
SubscribeLocalEvent<HeldByOniComponent, TakeStaminaDamageEvent>(OnStamHit);
}

private void OnEntInserted(EntityUid uid, OniComponent component, EntInsertedIntoContainerMessage args)
Expand Down Expand Up @@ -68,7 +68,7 @@ private void OnHeldMeleeHit(EntityUid uid, HeldByOniComponent component, MeleeHi
args.ModifiersList.Add(oni.MeleeModifiers);
}

private void OnStamHit(EntityUid uid, HeldByOniComponent component, StaminaMeleeHitEvent args)
private void OnStamHit(EntityUid uid, HeldByOniComponent component, TakeStaminaDamageEvent args)
{
if (!TryComp<OniComponent>(component.Holder, out var oni))
return;
Expand Down
12 changes: 5 additions & 7 deletions Content.Server/Nyanotrasen/Psionics/PsionicsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<PotentialPsionicComponent, MapInitEvent>(OnStartup);
SubscribeLocalEvent<AntiPsionicWeaponComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<AntiPsionicWeaponComponent, StaminaMeleeHitEvent>(OnStamHit);
SubscribeLocalEvent<AntiPsionicWeaponComponent, TakeStaminaDamageEvent>(OnStamHit);

SubscribeLocalEvent<PsionicComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<PsionicComponent, ComponentRemove>(OnRemove);
Expand Down Expand Up @@ -110,14 +110,12 @@ private void OnRemove(EntityUid uid, PsionicComponent component, ComponentRemove
_npcFactonSystem.RemoveFaction(uid, "PsionicInterloper");
}

private void OnStamHit(EntityUid uid, AntiPsionicWeaponComponent component, StaminaMeleeHitEvent args)
private void OnStamHit(EntityUid uid, AntiPsionicWeaponComponent component, TakeStaminaDamageEvent args)
{
var bonus = false;
foreach (var stam in args.HitList)
{
if (HasComp<PsionicComponent>(stam.Entity))
bonus = true;
}

if (HasComp<PsionicComponent>(args.Target))
bonus = true;

if (!bonus)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using Content.Shared.Damage.Components;
using Robust.Shared.Collections;
using Content.Shared.Inventory;

namespace Content.Shared.Damage.Events;

/// <summary>
/// The components in the list are going to be hit,
/// give opportunities to change the damage or other stuff.
/// </summary>
public sealed class StaminaMeleeHitEvent : HandledEntityEventArgs
public sealed class TakeStaminaDamageEvent : HandledEntityEventArgs, IInventoryRelayEvent
{
public SlotFlags TargetSlots { get; } = ~SlotFlags.POCKET;

/// <summary>
/// List of hit stamina components.
/// </summary>
public List<(EntityUid Entity, StaminaComponent Component)> HitList;
public EntityUid Target;

/// <summary>
/// The multiplier. Generally, try to use *= or /= instead of overwriting.
Expand All @@ -24,8 +26,8 @@ public sealed class StaminaMeleeHitEvent : HandledEntityEventArgs
/// </summary>
public float FlatModifier = 0;

public StaminaMeleeHitEvent(List<(EntityUid Entity, StaminaComponent Component)> hitList)
public TakeStaminaDamageEvent(EntityUid target)
{
HitList = hitList;
Target = target;
}
}
35 changes: 25 additions & 10 deletions Content.Shared/Damage/Systems/StaminaSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,20 @@ private void OnMeleeHit(EntityUid uid, StaminaDamageOnHitComponent component, Me
toHit.Add((ent, stam));
}

var hitEvent = new StaminaMeleeHitEvent(toHit);
RaiseLocalEvent(uid, hitEvent);
foreach (var (ent, comp) in toHit)
{
var hitEvent = new TakeStaminaDamageEvent(ent);
RaiseLocalEvent(uid, hitEvent);

if (hitEvent.Handled)
return;
if (hitEvent.Handled)
return;

var damage = component.Damage;
var damage = component.Damage;

damage *= hitEvent.Multiplier;
damage *= hitEvent.Multiplier;

damage += hitEvent.FlatModifier;
damage += hitEvent.FlatModifier;

foreach (var (ent, comp) in toHit)
{
TakeStaminaDamage(ent, damage / toHit.Count, comp, source: args.User, with: args.Weapon, sound: component.Sound);
}
}
Expand All @@ -204,12 +204,27 @@ private void OnThrowHit(EntityUid uid, StaminaDamageOnCollideComponent component

private void OnCollide(EntityUid uid, StaminaDamageOnCollideComponent component, EntityUid target)
{
if (!TryComp<StaminaComponent>(target, out var stamComp))
return;

var ev = new StaminaDamageOnHitAttemptEvent();
RaiseLocalEvent(uid, ref ev);
if (ev.Cancelled)
return;

TakeStaminaDamage(target, component.Damage, source: uid, sound: component.Sound);
var hitEvent = new TakeStaminaDamageEvent(target);
RaiseLocalEvent(target, hitEvent);

if (hitEvent.Handled)
return;

var damage = component.Damage;

damage *= hitEvent.Multiplier;

damage += hitEvent.FlatModifier;

TakeStaminaDamage(target, damage, source: uid, sound: component.Sound);
}

private void SetStaminaAlert(EntityUid uid, StaminaComponent? component = null)
Expand Down
2 changes: 2 additions & 0 deletions Content.Shared/Inventory/InventorySystem.Relay.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.Chemistry;
using Content.Shared.Damage;
using Content.Shared.Damage.Events;
using Content.Shared.Electrocution;
using Content.Shared.Explosion;
using Content.Shared.Eye.Blinding.Systems;
Expand All @@ -20,6 +21,7 @@ public partial class InventorySystem
public void InitializeRelay()
{
SubscribeLocalEvent<InventoryComponent, DamageModifyEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, TakeStaminaDamageEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, ElectrocutionAttemptEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, SlipAttemptEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, RefreshMovementSpeedModifiersEvent>(RelayInventoryEvent);
Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/Stunnable/StaminaDamageResistanceComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Stunnable;

[RegisterComponent, NetworkedComponent]
public sealed partial class StaminaDamageResistanceComponent : Component
{
/// <summary>
/// 1 - no reduction, 0 - full reduction
/// </summary>
[DataField] public float Coefficient = 1;
}
26 changes: 26 additions & 0 deletions Content.Shared/Stunnable/StaminaDamageResistanceSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Content.Shared.Damage.Events;
using Content.Shared.Examine;
using Content.Shared.Inventory;

namespace Content.Shared.Stunnable;

public sealed partial class StaminaDamageResistanceSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<StaminaDamageResistanceComponent, InventoryRelayedEvent<TakeStaminaDamageEvent>>(OnStaminaMeleeHit);
SubscribeLocalEvent<StaminaDamageResistanceComponent, ExaminedEvent>(OnExamine);
}

private void OnStaminaMeleeHit(Entity<StaminaDamageResistanceComponent> ent, ref InventoryRelayedEvent<TakeStaminaDamageEvent> args)
{
args.Args.Multiplier *= ent.Comp.Coefficient;
}
private void OnExamine(Entity<StaminaDamageResistanceComponent> ent, ref ExaminedEvent args)
{
var percentage = (1 - ent.Comp.Coefficient) * 100;
args.PushMarkup(Loc.GetString("armor-examine-stamina", ("num", percentage)));
}
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/armor/armor-examine.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ armor-damage-type-cold = Cold
armor-damage-type-poison = Poison
armor-damage-type-shock = Shock
armor-damage-type-structural = Structural
armor-examine-stamina = Reduces your stamina damage by [color=cyan]{$num}%[/color].
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
- type: Clothing
equipDelay: 2.5 # Hardsuits are heavy and take a while to put on/off.
unequipDelay: 2.5
- type: StaminaDamageResistance
coefficient: 0.75 # 25%

- type: entity
abstract: true
Expand Down
Loading

0 comments on commit 55aa822

Please sign in to comment.