mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description Title, it replaces the eshield in the BSO's loadout. I had to tweak the values to be a little less... extreme. Also made EMP immune untill somebody ports the eshield changes fully, as right now, the eshield is emp immune, so why would the greatshield be disabled by it. Also, added a way to smart-equip the shield from your belt, if you've already taken out the mace (which can also be put in the belt slot by itself just like a stun baton.) --- <details><summary><h1>Media</h1></summary> <p> [Video of the stamina damage of the mace, and the shield health & recharge.](https://github.com/user-attachments/assets/8b98dda2-e7ab-4b4d-be41-6f0c247b3e10) </p> </details> --- # Changelog 🆑 BramvanZijp - add: Added the BSO's Greatshield and Atrocity (Mace) as a primary weapon option. - remove: The Energy Shield has been removed from the BSO's loadout. --------- Signed-off-by: BramvanZijp <56019239+BramvanZijp@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com> (cherry picked from commit d1cc81ca03a35ecd5cf38d280b20b54c1bc63536)
133 lines
5.2 KiB
C#
133 lines
5.2 KiB
C#
using Content.Shared._White.Blocking;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Damage.Prototypes;
|
|
using Content.Shared.Item.ItemToggle.Components;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Containers;
|
|
|
|
namespace Content.Shared.Blocking;
|
|
|
|
public sealed partial class BlockingSystem
|
|
{
|
|
[Dependency] private readonly DamageableSystem _damageable = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
private void InitializeUser()
|
|
{
|
|
SubscribeLocalEvent<BlockingUserComponent, DamageModifyEvent>(OnUserDamageModified);
|
|
SubscribeLocalEvent<BlockingComponent, DamageModifyEvent>(OnDamageModified);
|
|
|
|
SubscribeLocalEvent<BlockingUserComponent, EntParentChangedMessage>(OnParentChanged);
|
|
SubscribeLocalEvent<BlockingUserComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
|
|
SubscribeLocalEvent<BlockingUserComponent, AnchorStateChangedEvent>(OnAnchorChanged);
|
|
SubscribeLocalEvent<BlockingUserComponent, EntityTerminatingEvent>(OnEntityTerminating);
|
|
|
|
SubscribeLocalEvent<BlockingUserComponent, MeleeBlockAttemptEvent>(OnMeleeBlockAttempt); // WD
|
|
}
|
|
|
|
// WD START
|
|
private void OnMeleeBlockAttempt(Entity<BlockingUserComponent> ent, ref MeleeBlockAttemptEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
var uid = ent.Comp.BlockingItem;
|
|
if (!TryComp(uid, out BlockingComponent? blocking) || !blocking.IsBlocking)
|
|
return;
|
|
|
|
if (TryComp(uid.Value, out ItemToggleComponent? toggle) && !toggle.Activated)
|
|
return;
|
|
|
|
if (!TryComp(uid.Value, out DamageableComponent? damageable))
|
|
return;
|
|
|
|
_audio.PlayPredicted(blocking.BlockSound, ent, args.Attacker);
|
|
_popupSystem.PopupPredicted(Loc.GetString("melee-block-event-blocked"), ent, args.Attacker);
|
|
_damageable.TryChangeDamage(uid.Value, args.Damage, damageable: damageable);
|
|
args.Handled = true;
|
|
}
|
|
// WD END
|
|
|
|
private void OnParentChanged(EntityUid uid, BlockingUserComponent component, ref EntParentChangedMessage args)
|
|
{
|
|
UserStopBlocking(uid, component);
|
|
}
|
|
|
|
private void OnInsertAttempt(
|
|
EntityUid uid,
|
|
BlockingUserComponent component,
|
|
ContainerGettingInsertedAttemptEvent args
|
|
)
|
|
{
|
|
UserStopBlocking(uid, component);
|
|
}
|
|
|
|
private void OnAnchorChanged(EntityUid uid, BlockingUserComponent component, ref AnchorStateChangedEvent args)
|
|
{
|
|
if (args.Anchored)
|
|
return;
|
|
|
|
UserStopBlocking(uid, component);
|
|
}
|
|
|
|
private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component, DamageModifyEvent args)
|
|
{
|
|
// A shield should only block damage it can itself absorb. To determine that we need the Damageable component on it.
|
|
if (!TryComp<BlockingComponent>(component.BlockingItem, out var blocking) || args.Damage.GetTotal() <= 0 ||
|
|
!TryComp<DamageableComponent>(component.BlockingItem, out var dmgComp))
|
|
return;
|
|
|
|
if (!_toggle.IsActivated(component.BlockingItem.Value)) // Goobstation
|
|
return;
|
|
|
|
var ev = new BeforeBlockingEvent(uid, args.Origin);
|
|
RaiseLocalEvent(component.BlockingItem.Value, ev);
|
|
if (ev.Cancelled)
|
|
return;
|
|
|
|
var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction;
|
|
blockFraction = Math.Clamp(blockFraction, 0, 1);
|
|
_damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage);
|
|
|
|
var modify = new DamageModifierSet();
|
|
foreach (var key in dmgComp.Damage.DamageDict.Keys)
|
|
modify.Coefficients.TryAdd(key, 1 - blockFraction);
|
|
|
|
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modify);
|
|
if (blocking.IsBlocking && !args.Damage.Equals(args.OriginalDamage))
|
|
_audio.PlayPvs(blocking.BlockSound, uid);
|
|
}
|
|
|
|
private void OnDamageModified(EntityUid uid, BlockingComponent component, DamageModifyEvent args)
|
|
{
|
|
var modifier = component.IsBlocking ? component.ActiveBlockDamageModifier : component.PassiveBlockDamageModifer;
|
|
if (modifier == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modifier);
|
|
}
|
|
|
|
private void OnEntityTerminating(EntityUid uid, BlockingUserComponent component, ref EntityTerminatingEvent args)
|
|
{
|
|
if (!TryComp<BlockingComponent>(component.BlockingItem, out var blockingComponent))
|
|
return;
|
|
|
|
StopBlockingHelper(component.BlockingItem.Value, blockingComponent, uid);
|
|
}
|
|
|
|
/// <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="uid">The user blocking</param>
|
|
/// <param name="component">The <see cref="BlockingUserComponent"/></param>
|
|
private void UserStopBlocking(EntityUid uid, BlockingUserComponent component)
|
|
{
|
|
if (TryComp<BlockingComponent>(component.BlockingItem, out var blockComp) && blockComp.IsBlocking)
|
|
StopBlocking(component.BlockingItem.Value, blockComp, uid);
|
|
}
|
|
}
|