2017-09-30 16:56:19 +02:00
|
|
|
|
using Content.Server.Interfaces.GameObjects;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Server.Interfaces.GameObjects;
|
2019-03-26 13:46:07 +01:00
|
|
|
|
using Content.Shared.GameObjects;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
2019-04-05 19:27:39 +02:00
|
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2019-04-08 12:18:27 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using Content.Shared.GameObjects.Components.Items;
|
2019-04-17 23:26:00 +02:00
|
|
|
|
using Content.Server.GameObjects.Components;
|
|
|
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Maths;
|
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
|
|
|
|
{
|
2019-04-25 22:22:51 +01:00
|
|
|
|
public class ItemComponent : StoreableComponent, IAttackHand
|
2017-09-24 21:09:26 +02:00
|
|
|
|
{
|
|
|
|
|
|
public override string Name => "Item";
|
2019-04-08 12:18:27 +02:00
|
|
|
|
public override uint? NetID => ContentNetIDs.ITEM;
|
|
|
|
|
|
public override Type StateType => typeof(ItemComponentState);
|
2018-05-10 19:21:15 +02:00
|
|
|
|
|
2019-04-08 12:18:27 +02:00
|
|
|
|
private string _equippedPrefix;
|
|
|
|
|
|
|
|
|
|
|
|
public string EquippedPrefix
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _equippedPrefix;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
Dirty();
|
|
|
|
|
|
_equippedPrefix = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-24 21:09:26 +02:00
|
|
|
|
|
|
|
|
|
|
public void RemovedFromSlot()
|
|
|
|
|
|
{
|
2018-05-10 19:21:15 +02:00
|
|
|
|
foreach (var component in Owner.GetAllComponents<ISpriteRenderableComponent>())
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
component.Visible = true;
|
|
|
|
|
|
}
|
2017-09-24 21:09:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-11 11:32:05 -08:00
|
|
|
|
public void EquippedToSlot()
|
2017-09-24 21:09:26 +02:00
|
|
|
|
{
|
2018-05-10 19:21:15 +02:00
|
|
|
|
foreach (var component in Owner.GetAllComponents<ISpriteRenderableComponent>())
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
component.Visible = false;
|
|
|
|
|
|
}
|
2017-09-24 21:09:26 +02:00
|
|
|
|
}
|
2017-10-06 21:05:21 +02:00
|
|
|
|
|
2019-04-05 19:27:39 +02:00
|
|
|
|
public bool AttackHand(AttackHandEventArgs eventArgs)
|
2017-10-06 21:05:21 +02:00
|
|
|
|
{
|
2019-04-05 19:27:39 +02:00
|
|
|
|
var hands = eventArgs.User.GetComponent<IHandsComponent>();
|
2018-02-05 13:57:26 -06:00
|
|
|
|
hands.PutInHand(this, hands.ActiveIndex, fallback: false);
|
|
|
|
|
|
return true;
|
2017-10-06 21:05:21 +02:00
|
|
|
|
}
|
2019-03-26 13:46:07 +01:00
|
|
|
|
|
|
|
|
|
|
[Verb]
|
|
|
|
|
|
public sealed class PickUpVerb : Verb<ItemComponent>
|
|
|
|
|
|
{
|
|
|
|
|
|
protected override string GetText(IEntity user, ItemComponent component)
|
|
|
|
|
|
{
|
2019-03-27 12:29:43 +00:00
|
|
|
|
if (user.TryGetComponent(out HandsComponent hands) && hands.IsHolding(component.Owner))
|
|
|
|
|
|
{
|
|
|
|
|
|
return "Pick Up (Already Holding)";
|
|
|
|
|
|
}
|
2019-03-26 13:46:07 +01:00
|
|
|
|
return "Pick Up";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override bool IsDisabled(IEntity user, ItemComponent component)
|
|
|
|
|
|
{
|
2019-03-27 12:29:43 +00:00
|
|
|
|
if (user.TryGetComponent(out HandsComponent hands) && hands.IsHolding(component.Owner))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2019-03-26 13:46:07 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Activate(IEntity user, ItemComponent component)
|
|
|
|
|
|
{
|
2019-03-27 12:29:43 +00:00
|
|
|
|
if (user.TryGetComponent(out HandsComponent hands) && !hands.IsHolding(component.Owner))
|
2019-03-26 13:46:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
hands.PutInHand(component);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-04-08 12:18:27 +02:00
|
|
|
|
|
|
|
|
|
|
public override ComponentState GetComponentState()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ItemComponentState(EquippedPrefix);
|
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
|
|
|
|
|
|
|
public void Fumble()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Owner.TryGetComponent<PhysicsComponent>(out var physicsComponent))
|
|
|
|
|
|
{
|
|
|
|
|
|
physicsComponent.LinearVelocity += RandomOffset();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Vector2 RandomOffset()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Vector2(RandomOffset(), RandomOffset());
|
|
|
|
|
|
float RandomOffset()
|
|
|
|
|
|
{
|
|
|
|
|
|
var size = 15.0F;
|
|
|
|
|
|
return (new Random().NextFloat() * size) - size / 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-24 21:09:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|