예제 #1
0
        public JointVehicleMotor ConnectWheel(VehiclePartEntity wheel, bool driving, bool powered)
        {
            wheel.SetFriction(2.5f);
            Vector3         left             = Quaternion.Transform(new Vector3(-1, 0, 0), wheel.GetOrientation());
            Vector3         up               = Quaternion.Transform(new Vector3(0, 0, 1), wheel.GetOrientation());
            JointSlider     pointOnLineJoint = new JointSlider(this, wheel, -new Location(up));
            JointLAxisLimit suspensionLimit  = new JointLAxisLimit(this, wheel, 0f, 0.1f, wheel.GetPosition(), wheel.GetPosition(), -new Location(up));
            JointPullPush   spring           = new JointPullPush(this, wheel, -new Location(up), true);

            BEPUphysics.CollisionRuleManagement.CollisionRules.AddRule(wheel.Body, this.Body, BEPUphysics.CollisionRuleManagement.CollisionRule.NoBroadPhase); // TODO: How necessary is this? Should we replicate this clientside?
            if (driving)
            {
                JointSpinner spinner = new JointSpinner(this, wheel, new Location(-left));
                TheRegion.AddJoint(spinner);
            }
            else
            {
                JointSwivelHinge swivelhinge = new JointSwivelHinge(this, wheel, new Location(up), new Location(-left));
                TheRegion.AddJoint(swivelhinge);
            }
            TheRegion.AddJoint(pointOnLineJoint);
            TheRegion.AddJoint(suspensionLimit);
            TheRegion.AddJoint(spring);
            if (powered)
            {
                JointVehicleMotor motor = new JointVehicleMotor(this, wheel, new Location(driving ? left : up), !driving);
                TheRegion.AddJoint(motor);
                return(motor);
            }
            return(null);
        }
예제 #2
0
        public JointVehicleMotor ConnectWheel(VehiclePartEntity wheel, bool driving, bool powered, double susp)
        {
            TheRegion.AddJoint(new ConstWheelStepUp(wheel, wheel.StepHeight));
            wheel.SetFriction(2.5f);
            Vector3         left             = BEPUutilities.Quaternion.Transform(new Vector3(-1, 0, 0), wheel.GetOrientation());
            Vector3         up               = BEPUutilities.Quaternion.Transform(new Vector3(0, 0, 1), wheel.GetOrientation());
            JointSlider     pointOnLineJoint = new JointSlider(this, wheel, -new Location(up));
            JointLAxisLimit suspensionLimit  = new JointLAxisLimit(this, wheel, 0f, susp, wheel.GetPosition(), wheel.GetPosition(), -new Location(up));
            JointPullPush   spring           = new JointPullPush(this, wheel, -new Location(up), true);

            if (driving)
            {
                JointSpinner spinner = new JointSpinner(this, wheel, new Location(-left));
                TheRegion.AddJoint(spinner);
            }
            else
            {
                JointSwivelHinge swivelhinge = new JointSwivelHinge(this, wheel, new Location(up), new Location(-left));
                TheRegion.AddJoint(swivelhinge);
            }
            TheRegion.AddJoint(pointOnLineJoint);
            TheRegion.AddJoint(suspensionLimit);
            TheRegion.AddJoint(spring);
            JointNoCollide jnc = new JointNoCollide(this, wheel);

            TheRegion.AddJoint(jnc);
            if (powered)
            {
                JointVehicleMotor motor = new JointVehicleMotor(this, wheel, new Location(driving ? left : up), !driving);
                TheRegion.AddJoint(motor);
                return(motor);
            }
            return(null);
        }
