Skip to content

Commit

Permalink
addBackShield
Browse files Browse the repository at this point in the history
  • Loading branch information
cherborr committed Nov 14, 2024
1 parent 99dbe76 commit a8ec525
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Content.Shared/Blocking/BlockingSystem.User.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Inventory;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
Expand All @@ -10,6 +11,7 @@ public sealed partial class BlockingSystem
{
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly InventorySystem _inventory = default!; // SS220 equip shield on back
private void InitializeUser()
{
SubscribeLocalEvent<BlockingUserComponent, DamageModifyEvent>(OnUserDamageModified);
Expand Down Expand Up @@ -52,6 +54,13 @@ private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component
if (!TryComp<DamageableComponent>(component.BlockingItem, out var dmgComp))
return;

// SS220 equip shield on back begin
if (_inventory.TryGetContainingSlot(component.BlockingItem.Value, out var slotDefinition) && blocking.AvaliableSlots.TryGetValue(slotDefinition.SlotFlags, out var coef))
{
blockFraction *= coef;
}
// SS220 equip shield on back end

blockFraction = Math.Clamp(blockFraction, 0, 1);
_damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage);

Expand Down
32 changes: 31 additions & 1 deletion Content.Shared/Blocking/BlockingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Content.Shared.Actions;
using Content.Shared.Damage;
using Content.Shared.Examine;
Expand All @@ -22,6 +22,7 @@
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Content.Shared.Weapons.Reflect;
using Content.Shared.Inventory.Events;

namespace Content.Shared.Blocking;

Expand All @@ -48,6 +49,11 @@ public override void Initialize()
SubscribeLocalEvent<BlockingComponent, GotUnequippedHandEvent>(OnUnequip);
SubscribeLocalEvent<BlockingComponent, DroppedEvent>(OnDrop);

// SS220 equip shield on back begin
SubscribeLocalEvent<BlockingComponent, GotEquippedEvent>(OnGotEquip);
SubscribeLocalEvent<BlockingComponent, GotUnequippedEvent>(OnGotUnequipped);
// SS220 equip shield on back end

SubscribeLocalEvent<BlockingComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<BlockingComponent, ToggleActionEvent>(OnToggleAction);

Expand Down Expand Up @@ -77,6 +83,30 @@ private void OnEquip(EntityUid uid, BlockingComponent component, GotEquippedHand
}
}

// SS220 equip shield on back begin
private void OnGotEquip(EntityUid uid, BlockingComponent component, GotEquippedEvent args)
{

if (!component.AvaliableSlots.ContainsKey(args.SlotFlags))
return;

component.User = args.Equipee;
Dirty(uid, component);

if (TryComp<PhysicsComponent>(args.Equipee, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static)
{
var userComp = EnsureComp<BlockingUserComponent>(args.Equipee);
userComp.BlockingItem = uid;
userComp.OriginalBodyType = physicsComponent.BodyType;
}
}

private void OnGotUnequipped(EntityUid uid, BlockingComponent component, GotUnequippedEvent args)
{
StopBlockingHelper(uid, component, args.Equipee);
}
// SS220 equip shield on back end

private void OnUnequip(EntityUid uid, BlockingComponent component, GotUnequippedHandEvent args)
{
StopBlockingHelper(uid, component, args.User);
Expand Down
10 changes: 10 additions & 0 deletions Content.Shared/Blocking/Components/BlockingComponent.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.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Physics.Collision.Shapes;
Expand Down Expand Up @@ -76,4 +77,13 @@ public sealed partial class BlockingComponent : Component
/// </summary>
[DataField("activeBlockFraction"), ViewVariables(VVAccess.ReadWrite)]
public float ActiveBlockFraction = 1.0f;

// SS220 equip shield on back begin
/// <summary>
/// The list of slots that supported a shield protection
/// and second arg it's protection efficiency of this slots
/// </summary>
[DataField]
public Dictionary<SlotFlags, float> AvaliableSlots = new();
// SS220 equip shield on back end
}

0 comments on commit a8ec525

Please sign in to comment.