2020-10-08 17:41:23 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Content.Shared.Construction;
|
|
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-01 03:11:29 +11:00
|
|
|
|
using Robust.Shared.Physics;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Construction.Conditions
|
|
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
|
public class EntityAnchored : IEdgeCondition
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Anchored { get; private set; }
|
|
|
|
|
|
|
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.Anchored, "anchored", true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> Condition(IEntity entity)
|
|
|
|
|
|
{
|
2021-03-01 03:11:29 +11:00
|
|
|
|
if (!entity.TryGetComponent(out IPhysBody physics)) return false;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
2021-03-01 03:11:29 +11:00
|
|
|
|
return (physics.BodyType == BodyType.Static && Anchored) || (physics.BodyType != BodyType.Static && !Anchored);
|
2020-10-08 17:41:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2021-03-01 03:11:29 +11:00
|
|
|
|
if (!entity.TryGetComponent(out IPhysBody physics)) return false;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
2020-12-03 22:49:00 +01:00
|
|
|
|
switch (Anchored)
|
|
|
|
|
|
{
|
2021-03-01 03:11:29 +11:00
|
|
|
|
case true when physics.BodyType == BodyType.Static:
|
2020-12-03 22:49:00 +01:00
|
|
|
|
message.AddMarkup("First, anchor it.\n");
|
|
|
|
|
|
return true;
|
2021-03-01 03:11:29 +11:00
|
|
|
|
case false when physics.BodyType == BodyType.Static:
|
2020-12-03 22:49:00 +01:00
|
|
|
|
message.AddMarkup("First, unanchor it.\n");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
2020-12-03 22:49:00 +01:00
|
|
|
|
return false;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|