Exemplo n.º 1
0
        public override void Update(IEntityManager entityManager)
        {
            var nearbyEntities = entityManager.EntitiesInRange(Position, PickupRange);

            if ((DateTime.UtcNow - SpawnTime).TotalSeconds > 1)
            {
                var player = nearbyEntities.FirstOrDefault(e => e is PlayerEntity && (e as PlayerEntity).Health != 0 &&
                                                           e.Position.DistanceTo(Position) <= PickupRange);
                if (player != null)
                {
                    var playerEntity = player as PlayerEntity;
                    playerEntity.OnPickUpItem(this);
                    entityManager.DespawnEntity(this);
                }
            }
            if ((DateTime.UtcNow - SpawnTime).TotalMinutes > 5)
            {
                entityManager.DespawnEntity(this);
            }
            base.Update(entityManager);
        }
Exemplo n.º 2
0
        public override void Update(IEntityManager entityManager)
        {
            var nearbyEntities = entityManager.EntitiesInRange(Position, PickupRange);

            if ((DateTime.Now - SpawnTime).TotalSeconds > 1)
            {
                var player = nearbyEntities.FirstOrDefault(e => e is PlayerEntity && (e as PlayerEntity).Health != 0 &&
                                                           e.Position.DistanceTo(Position) <= PickupRange);
                if (player != null)
                {
                    var playerEntity = player as PlayerEntity;
                    playerEntity.OnPickUpItem(this);
                    entityManager.DespawnEntity(this);
                }

                /* TODO: Merging item entities (this code behaves strangely
                 * var item = nearbyEntities.FirstOrDefault(e => e is ItemEntity
                 *  && e != this
                 *  && (DateTime.Now - (e as ItemEntity).SpawnTime).TotalSeconds > 1
                 *  && (e as ItemEntity).Item.ID == Item.ID && (e as ItemEntity).Item.Metadata == Item.Metadata
                 *  && (e as ItemEntity).Item.Nbt == Item.Nbt
                 *  && e.Position.DistanceTo(Position) < PickupRange);
                 * if (item != null)
                 * {
                 *  // Merge
                 *  entityManager.DespawnEntity(item);
                 *  var newItem = Item;
                 *  newItem.Count += (item as ItemEntity).Item.Count;
                 *  Item = newItem;
                 *  OnPropertyChanged("Metadata");
                 * }*/
            }
            if ((DateTime.Now - SpawnTime).TotalMinutes > 5)
            {
                entityManager.DespawnEntity(this);
            }
            base.Update(entityManager);
        }
Exemplo n.º 3
0
 public override void Update(IEntityManager entityManager)
 {
     var nearbyEntities = entityManager.EntitiesInRange(Position, PickupRange);
     if ((DateTime.UtcNow - SpawnTime).TotalSeconds > 1)
     {
         var player = nearbyEntities.FirstOrDefault(e => e is PlayerEntity && (e as PlayerEntity).Health != 0
                          && e.Position.DistanceTo(Position) <= PickupRange);
         if (player != null)
         {
             var playerEntity = player as PlayerEntity;
             playerEntity.OnPickUpItem(this);
             entityManager.DespawnEntity(this);
         }
     }
     if ((DateTime.UtcNow - SpawnTime).TotalMinutes > 5)
         entityManager.DespawnEntity(this);
     base.Update(entityManager);
 }