Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addBackShield #2233

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 deletions Content.Shared/Blocking/BlockingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading