Fix shield modifiers (#17071)
* use uid instead of .Owner * a bit of refactoring * block damage reimplemented
This commit is contained in:
@@ -12,8 +12,8 @@ public sealed partial class BlockingSystem
|
||||
|
||||
private void InitializeUser()
|
||||
{
|
||||
SubscribeLocalEvent<BlockingUserComponent, DamageChangedEvent>(OnDamageChanged);
|
||||
SubscribeLocalEvent<BlockingUserComponent, DamageModifyEvent>(OnUserDamageModified);
|
||||
SubscribeLocalEvent<BlockingComponent, DamageModifyEvent>(OnDamageModified);
|
||||
|
||||
SubscribeLocalEvent<BlockingUserComponent, EntParentChangedMessage>(OnParentChanged);
|
||||
SubscribeLocalEvent<BlockingUserComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
|
||||
@@ -39,27 +39,37 @@ public sealed partial class BlockingSystem
|
||||
UserStopBlocking(uid, component);
|
||||
}
|
||||
|
||||
private void OnDamageChanged(EntityUid uid, BlockingUserComponent component, DamageChangedEvent args)
|
||||
{
|
||||
if (args.DamageDelta != null && args.DamageIncreased)
|
||||
_damageable.TryChangeDamage(component.BlockingItem, args.DamageDelta, origin: args.Origin);
|
||||
}
|
||||
|
||||
private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component, DamageModifyEvent args)
|
||||
{
|
||||
if (TryComp<BlockingComponent>(component.BlockingItem, out var blockingComponent))
|
||||
if (TryComp<BlockingComponent>(component.BlockingItem, out var blocking))
|
||||
{
|
||||
if (_proto.TryIndex(blockingComponent.PassiveBlockDamageModifer, out DamageModifierSetPrototype? passiveblockModifier) && !blockingComponent.IsBlocking)
|
||||
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, passiveblockModifier);
|
||||
var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction;
|
||||
blockFraction = Math.Clamp(blockFraction, 0, 1);
|
||||
_damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage);
|
||||
|
||||
if (_proto.TryIndex(blockingComponent.ActiveBlockDamageModifier, out DamageModifierSetPrototype? activeBlockModifier) && blockingComponent.IsBlocking)
|
||||
args.Damage *= (1 - blockFraction);
|
||||
|
||||
if (blocking.IsBlocking)
|
||||
{
|
||||
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, activeBlockModifier);
|
||||
_audio.PlayPvs(blockingComponent.BlockSound, component.Owner, AudioParams.Default.WithVariation(0.2f));
|
||||
_audio.PlayPvs(blocking.BlockSound, uid, AudioParams.Default.WithVariation(0.2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDamageModified(EntityUid uid, BlockingComponent component, DamageModifyEvent args)
|
||||
{
|
||||
_proto.TryIndex<DamageModifierSetPrototype>(component.PassiveBlockDamageModifer, out var passiveblockModifier);
|
||||
_proto.TryIndex<DamageModifierSetPrototype>(component.ActiveBlockDamageModifier, out var activeBlockModifier);
|
||||
|
||||
var modifier = component.IsBlocking ? activeBlockModifier : passiveblockModifier;
|
||||
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))
|
||||
|
||||
@@ -59,4 +59,18 @@ public sealed class BlockingComponent : Component
|
||||
/// </summary>
|
||||
[DataField("blockSound")]
|
||||
public SoundSpecifier BlockSound = new SoundPathSpecifier("/Audio/Weapons/block_metal1.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Fraction of original damage shield will take instead of user
|
||||
/// when not blocking
|
||||
/// </summary>
|
||||
[DataField("passiveBlockFraction"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float PassiveBlockFraction = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// Fraction of original damage shield will take instead of user
|
||||
/// when blocking
|
||||
/// </summary>
|
||||
[DataField("activeBlockFraction"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float ActiveBlockFraction = 1.0f;
|
||||
}
|
||||
|
||||
@@ -313,10 +313,12 @@ namespace Content.Shared.Damage
|
||||
// Whenever locational damage is a thing, this should just check only that bit of armour.
|
||||
public SlotFlags TargetSlots { get; } = ~SlotFlags.POCKET;
|
||||
|
||||
public readonly DamageSpecifier OriginalDamage;
|
||||
public DamageSpecifier Damage;
|
||||
|
||||
public DamageModifyEvent(DamageSpecifier damage)
|
||||
{
|
||||
OriginalDamage = damage;
|
||||
Damage = damage;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user