Beispiel #1
0
        public bool Accept(PhysicsEntity sitter)
        {
            if (Sitter != null)
            {
                return(false);
            }
            Sitter = sitter;
            if (Sitter.CurrentSeat != null)
            {
                Sitter.CurrentSeat.Kick();
            }
            Sitter.CurrentSeat = this;
            OldPosition        = Sitter.GetPosition() - SeatHolder.GetPosition();
            Sitter.SetOrientation(SeatHolder.GetOrientation());
            Sitter.SetPosition(SeatHolder.GetPosition() + PositionOffset);
            if (Sitter is PlayerEntity)
            {
                ((PlayerEntity)Sitter).Teleport(SeatHolder.GetPosition() + PositionOffset); // TODO: Teleport method on all entities!
            }
            double len = (double)PositionOffset.Length();

            js  = new JointSlider(SeatHolder, sitter, PositionOffset / len);
            jbs = new JointBallSocket(SeatHolder, sitter, sitter.GetPosition());
            jnc = new JointNoCollide(SeatHolder, sitter);
            SeatHolder.TheRegion.AddJoint(js);
            SeatHolder.TheRegion.AddJoint(jbs);
            SeatHolder.TheRegion.AddJoint(jnc);
            if (SeatHolder is VehicleEntity && sitter is PlayerEntity)
            {
                ((VehicleEntity)SeatHolder).Accepted((PlayerEntity)sitter, this);
            }
            return(true);
        }
Beispiel #2
0
 public bool Accept(PhysicsEntity sitter)
 {
     if (Sitter != null)
     {
         return false;
     }
     Sitter = sitter;
     if (Sitter.CurrentSeat != null)
     {
         Sitter.CurrentSeat.Kick();
     }
     Sitter.CurrentSeat = this;
     OldPosition = Sitter.GetPosition() - SeatHolder.GetPosition();
     Sitter.SetOrientation(SeatHolder.GetOrientation());
     Sitter.SetPosition(SeatHolder.GetPosition() + PositionOffset);
     if (Sitter is PlayerEntity)
     {
         ((PlayerEntity)Sitter).Teleport(SeatHolder.GetPosition() + PositionOffset); // TODO: Teleport method on all entities!
     }
     double len = (double)PositionOffset.Length();
     js = new JointSlider(SeatHolder, sitter, PositionOffset / len);
     jbs = new JointBallSocket(SeatHolder, sitter, sitter.GetPosition());
     jnc = new JointNoCollide(SeatHolder, sitter);
     SeatHolder.TheRegion.AddJoint(js);
     SeatHolder.TheRegion.AddJoint(jbs);
     SeatHolder.TheRegion.AddJoint(jnc);
     if (SeatHolder is VehicleEntity && sitter is PlayerEntity)
     {
         ((VehicleEntity)SeatHolder).Accepted((PlayerEntity)sitter, this);
     }
     return true;
 }
Beispiel #3
0
 public JointDistance(PhysicsEntity e1, PhysicsEntity e2, double min, double max, Location e1pos, Location e2pos)
 {
     Ent1 = e1;
     Ent2 = e2;
     Min = min;
     Max = max;
     Ent1Pos = e1pos - e1.GetPosition();
     Ent2Pos = e2pos - e2.GetPosition();
 }
 public PhysicsEntityUpdatePacketOut(PhysicsEntity e)
 {
     UsageType = NetUsageType.ENTITIES;
     ID = ServerToClientPacket.PHYSICS_ENTITY_UPDATE;
     Data = new byte[24 + 24 + 16 + 24 + 1 + 8];
     e.GetPosition().ToDoubleBytes().CopyTo(Data, 0);
     e.GetVelocity().ToDoubleBytes().CopyTo(Data, 24);
     Utilities.QuaternionToBytes(e.GetOrientation()).CopyTo(Data, 24 + 24);
     e.GetAngularVelocity().ToDoubleBytes().CopyTo(Data, 24 + 24 + 16);
     Data[24 + 24 + 16 + 24] = (byte)((e.Body != null && e.Body.ActivityInformation.IsActive) ? 1 : 0);
     Utilities.LongToBytes(e.EID).CopyTo(Data, 24 + 24 + 16 + 24 + 1);
 }
Beispiel #5
0
        public void OnCollide(object sender, CollisionEventArgs args)
        {
            if (Stuck)
            {
                return;
            }
            double len = GetVelocity().Length();

            SetPosition(args.Info.Position + (GetVelocity() / len) * 0.05f);
            SetVelocity(Location.Zero);
            Gravity = Location.Zero;
            if (HasHat)
            {
                SolidHat = new ModelEntity("invisbox", TheRegion);
                SolidHat.SetMass(0);
                SolidHat.SetPosition(GetPosition());
                SolidHat.SetOrientation(GetOrientation());
                SolidHat.scale   = new Location(0.6, 1.5, 0.6);
                SolidHat.Visible = false;
                SolidHat.CanSave = false;
                TheRegion.SpawnEntity(SolidHat);
            }
            if (args.Info.HitEnt != null)
            {
                PhysicsEntity pe = (PhysicsEntity)args.Info.HitEnt.Tag;
                if (pe is EntityDamageable)
                {
                    ((EntityDamageable)pe).Damage(Damage + DamageTimesVelocity * (double)len);
                }
                Vector3 loc     = (args.Info.Position - pe.GetPosition()).ToBVector();
                Vector3 impulse = GetVelocity().ToBVector() * DamageTimesVelocity / 1000f;
                pe.Body.ApplyImpulse(ref loc, ref impulse);
                StuckTo = pe;
                if (HasHat)
                {
                    CollisionRules.AddRule(pe.Body, SolidHat.Body, CollisionRule.NoBroadPhase); // TODO: Broadcast this info! Perhaps abuse the joint system?
                }
            }
            TheRegion.SendToAll(new PrimitiveEntityUpdatePacketOut(this));
            if (args.Info.HitEnt != null)
            {
                PhysicsEntity  pe  = (PhysicsEntity)args.Info.HitEnt.Tag;
                JointForceWeld jfw = new JointForceWeld(pe, this);
                TheRegion.AddJoint(jfw);
            }
        }
Beispiel #6
0
 public void OnCollide(object sender, CollisionEventArgs args)
 {
     if (args.Info.HitEnt != null)
     {
         PhysicsEntity physent = ((PhysicsEntity)args.Info.HitEnt.Tag);
         Vector3       loc     = (GetPosition() - physent.GetPosition()).ToBVector();
         Vector3       impulse = GetVelocity().ToBVector() * Damage / 1000f;
         physent.Body.ApplyImpulse(ref loc, ref impulse);
         physent.Body.ActivityInformation.Activate();
         if (physent is EntityDamageable)
         {
             ((EntityDamageable)physent).Damage(Damage);
         }
     }
     if (SplashSize > 0 && SplashDamage > 0)
     {
         // TODO: Apply Splash Damage
         // TODO: Apply Splash Impulses
     }
     RemoveMe();
 }