Пример #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;
 }
Пример #2
0
 public void Kick()
 {
     if (js == null)
     {
         return;
     }
     if (SeatHolder is VehicleEntity && Sitter != null && Sitter is PlayerEntity)
     {
         ((VehicleEntity)SeatHolder).SeatKicked((PlayerEntity)Sitter, this);
     }
     SeatHolder.TheRegion.DestroyJoint(js);
     SeatHolder.TheRegion.DestroyJoint(jbs);
     SeatHolder.TheRegion.DestroyJoint(jnc);
     js = null;
     jbs = null;
     jnc = null;
     if (Sitter is PlayerEntity)
     {
         ((PlayerEntity)Sitter).Teleport(OldPosition + SeatHolder.GetPosition());
     }
     else
     {
         Sitter.SetPosition(OldPosition + SeatHolder.GetPosition());
     }
     Sitter.CurrentSeat = null;
     Sitter = null;
     OldPosition = Location.Zero;
 }