예제 #3
0
        public void ConnectFlap(VehiclePartEntity flap, FDSSection flapDat)
        {
            JointBallSocket jbs = new JointBallSocket(this, flap, flap.GetPosition()); // TODO: necessity?

            TheRegion.AddJoint(jbs);
            JointNoCollide jnc = new JointNoCollide(this, flap);

            TheRegion.AddJoint(jnc);
            string      mode = flapDat.GetString("mode");
            VehicleFlap vf   = new VehicleFlap()
            {
                MaxAngle = flapDat.GetDouble("max_angle", 10).Value,
                Speed    = flapDat.GetDouble("corrective_speed", 2.25).Value
            };

            if (mode == "roll/l")
            {
                JointHinge jh = new JointHinge(this, flap, new Location(1, 0, 0));
                TheRegion.AddJoint(jh);
                JointVehicleMotor jvm = new JointVehicleMotor(this, flap, new Location(1, 0, 0), true);
                TheRegion.AddJoint(jvm);
                vf.JVM = jvm;
                Flaps_RollL.Add(vf);
            }
            else if (mode == "roll/r")
            {
                JointHinge jh = new JointHinge(this, flap, new Location(1, 0, 0));
                TheRegion.AddJoint(jh);
                JointVehicleMotor jvm = new JointVehicleMotor(this, flap, new Location(1, 0, 0), true);
                TheRegion.AddJoint(jvm);
                vf.JVM = jvm;
                Flaps_RollR.Add(vf);
            }
            else if (mode == "yaw")
            {
                JointHinge jh = new JointHinge(this, flap, new Location(0, 0, 1));
                TheRegion.AddJoint(jh);
                JointVehicleMotor jvm = new JointVehicleMotor(this, flap, new Location(0, 0, 1), true);
                TheRegion.AddJoint(jvm);
                vf.JVM = jvm;
                Flaps_Yaw.Add(vf);
            }
            else if (mode == "pitch")
            {
                JointHinge jh = new JointHinge(this, flap, new Location(1, 0, 0));
                TheRegion.AddJoint(jh);
                JointVehicleMotor jvm = new JointVehicleMotor(this, flap, new Location(1, 0, 0), true);
                TheRegion.AddJoint(jvm);
                vf.JVM = jvm;
                Flaps_Pitch.Add(vf);
            }
        }
예제 #4
0
        public override bool ParseBytesAndExecute(byte[] data)
        {
            DataStream ds   = new DataStream(data);
            DataReader dr   = new DataReader(ds);
            long       PEID = dr.ReadLong();
            byte       type = dr.ReadByte();
            Entity     e    = TheClient.TheRegion.GetEntity(PEID);

            if (type == 0)
            {
                if (e is PlayerEntity)
                {
                    ((PlayerEntity)e).InVehicle = true;
                    int          drivecount = dr.ReadInt();
                    int          steercount = dr.ReadInt();
                    PlayerEntity player     = (PlayerEntity)e;
                    player.DrivingMotors.Clear();
                    player.SteeringMotors.Clear();
                    for (int i = 0; i < drivecount; i++)
                    {
                        long jid = dr.ReadLong();
                        JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid);
                        if (jvm == null)
                        {
                            dr.Close();
                            return(false);
                        }
                        player.DrivingMotors.Add(jvm);
                    }
                    for (int i = 0; i < steercount; i++)
                    {
                        long jid = dr.ReadLong();
                        JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid);
                        if (jvm == null)
                        {
                            dr.Close();
                            return(false);
                        }
                        player.SteeringMotors.Add(jvm);
                    }
                    dr.Close();
                    return(true);
                }
                // TODO: other CharacterEntity's
            }
            else if (type == 1)
            {
                if (e is PlayerEntity)
                {
                    long   heloid = dr.ReadLong();
                    Entity helo   = TheClient.TheRegion.GetEntity(heloid);
                    if (!(helo is ModelEntity))
                    {
                        dr.Close();
                        return(false);
                    }
                    ((PlayerEntity)e).InVehicle = true;
                    ((PlayerEntity)e).Vehicle   = helo;
                    ModelEntity helomod = (ModelEntity)helo;
                    helomod.TurnIntoHelicopter((PlayerEntity)e);
                    dr.Close();
                    return(true);
                }
                // TODO: other CharacterEntity's
                dr.Close();
                return(true);
            }
            else if (type == 2)
            {
                if (e is PlayerEntity)
                {
                    long   planeid = dr.ReadLong();
                    Entity plane   = TheClient.TheRegion.GetEntity(planeid);
                    if (!(plane is ModelEntity))
                    {
                        dr.Close();
                        return(false);
                    }
                    ((PlayerEntity)e).InVehicle = true;
                    ((PlayerEntity)e).Vehicle   = plane;
                    ModelEntity planemod = (ModelEntity)plane;
                    planemod.TurnIntoPlane((PlayerEntity)e);
                    dr.Close();
                    return(true);
                }
                // TODO: other CharacterEntity's
                dr.Close();
                return(true);
            }
            dr.Close();
            return(false);
        }
