Re-organize all projects (#4166)
This commit is contained in:
75
Content.Server/Items/ItemComponent.cs
Normal file
75
Content.Server/Items/ItemComponent.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
#nullable enable
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Items
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
public class ItemComponent : SharedItemComponent
|
||||
{
|
||||
public override void RemovedFromSlot()
|
||||
{
|
||||
foreach (var component in Owner.GetAllComponents<ISpriteRenderableComponent>())
|
||||
{
|
||||
component.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void EquippedToSlot()
|
||||
{
|
||||
foreach (var component in Owner.GetAllComponents<ISpriteRenderableComponent>())
|
||||
{
|
||||
component.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryPutInHand(IEntity user)
|
||||
{
|
||||
if (!CanPickup(user))
|
||||
return false;
|
||||
|
||||
if (!user.TryGetComponent(out IHandsComponent? hands))
|
||||
return false;
|
||||
|
||||
var activeHand = hands.ActiveHand;
|
||||
|
||||
if (activeHand == null)
|
||||
return false;
|
||||
|
||||
hands.PutInHand(this, activeHand, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Verb]
|
||||
public sealed class PickUpVerb : Verb<ItemComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, ItemComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user) ||
|
||||
component.Owner.IsInContainer() ||
|
||||
!component.CanPickup(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("Pick Up");
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, ItemComponent component)
|
||||
{
|
||||
if (user.TryGetComponent(out HandsComponent? hands) && !hands.IsHolding(component.Owner))
|
||||
{
|
||||
hands.PutInHand(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user