Steal condition fix (#10323)
This commit is contained in:
@@ -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