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 Resistance Real #679

Merged
merged 6 commits into from
Aug 6, 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
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 @@ -141,6 +141,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
Loading