public static bool InRangeUnOccluded( this IEntity origin, IComponent other, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = true) { return(ExamineSystemShared.InRangeUnOccluded(origin, other, range, predicate, ignoreInsideBlocker)); }
public static bool InRangeUnOccluded( this AfterInteractEventArgs args, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = true) { return(ExamineSystemShared.InRangeUnOccluded(args, range, predicate, ignoreInsideBlocker)); }
public static bool InRangeUnOccluded( this EntityUid origin, EntityUid other, float range = ExamineRange, Ignored?predicate = null, bool ignoreInsideBlocker = true) { return(ExamineSystemShared.InRangeUnOccluded(origin, other, range, predicate, ignoreInsideBlocker)); }
public static bool InRangeUnOccluded( this MapCoordinates origin, MapCoordinates other, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = false) { return(ExamineSystemShared.InRangeUnOccluded(origin, other, range, predicate, ignoreInsideBlocker)); }
public static bool InRangeUnOccluded( this EntityUid origin, IContainer other, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = true) { var otherEntity = other.Owner; return(ExamineSystemShared.InRangeUnOccluded(origin, otherEntity, range, predicate, ignoreInsideBlocker)); }
public static bool InRangeUnOccluded( this IComponent origin, EntityCoordinates other, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = true) { var originEntity = origin.Owner; return(ExamineSystemShared.InRangeUnOccluded(originEntity, other, range, predicate, ignoreInsideBlocker)); }
public static bool InRangeUnOccluded( this MapCoordinates origin, IContainer other, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = true) { var otherPosition = other.Owner.Transform.MapPosition; return(ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, ignoreInsideBlocker)); }
public static bool InRangeUnOccluded( this MapCoordinates origin, IContainer other, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = true) { var entMan = IoCManager.Resolve <IEntityManager>(); var otherPosition = entMan.GetComponent <TransformComponent>(other.Owner).MapPosition; return(ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, ignoreInsideBlocker)); }
public static bool InRangeUnOccluded( this EntityCoordinates origin, IEntity other, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = true) { var originPosition = origin.ToMap(other.EntityManager); var otherPosition = other.Transform.MapPosition; return(ExamineSystemShared.InRangeUnOccluded(originPosition, otherPosition, range, predicate, ignoreInsideBlocker)); }
private void DrawScreen(DrawingHandleScreen screen) { var viewport = _eyeManager.GetWorldViewport(); var ent = _playerManager.LocalPlayer?.ControlledEntity; if (ent == null || ent.TryGetComponent(out SuspicionRoleComponent sus) != true) { return; } foreach (var(_, uid) in sus.Allies) { // Otherwise the entity can not exist yet if (!_entityManager.TryGetEntity(uid, out var ally)) { return; } if (!ally.TryGetComponent(out IPhysicsComponent physics)) { return; } if (!ExamineSystemShared.InRangeUnOccluded(ent.Transform.MapPosition, ally.Transform.MapPosition, 15, entity => entity == ent || entity == ally)) { return; } // all entities have a TransformComponent var transform = physics.Entity.Transform; // if not on the same map, continue if (transform.MapID != _eyeManager.CurrentMap || !transform.IsMapTransform) { continue; } var worldBox = physics.WorldAABB; // if not on screen, or too small, continue if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty()) { continue; } var screenCoordinates = _eyeManager.WorldToScreen(physics.WorldAABB.TopLeft + (0, 0.5f)); DrawString(screen, _font, screenCoordinates, _traitorText, Color.OrangeRed); } }
public static bool InRangeUnOccluded( this MapCoordinates origin, EntityCoordinates other, float range = InteractionRange, Ignored?predicate = null, bool ignoreInsideBlocker = true, IEntityManager?entityManager = null) { IoCManager.Resolve(ref entityManager); var otherPosition = other.ToMap(entityManager); return(ExamineSystemShared.InRangeUnOccluded(origin, otherPosition, range, predicate, ignoreInsideBlocker)); }
private void DrawScreen(DrawingHandleScreen screen) { var viewport = _eyeManager.GetWorldViewport(); foreach (var uid in _allies) { // Otherwise the entity can not exist yet if (!_entityManager.TryGetEntity(uid, out var ally)) { return; } if (!ally.TryGetComponent(out ICollidableComponent collidable)) { return; } if (!ExamineSystemShared.InRangeUnOccluded(_user.Transform.MapPosition, ally.Transform.MapPosition, 15, entity => entity == _user || entity == ally)) { return; } // all entities have a TransformComponent var transform = collidable.Entity.Transform; // if not on the same map, continue if (transform.MapID != _eyeManager.CurrentMap || !transform.IsMapTransform) { continue; } var worldBox = collidable.WorldAABB; // if not on screen, or too small, continue if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty()) { continue; } var screenCoordinates = _eyeManager.WorldToScreen(collidable.WorldAABB.TopLeft + (0, 0.5f)); DrawString(screen, _font, screenCoordinates, _traitorText, Color.OrangeRed); } }
public override void Update(float frameTime) { base.Update(frameTime); var currentTime = _gameTiming.CurTime; // Can't see any I guess? if (_attachedEntity is not { Valid : true } entity || Deleted(entity)) { return; } var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f); foreach (var comp in EntityManager.EntityQuery <DoAfterComponent>(true)) { var doAfters = comp.DoAfters.ToList(); var compPos = EntityManager.GetComponent <TransformComponent>(comp.Owner).WorldPosition; if (doAfters.Count == 0 || EntityManager.GetComponent <TransformComponent>(comp.Owner).MapID != EntityManager.GetComponent <TransformComponent>(entity).MapID || !viewbox.Contains(compPos)) { comp.Disable(); continue; } var range = (compPos - EntityManager.GetComponent <TransformComponent>(entity).WorldPosition).Length + 0.01f; if (comp.Owner != _attachedEntity && !ExamineSystemShared.InRangeUnOccluded( EntityManager.GetComponent <TransformComponent>(entity).MapPosition, EntityManager.GetComponent <TransformComponent>(comp.Owner).MapPosition, range, entity => entity == comp.Owner || entity == _attachedEntity)) { comp.Disable(); continue; } comp.Enable(); var userGrid = EntityManager.GetComponent <TransformComponent>(comp.Owner).Coordinates; // Check cancellations / finishes foreach (var(id, doAfter) in doAfters) { var elapsedTime = (currentTime - doAfter.StartTime).TotalSeconds; // If we've passed the final time (after the excess to show completion graphic) then remove. if (elapsedTime > doAfter.Delay + ExcessTime) { comp.Remove(doAfter); continue; } // Don't predict cancellation if it's already finished. if (elapsedTime > doAfter.Delay) { continue; } // Predictions if (doAfter.BreakOnUserMove) { if (!userGrid.InRange(EntityManager, doAfter.UserGrid, doAfter.MovementThreshold)) { comp.Cancel(id, currentTime); continue; } } if (doAfter.BreakOnTargetMove) { if (EntityManager.EntityExists(doAfter.TargetUid) && !EntityManager.GetComponent <TransformComponent>(doAfter.TargetUid).Coordinates.InRange(EntityManager, doAfter.TargetGrid, doAfter.MovementThreshold)) { comp.Cancel(id, currentTime); continue; } } } var count = comp.CancelledDoAfters.Count; // Remove cancelled DoAfters after ExcessTime has elapsed for (var i = count - 1; i >= 0; i--) { var cancelled = comp.CancelledDoAfters[i]; if ((currentTime - cancelled.CancelTime).TotalSeconds > ExcessTime) { comp.Remove(cancelled.Message); } } } }
public override void Update(float frameTime) { base.Update(frameTime); var currentTime = _gameTiming.CurTime; var foundComps = new HashSet <DoAfterComponent>(); // Can't see any I guess? if (_attachedEntity == null || _attachedEntity.Deleted) { return; } foreach (var comp in ComponentManager.EntityQuery <DoAfterComponent>()) { if (!_knownComponents.Contains(comp)) { _knownComponents.Add(comp); } var doAfters = comp.DoAfters.ToList(); if (doAfters.Count == 0) { if (comp.Gui != null) { comp.Gui.FirstDraw = true; } continue; } var range = (comp.Owner.Transform.WorldPosition - _attachedEntity.Transform.WorldPosition).Length + 0.01f; if (comp.Owner != _attachedEntity && !ExamineSystemShared.InRangeUnOccluded( _attachedEntity.Transform.MapPosition, comp.Owner.Transform.MapPosition, range, entity => entity == comp.Owner || entity == _attachedEntity)) { if (comp.Gui != null) { comp.Gui.FirstDraw = true; } return; } comp.Enable(); var userGrid = comp.Owner.Transform.Coordinates; // Check cancellations / finishes foreach (var(id, doAfter) in doAfters) { var elapsedTime = (currentTime - doAfter.StartTime).TotalSeconds; // If we've passed the final time (after the excess to show completion graphic) then remove. if (elapsedTime > doAfter.Delay + ExcessTime) { comp.Remove(doAfter); continue; } // Don't predict cancellation if it's already finished. if (elapsedTime > doAfter.Delay) { continue; } // Predictions if (doAfter.BreakOnUserMove) { if (userGrid != doAfter.UserGrid) { comp.Cancel(id, currentTime); continue; } } if (doAfter.BreakOnTargetMove) { if (EntityManager.TryGetEntity(doAfter.TargetUid, out var targetEntity) && targetEntity.Transform.Coordinates != doAfter.TargetGrid) { comp.Cancel(id, currentTime); continue; } } } var count = comp.CancelledDoAfters.Count; // Remove cancelled DoAfters after ExcessTime has elapsed for (var i = count - 1; i >= 0; i--) { var cancelled = comp.CancelledDoAfters[i]; if ((currentTime - cancelled.CancelTime).TotalSeconds > ExcessTime) { comp.Remove(cancelled.Message); } } // Remove any components that we no longer need to track foundComps.Add(comp); } foreach (var comp in foundComps) { if (!_knownComponents.Contains(comp)) { _knownComponents.Remove(comp); comp.Disable(); } } }
/// <summary> /// Get all of the entities in an area for displaying on the context menu. /// </summary> public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true)] out List <EntityUid>?result) { result = null; if (_stateManager.CurrentState is not GameScreenBase gameScreenBase) { return(false); } var player = _playerManager.LocalPlayer?.ControlledEntity; if (player == null) { return(false); } // If FOV drawing is disabled, we will modify the visibility option to ignore visiblity checks. var visibility = _eyeManager.CurrentEye.DrawFov ? Visibility : Visibility | MenuVisibility.NoFov; // Do we have to do FoV checks? if ((visibility & MenuVisibility.NoFov) == 0) { var entitiesUnderMouse = gameScreenBase.GetEntitiesUnderPosition(targetPos); bool Predicate(EntityUid e) => e == player || entitiesUnderMouse.Contains(e); if (!_examineSystem.CanExamine(player.Value, targetPos, Predicate)) { return(false); } } // Get entities var entities = _entityLookup.GetEntitiesInRange(targetPos.MapId, targetPos.Position, EntityMenuLookupSize) .ToList(); if (entities.Count == 0) { return(false); } if (visibility == MenuVisibility.All) { result = entities; return(true); } // remove any entities in containers if ((visibility & MenuVisibility.InContainer) == 0) { foreach (var entity in entities.ToList()) { if (!player.Value.IsInSameOrTransparentContainer(entity)) { entities.Remove(entity); } } } // remove any invisible entities if ((visibility & MenuVisibility.Invisible) == 0) { foreach (var entity in entities.ToList()) { if (!EntityManager.TryGetComponent(entity, out ISpriteComponent? spriteComponent) || !spriteComponent.Visible) { entities.Remove(entity); continue; } if (entity.HasTag("HideContextMenu")) { entities.Remove(entity); } } } // Remove any entities that do not have LOS if ((visibility & MenuVisibility.NoFov) == 0) { var playerPos = EntityManager.GetComponent <TransformComponent>(player.Value).MapPosition; foreach (var entity in entities.ToList()) { if (!ExamineSystemShared.InRangeUnOccluded( playerPos, EntityManager.GetComponent <TransformComponent>(entity).MapPosition, ExamineSystemShared.ExamineRange, null)) { entities.Remove(entity); } } } if (entities.Count == 0) { return(false); } result = entities; return(true); }