internal void AddEntity(WorldEntity entity) { GridCell startingCell = FindCell(entity.Position); if (startingCell == null) { entity.Position = map.Settings.DefaultSpawnPoint.position; startingCell = FindCell(entity.Position); } Assert.IsNotNull(startingCell, $"Starting cell is not found for {entity.GetType()} at {entity.Position}"); startingCell.AddWorldEntity(entity); }
public void SetScopeOf(WorldEntity target, bool inScope) { if (player.BoltEntity.Controller != null) { if (inScope) { target.PrepareForScoping(); } target.BoltEntity.SetScope(player.BoltEntity.Controller, inScope); } if (player.IsLocalServerPlayer) { EventHandler.ExecuteEvent(player.World, GameEvents.ServerVisibilityChanged, target, inScope); } }
internal void AddWorldEntity(WorldEntity worldEntity) { worldEntity.CurrentCell = this; switch (worldEntity) { case Creature creature: worldCreatures.Add(creature); break; case Player player: worldPlayers.Add(player); break; default: throw new ArgumentOutOfRangeException(nameof(worldEntity)); } }
internal void RemoveWorldEntity(WorldEntity worldEntity) { worldEntity.CurrentCell = null; switch (worldEntity) { case Creature creature: Assert.IsTrue(worldCreatures.Contains(creature)); worldCreatures.Remove(creature); break; case Player player: Assert.IsTrue(worldPlayers.Contains(player)); worldPlayers.Remove(player); break; default: throw new ArgumentOutOfRangeException(nameof(worldEntity)); } }
public void UpdateVisibilityOf(WorldEntity target) { if (HasClientVisiblityOf(target)) { if (!player.CanSeeOrDetect(target, false, true)) { SetScopeOf(target, false); visibleEntities.Remove(target.Id); } } else { if (player.CanSeeOrDetect(target, false, true)) { SetScopeOf(target, true); visibleEntities.Add(target.Id); } } }
public static bool InRange(this WorldEntity entity, WorldEntity target, float range) { return(Vector3.Magnitude(entity.Position - target.Position) <= range); }
public static bool InRangeSqr(this WorldEntity entity, WorldEntity target, float sqrRange) { return(Vector3.SqrMagnitude(entity.Position - target.Position) <= sqrRange); }
public bool HasClientVisiblityOf(WorldEntity target) => visibleEntities.Contains(target.Id) || target == player;
internal void RemoveEntity(WorldEntity entity) { Assert.IsNotNull(entity.CurrentCell, $"Cell is missing on removal for {entity.GetType()} at {entity.Position}"); entity.CurrentCell.RemoveWorldEntity(entity); }
public void VisitInRadius(WorldEntity referer, float radius, IUnitVisitor unitVisitor) { mapGrid.VisitInRadius(referer, radius, unitVisitor); }
internal void RemoveWorldEntity(WorldEntity entity) { worldEntitiesById.Remove(entity.Id); mapGrid.RemoveEntity(entity); }
internal void AddWorldEntity(WorldEntity entity) { worldEntitiesById.Add(entity.Id, entity); mapGrid.AddEntity(entity); }