2017-09-30 16:56:19 +02:00
|
|
|
|
using Content.Server.Interfaces.GameObjects;
|
|
|
|
|
|
using SS14.Server.Interfaces.GameObjects;
|
2017-10-06 21:05:21 +02:00
|
|
|
|
using SS14.Shared.GameObjects;
|
2017-09-24 21:09:26 +02:00
|
|
|
|
using System;
|
2018-02-05 13:57:26 -06:00
|
|
|
|
using SS14.Shared.Interfaces.GameObjects;
|
2017-09-24 21:09:26 +02:00
|
|
|
|
|
2017-09-24 23:19:47 +02:00
|
|
|
|
namespace Content.Server.GameObjects
|
2017-09-24 21:09:26 +02:00
|
|
|
|
{
|
2018-02-05 13:57:26 -06: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
|
|
|
|
}
|
2017-10-06 21:05:21 +02:00
|
|
|
|
|
2018-02-05 13:57:26 -06:00
|
|
|
|
public bool Attackhand(IEntity user)
|
2017-10-06 21:05:21 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (ContainingSlot != null)
|
|
|
|
|
|
{
|
2018-02-05 13:57:26 -06:00
|
|
|
|
return false;
|
2017-10-06 21:05:21 +02:00
|
|
|
|
}
|
2018-02-05 13:57:26 -06:00
|
|
|
|
var hands = user.GetComponent<IHandsComponent>();
|
|
|
|
|
|
hands.PutInHand(this, hands.ActiveIndex, fallback: false);
|
|
|
|
|
|
return true;
|
2017-10-06 21:05:21 +02:00
|
|
|
|
}
|
2017-09-24 21:09:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|