Esempio n. 1
0
        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);
        }
Esempio n. 2
0
            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);
                }
            }
Esempio n. 3
0
        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));
                }
            }
Esempio n. 5
0
            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);
 }
Esempio n. 8
0
 public bool HasClientVisiblityOf(WorldEntity target) => visibleEntities.Contains(target.Id) || target == player;
Esempio n. 9
0
 internal void RemoveEntity(WorldEntity entity)
 {
     Assert.IsNotNull(entity.CurrentCell, $"Cell is missing on removal for {entity.GetType()} at {entity.Position}");
     entity.CurrentCell.RemoveWorldEntity(entity);
 }
Esempio n. 10
0
 public void VisitInRadius(WorldEntity referer, float radius, IUnitVisitor unitVisitor)
 {
     mapGrid.VisitInRadius(referer, radius, unitVisitor);
 }
Esempio n. 11
0
 internal void RemoveWorldEntity(WorldEntity entity)
 {
     worldEntitiesById.Remove(entity.Id);
     mapGrid.RemoveEntity(entity);
 }
Esempio n. 12
0
 internal void AddWorldEntity(WorldEntity entity)
 {
     worldEntitiesById.Add(entity.Id, entity);
     mapGrid.AddEntity(entity);
 }