CatStation/Content.Shared/Blocking/BlockingSystem.User.cs
Princess Cheeseballs 65ade7d35d
Shield Adjustments based on feedback. (#45510)
* shneeld

* mild buff that doesn't really matter but feels a bit better :P

* absolute woke nonsense

* ultra buff
2026-09-12 22:31:03 +00:00

83 lines
2.9 KiB
C#

using Content.Shared.Blocking.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
namespace Content.Shared.Blocking;
public sealed partial class BlockingSystem
{
[Dependency] private DamageableSystem _damageable = default!;
[Dependency] private SharedAudioSystem _audio = default!;
[SubscribeLocalEvent]
private void OnParentChanged(Entity<BlockingUserComponent> entity, ref EntParentChangedMessage args)
{
UserStopBlocking(entity);
}
[SubscribeLocalEvent]
private void OnInsertAttempt(Entity<BlockingUserComponent> entity, ref ContainerGettingInsertedAttemptEvent args)
{
UserStopBlocking(entity);
}
[SubscribeLocalEvent]
private void OnAnchorChanged(Entity<BlockingUserComponent> entity, ref AnchorStateChangedEvent args)
{
if (args.Anchored)
return;
UserStopBlocking(entity);
}
[SubscribeLocalEvent]
private void OnUserDamageModified(Entity<BlockingUserComponent> entity, ref DamageModifyEvent args)
{
if (entity.Comp.BlockingItem is not { } item || !_blockQuery.TryComp(item, out var blocking))
return;
if (args.Damage.GetTotal() <= 0)
return;
var blockFraction = blocking.IsRaised ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction;
blockFraction = Math.Clamp(blockFraction, 0, 1);
// This is how much damage the shield is attempting to block
var split = args.OriginalDamage * blockFraction;
var damage = _damageable.ChangeDamage(item, split);
// Of the damage that went through, reduce by the appropriate blocking modifiers.
var modifier = GetBlockingModifier((item, blocking));
var blowthrough = DamageSpecifier.ApplyModifierSet(split, modifier);
args.Damage *= 1f - blockFraction;
args.Damage += blowthrough;
if (blocking.IsRaised && damage.AnyPositive())
_audio.PlayPvs(blocking.BlockSound, entity);
}
[SubscribeLocalEvent]
private void OnEntityTerminating(Entity<BlockingUserComponent> entity, ref EntityTerminatingEvent args)
{
if (!_blockQuery.TryComp(entity.Comp.BlockingItem, out var blockComponent))
return;
StopBlocking((entity.Comp.BlockingItem.Value, blockComponent), entity);
}
/// <summary>
/// Check for the shield and has the user stop blocking
/// Used where you'd like the user to stop blocking, but also don't want to remove the <see cref="BlockingUserComponent"/>
/// </summary>
/// <param name="entity">The user blocking</param>
private void UserStopBlocking(Entity<BlockingUserComponent> entity)
{
if (!_blockQuery.TryComp(entity.Comp.BlockingItem, out var blockComponent))
return;
LowerShield((entity.Comp.BlockingItem.Value, blockComponent), entity);
}
}