multi-handed item component (#12523)
* multi-handed item component * pretty fucking obvious missed portion of this * holy shit was i on crack wtf was that code * DEWIT RIGHT
This commit is contained in:
15
Content.Client/Items/Systems/MultiHandedItemSystem.cs
Normal file
15
Content.Client/Items/Systems/MultiHandedItemSystem.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Item;
|
||||
|
||||
namespace Content.Client.Items.Systems;
|
||||
|
||||
public sealed class MultiHandedItemSystem : SharedMultiHandedItemSystem
|
||||
{
|
||||
protected override void OnEquipped(EntityUid uid, MultiHandedItemComponent component, GotEquippedHandEvent args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnUnequipped(EntityUid uid, MultiHandedItemComponent component, GotUnequippedHandEvent args)
|
||||
{
|
||||
}
|
||||
}
|
||||
23
Content.Server/Item/MultiHandedItemSystem.cs
Normal file
23
Content.Server/Item/MultiHandedItemSystem.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Item;
|
||||
|
||||
namespace Content.Server.Item;
|
||||
|
||||
public sealed class MultiHandedItemSystem : SharedMultiHandedItemSystem
|
||||
{
|
||||
[Dependency] private readonly HandVirtualItemSystem _virtualItem = default!;
|
||||
|
||||
protected override void OnEquipped(EntityUid uid, MultiHandedItemComponent component, GotEquippedHandEvent args)
|
||||
{
|
||||
for (var i = 0; i < component.HandsNeeded - 1; i++)
|
||||
{
|
||||
_virtualItem.TrySpawnVirtualItemInHand(uid, args.User);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUnequipped(EntityUid uid, MultiHandedItemComponent component, GotUnequippedHandEvent args)
|
||||
{
|
||||
_virtualItem.DeleteInHandsMatching(args.User, uid);
|
||||
}
|
||||
}
|
||||
14
Content.Shared/Item/MultiHandedItemComponent.cs
Normal file
14
Content.Shared/Item/MultiHandedItemComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Item;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for items that need
|
||||
/// multiple hands to be able to be picked up
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class MultiHandedItemComponent : Component
|
||||
{
|
||||
[DataField("handsNeeded"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public int HandsNeeded = 2;
|
||||
}
|
||||
48
Content.Shared/Item/SharedMultiHandedItemSystem.cs
Normal file
48
Content.Shared/Item/SharedMultiHandedItemSystem.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Item;
|
||||
|
||||
public abstract class SharedMultiHandedItemSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<MultiHandedItemComponent, GettingPickedUpAttemptEvent>(OnAttemptPickup);
|
||||
SubscribeLocalEvent<MultiHandedItemComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
|
||||
SubscribeLocalEvent<MultiHandedItemComponent, GotEquippedHandEvent>(OnEquipped);
|
||||
SubscribeLocalEvent<MultiHandedItemComponent, GotUnequippedHandEvent>(OnUnequipped);
|
||||
}
|
||||
|
||||
protected abstract void OnEquipped(EntityUid uid, MultiHandedItemComponent component, GotEquippedHandEvent args);
|
||||
protected abstract void OnUnequipped(EntityUid uid, MultiHandedItemComponent component, GotUnequippedHandEvent args);
|
||||
|
||||
private void OnAttemptPickup(EntityUid uid, MultiHandedItemComponent component, GettingPickedUpAttemptEvent args)
|
||||
{
|
||||
if (TryComp<SharedHandsComponent>(args.User, out var hands) && hands.CountFreeHands() >= component.HandsNeeded)
|
||||
return;
|
||||
|
||||
args.Cancel();
|
||||
if (_timing.IsFirstTimePredicted)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("multi-handed-item-pick-up-fail",
|
||||
("number", component.HandsNeeded - 1), ("item", uid)), args.User, Filter.Local());
|
||||
}
|
||||
}
|
||||
|
||||
private void OnVirtualItemDeleted(EntityUid uid, MultiHandedItemComponent component, VirtualItemDeletedEvent args)
|
||||
{
|
||||
if (args.BlockingEntity != uid)
|
||||
return;
|
||||
|
||||
_hands.TryDrop(args.User, uid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
multi-handed-item-pick-up-fail = {$number ->
|
||||
[one] You need one more free hand to pick up { THE($item) }.
|
||||
*[other] You need { $number } more free hands to pick up { THE($item) }.
|
||||
}
|
||||
Reference in New Issue
Block a user