Files
crystall-punk-14/Content.Server/GameObjects/Components/Items/ItemComponent.cs

58 lines
1.6 KiB
C#
Raw Normal View History

2017-09-30 16:56:19 +02:00
using Content.Server.Interfaces.GameObjects;
using SS14.Server.Interfaces.GameObjects;
using SS14.Shared.GameObjects;
2017-09-24 21:09:26 +02:00
using System;
using SS14.Shared.Interfaces.GameObjects;
2017-09-24 21:09:26 +02:00
namespace Content.Server.GameObjects
2017-09-24 21:09:26 +02:00
{
public class ItemComponent : Component, IItemComponent, EntitySystems.IAttackHand
2017-09-24 21:09:26 +02:00
{
public override string Name => "Item";
/// <inheritdoc />
public IInventorySlot ContainingSlot { get; private set; }
public void RemovedFromSlot()
{
if (ContainingSlot == null)
{
throw new InvalidOperationException("Item is not in a slot.");
}
ContainingSlot = null;
2017-09-30 16:56:19 +02:00
foreach (var component in Owner.GetComponents<ISpriteRenderableComponent>())
{
component.Visible = true;
}
2017-09-24 21:09:26 +02:00
}
public void EquippedToSlot(IInventorySlot slot)
{
if (ContainingSlot != null)
{
throw new InvalidOperationException("Item is already in a slot.");
}
ContainingSlot = slot;
2017-09-30 16:56:19 +02:00
foreach (var component in Owner.GetComponents<ISpriteRenderableComponent>())
{
component.Visible = false;
}
2017-09-24 21:09:26 +02:00
}
public bool Attackhand(IEntity user)
{
if (ContainingSlot != null)
{
return false;
}
var hands = user.GetComponent<IHandsComponent>();
hands.PutInHand(this, hands.ActiveIndex, fallback: false);
return true;
}
2017-09-24 21:09:26 +02:00
}
}