Steal condition fix (#10323)
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Containers
|
||||
{
|
||||
public static class ContainerExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Searches the entity, and the entities containers recursively for a prototypeId
|
||||
/// </summary>
|
||||
/// <param name="entityUid">The entity to search</param>
|
||||
/// <param name="prototypeId">The prototypeId to find</param>
|
||||
/// <param name="entityManager">Optional entity manager</param>
|
||||
/// <returns>True if entity is, or contains a prototype Id</returns>
|
||||
public static bool ContainsPrototypeRecursive(this EntityUid entityUid, string prototypeId, IEntityManager? entityManager = null)
|
||||
{
|
||||
IoCManager.Resolve(ref entityManager);
|
||||
var metaQuery = entityManager.GetEntityQuery<MetaDataComponent>();
|
||||
var managerQuery = entityManager.GetEntityQuery<ContainerManagerComponent>();
|
||||
var stack = new Stack<ContainerManagerComponent>();
|
||||
if (metaQuery.GetComponent(entityUid).EntityPrototype?.ID == prototypeId)
|
||||
return true;
|
||||
if (!managerQuery.TryGetComponent(entityUid, out var currentManager))
|
||||
return false;
|
||||
do
|
||||
{
|
||||
foreach (var container in currentManager.Containers.Values)
|
||||
{
|
||||
foreach (var entity in container.ContainedEntities)
|
||||
{
|
||||
if (metaQuery.GetComponent(entity).EntityPrototype?.ID == prototypeId)
|
||||
return true;
|
||||
if (!managerQuery.TryGetComponent(entity, out var containerManager))
|
||||
continue;
|
||||
stack.Push(containerManager);
|
||||
}
|
||||
}
|
||||
} while (stack.TryPop(out currentManager));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
using Content.Server.Containers;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Objectives.Conditions
|
||||
{
|
||||
// Oh god my eyes
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class StealCondition : IObjectiveCondition, ISerializationHooks
|
||||
@@ -46,9 +48,41 @@ namespace Content.Server.Objectives.Conditions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mind?.OwnedEntity is not {Valid: true} owned)
|
||||
return 0f;
|
||||
return owned.ContainsPrototypeRecursive(_prototypeId)? 1f : 0f;
|
||||
var uid = _mind?.OwnedEntity;
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
// TODO make this a container system function
|
||||
// or: just iterate through transform children, instead of containers?
|
||||
|
||||
var metaQuery = entMan.GetEntityQuery<MetaDataComponent>();
|
||||
var managerQuery = entMan.GetEntityQuery<ContainerManagerComponent>();
|
||||
var stack = new Stack<ContainerManagerComponent>();
|
||||
|
||||
if (!metaQuery.TryGetComponent(_mind?.OwnedEntity, out var meta))
|
||||
return 0;
|
||||
|
||||
if (meta.EntityPrototype?.ID == _prototypeId)
|
||||
return 1;
|
||||
|
||||
if (!managerQuery.TryGetComponent(uid, out var currentManager))
|
||||
return 0;
|
||||
|
||||
do
|
||||
{
|
||||
foreach (var container in currentManager.Containers.Values)
|
||||
{
|
||||
foreach (var entity in container.ContainedEntities)
|
||||
{
|
||||
if (metaQuery.GetComponent(entity).EntityPrototype?.ID == _prototypeId)
|
||||
return 1;
|
||||
if (!managerQuery.TryGetComponent(entity, out var containerManager))
|
||||
continue;
|
||||
stack.Push(containerManager);
|
||||
}
|
||||
}
|
||||
} while (stack.TryPop(out currentManager));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user