public virtual void teleportPlayer(GameBase gplayer, SceneObject exit)
        {
            Player     player = gplayer._ID;
            TransformF targetPosition;

            if (exit["reorientPlayer"].AsBool())
            {
                targetPosition = exit.getTransform();
            }
            else
            {
                targetPosition = exit.getTransform();
                TransformF playerrot = player.getTransform();
                targetPosition.mOrientationX = playerrot.mOrientationX;
                targetPosition.mOrientationY = playerrot.mOrientationY;
                targetPosition.mOrientationZ = playerrot.mOrientationZ;
                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();
        }
Пример #2
0
        public override void onMount(GameBase obj, SceneObject mountObj, int node)
        {
            Player      player           = obj.getId();
            VehicleData vehicleDataBlock = mountObj.getDataBlock();

            if (node == 0)
            {
                player.setTransform(new TransformF("0 0 0 0 0 1 0"));
                string mountPose = vehicleDataBlock["mountPose[" + node + "]"];
                player.setActionThread(mountPose, true, true);
                player["lastWeapon"] = player.getMountedImage(Constants.WeaponSlot).AsString();
                GameConnection client = player["client"];
                if (client.isObject())
                {
                    player["lastperson"] = client.isFirstPerson().AsString();
                }
                player.unmountImage(Constants.WeaponSlot);
                player.setControlObject(mountObj);
                if (player.getClassName() == "Player")
                {
                    console.commandToClient(player["client"], console.addTaggedString("toggleVehicleMapToggle"),
                                            new[] { "true" });
                }
            }
            else
            {
                string pose = vehicleDataBlock["mountPose[" + node + "]"];
                player.setActionThread(pose != string.Empty ? pose : "root", false, true);
            }
        }
Пример #3
0
        public static void serverCmdcarUnmountObj(GameConnection client, Player obj)
        {
            obj.unmount();
            obj.setControlObject(obj);

            TransformF ejectpos = obj.getTransform();

            ejectpos += new TransformF(0, 0, 5);
            obj.setTransform(ejectpos);

            Vehicle mvehicle = obj["mVehicle"];

            Point3F ejectvel = mvehicle.getVelocity();

            ejectvel += new Point3F(0, 0, 10);

            ejectvel = ejectvel.vectorScale(((SimDataBlock)(obj.getDataBlock()))["mass"].AsFloat());

            obj.applyImpulse(ejectpos.GetPosition(), ejectvel);
        }
Пример #4
0
        public virtual bool SpawnPlayer(string spawnpoint, bool nocontrol)
        {
            Player player = this["player"];


            if (player.isObject())
            {
                console.error("Attempting to create a player for a client that already has one!");
                return(false);
            }

            if ((spawnpoint.Split(' ').GetUpperBound(0) == 0) && (spawnpoint.isObject()))
            {
                // Attempt to treat %spawnPoint as an object
                string spawnclass     = sGlobal["$Game::DefaultPlayerClass"];
                string spawndatablock = sGlobal["$Game::DefaultPlayerDataBlock"];

                SimObject ospawnpoint = spawnpoint;


                // Overrides by the %spawnPoint
                if (ospawnpoint["spawnClass"] != "")
                {
                    spawnclass = ospawnpoint["spawnClass"];
                    //spawndatablock = ospawnpoint["spawnDataBlock"];
                }

                else if (ospawnpoint["spawnDatablock"] != "")
                {
                    // This may seem redundant given the above but it allows
                    // the SpawnSphere to override the datablock without
                    // overriding the default player class
                    spawndatablock = ospawnpoint["spawnDatablock"];
                }
                string spawnproperties = ospawnpoint["spawnProperties"];
                string spawnScript     = ospawnpoint["spawnScript"];

                // Spawn with the engine's Sim::spawnObject() function
                player = Util.spawnObject(spawnclass, spawndatablock, "", spawnproperties, spawnScript, typeof(Player).FullName);


                //player.TickCounterNotifyServer = true;
                //player.TickCounterAdd("TestCheck", 100);


                //player.TickNotifyBefore = true;
                //player.TickNotifyClient = true;
                //player.TickNotifyServer = true;
                //player.TickNotifyBefore = true;

                // If we have an object do some initial setup
                if (console.isObject(player))
                {
                    // Pick a location within the spawn sphere.
                    player.setTransform(PointInSpawnSphere(player, (spawnpoint)));
                }
                else
                {
                    // If we weren't able to create the player object then warn the user
                    // When the player clicks OK in one of these message boxes, we will fall through
                    // to the "if (!isObject(%player))" check below.
                    if (console.GetVarString(spawndatablock).Trim() != "")
                    {
                        WinterLeaf.Demo.Full.Models.User.GameCode.Client.Gui.messageBox.MessageBoxOK("Spawn Player Failed",
                                                                                                     "Unable to create a player with class " + spawnclass + " and datablock " + spawndatablock +
                                                                                                     ".\n\nStarting as an Observer instead.", "");
                    }
                    else
                    {
                        WinterLeaf.Demo.Full.Models.User.GameCode.Client.Gui.messageBox.MessageBoxOK("Spawn Player Failed",
                                                                                                     "Unable to create a player with class " + spawnclass +
                                                                                                     ".\n\nStarting as an Observer instead.", "");
                    }
                }
            }
            else
            {
                // Create a default player
                player = console.SpawnObject(sGlobal["$Game::DefaultPlayerClass"],
                                             sGlobal["$Game::DefaultPlayerDataBlock"], string.Empty, string.Empty, string.Empty);

                if (player.isMemberOfClass("Player"))
                {
                    //if (SimObject.SimObject_isMemberOfClass(player, "Player"))
                    console.warn("Trying to spawn a class that does not derive from player!!!!!");
                }
                // Treat %spawnPoint as a transform
                player.setTransform(new TransformF(spawnpoint));
            }

            // Update the default camera to start with the player
            if (!console.isObject(player))
            {
                this["spawnCamera"] = spawnpoint;
                return(false);
            }

            ((SimSet)"MissionCleanup").pushToBack(player);
            // Update the default camera to start with the player


            // Store the client object on the player object for
            // future reference
            player["client"] = this;

            // If the player's client has some owned turrets, make sure we let them
            // know that we're a friend too.

            if (this["ownedTurrets"].AsInt() >= 1)
            {
                SimSet turrets = this["ownedTurrets"];
                for (uint i = 0; i < turrets.getCount(); i++)
                {
                    ((AITurretShape)turrets.getObject(i)).addToIgnoreList(player);
                }
            }

            player.setShapeName(this["playerName"]);

            SimDataBlock playerdata = player.getDataBlock();

            player.setEnergyLevel(playerdata["maxEnergy"].AsFloat());

            if (this["skin"] != string.Empty)
            {
                string availableSkins = playerdata["availableSkins"];
                foreach (GameConnection other in ClientGroup.Where(other => other != this))
                {
                    availableSkins = availableSkins.Replace(console.GetVarString(other + ".skin"), " ");

                    availableSkins = availableSkins.Replace("  ", " ");
                }
                List <string> availskin = availableSkins.Split('\t').ToList();
                if (availskin.Count > 0)
                {
                    int r = new Random().Next(0, availskin.Count - 1);
                    this["skin"] = availskin[r];
                }
            }

            player.setSkinName(this["skin"]);
            this["player"] = player;
            console.error("--->Player ID is " + player);

            SimObject control = null;

            if (console.GetVarString("$startWorldEditor") == "1")
            {
                control = this["camera"];
                Camera c = this["camera"];
                c.setMode("Fly");
                console.Call("EditorGui", "syncCameraGui");
            }
            else
            {
                control = player;
            }

            if (!nocontrol)
            {
                this.setControlObject(control);
            }

            int team = new Random().Next(1, 2);

            player.AddObjectTo_MobSearchGroup(team);

            message.MessageClient(this, "System", "Your on Team " + team);

            console.error(DateTime.Now + " --- PLAYER JOIN::Name '" + Util.StripMLControlChars(player.getShapeName()) +
                          "'::ID '" + player + "'");
            return(true);
        }
        public static void serverCmdcarUnmountObj(GameConnection client, Player obj)
        {
            obj.unmount();
            obj.setControlObject(obj);

            TransformF ejectpos = obj.getTransform();
            ejectpos += new TransformF(0, 0, 5);
            obj.setTransform(ejectpos);

            Vehicle mvehicle = obj["mVehicle"];

            Point3F ejectvel = mvehicle.getVelocity();
            ejectvel += new Point3F(0, 0, 10);

            ejectvel = ejectvel.vectorScale(((SimDataBlock) (obj.getDataBlock()))["mass"].AsFloat());

            obj.applyImpulse(ejectpos.GetPosition(), ejectvel);
        }
Пример #6
0
        public override void doDismount(Player obj)
        {
            Player player = obj.getId();

            Vehicle vehicle = player["mVehicle"];

            if (!vehicle.isObject())
            {
                return;
            }
            if (!player.isMounted())
            {
                return;
            }


            Point3F     vvel             = vehicle.getVelocity();
            VehicleData 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.GetPosition();
                pos.mPositionX = 0;
                pos.mPositionY = 0;
                pos.mPositionZ = 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.GetPosition(), pos.GetPosition()))
                    {
                        continue;
                    }
                    success    = i;
                    impulsevec = vecs[i].copy();
                    break;
                }
                //if ((forced) && (success == -1))
                if (success == -1)
                {
                    pos = oldpos.copy();
                }

                player["mountVehicle"] = false.AsString();
                player.schedule("4000", "mountVehicles", "true");
                player.unmount();
                player.setTransform(new TransformF(pos.mPositionX, pos.mPositionY, pos.mPositionZ, rot.mOrientationX,
                                                   rot.mOrientationY, rot.mOrientationZ, rot.MAngle));


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

                player.applyImpulse(pos.GetPosition(), 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
            {
                message.MessageClient(player["client"], "msgUnmount", @"\c2Cannot exit %1 while moving.",
                                      console.GetVarString(vdb + ".nameTag"));
            }
        }