Example #1
0
 public void Grab(PlayerEntity player, PhysicsEntity pe, Location hit)
 {
     AltClick(player, null);
     JointBallSocket jbs = new JointBallSocket(player.CursorMarker, pe, hit);
     player.TheRegion.AddJoint(jbs);
     player.GrabJoint = jbs;
 }
Example #2
0
 public JointSwivelHinge(PhysicsEntity e1, PhysicsEntity e2, Location hinge, Location twist)
 {
     Ent1 = e1;
     Ent2 = e2;
     WorldHinge = hinge;
     WorldTwist = twist;
 }
Example #3
0
 public JointPullPush(PhysicsEntity e1, PhysicsEntity e2, Location axis, bool mode)
 {
     Ent1 = e1;
     Ent2 = e2;
     Axis = axis;
     Mode = mode;
 }
Example #4
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);
        }
Example #5
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;
 }
Example #6
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;
 }
Example #7
0
 public JointVehicleMotor(PhysicsEntity e1, PhysicsEntity e2, Location dir, bool isSteering)
 {
     Ent1 = e1;
     Ent2 = e2;
     Direction = dir;
     IsSteering = isSteering;
 }
Example #8
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();
 }
Example #9
0
 public JointLAxisLimit(PhysicsEntity e1, PhysicsEntity e2, double min, double max, Location cpos1, Location cpos2, Location axis)
 {
     Ent1 = e1;
     Ent2 = e2;
     Min = min;
     Max = max;
     CPos1 = cpos1;
     CPos2 = cpos2;
     Axis = axis;
 }
 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);
 }
Example #11
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);
            }
        }
Example #12
0
        private void Events_ContactCreated(EntityCollidable sender, Collidable other, CollidablePairHandler pair, ContactData contact)
        {
            if (ApplyDamage > 0)
            {
                return;
            }
            if (!(other is EntityCollidable))
            {
                return;
            }
            PhysicsEntity pe = (PhysicsEntity)((EntityCollidable)other).Entity.Tag;

            if (pe.TryGetProperty(out DamageableEntityProperty damageable))
            {
                damageable.Damage(DamageAmt);
                ApplyDamage = DamageDelay;
            }
        }
Example #13
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();
 }
Example #14
0
 public Seat(PhysicsEntity seatHolder, Location posOffset)
 {
     SeatHolder = seatHolder;
     PositionOffset = posOffset;
 }
Example #15
0
 public JointWeld(PhysicsEntity e1, PhysicsEntity e2)
 {
     Ent1 = e1;
     Ent2 = e2;
 }
Example #16
0
 public PhysicsEntityTag(PhysicsEntity ent)
 {
     Internal = ent;
 }
Example #17
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;
 }
Example #18
0
 public JointNoCollide(PhysicsEntity e1, PhysicsEntity e2)
 {
     One = e1;
     Two = e2;
 }
Example #19
0
 public Seat(PhysicsEntity seatHolder, Location posOffset)
 {
     SeatHolder     = seatHolder;
     PositionOffset = posOffset;
 }
Example #20
0
 public JointBallSocket(PhysicsEntity e1, PhysicsEntity e2, Location pos)
 {
     One = e1;
     Two = e2;
     Position = pos;
 }
Example #21
0
 public ConstWheelStepUp(PhysicsEntity ent, double height)
 {
     One = ent;
     Two = ent;
     Height = height;
 }
Example #22
0
 public JointSpinner(PhysicsEntity e1, PhysicsEntity e2, Location dir)
 {
     One = e1;
     Two = e2;
     Direction = dir;
 }
Example #23
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);
     }
 }
Example #24
0
 public JointSlider(PhysicsEntity e1, PhysicsEntity e2, Location dir)
 {
     Ent1 = e1;
     Ent2 = e2;
     Direction = dir;
 }