StackSystem uses EntityUid for Split and Spawn

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 15:34:40 +01:00
parent 6f2cc733e7
commit 8b57bafcd1
13 changed files with 60 additions and 44 deletions

View File

@@ -10,9 +10,9 @@ namespace Content.Shared.Construction.Steps
{
[DataField("component")] public string Component { get; } = string.Empty;
public override bool EntityValid(IEntity entity)
public override bool EntityValid(EntityUid uid, IEntityManager entityManager)
{
foreach (var component in entity.GetAllComponents())
foreach (var component in entityManager.GetComponents(uid))
{
if (component.Name == Component)
return true;

View File

@@ -8,6 +8,6 @@ namespace Content.Shared.Construction.Steps
{
[DataField("store")] public string Store { get; } = string.Empty;
public abstract bool EntityValid(IEntity entity);
public abstract bool EntityValid(EntityUid uid, IEntityManager entityManager);
}
}

View File

@@ -27,9 +27,9 @@ namespace Content.Shared.Construction.Steps
examinedEvent.Message.AddMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", material.Name)));
}
public override bool EntityValid(IEntity entity)
public override bool EntityValid(EntityUid uid, IEntityManager entityManager)
{
return entity.TryGetComponent(out SharedStackComponent? stack) && stack.StackTypeId.Equals(MaterialPrototypeId) && stack.Count >= Amount;
return entityManager.TryGetComponent(uid, out SharedStackComponent? stack) && stack.StackTypeId.Equals(MaterialPrototypeId) && stack.Count >= Amount;
}
public bool EntityValid(IEntity entity, [NotNullWhen(true)] out SharedStackComponent? stack)

View File

@@ -18,16 +18,20 @@ namespace Content.Shared.Construction.Steps
return list == null || list.Count == 0;
}
public override bool EntityValid(IEntity entity)
public override bool EntityValid(EntityUid uid, IEntityManager entityManager)
{
// This step can only happen if either list has tags.
if (IsNullOrEmpty(_allTags) && IsNullOrEmpty(_anyTags))
return false; // Step is somehow invalid, we return.
if (_allTags != null && !entity.HasAllTags(_allTags))
// No tags at all.
if (!entityManager.TryGetComponent(uid, out TagComponent? tags))
return false;
if (_allTags != null && !tags.HasAllTags(_allTags))
return false; // We don't have all the tags needed.
if (_anyTags != null && !entity.HasAnyTag(_anyTags))
if (_anyTags != null && !tags.HasAnyTag(_anyTags))
return false; // We don't have any of the tags needed.
// This entity is valid!

View File

@@ -10,9 +10,9 @@ namespace Content.Shared.Construction.Steps
{
[DataField("prototype")] public string Prototype { get; } = string.Empty;
public override bool EntityValid(IEntity entity)
public override bool EntityValid(EntityUid uid, IEntityManager entityManager)
{
return entity.Prototype?.ID == Prototype;
return entityManager.GetComponent<MetaDataComponent>(uid).EntityPrototype?.ID == Prototype;
}
public override void DoExamine(ExaminedEvent examinedEvent)

View File

@@ -10,9 +10,9 @@ namespace Content.Shared.Construction.Steps
[DataField("tag")]
private string? _tag = null;
public override bool EntityValid(IEntity entity)
public override bool EntityValid(EntityUid uid, IEntityManager entityManager)
{
return !string.IsNullOrEmpty(_tag) && entity.HasTag(_tag);
return !string.IsNullOrEmpty(_tag) && entityManager.TryGetComponent(uid, out TagComponent? tags) && tags.HasTag(_tag);
}
}
}