예제 #5
0
        public override bool ParseBytesAndExecute(byte[] data)
        {
            int len = 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4;

            if (data.Length < len)
            {
                SysConsole.Output(OutputType.WARNING, "Joint packet: Bad initial length!");
                return(false);
            }
            byte type = data[0];
            long EID1 = Utilities.BytesToLong(Utilities.BytesPartial(data, 1, 8));
            long EID2 = Utilities.BytesToLong(Utilities.BytesPartial(data, 1 + 8, 8));
            long JID  = Utilities.BytesToLong(Utilities.BytesPartial(data, 1 + 8 + 8, 8));

            if (TheClient.TheRegion.GetJoint(JID) != null)
            {
                // If we already know this joint, just keep on going.
                return(true);
            }
            Entity pe1 = TheClient.TheRegion.GetEntity(EID1);
            Entity pe2 = TheClient.TheRegion.GetEntity(EID2);

            if (pe1 == null)
            {
                SysConsole.Output(OutputType.WARNING, "Joint Packet: Invalid EID-1 " + EID1);
                return(false);
            }
            if (pe2 == null)
            {
                SysConsole.Output(OutputType.WARNING, "Joint Packet: Invalid EID-2 " + EID2);
                return(false);
            }
            Location pos1 = Location.FromDoubleBytes(data, 1 + 8 + 8 + 8);
            float    qx1  = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24, 4));
            float    qy1  = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4, 4));
            float    qz1  = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4, 4));
            float    qw1  = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4, 4));

            BEPUutilities.Quaternion quat1 = new BEPUutilities.Quaternion(qx1, qy1, qz1, qw1);
            pe1.SetPosition(pos1);
            pe1.SetOrientation(quat1);
            Location pos2 = Location.FromDoubleBytes(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4);
            float    qx2  = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 24 + 4 + 4 + 4 + 4, 4));
            float    qy2  = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 24 + 4 + 4 + 4 + 4, 4));
            float    qz2  = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 24 + 4 + 4 + 4 + 4, 4));
            float    qw2  = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4, 4));

            BEPUutilities.Quaternion quat2 = new BEPUutilities.Quaternion(qx2, qy2, qz2, qw2);
            pe1.SetPosition(pos1);
            pe1.SetOrientation(quat1);
            pe2.SetPosition(pos2);
            pe2.SetOrientation(quat2);
            if (type == 0)
            {
                if (data.Length != len + 24)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                Location        pos = Location.FromDoubleBytes(data, len);
                JointBallSocket jbs = new JointBallSocket((PhysicsEntity)pe1, (PhysicsEntity)pe2, pos)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jbs);
                return(true);
            }
            else if (type == 1)
            {
                if (data.Length != len + 24)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                Location    dir = Location.FromDoubleBytes(data, len);
                JointSlider js  = new JointSlider((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(js);
                return(true);
            }
            else if (type == 2)
            {
                if (data.Length != len + 4 + 4 + 24 + 24)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                float         min     = Utilities.BytesToFloat(Utilities.BytesPartial(data, len, 4));
                float         max     = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 4, 4));
                Location      ent1pos = Location.FromDoubleBytes(data, len + 4 + 4);
                Location      ent2pos = Location.FromDoubleBytes(data, len + 4 + 4 + 24);
                JointDistance jd      = new JointDistance((PhysicsEntity)pe1, (PhysicsEntity)pe2, min, max, ent1pos, ent2pos)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jd);
                return(true);
            }
            else if (type == 3)
            {
                if (data.Length != len + 24 + 1)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                Location      axis = Location.FromDoubleBytes(data, len);
                bool          mode = data[len + 24] == 1;
                JointPullPush jpp  = new JointPullPush((PhysicsEntity)pe1, (PhysicsEntity)pe2, axis, mode)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jpp);
                return(true);
            }
            else if (type == 4)
            {
                if (data.Length != len)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                JointForceWeld jfw = new JointForceWeld(pe1, pe2)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jfw);
                return(true);
            }
            else if (type == 5)
            {
                if (data.Length != len + 24)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                Location     dir = Location.FromDoubleBytes(data, len);
                JointSpinner js  = new JointSpinner((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(js);
                return(true);
            }
            else if (type == 6)
            {
                if (data.Length != len + 24 + 24)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                Location   a1 = Location.FromDoubleBytes(data, len);
                Location   a2 = Location.FromDoubleBytes(data, len + 24);
                JointTwist jt = new JointTwist((PhysicsEntity)pe1, (PhysicsEntity)pe2, a1, a2)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jt);
                return(true);
            }
            else if (type == 7)
            {
                if (data.Length != len)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                JointWeld jw = new JointWeld((PhysicsEntity)pe1, (PhysicsEntity)pe2)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jw);
                return(true);
            }
            else if (type == 8)
            {
                if (data.Length != len + 24 + 1)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                Location          dir        = Location.FromDoubleBytes(data, len);
                bool              issteering = data[len + 24] == 1;
                JointVehicleMotor jm         = new JointVehicleMotor((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir, issteering)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jm);
                return(true);
            }
            else if (type == 9)
            {
                if (data.Length != len + 24 + 24 + 24 + 4 + 4)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                Location        cpos1 = Location.FromDoubleBytes(data, len);
                Location        cpos2 = Location.FromDoubleBytes(data, len + 24);
                Location        axis  = Location.FromDoubleBytes(data, len + 24 + 24);
                float           min   = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 24 + 24 + 24, 4));
                float           max   = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 24 + 24 + 24 + 4, 4));
                JointLAxisLimit jlal  = new JointLAxisLimit((PhysicsEntity)pe1, (PhysicsEntity)pe2, min, max, cpos1, cpos2, axis)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jlal);
                return(true);
            }
            else if (type == 10)
            {
                if (data.Length != len + 24 + 24)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                Location         hinge = Location.FromDoubleBytes(data, len);
                Location         twist = Location.FromDoubleBytes(data, len + 24);
                JointSwivelHinge jlal  = new JointSwivelHinge((PhysicsEntity)pe1, (PhysicsEntity)pe2, hinge, twist)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jlal);
                return(true);
            }
            else if (type == 11)
            {
                if (data.Length != len + 4)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                float            height = Utilities.BytesToFloat(Utilities.BytesPartial(data, len, 4));
                ConstWheelStepUp cwsu   = new ConstWheelStepUp((PhysicsEntity)pe1, height)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(cwsu);
                return(true);
            }
            else if (type == 12)
            {
                if (data.Length != len + 4 + 1)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                ConnectorBeam cb = new ConnectorBeam()
                {
                    One   = pe1,
                    Two   = pe2,
                    color = System.Drawing.Color.FromArgb(Utilities.BytesToInt(Utilities.BytesPartial(data, len, 4))),
                    JID   = JID,
                    type  = (BeamType)data[len + 4]
                };
                TheClient.TheRegion.AddJoint(cb);
                return(true);
            }
            else if (type == 13)
            {
                if (data.Length != len)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                JointFlyingDisc jfd = new JointFlyingDisc((PhysicsEntity)pe1)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jfd);
                return(true);
            }
            else if (type == 14)
            {
                if (data.Length != len)
                {
                    SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
                    return(false);
                }
                JointNoCollide jnc = new JointNoCollide((PhysicsEntity)pe1, (PhysicsEntity)pe2)
                {
                    JID = JID
                };
                TheClient.TheRegion.AddJoint(jnc);
                return(true);
            }
            else
            {
                SysConsole.Output(OutputType.WARNING, "Unknown joint type " + type);
                return(false);
            }
        }
