Пример #1
0
    public bool TryPrototype(EntityUid uid, [NotNullWhen(true)] out EntityPrototype?prototype, MetaDataComponent?metaData = null)
    {
        if (!Resolve(uid, ref metaData, false))
        {
            prototype = null;
            return(false);
        }

        prototype = metaData.EntityPrototype;
        return(prototype != null);
    }
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            var id               = args.Length == 0 ? null : string.Join(" ", args);
            var entityManager    = IoCManager.Resolve <IEntityManager>();
            var prototypeManager = IoCManager.Resolve <IPrototypeManager>();

            EntityPrototype?prototype      = null;
            var             checkPrototype = !string.IsNullOrEmpty(id);

            if (checkPrototype && !prototypeManager.TryIndex(id !, out prototype))
            {
                shell.WriteError($"Can't find entity prototype with id \"{id}\"!");
                return;
            }

            var entities   = 0;
            var components = 0;

            foreach (var entity in entityManager.GetEntities())
            {
                var metaData = entityManager.GetComponent <MetaDataComponent>(entity);
                if (checkPrototype && metaData.EntityPrototype != prototype || metaData.EntityPrototype == null)
                {
                    continue;
                }

                var modified = false;

                foreach (var component in entityManager.GetComponents(entity))
                {
                    if (metaData.EntityPrototype.Components.ContainsKey(component.Name))
                    {
                        continue;
                    }

                    entityManager.RemoveComponent(entity, component);
                    components++;

                    modified = true;
                }

                if (modified)
                {
                    entities++;
                }
            }

            shell.WriteLine($"Removed {components} components from {entities} entities{(id == null ? "." : $" with id {id}")}");
Пример #3
0
        /// <summary>
        ///     Allocates an entity and stores it but does not load components or do initialization.
        /// </summary>
        private protected Entity AllocEntity(string?prototypeName, EntityUid?uid = null)
        {
            EntityPrototype?prototype = null;

            if (!string.IsNullOrWhiteSpace(prototypeName))
            {
                // If the prototype doesn't exist then we throw BEFORE we allocate the entity.
                prototype = PrototypeManager.Index <EntityPrototype>(prototypeName);
            }

            var entity = AllocEntity(uid);

            entity.Prototype = prototype;

            return(entity);
        }
Пример #4
0
 public PrototypeSerializationContext(EntityPrototype?owner)
 {
     prototype = owner;
 }