Skip to content

Commit

Permalink
Create a Armor CoeffientQuery (#35024)
Browse files Browse the repository at this point in the history
* Create a Armor CoeffientQuery

- add Armor Coefficent Query Event for InventoryRelay system

* CR - cleanup, comments and fix typos

* CR - Remove Whitespace

* typos

* on't

---------

Co-authored-by: ScarKy0 <[email protected]>
  • Loading branch information
poklj and ScarKy0 authored Feb 10, 2025
1 parent 96cb951 commit 9d48f66
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Content.Shared/Armor/ArmorComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Damage;
using Content.Shared.Inventory;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;

Expand Down Expand Up @@ -30,3 +31,24 @@ public sealed partial class ArmorComponent : Component
/// <param name="Msg"></param>
[ByRefEvent]
public record struct ArmorExamineEvent(FormattedMessage Msg);

/// <summary>
/// A Relayed inventory event, gets the total Armor for all Inventory slots defined by the Slotflags in TargetSlots
/// </summary>
public sealed class CoefficientQueryEvent : EntityEventArgs, IInventoryRelayEvent
{
/// <summary>
/// All slots to relay to
/// </summary>
public SlotFlags TargetSlots { get; set; }

/// <summary>
/// The Total of all Coefficients.
/// </summary>
public DamageModifierSet DamageModifiers { get; set; } = new DamageModifierSet();

public CoefficientQueryEvent(SlotFlags slots)
{
TargetSlots = slots;
}
}
14 changes: 14 additions & 0 deletions Content.Shared/Armor/SharedArmorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,25 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<CoefficientQueryEvent>>(OnCoefficientQuery);
SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify);
SubscribeLocalEvent<ArmorComponent, BorgModuleRelayedEvent<DamageModifyEvent>>(OnBorgDamageModify);
SubscribeLocalEvent<ArmorComponent, GetVerbsEvent<ExamineVerb>>(OnArmorVerbExamine);
}

/// <summary>
/// Get the total Damage reduction value of all equipment caught by the relay.
/// </summary>
/// <param name="ent">The item that's being relayed to</param>
/// <param name="args">The event, contains the running count of armor percentage as a coefficient</param>
private void OnCoefficientQuery(Entity<ArmorComponent> ent, ref InventoryRelayedEvent<CoefficientQueryEvent> args)
{
foreach (var armorCoefficient in ent.Comp.Modifiers.Coefficients)
{
args.Args.DamageModifiers.Coefficients[armorCoefficient.Key] = args.Args.DamageModifiers.Coefficients.TryGetValue(armorCoefficient.Key, out var coefficient) ? coefficient * armorCoefficient.Value : armorCoefficient.Value;
}
}

private void OnDamageModify(EntityUid uid, ArmorComponent component, InventoryRelayedEvent<DamageModifyEvent> args)
{
args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers);
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,3 +1,4 @@
using Content.Shared.Armor;
using Content.Shared.Chat;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Hypospray.Events;
Expand Down Expand Up @@ -40,6 +41,7 @@ public void InitializeRelay()
SubscribeLocalEvent<InventoryComponent, TargetBeforeHyposprayInjectsEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, SelfBeforeGunShotEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, SelfBeforeClimbEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, CoefficientQueryEvent>(RelayInventoryEvent);

// by-ref events
SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
Expand Down

0 comments on commit 9d48f66

Please sign in to comment.