ECS tags (#6504)
This commit is contained in:
@@ -9,6 +9,7 @@ using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Construction.Conditions
|
||||
{
|
||||
@@ -39,18 +40,23 @@ namespace Content.Shared.Construction.Conditions
|
||||
var physics = EntitySystem.Get<SharedPhysicsSystem>();
|
||||
var rUserToObj = new CollisionRay(userWorldPosition, userToObject.Normalized, (int) CollisionGroup.Impassable);
|
||||
var length = userToObject.Length;
|
||||
|
||||
var tagSystem = EntitySystem.Get<TagSystem>();
|
||||
|
||||
var userToObjRaycastResults = physics.IntersectRayWithPredicate(entManager.GetComponent<TransformComponent>(user).MapID, rUserToObj, maxLength: length,
|
||||
predicate: (e) => !e.HasTag("Wall"));
|
||||
if (!userToObjRaycastResults.Any())
|
||||
predicate: (e) => !tagSystem.HasTag(e, "Wall"));
|
||||
|
||||
var targetWall = userToObjRaycastResults.FirstOrNull();
|
||||
|
||||
if (targetWall == null)
|
||||
return false;
|
||||
|
||||
// get this wall entity
|
||||
var targetWall = userToObjRaycastResults.First().HitEntity;
|
||||
|
||||
// check that we didn't try to build wallmount that facing another adjacent wall
|
||||
var rAdjWall = new CollisionRay(objWorldPosition, directionWithOffset.Normalized, (int) CollisionGroup.Impassable);
|
||||
var adjWallRaycastResults = physics.IntersectRayWithPredicate(entManager.GetComponent<TransformComponent>(user).MapID, rAdjWall, maxLength: 0.5f,
|
||||
predicate: (e) => e == targetWall || !e.HasTag("Wall"));
|
||||
predicate: (e) => e == targetWall.Value.HitEntity || !tagSystem.HasTag(e, "Wall"));
|
||||
|
||||
return !adjWallRaycastResults.Any();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,12 @@ namespace Content.Shared.Construction.Steps
|
||||
if (!entityManager.TryGetComponent(uid, out TagComponent? tags))
|
||||
return false;
|
||||
|
||||
if (_allTags != null && !tags.HasAllTags(_allTags))
|
||||
var tagSystem = EntitySystem.Get<TagSystem>();
|
||||
|
||||
if (_allTags != null && !tagSystem.HasAllTags(tags, _allTags))
|
||||
return false; // We don't have all the tags needed.
|
||||
|
||||
if (_anyTags != null && !tags.HasAnyTag(_anyTags))
|
||||
if (_anyTags != null && !tagSystem.HasAnyTag(tags, _anyTags))
|
||||
return false; // We don't have any of the tags needed.
|
||||
|
||||
// This entity is valid!
|
||||
|
||||
@@ -12,7 +12,8 @@ namespace Content.Shared.Construction.Steps
|
||||
|
||||
public override bool EntityValid(EntityUid uid, IEntityManager entityManager)
|
||||
{
|
||||
return !string.IsNullOrEmpty(_tag) && entityManager.TryGetComponent(uid, out TagComponent? tags) && tags.HasTag(_tag);
|
||||
var tagSystem = EntitySystem.Get<TagSystem>();
|
||||
return !string.IsNullOrEmpty(_tag) && tagSystem.HasTag(uid, _tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user