示例#1
0
        public void WeaponImageonWetFire(coScriptObject thisobj, coPlayer obj, int slot)
            {
            if (!thisobj["projectile"].isObject())
                {
                console.error("WeaponImage::onFire() - Invalid projectile datablock");
                return;
                }
            // Decrement inventory ammo. The image's ammo state is updated
            // automatically by the ammo inventory hooks.
            if (!thisobj["infiniteAmmo"].AsBool())
                ShapeBaseShapeBaseDecInventory(obj, thisobj["ammo"], 1);

            // Get the player's velocity, we'll then add it to that of the projectile
            int numProjectiles = thisobj["projectileNum"].AsInt();
            if (numProjectiles == 0)
                numProjectiles = 1;
            TransformF muzzleVector = new TransformF();

            for (int i = 0; i < numProjectiles; i++)
                {
                if (thisobj["wetProjectileSpread"].AsBool())
                    {
                    // We'll need to "skew" this projectile a little bit.  We start by
                    // getting the straight ahead aiming point of the gun
                    Point3F vec = obj.getMuzzleVector(slot);
                    // Then we'll create a spread matrix by randomly generating x, y, and z
                    // points in a circle
                    Random r = new Random();
                    TransformF matrix = new TransformF();
                    matrix.MPosition.x = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat());
                    matrix.MPosition.y = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat());
                    matrix.MPosition.z = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat());
                    TransformF mat = math.MatrixCreateFromEuler(matrix);

                    muzzleVector = math.MatrixMulVector(mat, vec);
                    }
                else
                    {
                    muzzleVector = new TransformF(obj.getMuzzleVector(slot));
                    }
                Point3F objectVelocity = obj.getVelocity();

                muzzleVector = muzzleVector.vectorScale(thisobj["wetProjectile.muzzleVelocity"].AsFloat());

                objectVelocity = objectVelocity.vectorScale(thisobj["wetProjectile.velInheritFactor"].AsFloat());
                Point3F muzzleVelocity = muzzleVector.MPosition + objectVelocity;

                Torque_Class_Helper tch = new Torque_Class_Helper(thisobj["projectileType"]);


                tch.Props.Add("dataBlock", thisobj["wetProjectile"]);
                tch.Props.Add("initialVelocity", '"' + muzzleVelocity.AsString() + '"');
                tch.Props.Add("initialPosition", '"' + obj.getMuzzlePoint(slot).AsString() + '"');
                tch.Props.Add("sourceObject", obj);
                tch.Props.Add("sourceSlot", slot.AsString());
                tch.Props.Add("client", obj["client"]);
                tch.Props.Add("sourceClass", obj.getClassName());

                coItem projectile = tch.Create();
                ((coSimSet)"MissionCleanup").pushToBack(projectile);
                }
            }
 public void TeleporterTriggerTeleportPlayer(coSimDataBlock thisobj, coPlayer player, coSceneObject exit)
     {
     TransformF targetPosition;
     if (exit["reorientPlayer"].AsBool())
         {
         targetPosition = exit.getTransform();
         }
     else
         {
         targetPosition = exit.getTransform();
         TransformF playerrot = player.getTransform();
         targetPosition.MOrientation.x = playerrot.MOrientation.x;
         targetPosition.MOrientation.y = playerrot.MOrientation.y;
         targetPosition.MOrientation.z = playerrot.MOrientation.z;
         targetPosition.MAngle = playerrot.MAngle;
         }
     player.setTransform(targetPosition);
     Point3F playervelocity = player.getVelocity();
     playervelocity = playervelocity.vectorScale(exit["exitVelocityScale"].AsFloat());
     player.setVelocity(playervelocity);
     // Prevent the object from doing an immediate second teleport
     // In the case of a bidirectional teleporter
     player["isTeleporting"] = true.AsString();
     }
        public string RocketLauncherImageOnAltFire(coItem thisobj, coPlayer obj, string slot)
            {
            int currentAmmo = ShapeBaseShapeBaseGetInventory(obj, (thisobj["ammo"]));
            if (currentAmmo < thisobj["loadCount"].AsInt())
                thisobj["loadCount"] = currentAmmo.AsString();
            coProjectile projectile = null;
            for (int shotCount = 0; shotCount < thisobj["loadCount"].AsInt(); shotCount++)
                {
                // Decrement inventory ammo. The image's ammo state is updated
                // automatically by the ammo inventory hooks.
                ShapeBaseShapeBaseDecInventory(obj, (thisobj["ammo"]), 1);
                // We fire our weapon using the straight ahead aiming point of the gun
                // We'll need to "skew" the projectile a little bit.  We start by getting
                // the straight ahead aiming point of the gun
                Point3F vec = obj.getMuzzleVector(slot.AsInt());
                Random r = new Random();
                TransformF matrix = new TransformF();
                matrix.MPosition.x = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008);
                matrix.MPosition.y = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008);
                matrix.MPosition.z = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008);
                TransformF mat = math.MatrixCreateFromEuler(matrix);

                // Which we'll use to alter the projectile's initial vector with
                TransformF muzzleVector = math.MatrixMulVector(mat, vec);

                // Get the player's velocity, we'll then add it to that of the projectile
                TransformF objectVelocity = new TransformF(obj.getVelocity());

                muzzleVector = muzzleVector.vectorScale(thisobj["projectile.muzzleVelocity"].AsFloat());
                objectVelocity = objectVelocity.vectorScale(thisobj["projectile.velInheritFactor"].AsFloat());
                TransformF muzzleVelocity = muzzleVector + objectVelocity;

                Torque_Class_Helper tch = new Torque_Class_Helper(thisobj["projectileType"], "");
                tch.Props.Add("dataBlock", thisobj["projectile"]);
                tch.Props.Add("initialVelocity", '"' + muzzleVelocity.ToString() + '"');
                tch.Props.Add("initialPosition", '"' + obj.getMuzzlePoint(slot.AsInt()).AsString() + '"');
                tch.Props.Add("sourceObject", obj);
                tch.Props.Add("sourceSlot", slot);
                tch.Props.Add("client", obj["client"]);


                projectile = tch.Create();
                ((coSimSet) "MissionCleanup").pushToBack(projectile);
                }
            return projectile;
            }
