Fix being able to buckle through a locker and reality collapsing

This commit is contained in:
DrSmugleaf
2020-07-03 14:54:45 +02:00
parent 3ee480a3b1
commit dd72c1e3f0
11 changed files with 60 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
using Content.Server.AI.Utility;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Utility;
using Robust.Shared.Interfaces.GameObjects;

View File

@@ -1,6 +1,7 @@
using Content.Server.AI.Utility;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Utility;
using Content.Shared.GameObjects.EntitySystems;

View File

@@ -3,6 +3,7 @@ using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.GameObjects;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
using Robust.Shared.Containers;
namespace Content.Server.AI.Utility.Considerations.Containers

View File

@@ -2,6 +2,7 @@ using System.Collections.Generic;
using Content.Server.AI.Utils;
using Content.Server.GameObjects;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Movement;
using JetBrains.Annotations;
using Robust.Shared.Containers;

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
using Robust.Shared.Interfaces.GameObjects;
using Logger = Robust.Shared.Log.Logger;

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Content.Server.AI.Utils;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Movement;
using Content.Server.GameObjects.Components.Nutrition;
using JetBrains.Annotations;

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Content.Server.AI.Utils;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Movement;
using Content.Server.GameObjects.Components.Nutrition;
using JetBrains.Annotations;

View File

@@ -1,3 +1,4 @@
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Weapon;
using Content.Server.GameObjects.EntitySystems;
using Robust.Server.GameObjects.EntitySystems;

View File

