Files
tbd-station-14/Content.Shared/Blocking/BlockingUserSystem.cs
keronshb d65601f024 Blocking and Shields (#8584)
* Blocking

* Fixes Bodytype bug

* Blocking Damage Modifier

* Storing bodytype

* Consolidates Stop Blocking code

* Consolidates more methods

* Some cleanup, hitbox fix

* Shield Textures

* Passive blocking modifier check

* Localization, popups, and more cleanup

* Small cleanup

* Relay event

* Fixes a shutdown bug, adds specific containers and sets

* Popups and sounds

* Fixes typo

* Removes whitespace, adds comment

* Some requested changes

* Remove Shared

* Audio fix

* More changes

* More requested changes

* Properly remove on shutdown

* Adds riot shields to seclathes

* SecTech Riot shield

* Constant variable

* Relay transfer to user blocking system

* More destruction behavior

* Adds a shape field

* Riot shield cleanup

* More requested changes.

* Prevents blocking attempt where a user cannot be anchored

* Listen for anchor change

* Unused using cleanup

* More shields.

* Buckler

* Construction

* Linter fix
2022-07-04 16:31:12 +10:00

61 lines
2.5 KiB
C#

using Content.Shared.Audio;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Hands.EntitySystems;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Shared.Blocking;
public sealed class BlockingUserSystem : EntitySystem
{
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly BlockingSystem _blockingSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlockingUserComponent, DamageChangedEvent>(OnDamageChanged);
SubscribeLocalEvent<BlockingUserComponent, DamageModifyEvent>(OnUserDamageModified);
SubscribeLocalEvent<BlockingUserComponent, AnchorStateChangedEvent>(OnAnchorChanged);
}
private void OnAnchorChanged(EntityUid uid, BlockingUserComponent component, ref AnchorStateChangedEvent args)
{
if (!args.Anchored)
return;
if (TryComp<BlockingComponent>(component.BlockingItem, out var blockComp) && blockComp.IsBlocking)
{
_blockingSystem.StopBlocking(component.BlockingItem.Value, blockComp, uid);
}
}
private void OnDamageChanged(EntityUid uid, BlockingUserComponent component, DamageChangedEvent args)
{
if (component.BlockingItem != null)
{
RaiseLocalEvent(component.BlockingItem.Value, args);
}
}
private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component, DamageModifyEvent args)
{
if (TryComp<BlockingComponent>(component.BlockingItem, out var blockingComponent))
{
if (_proto.TryIndex(blockingComponent.PassiveBlockDamageModifer, out DamageModifierSetPrototype? passiveblockModifier) && !blockingComponent.IsBlocking)
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, passiveblockModifier);
if (_proto.TryIndex(blockingComponent.ActiveBlockDamageModifier, out DamageModifierSetPrototype? activeBlockModifier) && blockingComponent.IsBlocking)
{
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, activeBlockModifier);
SoundSystem.Play(blockingComponent.BlockSound.GetSound(), Filter.Pvs(component.Owner, entityManager: EntityManager), component.Owner, AudioHelpers.WithVariation(0.2f));
}
}
}
}