예제 #6
0
 public override bool ParseBytesAndExecute(byte[] data)
 {
     int len = 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4;
     if (data.Length < len)
     {
         SysConsole.Output(OutputType.WARNING, "Joint packet: Bad initial length!");
         return false;
     }
     byte type = data[0];
     long EID1 = Utilities.BytesToLong(Utilities.BytesPartial(data, 1, 8));
     long EID2 = Utilities.BytesToLong(Utilities.BytesPartial(data, 1 + 8, 8));
     long JID = Utilities.BytesToLong(Utilities.BytesPartial(data, 1 + 8 + 8, 8));
     if (TheClient.TheRegion.GetJoint(JID) != null)
     {
         // If we already know this joint, just keep on going.
         return true;
     }
     Entity pe1 = TheClient.TheRegion.GetEntity(EID1);
     Entity pe2 = TheClient.TheRegion.GetEntity(EID2);
     if (pe1 == null)
     {
         SysConsole.Output(OutputType.WARNING, "Joint Packet: Invalid EID-1 " + EID1);
         return false;
     }
     if (pe2 == null)
     {
         SysConsole.Output(OutputType.WARNING, "Joint Packet: Invalid EID-2 " + EID2);
         return false;
     }
     Location pos1 = Location.FromDoubleBytes(data, 1 + 8 + 8 + 8);
     float qx1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24, 4));
     float qy1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4, 4));
     float qz1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4, 4));
     float qw1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4, 4));
     BEPUutilities.Quaternion quat1 = new BEPUutilities.Quaternion(qx1, qy1, qz1, qw1);
     pe1.SetPosition(pos1);
     pe1.SetOrientation(quat1);
     Location pos2 = Location.FromDoubleBytes(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4);
     float qx2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 24 + 4 + 4 + 4 + 4, 4));
     float qy2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 24 + 4 + 4 + 4 + 4, 4));
     float qz2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 24 + 4 + 4 + 4 + 4, 4));
     float qw2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4, 4));
     BEPUutilities.Quaternion quat2 = new BEPUutilities.Quaternion(qx2, qy2, qz2, qw2);
     pe1.SetPosition(pos1);
     pe1.SetOrientation(quat1);
     pe2.SetPosition(pos2);
     pe2.SetOrientation(quat2);
     if (type == 0)
     {
         if (data.Length != len + 24)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         Location pos = Location.FromDoubleBytes(data, len);
         JointBallSocket jbs = new JointBallSocket((PhysicsEntity)pe1, (PhysicsEntity)pe2, pos);
         jbs.JID = JID;
         TheClient.TheRegion.AddJoint(jbs);
         return true;
     }
     else if (type == 1)
     {
         if (data.Length != len + 24)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         Location dir = Location.FromDoubleBytes(data, len);
         JointSlider js = new JointSlider((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir);
         js.JID = JID;
         TheClient.TheRegion.AddJoint(js);
         return true;
     }
     else if (type == 2)
     {
         if (data.Length != len + 4 + 4 + 24 + 24)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         float min = Utilities.BytesToFloat(Utilities.BytesPartial(data, len, 4));
         float max = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 4, 4));
         Location ent1pos = Location.FromDoubleBytes(data, len + 4 + 4);
         Location ent2pos = Location.FromDoubleBytes(data, len + 4 + 4 + 24);
         JointDistance jd = new JointDistance((PhysicsEntity)pe1, (PhysicsEntity)pe2, min, max, ent1pos, ent2pos);
         jd.JID = JID;
         TheClient.TheRegion.AddJoint(jd);
         return true;
     }
     else if (type == 3)
     {
         if (data.Length != len + 24 + 1)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         Location axis = Location.FromDoubleBytes(data, len);
         bool mode = data[len + 24] == 1;
         JointPullPush jpp = new JointPullPush((PhysicsEntity)pe1, (PhysicsEntity)pe2, axis, mode);
         jpp.JID = JID;
         TheClient.TheRegion.AddJoint(jpp);
         return true;
     }
     else if (type == 4)
     {
         if (data.Length != len)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         JointForceWeld jfw = new JointForceWeld(pe1, pe2);
         jfw.JID = JID;
         TheClient.TheRegion.AddJoint(jfw);
         return true;
     }
     else if (type == 5)
     {
         if (data.Length != len + 24)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         Location dir = Location.FromDoubleBytes(data, len);
         JointSpinner js = new JointSpinner((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir);
         js.JID = JID;
         TheClient.TheRegion.AddJoint(js);
         return true;
     }
     else if (type == 6)
     {
         if (data.Length != len + 24 + 24)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         Location a1 = Location.FromDoubleBytes(data, len);
         Location a2 = Location.FromDoubleBytes(data, len + 24);
         JointTwist jt = new JointTwist((PhysicsEntity)pe1, (PhysicsEntity)pe2, a1, a2);
         jt.JID = JID;
         TheClient.TheRegion.AddJoint(jt);
         return true;
     }
     else if (type == 7)
     {
         if (data.Length != len)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         JointWeld jw = new JointWeld((PhysicsEntity)pe1, (PhysicsEntity)pe2);
         jw.JID = JID;
         TheClient.TheRegion.AddJoint(jw);
         return true;
     }
     else if (type == 8)
     {
         if (data.Length != len + 24 + 1)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         Location dir = Location.FromDoubleBytes(data, len);
         bool issteering = data[len + 24] == 1;
         JointVehicleMotor jm = new JointVehicleMotor((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir, issteering);
         jm.JID = JID;
         TheClient.TheRegion.AddJoint(jm);
         return true;
     }
     else if (type == 9)
     {
         if (data.Length != len + 24 + 24 + 24 + 4 + 4)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         Location cpos1 = Location.FromDoubleBytes(data, len);
         Location cpos2 = Location.FromDoubleBytes(data, len + 24);
         Location axis = Location.FromDoubleBytes(data, len + 24 + 24);
         float min = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 24 + 24 + 24, 4));
         float max = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 24 + 24 + 24 + 4, 4));
         JointLAxisLimit jlal = new JointLAxisLimit((PhysicsEntity)pe1, (PhysicsEntity)pe2, min, max, cpos1, cpos2, axis);
         jlal.JID = JID;
         TheClient.TheRegion.AddJoint(jlal);
         return true;
     }
     else if (type == 10)
     {
         if (data.Length != len + 24 + 24)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         Location hinge = Location.FromDoubleBytes(data, len);
         Location twist = Location.FromDoubleBytes(data, len + 24);
         JointSwivelHinge jlal = new JointSwivelHinge((PhysicsEntity)pe1, (PhysicsEntity)pe2, hinge, twist);
         jlal.JID = JID;
         TheClient.TheRegion.AddJoint(jlal);
         return true;
     }
     else if (type == 11)
     {
         if (data.Length != len + 4)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         float height = Utilities.BytesToFloat(Utilities.BytesPartial(data, len, 4));
         ConstWheelStepUp cwsu = new ConstWheelStepUp((PhysicsEntity)pe1, height);
         cwsu.JID = JID;
         TheClient.TheRegion.AddJoint(cwsu);
         return true;
     }
     else if (type == 12)
     {
         if (data.Length != len + 4 + 1)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         ConnectorBeam cb = new ConnectorBeam();
         cb.One = pe1;
         cb.Two = pe2;
         cb.color = System.Drawing.Color.FromArgb(Utilities.BytesToInt(Utilities.BytesPartial(data, len, 4)));
         cb.JID = JID;
         cb.type = (BeamType)data[len + 4];
         TheClient.TheRegion.AddJoint(cb);
         return true;
     }
     else if (type == 13)
     {
         if (data.Length != len)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         JointFlyingDisc jfd = new JointFlyingDisc((PhysicsEntity)pe1);
         jfd.JID = JID;
         TheClient.TheRegion.AddJoint(jfd);
         return true;
     }
     else if (type == 14)
     {
         if (data.Length != len)
         {
             SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!");
             return false;
         }
         JointNoCollide jnc = new JointNoCollide((PhysicsEntity)pe1, (PhysicsEntity)pe2);
         jnc.JID = JID;
         TheClient.TheRegion.AddJoint(jnc);
         return true;
     }
     else
     {
         SysConsole.Output(OutputType.WARNING, "Unknown joint type " + type);
         return false;
     }
 }