@@ -1,8 +1,6 @@
using System;
using System.Linq;
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Sound;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Interactable;
@@ -25,12 +23,12 @@ using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components
namespace Content.Server.GameObjects.Components.Items.Storage
{
[RegisterComponent]
[ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(IStorageComponent))]
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IActionBlocker
{
public override string Name => "EntityStorage";
@@ -40,13 +38,13 @@ namespace Content.Server.GameObjects.Components
private TimeSpan _lastInternalOpenAttempt;
[ViewVariables]
private int StorageCapacityMax;
private int _storageCapacityMax;
[ViewVariables]
private bool IsCollidableWhenOpen;
private bool _isCollidableWhenOpen;
[ViewVariables]
private Container Contents;
private Container _contents;
[ViewVariables]
private IEntityQuery entityQuery;
private IEntityQuery _entityQuery;
private bool _showContents;
private bool _open;
private bool _isWeldedShut;
@@ -63,7 +61,7 @@ namespace Content.Server.GameObjects.Components
set
{
_showContents = value;
Contents.ShowContents = _showContents;
_contents.ShowContents = _showContents;
}
}
@@ -96,10 +94,10 @@ namespace Content.Server.GameObjects.Components
public override void Initialize()
{
base.Initialize();
Contents = ContainerManagerComponent.Ensure<Container>(nameof(EntityStorageComponent), Owner);
entityQuery = new IntersectingEntityQuery(Owner);
_contents = ContainerManagerComponent.Ensure<Container>(nameof(EntityStorageComponent), Owner);
_entityQuery = new IntersectingEntityQuery(Owner);
Contents.ShowContents = _showContents;
_contents.ShowContents = _showContents;
if (Owner.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
{
@@ -112,8 +110,8 @@ namespace Content.Server.GameObjects.Components
{
base.ExposeData(serializer);
serializer.DataField(ref StorageCapacityMax, "Capacity", 30);
serializer.DataField(ref IsCollidableWhenOpen, "IsCollidableWhenOpen", false);
serializer.DataField(ref _storageCapacityMax, "Capacity", 30);
serializer.DataField(ref _isCollidableWhenOpen, "IsCollidableWhenOpen", false);
serializer.DataField(ref _showContents, "showContents", false);
serializer.DataField(ref _open, "open", false);
serializer.DataField(this, a => a.IsWeldedShut, "IsWeldedShut", false);
@@ -146,7 +144,7 @@ namespace Content.Server.GameObjects.Components
private void CloseStorage()
{
Open = false;
var entities = Owner.EntityManager.GetEntities(entityQuery);
var entities = Owner.EntityManager.GetEntities(_entityQuery);
var count = 0;
foreach (var entity in entities)
{
@@ -163,7 +161,7 @@ namespace Content.Server.GameObjects.Components
continue;
}
count++;
if (count >= StorageCapacityMax)
if (count >= _storageCapacityMax)
{
break;
}
@@ -180,12 +178,11 @@ namespace Content.Server.GameObjects.Components
EmptyContents();
ModifyComponents();
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/machines/closetopen.ogg", Owner);
}
private void ModifyComponents()
{
if (!IsCollidableWhenOpen && Owner.TryGetComponent<ICollidableComponent>(out var collidableComponent))
if (!_isCollidableWhenOpen && Owner.TryGetComponent<ICollidableComponent>(out var collidableComponent))
{
var physShape = collidableComponent.PhysicsShapes[0];
if (Open)
@@ -242,7 +239,7 @@ namespace Content.Server.GameObjects.Components
entity.Transform.WorldPosition += new Vector2(0, collidableComponent.WorldAABB.Top - entityCollidableComponent.WorldAABB.Top);
}
}
if (Contents.CanInsert(entity))
if (_contents.CanInsert(entity))
{
// Because Insert sets the local position to (0,0), and we want to keep the contents spread out,
// we re-apply the world position after inserting.
@@ -255,7 +252,7 @@ namespace Content.Server.GameObjects.Components
{
worldPos = entity.Transform.WorldPosition;
}
Contents.Insert(entity);
_contents.Insert(entity);
entity.Transform.WorldPosition = worldPos;
if (entityCollidableComponent != null)
{
@@ -268,9 +265,9 @@ namespace Content.Server.GameObjects.Components
private void EmptyContents()
{
foreach (var contained in Contents.ContainedEntities.ToArray())
foreach (var contained in _contents.ContainedEntities.ToArray())
{
if(Contents.Remove(contained))
if(_contents.Remove(contained))
{
if (contained.TryGetComponent<ICollidableComponent>(out var entityCollidableComponent))
{
@@ -317,7 +314,7 @@ namespace Content.Server.GameObjects.Components
/// <inheritdoc />
public bool Remove(IEntity entity)
{
return Contents.CanRemove(entity);
return _contents.CanRemove(entity);
}
/// <inheritdoc />
@@ -330,7 +327,7 @@ namespace Content.Server.GameObjects.Components
return true;
}
return Contents.Insert(entity);
return _contents.Insert(entity);
}
/// <inheritdoc />
@@ -341,12 +338,12 @@ namespace Content.Server.GameObjects.Components
return true;
}
if (Contents.ContainedEntities.Count >= StorageCapacityMax)
if (_contents.ContainedEntities.Count >= _storageCapacityMax)
{
return false;
}
return Contents.CanInsert(entity);
return _contents.CanInsert(entity);
}
[Verb]

View File

@@ -9,6 +9,7 @@ using Content.Shared.GameObjects.Components.Strap;
using Content.Shared.GameObjects.EntitySystems;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
@@ -59,6 +60,22 @@ namespace Content.Server.GameObjects.Components.Mobs
}
}
private bool IsContained()
{
var parent = Owner.Transform.Parent;
if (parent == null)
{
return false;
}
if (parent.Owner.TryGetComponent(out ContainerManagerComponent container))
{
return container.ContainsEntity(Owner);
}
return false;
}
private bool TryBuckle(IEntity user, IEntity to)
{
if (user == null || user == to)
@@ -76,7 +93,8 @@ namespace Content.Server.GameObjects.Components.Mobs
var strapPosition = Owner.Transform.MapPosition;
var range = SharedInteractionSystem.InteractionRange / 2;
if (!InteractionChecks.InRangeUnobstructed(user, strapPosition, range))
if (!InteractionChecks.InRangeUnobstructed(user, strapPosition, range) ||
IsContained())
{
_notifyManager.PopupMessage(user, user,
Loc.GetString("You can't reach there!"));

View File

@@ -149,6 +149,16 @@ namespace Content.Server.GameObjects.Components.Strap
OccupiedSize = 0;
}
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent(out BuckleComponent buckle))
{
return false;
}
return buckle.ToggleBuckle(eventArgs.User, Owner);
}
[Verb]
private sealed class StrapVerb : Verb<StrapComponent>
{
@@ -201,15 +211,5 @@ namespace Content.Server.GameObjects.Components.Strap
buckle.ToggleBuckle(user, component.Owner);
}
}
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent(out BuckleComponent buckle))
{
return false;
}
return buckle.ToggleBuckle(eventArgs.User, Owner);
}
}
}