2020-10-08 17:41:23 +02:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Content.Shared.Construction;
|
|
|
|
|
|
using JetBrains.Annotations;
|
2021-03-01 15:24:46 -08:00
|
|
|
|
using Robust.Shared.Containers;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Construction.Conditions
|
|
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
|
public class ContainerEmpty : IEdgeCondition
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Container { get; private set; } = string.Empty;
|
|
|
|
|
|
public string Text { get; private set; } = string.Empty;
|
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
|
void IExposeData.ExposeData(ObjectSerializer serializer)
|
2020-10-08 17:41:23 +02:00
|
|
|
|
{
|
|
|
|
|
|
serializer.DataField(this, x => x.Container, "container", string.Empty);
|
|
|
|
|
|
serializer.DataField(this, x => x.Text, "text", string.Empty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> Condition(IEntity entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
|
|
|
|
|
!containerManager.TryGetContainer(Container, out var container)) return true;
|
|
|
|
|
|
|
|
|
|
|
|
return container.ContainedEntities.Count == 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-03 22:49:00 +01:00
|
|
|
|
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange)
|
2020-10-08 17:41:23 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
2020-12-03 22:49:00 +01:00
|
|
|
|
!containerManager.TryGetContainer(Container, out var container)) return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (container.ContainedEntities.Count == 0)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
message.AddMarkup(Text);
|
|
|
|
|
|
return true;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|