Example #1
0
        public void Update(IMobEntity entity, IEntityManager manager)
        {
            var cast = entity as IEntity;

            if (entity.CurrentPath != null)
            {
                if (entity.AdvancePath(manager.TimeSinceLastUpdate))
                {
                    entity.CurrentState = new IdleState(new WanderState());
                }
            }
            else
            {
                var target = new Coordinates3D(
                    (int)(cast.Position.X + (MathHelper.Random.Next(Distance) - Distance / 2)),
                    0,
                    (int)(cast.Position.Z + (MathHelper.Random.Next(Distance) - Distance / 2))
                    );
                IChunk chunk;
                var    adjusted = entity.World.FindBlockPosition(target, out chunk, false);
                target.Y = chunk.GetHeight((byte)adjusted.X, (byte)adjusted.Z) + 1;
                Task.Factory.StartNew(() =>
                {
                    entity.CurrentPath = PathFinder.FindPath(entity.World, entity.BoundingBox,
                                                             (Coordinates3D)cast.Position, target);
                });
            }
        }
Example #2
0
 public void Update(IMobEntity entity, IEntityManager manager)
 {
     var cast = entity as IEntity;
     if (entity.CurrentPath != null)
         entity.AdvancePath(manager.TimeSinceLastUpdate);
     else
     {
         if (MathHelper.Random.Next(IdleChance) == 0)
         {
             var target = new Coordinates3D(
                 (int)(cast.Position.X + (MathHelper.Random.Next(Distance) - Distance / 2)),
                 0,
                 (int)(cast.Position.Z + (MathHelper.Random.Next(Distance) - Distance / 2))
             );
             IChunk chunk;
             var adjusted = entity.World.FindBlockPosition(target, out chunk, generate: false);
             target.Y = chunk.GetHeight((byte)adjusted.X, (byte)adjusted.Z) + 1;
             Task.Factory.StartNew(() =>
             {
                     entity.CurrentPath = PathFinder.FindPath(entity.World, entity.BoundingBox,
                         (Coordinates3D)cast.Position, target);
             });
         }
     }
 }
Example #3
0
 public Move_Behavior(IEntity entity, int rate, int chance, ChooseDestinationHandler chooseDestination)
     : base(entity, rate)
 {
     this.entity_move = entity as IMobEntity;
     this.Chance = chance;
     this.ChooseDestination = chooseDestination;
 }
Example #4
0
 public void Update(IMobEntity entity, IEntityManager manager)
 {
     if (DateTime.UtcNow >= Expiry)
     {
         entity.CurrentState = NextState;
     }
 }
Example #5
0
        public override void Dispose()
        {
            this.entity_move = null;

            base.Dispose();
        }