Ejemplo n.º 1
0
        public virtual double CalculateFallDamage(Player player, double damage, Player target)
        {
            var fallDamage = new Random().Next((int)(damage / 2 + 2));

            McpeAnimate animate = McpeAnimate.CreateObject();

            animate.entityId = target.EntityId;
            animate.actionId = 4;
            player.Level.RelayBroadcast(animate);
            return(fallDamage);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Handles an animate packet.
        /// </summary>
        /// <param name="message">The message.</param>
        private void HandleAnimate(McpeAnimate message)
        {
            Log.DebugFormat("Action: {0}", message.actionId);

            McpeAnimate msg = McpeAnimate.CreateObject();

            msg.entityId = message.entityId;
            msg.actionId = message.actionId;

            Level.RelayBroadcast(this, msg);
        }
Ejemplo n.º 3
0
 public void HandleMcpeAnimate(McpeAnimate message)
 {
 }
Ejemplo n.º 4
0
        public override void OnTick()
        {
            base.OnTick();

            if (KnownPosition.Y <= 0 ||
                (Velocity.Distance <= 0 && DespawnOnImpact) ||
                (Velocity.Distance <= 0 && !DespawnOnImpact && Ttl <= 0))
            {
                DespawnEntity();
                return;
            }

            Ttl--;

            if (KnownPosition.Y <= 0 || Velocity.Distance <= 0)
            {
                return;
            }

            Entity entityCollided = CheckEntityCollide(KnownPosition.ToVector3(), Velocity);

            bool collided = false;

            if (entityCollided != null)
            {
                double speed  = Math.Sqrt(Velocity.X * Velocity.X + Velocity.Y * Velocity.Y + Velocity.Z * Velocity.Z);
                double damage = Math.Ceiling(speed * Damage);
                if (IsCritical)
                {
                    damage += Level.Random.Next((int)(damage / 2 + 2));

                    McpeAnimate animate = McpeAnimate.CreateObject();
                    animate.entityId = entityCollided.EntityId;
                    animate.actionId = 4;
                    Level.RelayBroadcast(animate);
                }

                Player player = entityCollided as Player;

                if (player != null)
                {
                    damage = player.CalculatePlayerDamage(player, damage);
                }

                entityCollided.HealthManager.TakeHit(this, (int)damage, DamageCause.Projectile);
                entityCollided.HealthManager.LastDamageSource = Shooter;
                collided = true;
            }
            else
            {
                var velocity2 = Velocity;
                velocity2 *= (1.0d - Drag);
                velocity2 -= new Vector3(0, Gravity, 0);
                double distance = velocity2.Distance;
                velocity2 = velocity2.Normalize() / 2;

                for (int i = 0; i < Math.Ceiling(distance) * 2; i++)
                {
                    PlayerLocation nextPos = (PlayerLocation)KnownPosition.Clone();
                    nextPos.X += (float)velocity2.X * i;
                    nextPos.Y += (float)velocity2.Y * i;
                    nextPos.Z += (float)velocity2.Z * i;

                    BlockCoordinates coord = new BlockCoordinates(nextPos);
                    Block            block = Level.GetBlock(coord);
                    collided = block.Id != 0 && (block.GetBoundingBox()).Contains(nextPos.ToVector3());
                    if (collided)
                    {
                        SetIntersectLocation(block.GetBoundingBox(), KnownPosition);
                        break;
                    }
                }
            }

            if (collided)
            {
                Velocity = Vector3.Zero;
            }
            else
            {
                KnownPosition.X += (float)Velocity.X;
                KnownPosition.Y += (float)Velocity.Y;
                KnownPosition.Z += (float)Velocity.Z;

                Velocity *= (1.0 - Drag);
                Velocity -= new Vector3(0, Gravity, 0);

                KnownPosition.Yaw   = (float)Velocity.GetYaw();
                KnownPosition.Pitch = (float)Velocity.GetPitch();
            }

            // For debugging of flight-path
            if (BroadcastMovement)
            {
                BroadcastMoveAndMotion();
            }
        }
Ejemplo n.º 5
0
        public override void OnTick(Entity[] entities)
        {
            //base.OnTick();

            if (KnownPosition.Y <= 0 ||
                (Velocity.Length() <= 0 && DespawnOnImpact) ||
                (Velocity.Length() <= 0 && !DespawnOnImpact && Ttl <= 0))
            {
                if (DespawnOnImpact || (!DespawnOnImpact && Ttl <= 0))
                {
                    DespawnEntity();
                    return;
                }
                else
                {
                    IsCritical = false;
                }
                return;
            }

            Ttl--;

            if (KnownPosition.Y <= 0 || Velocity.Length() <= 0)
            {
                return;
            }

            Entity entityCollided = CheckEntityCollide(KnownPosition, Velocity);

            bool collided = false;

            if (entityCollided != null)
            {
                if (OnEntityColission(entityCollided))
                {
                    double speed  = Math.Sqrt(Velocity.X * Velocity.X + Velocity.Y * Velocity.Y + Velocity.Z * Velocity.Z);
                    double damage = Math.Ceiling(speed * Damage);
                    if (IsCritical)
                    {
                        damage += Level.Random.Next((int)(damage / 2 + 2));

                        McpeAnimate animate = McpeAnimate.CreateObject();
                        animate.runtimeEntityId = entityCollided.EntityId;
                        animate.actionId        = 4;
                        Level.RelayBroadcast(animate);
                    }

                    if (PowerLevel > 0)
                    {
                        damage = damage + ((PowerLevel + 1) * 0.25);
                    }


                    Player player = entityCollided as Player;

                    if (player != null)
                    {
                        damage = player.DamageCalculator.CalculatePlayerDamage(this, player, null, damage, DamageCause.Projectile);
                        player.LastAttackTarget = entityCollided;
                    }

                    entityCollided.HealthManager.TakeHit(this, (int)damage, DamageCause.Projectile);
                    entityCollided.HealthManager.LastDamageSource = Shooter;

                    DespawnEntity();
                    return;
                }
            }
            else
            {
                var velocity2 = Velocity;
                velocity2 *= (float)(1.0d - Drag);
                velocity2 -= new Vector3(0, (float)Gravity, 0);
                double distance = velocity2.Length();
                velocity2 = Vector3.Normalize(velocity2) / 2;

                for (int i = 0; i < Math.Ceiling(distance) * 2; i++)
                {
                    Vector3 nextPos = KnownPosition.ToVector3();
                    nextPos.X += velocity2.X * i;
                    nextPos.Y += velocity2.Y * i;
                    nextPos.Z += velocity2.Z * i;

                    Block block = Level.GetBlock(nextPos);
                    collided = block.IsSolid && block.GetBoundingBox().Contains(nextPos);
                    if (collided && OnBlockColission(block))
                    {
                        SetIntersectLocation(block.GetBoundingBox(), KnownPosition.ToVector3());
                        break;
                    }
                }
            }

            if (collided)
            {
                Velocity = Vector3.Zero;
            }
            else
            {
                KnownPosition.X += (float)Velocity.X;
                KnownPosition.Y += (float)Velocity.Y;
                KnownPosition.Z += (float)Velocity.Z;

                Velocity *= (float)(1.0 - Drag);
                Velocity -= new Vector3(0, (float)Gravity, 0);

                KnownPosition.Yaw   = (float)Velocity.GetYaw();
                KnownPosition.Pitch = (float)Velocity.GetPitch();
            }

            // For debugging of flight-path
            if (BroadcastMovement)
            {
                //LastUpdatedTime = DateTime.UtcNow;

                BroadcastMoveAndMotion();
            }
        }
Ejemplo n.º 6
0
		/// <summary>
		///     Handles an animate packet.
		/// </summary>
		/// <param name="message">The message.</param>
		protected virtual void HandleAnimate(McpeAnimate message)
		{
			if (Level == null) return;

			Log.DebugFormat("HandleAnimate Action: {0}", message.actionId);

			McpeAnimate msg = McpeAnimate.CreateObject();
			msg.entityId = EntityId;
			msg.actionId = message.actionId;

			Level.RelayBroadcast(this, msg);
		}
 public abstract void HandleMcpeAnimate(McpeAnimate message);
Ejemplo n.º 8
0
 public override void HandleMcpeAnimate(McpeAnimate message)
 {
 }
Ejemplo n.º 9
0
        /// <summary>
        ///     Handles an animate packet.
        /// </summary>
        /// <param name="message">The message.</param>
        private void HandleAnimate(McpeAnimate message)
        {
            Log.DebugFormat("Action: {0}", message.actionId);

            McpeAnimate msg = McpeAnimate.CreateObject();
            msg.entityId = message.entityId;
            msg.actionId = message.actionId;

            Level.RelayBroadcast(this, msg);
        }
 public void HandleMcpeAnimate(McpeAnimate message)
 {
     WritePackage(message);
 }
Ejemplo n.º 11
0
 public override void HandleMcpeAnimate(McpeAnimate message)
 {
     UnhandledPackage(message);
 }
Ejemplo n.º 12
0
 public void HandleMcpeAnimate(McpeAnimate message)
 {
 }