示例#4
0
        public void ArmorDoDismount(coPlayerData datablock, coPlayer player, bool forced)
            {
            coVehicle vehicle = player["mVehicle"];
            if (!vehicle.isObject())
                return;
            if (!player.isMounted())
                return;


            Point3F vvel = vehicle.getVelocity();
            coVehicleData vdb = vehicle.getDataBlock();
            int maxDismountSpeed = vdb["maxDismountSpeed"].AsInt();
            if ((vvel.len() <= maxDismountSpeed) || (forced))
                {
                TransformF pos = player.getTransform();
                TransformF rot = pos;
                TransformF oldpos = pos.copy();

                List<Point3F> vecs = new List<Point3F> { new Point3F(-1, 0, 0), new Point3F(0, 0, 1), new Point3F(0, 0, -1), new Point3F(1, 0, 0), new Point3F(0, -1, 0), new Point3F(0, 0, 0) };

                Point3F impulsevec = new Point3F(0, 0, 0);


                TransformF r = math.MatrixMulVector(player.getTransform(), vecs[0]);

                vecs[0] = r.MPosition;
                pos.MPosition.x = 0;
                pos.MPosition.y = 0;
                pos.MPosition.z = 0;

                const int numofAttempts = 5;
                int success = -1;

                for (int i = 0; i < numofAttempts; i++)
                    {
                    Point3F vectorscale = vecs[i].vectorScale(3);

                    pos = oldpos + new TransformF(vectorscale);
                    if (!player.checkDismountPoint(oldpos.MPosition, pos.MPosition))
                        continue;
                    success = i;
                    impulsevec = vecs[i].copy();
                    break;
                    }
                if ((forced) && (success == -1))
                    pos = oldpos.copy();

                player["mountVehicle"] = false.AsString();
                player.schedule("4000", "mountVehicles", "true");
                player.unmount();
                player.setTransform(new TransformF(pos.MPosition.x, pos.MPosition.y, pos.MPosition.z, rot.MOrientation.x, rot.MOrientation.y, rot.MOrientation.z, rot.MAngle));


                Point3F velo = impulsevec.vectorScale(player["mass"].AsFloat());
                velo.z = 1;

                player.applyImpulse(pos.MPosition, velo);


                Point3F vel = player.getVelocity();
                float vec = Point3F.vectorDot(vel, vel.normalizeSafe());
                if (vec > 50)
                    {
                    float scale = 50 / vec;
                    player.setVelocity(vel.vectorScale(scale));
                    }
                }
            else
                {
                MessageClient(player["client"], "msgUnmount", @"\c2Cannot exit %1 while moving.", console.GetVarString(vdb + ".nameTag"));
                }
            }