Beispiel #1
0
 protected Projectile(Player shooter, int entityTypeId, Level level)
     : base(entityTypeId, level)
 {
     Shooter = shooter;
     Ttl = 0;
     DespawnOnImpact = true;
     Collided = false;
     KnownPosition = new PlayerLocation(shooter.KnownPosition.X, shooter.KnownPosition.Y, shooter.KnownPosition.Z) {Yaw = shooter.KnownPosition.Yaw, Pitch = shooter.KnownPosition.Pitch};
 }
Beispiel #2
0
        public Entity(int entityTypeId, Level level)
        {
            Height = 1;
            Width = 1;
            Length = 1;
            Drag = 0;
            Gravity = 0;

            EntityId = EntityManager.GetEntityId();
            Level = level;
            EntityTypeId = entityTypeId;
            KnownPosition = new PlayerLocation(0, 0, 0);
            HealthManager = new HealthManager(this);
        }
Beispiel #3
0
 public void Teleport(PlayerLocation newPosition)
 {
     new EntityTeleport(Wrapper)
     {
         UniqueServerId = EntityId,
         Coordinates = newPosition.ToVector3(),
         OnGround = newPosition.OnGround,
         Pitch = newPosition.Pitch,
         Yaw = newPosition.Yaw
     }.Broadcast(Level, true, this);
 }
Beispiel #4
0
 public void LoadPlayer()
 {
     string savename = ServerSettings.OnlineMode ? Uuid : Username;
     if (File.Exists("Players/" + savename + ".pdata"))
     {
         byte[] data = File.ReadAllBytes("Players/" + savename + ".pdata");
         data = Globals.Decompress(data);
         DataBuffer reader = new DataBuffer(data);
         double x = reader.ReadDouble();
         double y = reader.ReadDouble();
         double z = reader.ReadDouble();
         float yaw = reader.ReadFloat();
         float pitch = reader.ReadFloat();
         bool onGround = reader.ReadBool();
         KnownPosition = new PlayerLocation(x, y, z) {Yaw = yaw, Pitch = pitch, OnGround = onGround};
         Gamemode = (Gamemode) reader.ReadVarInt();
         int healthLength = reader.ReadVarInt();
         byte[] healthData = reader.Read(healthLength);
         int inventoryLength = reader.ReadVarInt();
         byte[] inventoryData = reader.Read(inventoryLength);
         HealthManager.Import(healthData);
         Inventory.Import(inventoryData);
     }
     else
     {
         KnownPosition = Level.GetSpawnPoint();
     }
     Loaded = true;
 }
Beispiel #5
0
 public double DistanceTo(PlayerLocation other)
 {
     return(Math.Sqrt(Square(other.X - X) +
                      Square(other.Y - Y) +
                      Square(other.Z - Z)));
 }
Beispiel #6
0
        private Entity CheckEntityCollide(Vector3 position, Vector3 direction)
        {
            var players = Level.GetOnlinePlayers.OrderBy(player => position.DistanceTo(player.KnownPosition.ToVector3()));
            Ray2 ray = new Ray2
            {
                x = position,
                d = direction.Normalize()
            };

            foreach (var entity in players)
            {
                if (entity == Shooter) continue;

                if (Intersect(entity.GetBoundingBox(), ray))
                {
                    if (ray.tNear < direction.Distance) break;

                    Vector3 p = ray.x + ray.tNear * ray.d;
                    KnownPosition = new PlayerLocation((float)p.X, (float)p.Y, (float)p.Z);
                    return entity;
                }
            }

            var entities = Level.Entities.OrderBy(entity => position.DistanceTo(entity.KnownPosition.ToVector3()));
            foreach (var entity in entities)
            {
                if (entity == Shooter) continue;
                if (entity == this) continue;

                if (Intersect(entity.GetBoundingBox(), ray))
                {
                    if (ray.tNear < direction.Distance) break;

                    Vector3 p = ray.x + ray.tNear * ray.d;
                    KnownPosition = new PlayerLocation((float)p.X, (float)p.Y, (float)p.Z);
                    return entity;
                }
            }

            return null;
        }
Beispiel #7
0
        public bool SetIntersectLocation(BoundingBox bbox, PlayerLocation location)
        {
            var ray = new Ray(location.ToVector3() - Velocity, Velocity.Normalize());
            var distance = ray.Intersects(bbox);
            if (distance != null)
            {
                var dist = (double) distance - 0.1;
                var pos = ray.Position + (ray.Direction*dist);
                KnownPosition.X = (float) pos.X;
                KnownPosition.Y = (float) pos.Y;
                KnownPosition.Z = (float) pos.Z;
                return true;
            }

            return false;
        }
Beispiel #8
0
 public double DistanceTo(PlayerLocation other)
 {
     return Math.Sqrt(Square(other.X - X) +
                      Square(other.Y - Y) +
                      Square(other.Z - Z));
 }