using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; using Robust.Shared.Timing; namespace Robust.Shared.GameObjects; public partial class EntitySystem { #region Entity LifeStage /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool Exists(EntityUid uid) { return EntityManager.EntityExists(uid); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool Exists([NotNullWhen(true)] EntityUid? uid) { return EntityManager.EntityExists(uid); } /// /// Retrieves whether the entity is initializing. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool Initializing(EntityUid uid, MetaDataComponent? metaData = null) { return LifeStage(uid, metaData) == EntityLifeStage.Initializing; } /// /// Retrieves whether the entity has been initialized and has not yet been deleted. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool Initialized(EntityUid uid, MetaDataComponent? metaData = null) { return LifeStage(uid, metaData) is >= EntityLifeStage.Initialized and < EntityLifeStage.Terminating; } /// /// Retrieves whether the entity is being terminated. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool Terminating(EntityUid uid, MetaDataComponent? metaData = null) { return LifeStage(uid, metaData) == EntityLifeStage.Terminating; } /// /// Retrieves whether the entity is deleted or is nonexistent. Returns false if the entity is currently in the /// process of being deleted. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool Deleted(EntityUid uid, MetaDataComponent? metaData = null) { return LifeStage(uid, metaData) >= EntityLifeStage.Deleted; } /// /// Checks whether the entity is being or has been deleted (or never existed in the first place). /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TerminatingOrDeleted(EntityUid uid, MetaDataComponent? metaData = null) { return LifeStage(uid, metaData) >= EntityLifeStage.Terminating; } /// /// Checks whether the entity is being or has been deleted (or never existed in the first place). /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TerminatingOrDeleted(EntityUid? uid, MetaDataComponent? metaData = null) { return !uid.HasValue || TerminatingOrDeleted(uid.Value, metaData); } [Obsolete("Use override without the EntityQuery")] protected bool Deleted(EntityUid uid, EntityQuery metaQuery) => Deleted(uid); /// /// Retrieves whether the entity is deleted or is nonexistent. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool Deleted([NotNullWhen(false)] EntityUid? uid) { return !uid.HasValue || Deleted(uid.Value); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityLifeStage LifeStage(EntityUid uid, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) return EntityLifeStage.Deleted; return metaData.EntityLifeStage; } [Obsolete("Use LifeStage()")] protected bool TryLifeStage(EntityUid uid, [NotNullWhen(true)] out EntityLifeStage? lifeStage, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) { lifeStage = null; return false; } lifeStage = metaData.EntityLifeStage; return true; } #endregion #region Entity Metadata [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool IsPaused(EntityUid? uid, MetaDataComponent? metadata = null) { return EntityManager.IsPaused(uid, metadata); } /// /// Marks this entity as dirty so that it will be updated over the network. /// /// /// Calling Dirty on a component will call this directly. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void DirtyEntity(EntityUid uid, MetaDataComponent? meta = null) { EntityManager.DirtyEntity(uid, meta); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void Dirty(EntityUid uid, IComponent component, MetaDataComponent? meta = null) { EntityManager.Dirty(uid, component, meta); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void DirtyField(EntityUid uid, IComponentDelta delta, string fieldName, MetaDataComponent? meta = null) { EntityManager.DirtyField(uid, delta, fieldName, meta); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void DirtyField(Entity entity, string fieldName, MetaDataComponent? meta = null) where T : IComponentDelta { if (!Resolve(entity.Owner, ref entity.Comp)) return; EntityManager.DirtyField(entity.Owner, entity.Comp, fieldName, meta); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void DirtyField(EntityUid uid, T component, string fieldName, MetaDataComponent? meta = null) where T : IComponentDelta { EntityManager.DirtyField(uid, component, fieldName, meta); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void DirtyFields(EntityUid uid, T comp, MetaDataComponent? meta, params string[] fields) where T : IComponentDelta { EntityManager.DirtyFields(uid, comp, meta, fields); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void DirtyFields(Entity ent, MetaDataComponent? meta, params string[] fields) where T : IComponentDelta { if (!Resolve(ent, ref ent.Comp)) return; EntityManager.DirtyFields(ent, ent.Comp, meta, fields); } /// /// Marks a component as dirty. This also implicitly dirties the entity this component belongs to. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void Dirty(Entity ent, MetaDataComponent? meta = null) where T : IComponent? { var comp = ent.Comp; if (comp == null && !EntityManager.TryGetComponent(ent.Owner, out comp)) return; EntityManager.Dirty(ent, comp, meta); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void Dirty(Entity ent, MetaDataComponent? meta = null) where T1 : IComponent where T2 : IComponent { EntityManager.Dirty(ent, meta); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void Dirty(Entity ent, MetaDataComponent? meta = null) where T1 : IComponent where T2 : IComponent where T3 : IComponent { EntityManager.Dirty(ent, meta); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void Dirty(Entity ent, MetaDataComponent? meta = null) where T1 : IComponent where T2 : IComponent where T3 : IComponent where T4 : IComponent { EntityManager.Dirty(ent, meta); } /// /// Retrieves the name of an entity. /// /// Thrown when the entity doesn't exist. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected string Name(EntityUid uid, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) throw CompNotFound(uid); return metaData.EntityName; } /// /// Retrieves the description of an entity. /// /// Thrown when the entity doesn't exist. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected string Description(EntityUid uid, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) throw CompNotFound(uid); return metaData.EntityDescription; } /// /// Retrieves the prototype of an entity, if any. /// /// Thrown when the entity doesn't exist. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityPrototype? Prototype(EntityUid uid, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) throw CompNotFound(uid); return metaData.EntityPrototype; } /// /// Retrieves the last the entity was modified at. /// /// Thrown when the entity doesn't exist. protected GameTick LastModifiedTick(EntityUid uid, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) throw CompNotFound(uid); return metaData.EntityLastModifiedTick; } /// /// Retrieves whether the entity is paused or not. /// /// Thrown when the entity doesn't exist. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool Paused(EntityUid uid, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) throw CompNotFound(uid); return metaData.EntityPaused; } /// /// Sets the paused status on an entity. /// /// Thrown when the entity doesn't exist. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void SetPaused(EntityUid uid, bool paused, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) throw CompNotFound(uid); EntityManager.EntitySysManager.GetEntitySystem().SetEntityPaused(uid, paused, metaData); } /// /// Attempts to mark an entity as dirty. /// /// Whether the operation succeeded. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryDirty(EntityUid uid, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) return false; DirtyEntity(uid, metaData); return true; } /// /// Attempts to retrieve the name of an entity. /// /// Whether the name could be retrieved. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryName(EntityUid uid, [NotNullWhen(true)] out string? name, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) { name = null; return false; } name = metaData.EntityName; return true; } /// /// Attempts to retrieve the description of an entity. /// /// Whether the description could be retrieved. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryDescription(EntityUid uid, [NotNullWhen(true)] out string? description, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) { description = null; return false; } description = metaData.EntityDescription; return true; } /// /// Attempts to retrieve the prototype of an entity. /// /// Whether the prototype could be retrieved and was not null. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryPrototype(EntityUid uid, [NotNullWhen(true)] out EntityPrototype? prototype, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) { prototype = null; return false; } prototype = metaData.EntityPrototype; return prototype != null; } /// /// Attempts to retrieve the last the entity was modified at. /// /// Whether the last modified tick could be retrieved. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryLastModifiedTick(EntityUid uid, [NotNullWhen(true)] out GameTick? lastModifiedTick, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) { lastModifiedTick = null; return false; } lastModifiedTick = metaData.EntityLastModifiedTick; return true; } /// /// Attempts to retrieve the paused status on an entity. /// /// Whether the pause status could be retrieved. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryPaused(EntityUid uid, [NotNullWhen(true)] out bool? paused, MetaDataComponent? metaData = null) { if (!EntityManager.MetaQuery.Resolve(uid, ref metaData, false)) { paused = null; return false; } paused = metaData.EntityPaused; return true; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: NotNullIfNotNull("uid")] protected EntityStringRepresentation? ToPrettyString(EntityUid? uid, MetaDataComponent? metadata = null) { return EntityManager.ToPrettyString(uid, metadata); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: NotNullIfNotNull("netEntity")] protected EntityStringRepresentation? ToPrettyString(NetEntity? netEntity) { return EntityManager.ToPrettyString(netEntity); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metadata) => EntityManager.ToPrettyString((uid, metadata)); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityStringRepresentation ToPrettyString(Entity entity) => EntityManager.ToPrettyString(entity); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityStringRepresentation ToPrettyString(NetEntity netEntity) => EntityManager.ToPrettyString(netEntity); #endregion #region Component Get /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected T Comp(EntityUid uid) where T : IComponent { return EntityManager.GetComponent(uid); } /// /// Returns the component of a specific type, or null when it's missing or the entity does not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected T? CompOrNull(EntityUid uid) where T : IComponent { return EntityManager.GetComponentOrNull(uid); } /// /// Returns the component of a specific type, or null when it's missing or the entity does not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected T? CompOrNull(EntityUid? uid) where T : IComponent { return uid.HasValue ? EntityManager.GetComponentOrNull(uid.Value) : default; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [PreferNonGenericVariantFor(typeof(TransformComponent), typeof(MetaDataComponent))] protected bool TryComp(EntityUid uid, [NotNullWhen(true)] out T? comp) where T : IComponent { return EntityManager.TryGetComponent(uid, out comp); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryComp(EntityUid uid, [NotNullWhen(true)] out TransformComponent? comp) { return EntityManager.TransformQuery.TryGetComponent(uid, out comp); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryComp(EntityUid uid, [NotNullWhen(true)] out MetaDataComponent? comp) { return EntityManager.MetaQuery.TryGetComponent(uid, out comp); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryComp([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)] out T? comp) where T : IComponent { if (!uid.HasValue) { comp = default; return false; } return EntityManager.TryGetComponent(uid.Value, out comp); } /// protected bool TryComp([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)] out TransformComponent? comp) { if (!uid.HasValue) { comp = default; return false; } return EntityManager.TransformQuery.TryGetComponent(uid.Value, out comp); } /// protected bool TryComp([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)] out MetaDataComponent? comp) { if (!uid.HasValue) { comp = default; return false; } return EntityManager.MetaQuery.TryGetComponent(uid.Value, out comp); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected IEnumerable AllComps(EntityUid uid) { return EntityManager.GetComponents(uid); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected IEnumerable AllComps(EntityUid uid) { return EntityManager.GetComponents(uid); } /// /// Returns the on an entity. /// /// Thrown when the entity doesn't exist. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected TransformComponent Transform(EntityUid uid) { return EntityManager.TransformQuery.GetComponent(uid); } /// /// Returns the on an entity. /// /// Thrown when the entity doesn't exist. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected MetaDataComponent MetaData(EntityUid uid) { return EntityManager.MetaQuery.GetComponent(uid); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected (EntityUid, MetaDataComponent) GetEntityData(NetEntity nuid) { return EntityManager.GetEntityData(nuid); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryGetEntityData(NetEntity nuid, [NotNullWhen(true)] out EntityUid? uid, [NotNullWhen(true)] out MetaDataComponent? meta) { return EntityManager.TryGetEntityData(nuid, out uid, out meta); } #endregion #region Component Copy /// protected bool TryCopyComponent( EntityUid source, EntityUid target, ref T? sourceComponent, [NotNullWhen(true)] out T? targetComp, MetaDataComponent? meta = null) where T : IComponent { return EntityManager.TryCopyComponent(source, target, ref sourceComponent, out targetComp, meta); } /// protected bool TryCopyComponents( EntityUid source, EntityUid target, MetaDataComponent? meta = null, params Type[] sourceComponents) { return EntityManager.TryCopyComponents(source, target, meta, sourceComponents); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected IComponent CopyComp(EntityUid source, EntityUid target, IComponent sourceComponent, MetaDataComponent? meta = null) { return EntityManager.CopyComponent(source, target, sourceComponent, meta); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected T CopyComp(EntityUid source, EntityUid target, T sourceComponent, MetaDataComponent? meta = null) where T : IComponent { return EntityManager.CopyComponent(source, target, sourceComponent, meta); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void CopyComps(EntityUid source, EntityUid target, MetaDataComponent? meta = null, params IComponent[] sourceComponents) { EntityManager.CopyComponents(source, target, meta, sourceComponents); } #endregion #region Component Has /// /// Retrieves whether the entity has the specified component or not. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool HasComp(EntityUid uid) where T : IComponent { return EntityManager.HasComponent(uid); } /// /// Retrieves whether the entity has the specified component or not. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool HasComp(EntityUid uid, Type type) { return EntityManager.HasComponent(uid, type); } /// /// Retrieves whether the entity has the specified component or not. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool HasComp([NotNullWhen(true)] EntityUid? uid) where T : IComponent { return EntityManager.HasComponent(uid); } /// /// Retrieves whether the entity has the specified component or not. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool HasComp([NotNullWhen(true)] EntityUid? uid, Type type) { return EntityManager.HasComponent(uid, type); } #endregion #region Component Add /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected T AddComp(EntityUid uid) where T : Component, new() { return EntityManager.AddComponent(uid); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void AddComp(EntityUid uid, T component, bool overwrite = false) where T : IComponent { EntityManager.AddComponent(uid, component, overwrite); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected T EnsureComp(EntityUid uid) where T : IComponent, new() { return EntityManager.EnsureComponent(uid); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool EnsureComp(EntityUid uid, out T comp) where T : IComponent, new() { return EntityManager.EnsureComponent(uid, out comp); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool EnsureComp(ref Entity entity) where T : IComponent, new() { return EntityManager.EnsureComponent(ref entity); } #endregion #region Component Remove Deferred /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool RemCompDeferred(EntityUid uid) where T : IComponent { return EntityManager.RemoveComponentDeferred(uid); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool RemCompDeferred(EntityUid uid, Type type) { return EntityManager.RemoveComponentDeferred(uid, type); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void RemCompDeferred(EntityUid uid, IComponent component) { EntityManager.RemoveComponentDeferred(uid, component); } #endregion #region Component count /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Count() where T : IComponent { return EntityManager.Count(); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Count(Type type) { return EntityManager.Count(type); } #endregion #region Component Remove /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool RemComp(EntityUid uid) where T : IComponent { return EntityManager.RemoveComponent(uid); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool RemComp(EntityUid uid, Type type) { return EntityManager.RemoveComponent(uid, type); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void RemComp(EntityUid uid, IComponent component) { EntityManager.RemoveComponent(uid, component); } #endregion #region Entity Delete /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void Del(EntityUid? uid) { EntityManager.DeleteEntity(uid); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void QueueDel(EntityUid? uid) { EntityManager.QueueDeleteEntity(uid); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryQueueDel(EntityUid? uid) { return EntityManager.TryQueueDeleteEntity(uid); } #endregion #region Entity Spawning // This method will be obsoleted soon(TM). [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid Spawn(string? prototype, EntityCoordinates coordinates) { return ((IEntityManager)EntityManager).SpawnEntity(prototype, coordinates); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid Spawn(string? prototype, MapCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default) => EntityManager.Spawn(prototype, coordinates, overrides, rotation); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid Spawn(string? prototype = null, ComponentRegistry? overrides = null, bool doMapInit = true) => EntityManager.Spawn(prototype, overrides, doMapInit); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid SpawnAttachedTo(string? prototype, EntityCoordinates coordinates, ComponentRegistry? overrides = null) => EntityManager.SpawnAttachedTo(prototype, coordinates, overrides); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid SpawnAtPosition(string? prototype, EntityCoordinates coordinates, ComponentRegistry? overrides = null) => EntityManager.SpawnAtPosition(prototype, coordinates, overrides); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TrySpawnInContainer( string? protoName, EntityUid containerUid, string containerId, [NotNullWhen(true)] out EntityUid? uid, ContainerManagerComponent? containerComp = null, ComponentRegistry? overrides = null) { return EntityManager.TrySpawnInContainer(protoName, containerUid, containerId, out uid, containerComp, overrides); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TrySpawnNextTo( string? protoName, EntityUid target, [NotNullWhen(true)] out EntityUid? uid, TransformComponent? xform = null, ComponentRegistry? overrides = null) { return EntityManager.TrySpawnNextTo(protoName, target, out uid, xform, overrides); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid SpawnNextToOrDrop( string? protoName, EntityUid target, TransformComponent? xform = null, ComponentRegistry? overrides = null) { return EntityManager.SpawnNextToOrDrop(protoName, target, xform, overrides); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid SpawnInContainerOrDrop( string? protoName, EntityUid containerUid, string containerId, TransformComponent? xform = null, ContainerManagerComponent? container = null, ComponentRegistry? overrides = null) { return EntityManager.SpawnInContainerOrDrop(protoName, containerUid, containerId, xform, container, overrides); } #endregion #region Utils /// /// Utility static method to create an exception to be thrown when an entity doesn't have a specific component. /// private static KeyNotFoundException CompNotFound(EntityUid uid) => new($"Entity {uid} does not have a component of type {typeof(T)}"); #endregion #region All Entity Query [MethodImpl(MethodImplOptions.AggressiveInlining)] protected AllEntityQueryEnumerator AllEntityQuery() where TComp1 : IComponent { return EntityManager.AllEntityQueryEnumerator(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected AllEntityQueryEnumerator AllEntityQuery() where TComp1 : IComponent where TComp2 : IComponent { return EntityManager.AllEntityQueryEnumerator(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected AllEntityQueryEnumerator AllEntityQuery() where TComp1 : IComponent where TComp2 : IComponent where TComp3 : IComponent { return EntityManager.AllEntityQueryEnumerator(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected AllEntityQueryEnumerator AllEntityQuery() where TComp1 : IComponent where TComp2 : IComponent where TComp3 : IComponent where TComp4 : IComponent { return EntityManager.AllEntityQueryEnumerator(); } #endregion #region Get Entity Query [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityQueryEnumerator EntityQueryEnumerator() where TComp1 : IComponent { return EntityManager.EntityQueryEnumerator(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityQueryEnumerator EntityQueryEnumerator() where TComp1 : IComponent where TComp2 : IComponent { return EntityManager.EntityQueryEnumerator(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityQueryEnumerator EntityQueryEnumerator() where TComp1 : IComponent where TComp2 : IComponent where TComp3 : IComponent { return EntityManager.EntityQueryEnumerator(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityQueryEnumerator EntityQueryEnumerator() where TComp1 : IComponent where TComp2 : IComponent where TComp3 : IComponent where TComp4 : IComponent { return EntityManager.EntityQueryEnumerator(); } #endregion #region Entity Query /// /// If you need the EntityUid, use /// [MethodImpl(MethodImplOptions.AggressiveInlining)] [Pure] protected EntityQuery GetEntityQuery() where T : IComponent { return EntityManager.GetEntityQuery(); } /// /// If you need the EntityUid, use /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected IEnumerable EntityQuery(bool includePaused = false) where TComp1 : IComponent { return EntityManager.EntityQuery(includePaused); } /// /// If you need the EntityUid, use /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected IEnumerable<(TComp1, TComp2)> EntityQuery(bool includePaused = false) where TComp1 : IComponent where TComp2 : IComponent { return EntityManager.EntityQuery(includePaused); } /// /// If you need the EntityUid, use /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected IEnumerable<(TComp1, TComp2, TComp3)> EntityQuery(bool includePaused = false) where TComp1 : IComponent where TComp2 : IComponent where TComp3 : IComponent { return EntityManager.EntityQuery(includePaused); } /// /// If you need the EntityUid, use /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected IEnumerable<(TComp1, TComp2, TComp3, TComp4)> EntityQuery(bool includePaused = false) where TComp1 : IComponent where TComp2 : IComponent where TComp3 : IComponent where TComp4 : IComponent { return EntityManager.EntityQuery(includePaused); } #endregion #region Networked Events /// /// Sends a networked message to the server, while also repeatedly raising it locally for every time this tick gets re-predicted. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void RaisePredictiveEvent(T msg) where T : EntityEventArgs { EntityManager.RaisePredictiveEvent(msg); } #endregion #region NetEntities [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool IsClientSide(EntityUid entity, MetaDataComponent? meta = null) { return EntityManager.IsClientSide(entity, meta); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool IsClientSide(Entity entity) { return EntityManager.IsClientSide(entity, entity.Comp); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryGetEntity(NetEntity nEntity, [NotNullWhen(true)] out EntityUid? entity) { return EntityManager.TryGetEntity(nEntity, out entity); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected bool TryGetEntity(NetEntity? nEntity, [NotNullWhen(true)] out EntityUid? entity) { return EntityManager.TryGetEntity(nEntity, out entity); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetNetEntity(EntityUid uid, [NotNullWhen(true)] out NetEntity? netEntity, MetaDataComponent? metadata = null) { return EntityManager.TryGetNetEntity(uid, out netEntity); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetNetEntity(EntityUid? uid, [NotNullWhen(true)] out NetEntity? netEntity, MetaDataComponent? metadata = null) { return EntityManager.TryGetNetEntity(uid, out netEntity); } /// /// Returns the of an entity. Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected NetEntity GetNetEntity(EntityUid uid, MetaDataComponent? metadata = null) { return EntityManager.GetNetEntity(uid, metadata); } /// /// Returns the of an entity. Logs an error if the entity does not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected NetEntity? GetNetEntity(EntityUid? uid, MetaDataComponent? metadata = null) { return EntityManager.GetNetEntity(uid, metadata); } /// /// Returns the of an entity or creates a new entity if none exists. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid EnsureEntity(NetEntity netEntity, EntityUid callerEntity) { return EntityManager.EnsureEntity(netEntity, callerEntity); } /// /// Returns the of an entity or creates a new one if not null. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid? EnsureEntity(NetEntity? netEntity, EntityUid callerEntity) { return EntityManager.EnsureEntity(netEntity, callerEntity); } /// /// Returns the of an entity or creates a new entity if none exists. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityCoordinates EnsureCoordinates(NetCoordinates netCoordinates, EntityUid callerEntity) { return EntityManager.EnsureCoordinates(netCoordinates, callerEntity); } /// /// Returns the of an entity or creates a new one if not null. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityCoordinates? EnsureCoordinates(NetCoordinates? netCoordinates, EntityUid callerEntity) { return EntityManager.EnsureCoordinates(netCoordinates, callerEntity); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected HashSet EnsureEntitySet(HashSet netEntities, EntityUid callerEntity) { return EntityManager.EnsureEntitySet(netEntities, callerEntity); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void EnsureEntitySet(HashSet netEntities, EntityUid callerEntity, HashSet entities) { EntityManager.EnsureEntitySet(netEntities, callerEntity, entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List EnsureEntityList(List netEntities, EntityUid callerEntity) { return EntityManager.EnsureEntityList(netEntities, callerEntity); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void EnsureEntityList(List netEntities, EntityUid callerEntity, List entities) { EntityManager.EnsureEntityList(netEntities, callerEntity, entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void EnsureEntityDictionary(Dictionary netEntities, EntityUid callerEntity, Dictionary entities) { EntityManager.EnsureEntityDictionary(netEntities, callerEntity, entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void EnsureEntityDictionaryNullableValue(Dictionary netEntities, EntityUid callerEntity, Dictionary entities) { EntityManager.EnsureEntityDictionaryNullableValue(netEntities, callerEntity, entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void EnsureEntityDictionary(Dictionary netEntities, EntityUid callerEntity, Dictionary entities) where TKey : notnull { EntityManager.EnsureEntityDictionary(netEntities, callerEntity, entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void EnsureEntityDictionary(Dictionary netEntities, EntityUid callerEntity, Dictionary entities) where TKey : notnull { EntityManager.EnsureEntityDictionary(netEntities, callerEntity, entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void EnsureEntityDictionary(Dictionary netEntities, EntityUid callerEntity, Dictionary entities) { EntityManager.EnsureEntityDictionary(netEntities, callerEntity, entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void EnsureEntityDictionary(Dictionary netEntities, EntityUid callerEntity, Dictionary entities) { EntityManager.EnsureEntityDictionary(netEntities, callerEntity, entities); } /// /// Returns the of a . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid GetEntity(NetEntity netEntity) { return EntityManager.GetEntity(netEntity); } /// /// Returns the of a . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid? GetEntity(NetEntity? netEntity) { return EntityManager.GetEntity(netEntity); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected HashSet GetNetEntitySet(HashSet uids) { return EntityManager.GetNetEntitySet(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected HashSet GetEntitySet(HashSet netEntities) { return EntityManager.GetEntitySet(netEntities); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetNetEntityList(ICollection uids) { return EntityManager.GetNetEntityList(uids); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetNetEntityList(IReadOnlyList uids) { return EntityManager.GetNetEntityList(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetEntityList(ICollection netEntities) { return EntityManager.GetEntityList(netEntities); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetNetEntityList(List uids) { return EntityManager.GetNetEntityList(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetEntityList(List netEntities) { return EntityManager.GetEntityList(netEntities); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetNetEntityList(List uids) { return EntityManager.GetNetEntityList(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetEntityList(List netEntities) { return EntityManager.GetEntityList(netEntities); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected NetEntity[] GetNetEntityArray(EntityUid[] uids) { return EntityManager.GetNetEntityArray(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid[] GetEntityArray(NetEntity[] netEntities) { return EntityManager.GetEntityArray(netEntities); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected NetEntity?[] GetNetEntityArray(EntityUid?[] uids) { return EntityManager.GetNetEntityArray(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityUid?[] GetEntityArray(NetEntity?[] netEntities) { return EntityManager.GetEntityArray(netEntities); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetNetEntityDictionary(Dictionary uids) { return EntityManager.GetNetEntityDictionary(uids); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetNetEntityDictionary(Dictionary uids) where T : notnull { return EntityManager.GetNetEntityDictionary(uids); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetNetEntityDictionary(Dictionary uids) where T : notnull { return EntityManager.GetNetEntityDictionary(uids); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetNetEntityDictionary(Dictionary uids) { return EntityManager.GetNetEntityDictionary(uids); } /// /// Returns the versions of the supplied entities. Logs an error if the entities do not exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetNetEntityDictionary(Dictionary uids) { return EntityManager.GetNetEntityDictionary(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetEntityDictionary(Dictionary uids) { return EntityManager.GetEntityDictionary(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetEntityDictionary(Dictionary uids) where T : notnull { return EntityManager.GetEntityDictionary(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetEntityDictionary(Dictionary uids) where T : notnull { return EntityManager.GetEntityDictionary(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetEntityDictionary(Dictionary uids) { return EntityManager.GetEntityDictionary(uids); } /// /// Returns the versions of the supplied . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected Dictionary GetEntityDictionary(Dictionary uids) { return EntityManager.GetEntityDictionary(uids); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected NetCoordinates GetNetCoordinates(EntityCoordinates coordinates, MetaDataComponent? metadata = null) { return EntityManager.GetNetCoordinates(coordinates, metadata); } /// /// Returns the of an entity. Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected NetCoordinates? GetNetCoordinates(EntityCoordinates? coordinates, MetaDataComponent? metadata = null) { return EntityManager.GetNetCoordinates(coordinates, metadata); } /// /// Returns the of a . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityCoordinates GetCoordinates(NetCoordinates netEntity) { return EntityManager.GetCoordinates(netEntity); } /// /// Returns the of a . Returns if it doesn't exist. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityCoordinates? GetCoordinates(NetCoordinates? netEntity) { return EntityManager.GetCoordinates(netEntity); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected HashSet GetEntitySet(HashSet netEntities) { return EntityManager.GetEntitySet(netEntities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetEntityList(List netEntities) { return EntityManager.GetEntityList(netEntities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetEntityList(ICollection netEntities) { return EntityManager.GetEntityList(netEntities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetEntityList(List netEntities) { return EntityManager.GetEntityList(netEntities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityCoordinates[] GetEntityArray(NetCoordinates[] netEntities) { return EntityManager.GetEntityArray(netEntities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected EntityCoordinates?[] GetEntityArray(NetCoordinates?[] netEntities) { return EntityManager.GetEntityArray(netEntities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected HashSet GetNetCoordinatesSet(HashSet entities) { return EntityManager.GetNetCoordinatesSet(entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetNetCoordinatesList(List entities) { return EntityManager.GetNetCoordinatesList(entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetNetCoordinatesList(ICollection entities) { return EntityManager.GetNetCoordinatesList(entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected List GetNetCoordinatesList(List entities) { return EntityManager.GetNetCoordinatesList(entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected NetCoordinates[] GetNetCoordinatesArray(EntityCoordinates[] entities) { return EntityManager.GetNetCoordinatesArray(entities); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected NetCoordinates?[] GetNetCoordinatesArray(EntityCoordinates?[] entities) { return EntityManager.GetNetCoordinatesArray(entities); } #endregion }