Actual lockers (#195)
Adds storing entities into lockers the way we all know and love. Relies on an implementation of ITileDefinition in https://github.com/space-wizards/space-station-14/pull/193 (just like origin/master) #191
This commit is contained in:
committed by
Pieter-Jan Briers
parent
1fe24eeb12
commit
903961771b
@@ -6,10 +6,13 @@ using Content.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Server.GameObjects
|
||||
{
|
||||
public class ItemComponent : StoreableComponent, IAttackHand
|
||||
public class ItemComponent : StoreableComponent, IAttackHand, IAfterAttack
|
||||
{
|
||||
public override string Name => "Item";
|
||||
public override uint? NetID => ContentNetIDs.ITEM;
|
||||
@@ -87,5 +90,38 @@ namespace Content.Server.GameObjects
|
||||
{
|
||||
return new ItemComponentState(EquippedPrefix);
|
||||
}
|
||||
|
||||
public void AfterAttack(AfterAttackEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent<HandsComponent>(out var handComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!eventArgs.Attacked.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
handComponent.Drop(handComponent.ActiveIndex);
|
||||
Owner.Transform.WorldPosition = eventArgs.ClickLocation.Position;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ using System.Collections.Generic;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.GameObjects.EntitySystemMessages;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Content.Server.GameObjects.Components;
|
||||
|
||||
namespace Content.Server.GameObjects
|
||||
{
|
||||
@@ -131,13 +132,20 @@ namespace Content.Server.GameObjects
|
||||
/// <param name="user"></param>
|
||||
/// <param name="attackwith"></param>
|
||||
/// <returns></returns>
|
||||
bool IAttackBy.AttackBy(AttackByEventArgs eventArgs)
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
_ensureInitialCalculated();
|
||||
Logger.DebugS("Storage", "Storage (UID {0}) attacked by user (UID {1}) with entity (UID {2}).", Owner.Uid, eventArgs.User.Uid, eventArgs.AttackWith.Uid);
|
||||
|
||||
if (!eventArgs.User.TryGetComponent(out HandsComponent hands))
|
||||
if(Owner.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!eventArgs.User.TryGetComponent(out HandsComponent hands))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check that we can drop the item from our hands first otherwise we obviously cant put it inside
|
||||
if (CanInsert(hands.GetActiveHand.Owner) && hands.Drop(hands.ActiveIndex))
|
||||
@@ -324,10 +332,5 @@ namespace Content.Server.GameObjects
|
||||
|
||||
_storageInitialCalculated = true;
|
||||
}
|
||||
|
||||
public bool Attackby(AttackByEventArgs eventArgs)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user