Exemplo n.º 1
0
        protected override byte GetDirection(LivingEntity living, StructBlock block, StructBlock targetBlock, BlockFace face)
        {
            Chunk chunk = GetBlockChunk(block);
            // Load the blocks surrounding the position (NSEW) not diagonals
            var nsewBlocks = new BlockData.Blocks[4];
            var nsewBlockPositions = new UniversalCoords[4];
            int nsewCount = 0;

            int secondChestIndex = -1;
            chunk.ForNSEW(block.Coords, uc =>
            {
                byte? nearbyBlockId = block.World.GetBlockId(uc);

                if (nearbyBlockId == null)
                    return;

                if (nearbyBlockId == (byte)BlockData.Blocks.Chest)
                    secondChestIndex = nsewCount;

                nsewBlocks[nsewCount] = (BlockData.Blocks)nearbyBlockId;
                nsewBlockPositions[nsewCount] = uc;
                nsewCount++;
            });
            byte direction = base.GetDirection(living, block, targetBlock, face);
            if (secondChestIndex != -1)
            {
                var secondChestCoords = nsewBlockPositions[secondChestIndex];
                byte secondChestDirection = chunk.GetData(secondChestCoords);
                if (secondChestDirection != direction)
                {
                    if (secondChestCoords.WorldX == block.Coords.WorldX)
                    {
                        if (direction != (byte)MetaData.Container.South && direction != (byte)MetaData.Container.North)
                            direction = (byte)MetaData.Container.South;                          
                    }
                    else
                    {
                        if (direction != (byte)MetaData.Container.East && direction != (byte)MetaData.Container.West)
                            direction = (byte)MetaData.Container.West;
                    }
                }
                else
                {

                    if (secondChestCoords.WorldX == block.Coords.WorldX && block.MetaData != (byte)MetaData.Container.North && block.MetaData != (byte)MetaData.Container.South)
                        direction = (byte)MetaData.Container.South;
                    else
                        if (block.MetaData != (byte)MetaData.Container.West && block.MetaData != (byte)MetaData.Container.East)
                            direction = (byte)MetaData.Container.West;
                }
            }

            return direction;
        }
Exemplo n.º 2
0
        protected virtual byte GetDirection(LivingEntity living, StructBlock block, StructBlock targetBlock, BlockFace face)
        {
            byte direction = 0;
            switch (face)
            {
                case BlockFace.East:
                    direction = (byte)MetaData.Container.East;
                    break;
                case BlockFace.West:
                    direction = (byte)MetaData.Container.West;
                    break;
                case BlockFace.North:
                    direction = (byte)MetaData.Container.North;
                    break;
                case BlockFace.South:
                    direction = (byte)MetaData.Container.South;
                    break;
                default:
                    switch (living.FacingDirection(4)) // Built on floor, set by facing dir
                    {
                        case "N":
                            direction = (byte)MetaData.Container.North;
                            break;
                        case "W":
                            direction = (byte)MetaData.Container.West;
                            break;
                        case "S":
                            direction = (byte)MetaData.Container.South;
                            break;
                        case "E":
                            direction = (byte)MetaData.Container.East;
                            break;
                        default:
                            return 0;

                    }
                    break;
            }
            return direction;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Faces the entity.
        /// </summary>
        /// <param name='entity'>
        /// Entity to face.
        /// </param>
        /// <param name='yawSpeed'>
        /// Yaw speed.
        /// </param>
        /// <param name='pitchSpeed'>
        /// Pitch speed.
        /// </param>
        internal void FaceEntity(EntityBase entity, float yawSpeed, float pitchSpeed)
        {
            double xDistance = entity.Position.X - this.Position.X;
            double zDistance = entity.Position.Z - this.Position.Z;
            double yDistance;

            if (entity is LivingEntity)
            {
                LivingEntity livingEntity = entity as LivingEntity;
                yDistance = (this.Position.Y + (double)this.EyeHeight) - (livingEntity.Position.Y + (double)livingEntity.EyeHeight);
            }
            else
            {
                yDistance = (entity.BoundingBox.Minimum.Y + entity.BoundingBox.Maximum.Y) / 2.0 - (this.Position.Y + this.EyeHeight);
            }

            double xzDistance       = Math.Sqrt(xDistance * xDistance + zDistance * zDistance);
            double destinationYaw   = ((Math.Atan2(zDistance, xDistance) * 180.0) / Math.PI) - 90f;
            double destinationPitch = -((Math.Atan2(yDistance, xzDistance) * 180) / Math.PI);

            this.Pitch = -UpdateRotation(this.Pitch, destinationPitch, pitchSpeed);
            this.Yaw   = UpdateRotation(this.Yaw, destinationYaw, yawSpeed);
        }
Exemplo n.º 4
0
 public override void Attack(LivingEntity target)
 {
     if (target == null)
         return;
     target.Damage(DamageCause.EntityAttack, AttackStrength, this);
 }
Exemplo n.º 5
0
 internal void SendEntityMetadata(LivingEntity entity)
 {
     SendPacket(new EntityMetadataPacket
     {
         EntityId = entity.EntityId,
         Data = entity.Data
     });
 }
Exemplo n.º 6
0
        public override void Attack(LivingEntity target)
        {
            if (target == null)
                return;
            short weaponDmg = GetWeaponDamage();

            //Start Event
            EntityAttackEventArgs e = new EntityAttackEventArgs(this, weaponDmg, target);
            Server.PluginManager.CallEvent(Event.EntityAttack, e);
            if(e.EventCanceled) return;
            target = (LivingEntity)e.EntityToAttack;
            weaponDmg = e.Damage;
            //End Event

            target.Damage(DamageCause.EntityAttack, weaponDmg, this);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Determines whether this instance can see the specified entity.
 /// </summary>
 /// <returns>
 /// <c>true</c> if this instance can see the specified entity; otherwise, <c>false</c>.
 /// </returns>
 /// <param name='entity'>
 /// The entity to check for line of sight to.
 /// </param>
 public bool CanSee(LivingEntity entity)
 {
     return this.World.RayTraceBlocks(new AbsWorldCoords(this.Position.X, this.Position.Y + this.EyeHeight, this.Position.Z), new AbsWorldCoords(entity.Position.X, entity.Position.Y + entity.EyeHeight, entity.Position.Z)) == null;
 }
Exemplo n.º 8
0
 public abstract void Attack(LivingEntity target);