public override bool IsNotRelevant(INetObjectViewer viewer)
 {
     if (viewer is IWorldObserver)
     {
         IWorldObserver observer           = viewer as IWorldObserver;
         var            closestWrapped     = World.ClosestWrappedLocation(observer.Position, this.Position);
         var            notVisibleDistance = observer.ViewDistance + Eco.Shared.Voxel.Chunk.Size;
         var            v = closestWrapped - observer.Position;
         if (Mathf.Abs(v.x) >= notVisibleDistance || Mathf.Abs(v.z) >= notVisibleDistance)
         {
             if (this.Controller != null && this.Controller.Equals(viewer))
             {
                 this.SetPhysicsController(null);
             }
             return(true);
         }
         else
         {
             // Still relevant, Check if viewer would be a better controller
             if (this.Controller == null)
             {
                 this.SetPhysicsController(viewer);
             }
             else if (this.Controller != viewer && Vector2.WrappedDistance(observer.Position.XZ, this.Position.XZ) < 10f)
             {
                 IWorldObserver other = this.Controller as IWorldObserver;
                 if (Vector2.WrappedDistance(other.Position.XZ, this.Position.XZ) > 15f)
                 {
                     this.SetPhysicsController(viewer);
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        public CommandList(IWorldObserver worldObserver, CommandContext context)
        {
            worldObserver.ThrowIfNull("worldObserver");
            context.ThrowIfNull("context");

            _worldObserver = worldObserver;
            _context = context;
        }
        public CommandQueue(IWorldObserver worldObserver, WorldInstance worldInstance)
        {
            _worldObserver = worldObserver;
            _worldInstance = worldInstance;
            worldObserver.ThrowIfNull("worldObserver");
            worldInstance.ThrowIfNull("worldInstance");

            _context = new CommandContext(_worldInstance, this);
            _commandList = new CommandList(worldObserver, _context);
        }
Ejemplo n.º 4
0
 /// <inheritdoc/>
 public void RemoveObserver(IWorldObserver observer)
 {
     this.ObserverLock.EnterWriteLock();
     try
     {
         this.Observers.Remove(observer);
     }
     finally
     {
         this.ObserverLock.ExitWriteLock();
     }
 }
Ejemplo n.º 5
0
 /// <inheritdoc/>
 public void AddObserver(IWorldObserver observer)
 {
     this.ObserverLock.EnterWriteLock();
     try
     {
         this.Observers.Add(observer);
     }
     finally
     {
         this.ObserverLock.ExitWriteLock();
     }
 }
 public override bool IsRelevant(INetObjectViewer viewer)
 {
     if (viewer is IWorldObserver)
     {
         IWorldObserver observer           = viewer as IWorldObserver;
         var            closestWrapped     = World.ClosestWrappedLocation(observer.Position, this.Position);
         var            notVisibleDistance = observer.ViewDistance + Eco.Shared.Voxel.Chunk.Size;
         var            v = closestWrapped - observer.Position;
         if (Mathf.Abs(v.x) >= notVisibleDistance || Mathf.Abs(v.z) >= notVisibleDistance)
         {
             if (this.Controller == null)
             {
                 this.SetPhysicsController(viewer);
             }
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 7
0
        // temporary solution for hunting without affecting the environment
        // spawn a corpse nearby when a hungry animal becomes visible
        public override void OnBecameVisible(IWorldObserver observer, Animal animal)
        {
            base.OnBecameVisible(observer, animal);

            if (animal.Dead || animal.Hunger < HungerThreshold || !RandomUtil.Chance(ChanceCaughtPreyWhileOffscreen))
            {
                return;
            }

            var preyType = this.GetRegionalPrey(animal);

            if (preyType != null)
            {
                var preySpecies = EcoSim.GetSpecies(preyType.Name) as AnimalSpecies;
                var spawnPos    = (Vector3)animal.Position.WorldPosition3i.SpiralOutXZIter(10).Skip(20)
                                  .Select(x => RouteManager.NearestWalkableY(x, 10)).Where(x => x.IsValid && RouteCacheData.IsFlatGround(x)).FirstOrDefault();
                if (spawnPos != default(Vector3))
                {
                    EcoSim.AnimalSim.SpawnCorpse(preySpecies, spawnPos);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ObserverToWorldViewAdapter" /> class.
 /// </summary>
 /// <param name="adaptee">The adaptee.</param>
 /// <param name="infoRange">The information range.</param>
 public ObserverToWorldViewAdapter(IWorldObserver adaptee, int infoRange)
 {
     this.adaptee   = adaptee;
     this.InfoRange = infoRange;
 }