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
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.AI;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
@@ -119,7 +119,7 @@ namespace Content.Server.AI
|
||||
|
||||
// build the ray
|
||||
var dir = entity.GetComponent<ITransformComponent>().WorldPosition - myTransform.WorldPosition;
|
||||
var ray = new Ray(myTransform.WorldPosition, dir.Normalized,0); //TODO verify if 0 is the correct Collision Mask
|
||||
var ray = new Ray(myTransform.WorldPosition, dir.Normalized, (int)(CollisionGroup.Mob | CollisionGroup.Grid));
|
||||
|
||||
// cast the ray
|
||||
var result = _physMan.IntersectRay(ray, maxRayLen);
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.Linq" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@@ -71,6 +72,7 @@
|
||||
<Compile Include="GameObjects\Components\CatwalkComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Damage\DamageThreshold.cs" />
|
||||
<Compile Include="GameObjects\Components\Doors\ServerDoorComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\EntityStorageComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Mobs\HeatResistanceComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Interactable\HandheldLightComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Interactable\Tools\BaseTool.cs" />
|
||||
@@ -93,6 +95,7 @@
|
||||
<Compile Include="GameObjects\Components\Mobs\SpeciesComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Movement\AiControllerComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Movement\PlayerInputMoverComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\PlaceableSurfaceComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Power\LightBulbComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Power\PowerCellComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\Power\PowerStorageComponent.cs" />
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace Content.Server
|
||||
factory.Register<ClothingComponent>();
|
||||
factory.RegisterReference<ClothingComponent, ItemComponent>();
|
||||
factory.RegisterReference<ClothingComponent, StoreableComponent>();
|
||||
factory.Register<PlaceableSurfaceComponent>();
|
||||
|
||||
factory.Register<DamageableComponent>();
|
||||
factory.Register<DestructibleComponent>();
|
||||
@@ -117,6 +118,7 @@ namespace Content.Server
|
||||
|
||||
factory.Register<ServerStorageComponent>();
|
||||
factory.RegisterReference<ServerStorageComponent, IActivate>();
|
||||
factory.Register<EntityStorageComponent>();
|
||||
|
||||
factory.Register<PowerDebugTool>();
|
||||
factory.Register<PoweredLightComponent>();
|
||||
|
||||
160
Content.Server/GameObjects/Components/EntityStorageComponent.cs
Normal file
160
Content.Server/GameObjects/Components/EntityStorageComponent.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
public class EntityStorageComponent : Component, IAttackHand
|
||||
{
|
||||
public override string Name => "EntityStorage";
|
||||
|
||||
private ServerStorageComponent StorageComponent;
|
||||
private int StorageCapacityMax;
|
||||
private bool IsCollidableWhenOpen;
|
||||
private Container Contents;
|
||||
private IEntityQuery entityQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Contents = ContainerManagerComponent.Ensure<Container>($"{typeof(EntityStorageComponent).FullName}{Owner.Uid.ToString()}", Owner);
|
||||
StorageComponent = Owner.AddComponent<ServerStorageComponent>();
|
||||
StorageComponent.Initialize();
|
||||
entityQuery = new IntersectingEntityQuery(Owner);
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref StorageCapacityMax, "Capacity", 30);
|
||||
serializer.DataField(ref IsCollidableWhenOpen, "IsCollidableWhenOpen", false);
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Open
|
||||
{
|
||||
get => StorageComponent.Open;
|
||||
set => StorageComponent.Open = value;
|
||||
}
|
||||
|
||||
public bool AttackHand(AttackHandEventArgs eventArgs)
|
||||
{
|
||||
if (Open)
|
||||
{
|
||||
CloseStorage();
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenStorage();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CloseStorage()
|
||||
{
|
||||
Open = false;
|
||||
var entities = Owner.EntityManager.GetEntities(entityQuery);
|
||||
int count = 0;
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (!AddToContents(entity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
if (count >= StorageCapacityMax)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
ModifyComponents();
|
||||
}
|
||||
|
||||
private void OpenStorage()
|
||||
{
|
||||
Open = true;
|
||||
EmptyContents();
|
||||
ModifyComponents();
|
||||
}
|
||||
|
||||
private void ModifyComponents()
|
||||
{
|
||||
if (Owner.TryGetComponent<ICollidableComponent>(out var collidableComponent))
|
||||
{
|
||||
collidableComponent.CollisionEnabled = IsCollidableWhenOpen || !Open;
|
||||
}
|
||||
if (Owner.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
|
||||
{
|
||||
placeableSurfaceComponent.IsPlaceable = Open;
|
||||
}
|
||||
}
|
||||
|
||||
private bool AddToContents(IEntity entity)
|
||||
{
|
||||
var collidableComponent = Owner.GetComponent<ICollidableComponent>();
|
||||
if(entity.TryGetComponent<ICollidableComponent>(out var entityCollidableComponent))
|
||||
{
|
||||
if(collidableComponent.WorldAABB.Size.X < entityCollidableComponent.WorldAABB.Size.X
|
||||
|| collidableComponent.WorldAABB.Size.Y < entityCollidableComponent.WorldAABB.Size.Y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (collidableComponent.WorldAABB.Left > entityCollidableComponent.WorldAABB.Left)
|
||||
{
|
||||
entity.Transform.WorldPosition += new Vector2(collidableComponent.WorldAABB.Left - entityCollidableComponent.WorldAABB.Left, 0);
|
||||
}
|
||||
else if (collidableComponent.WorldAABB.Right < entityCollidableComponent.WorldAABB.Right)
|
||||
{
|
||||
entity.Transform.WorldPosition += new Vector2(collidableComponent.WorldAABB.Right - entityCollidableComponent.WorldAABB.Right, 0);
|
||||
}
|
||||
if (collidableComponent.WorldAABB.Bottom > entityCollidableComponent.WorldAABB.Bottom)
|
||||
{
|
||||
entity.Transform.WorldPosition += new Vector2(0, collidableComponent.WorldAABB.Bottom - entityCollidableComponent.WorldAABB.Bottom);
|
||||
}
|
||||
else if (collidableComponent.WorldAABB.Top < entityCollidableComponent.WorldAABB.Top)
|
||||
{
|
||||
entity.Transform.WorldPosition += new Vector2(0, collidableComponent.WorldAABB.Top - entityCollidableComponent.WorldAABB.Top);
|
||||
}
|
||||
}
|
||||
if (Contents.CanInsert(entity))
|
||||
{
|
||||
Contents.Insert(entity);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void EmptyContents()
|
||||
{
|
||||
while (Contents.ContainedEntities.Count > 0 )
|
||||
{
|
||||
var containedEntity = Contents.ContainedEntities.First();
|
||||
Contents.Remove(containedEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
||||
{
|
||||
base.HandleMessage(message, netChannel, component);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case RelayMovementEntityMessage msg:
|
||||
if(msg.Entity.TryGetComponent<HandsComponent>(out var handsComponent))
|
||||
{
|
||||
OpenStorage();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,6 +248,10 @@ namespace Content.Server.GameObjects
|
||||
|
||||
// TODO: The item should be dropped to the container our owner is in, if any.
|
||||
item.Owner.Transform.GridPosition = Owner.Transform.GridPosition;
|
||||
if (item.Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
|
||||
{
|
||||
spriteComponent.RenderOrder = item.Owner.EntityManager.CurrentTick.Value;
|
||||
}
|
||||
|
||||
Dirty();
|
||||
return true;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
public class PlaceableSurfaceComponent : Component
|
||||
{
|
||||
public override string Name => "PlaceableSurface";
|
||||
|
||||
private bool _isPlaceable;
|
||||
public bool IsPlaceable { get => _isPlaceable; set => _isPlaceable = value; }
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _isPlaceable, "IsPlaceable", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Content.Server.GameObjects.Components.Projectiles;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
|
||||
@@ -25,9 +26,10 @@ namespace Content.Server.GameObjects.Components
|
||||
// after impacting the first object.
|
||||
// For realism this should actually be changed when the velocity of the object is less than a threshold.
|
||||
// This would allow ricochets off walls, and weird gravity effects from slowing the object.
|
||||
if (collidedwith.Count > 0 && Owner.TryGetComponent(out ICollidableComponent body))
|
||||
if (collidedwith.Count > 0 && Owner.TryGetComponent(out CollidableComponent body))
|
||||
{
|
||||
body.CollisionMask &= (int) ~CollisionGroup.Mob;
|
||||
body.CollisionMask &= (int)~CollisionGroup.Mob;
|
||||
body.IsScrapingFloor = true;
|
||||
|
||||
// KYS, your job is finished.
|
||||
Owner.RemoveComponent<ThrownItemComponent>();
|
||||
|
||||
@@ -16,6 +16,7 @@ using Robust.Shared.GameObjects;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Physics;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
|
||||
{
|
||||
@@ -84,7 +85,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
|
||||
var userPosition = user.Transform.WorldPosition; //Remember world positions are ephemeral and can only be used instantaneously
|
||||
var angle = new Angle(clickLocation.Position - userPosition);
|
||||
|
||||
var ray = new Ray(userPosition, angle.ToVec(), 0); //TODO set the CollsionMask for this ray.
|
||||
var ray = new Ray(userPosition, angle.ToVec(), (int)(CollisionGroup.Grid | CollisionGroup.Mob));
|
||||
var rayCastResults = IoCManager.Resolve<IPhysicsManager>().IntersectRay(ray, MaxLength,
|
||||
Owner.Transform.GetMapTransform().Owner);
|
||||
|
||||
|
||||
@@ -109,23 +109,17 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
var ent = ((IPlayerSession) session).AttachedEntity;
|
||||
|
||||
if(ent == null || !ent.IsValid())
|
||||
if (ent == null || !ent.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ent.TryGetComponent(out HandsComponent handsComp))
|
||||
{
|
||||
return;
|
||||
|
||||
var transform = ent.Transform;
|
||||
|
||||
if (transform.GridPosition.InRange(coords, InteractionSystem.INTERACTION_RANGE))
|
||||
{
|
||||
handsComp.Drop(handsComp.ActiveIndex, coords);
|
||||
}
|
||||
else
|
||||
{
|
||||
handsComp.Drop(handsComp.ActiveIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleActivateItem(ICommonSession session)
|
||||
{
|
||||
@@ -163,22 +157,17 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
if (!throwEnt.TryGetComponent(out CollidableComponent colComp))
|
||||
{
|
||||
colComp = throwEnt.AddComponent<CollidableComponent>();
|
||||
|
||||
if(!colComp.Running)
|
||||
colComp.Startup();
|
||||
return;
|
||||
}
|
||||
|
||||
colComp.CollisionEnabled = true;
|
||||
colComp.CollisionLayer |= (int)CollisionGroup.Items;
|
||||
colComp.CollisionMask |= (int)CollisionGroup.Grid;
|
||||
|
||||
// I can now collide with player, so that i can do damage.
|
||||
colComp.CollisionMask |= (int) CollisionGroup.Mob;
|
||||
|
||||
if (!throwEnt.TryGetComponent(out ThrownItemComponent projComp))
|
||||
{
|
||||
projComp = throwEnt.AddComponent<ThrownItemComponent>();
|
||||
colComp.CollisionMask |= (int)CollisionGroup.Mob;
|
||||
colComp.IsScrapingFloor = false;
|
||||
}
|
||||
|
||||
projComp.IgnoreEntity(plyEnt);
|
||||
|
||||
@@ -122,5 +122,6 @@
|
||||
<Name>Robust.Shared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -7,7 +7,7 @@ namespace Content.Shared.GameObjects.Components.Storage
|
||||
{
|
||||
public abstract class SharedStorageComponent : Component
|
||||
{
|
||||
public sealed override string Name => "Storage";
|
||||
public override string Name => "Storage";
|
||||
public override uint? NetID => ContentNetIDs.INVENTORY;
|
||||
public override Type StateType => typeof(StorageComponentState);
|
||||
|
||||
|
||||
@@ -17,5 +17,6 @@
|
||||
public const uint SOUND = 1012;
|
||||
public const uint ITEM = 1013;
|
||||
public const uint CLOTHING = 1014;
|
||||
public const uint ENTITYSTORAGE = 1015;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ namespace Content.Shared.Physics
|
||||
[Flags]
|
||||
public enum CollisionGroup
|
||||
{
|
||||
None = 0x0000,
|
||||
Grid = 0x0001, // Walls
|
||||
Mob = 0x0002, // Mobs, like the player or NPCs
|
||||
Fixture = 0x0004, // wall fixtures, like APC or posters
|
||||
Items = 0x008, // Items on the ground
|
||||
None = 0,
|
||||
Grid = 1, // Walls
|
||||
Mob = 2, // Mobs, like the player or NPCs
|
||||
Fixture = 4, // wall fixtures, like APC or posters
|
||||
Items = 8 // Items on the ground
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
Size: 5
|
||||
- type: Clickable
|
||||
- type: BoundingBox
|
||||
aabb: "-0.15,-0.15,0.15,0.15"
|
||||
- type: Collidable
|
||||
mask: 5
|
||||
layer: 8
|
||||
IsScrapingFloor: true
|
||||
- type: Physics
|
||||
mass: 5
|
||||
- type: Sprite
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
mass: 85
|
||||
|
||||
- type: Collidable
|
||||
mask: 3
|
||||
layer: 2
|
||||
DebugColor: "#0000FF"
|
||||
|
||||
- type: Input
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
- type: BoundingBox
|
||||
aabb: "-0.5,-0.25,0.5,0.25"
|
||||
- type: Collidable
|
||||
IsInteractingWithFloor: true
|
||||
- type: Storage
|
||||
Capacity: 80
|
||||
mask: 11
|
||||
IsScrapingFloor: true
|
||||
- type: Physics
|
||||
mass: 25
|
||||
Anchored: false
|
||||
- type: EntityStorage
|
||||
- type: PlaceableSurface
|
||||
|
||||
placement:
|
||||
snap:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
name: "worktop"
|
||||
components:
|
||||
- type: Clickable
|
||||
- type: PlaceableSurface
|
||||
- type: Sprite
|
||||
netsync: false
|
||||
sprite: Buildings/table_solid.rsi
|
||||
|
||||
Reference in New Issue
Block a user