예제 #7
0
        public override bool ParseBytesAndExecute(byte[] data)
        {
            DataStream  ds   = new DataStream(data);
            DataReader  dr   = new DataReader(ds);
            long        PEID = dr.ReadLong();
            VehicleType type = (VehicleType)dr.ReadByte();
            float       vbm  = dr.ReadFloat();
            Entity      e    = TheClient.TheRegion.GetEntity(PEID);

            if (type == VehicleType.CAR)
            {
                if (e is PlayerEntity player)
                {
                    player.InVehicle = true;
                    player.VehicleViewBackMultiplier = vbm;
                    int drivecount = dr.ReadInt();
                    int steercount = dr.ReadInt();
                    player.DrivingMotors.Clear();
                    player.SteeringMotors.Clear();
                    for (int i = 0; i < drivecount; i++)
                    {
                        long jid = dr.ReadLong();
                        JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid);
                        if (jvm == null)
                        {
                            dr.Close();
                            return(false);
                        }
                        player.DrivingMotors.Add(jvm);
                    }
                    for (int i = 0; i < steercount; i++)
                    {
                        long jid = dr.ReadLong();
                        JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid);
                        if (jvm == null)
                        {
                            dr.Close();
                            return(false);
                        }
                        player.SteeringMotors.Add(jvm);
                    }
                    dr.Close();
                    return(true);
                }
                // TODO: other CharacterEntity's
            }
            else if (type == VehicleType.HELICOPTER)
            {
                if (e is PlayerEntity player)
                {
                    long   heloid = dr.ReadLong();
                    Entity helo   = TheClient.TheRegion.GetEntity(heloid);
                    if (!(helo is ModelEntity helomod))
                    {
                        dr.Close();
                        return(false);
                    }
                    player.VehicleViewBackMultiplier = vbm;
                    player.InVehicle = true;
                    player.Vehicle   = helo;
                    helomod.TurnIntoHelicopter(player);
                    dr.Close();
                    return(true);
                }
                // TODO: other CharacterEntity's
                dr.Close();
                return(true);
            }
            else if (type == VehicleType.PLANE)
            {
                // TODO: Wheels!
                if (e is PlayerEntity player)
                {
                    long   planeid = dr.ReadLong();
                    Entity plane   = TheClient.TheRegion.GetEntity(planeid);
                    if (!(plane is ModelEntity planemod))
                    {
                        dr.Close();
                        return(false);
                    }
                    player.VehicleViewBackMultiplier = vbm;
                    player.InVehicle = true;
                    player.Vehicle   = plane;
                    planemod.TurnIntoPlane(player);
                    dr.Close();
                    return(true);
                }
                // TODO: other CharacterEntity's
                dr.Close();
                return(true);
            }
            dr.Close();
            return(false);
        }