public void TeleporterTriggerOnAdd(coSimDataBlock thisobj, coShapeBase teleporter)
            {
            if (teleporter["exit"] == "")
                teleporter["exit"] = "NameOfTeleporterExit";

            if (teleporter["teleporterCooldown"] == "")
                teleporter["teleporterCooldown"] = thisobj["teleporterCooldown"];

            if (teleporter["exitVelocityScale"] == "")
                teleporter["exitVelocityScale"] = thisobj["exitVelocityScale"];

            if (teleporter["reorientPlayer"] == "")
                teleporter["reorientPlayer"] = thisobj["reorientPlayer"];

            if (teleporter["oneSided"] == "")
                teleporter["oneSided"] = thisobj["oneSided"];

            if (teleporter["entranceEffect"] == "")
                teleporter["entranceEffect"] = thisobj["entranceEffect"];

            if (teleporter["exitEffect"] == "")
                teleporter["exitEffect"] = thisobj["exitEffect"];
            // We do not want to save this variable between levels, 
            // clear it out every time the teleporter is added 
            // to the scene.

            teleporter["timeOfLastTeleport"] = "";
            }
 public string StaticShapeDataCreate(coSimDataBlock data)
     {
     Torque_Class_Helper tch = new Torque_Class_Helper("StaticShape");
     tch.Props.Add("dataBlock", data);
     coSimObject obj = tch.Create();
     return obj;
     }
        public void DefaultTriggerOnTickTrigger(coSimDataBlock thisobj, coShapeBase trigger)
            {
            // This method is called every tickPerioMS, as long as any
            // objects intersect the trigger.

            // You can iterate through the objects in the list by using these
            // methods:
            //    %trigger.getNumObjects();
            //    %trigger.getObject(n);
            }
 public void DefaultTriggerOnLeaveTrigger(coSimDataBlock thisobj, coShapeBase trigger, coShapeBase obj)
     {
     // This method is called whenever an object leaves the %trigger
     // area, the object is passed as %obj.
     }
 public void DetonadeOnDestroyed(coSimDataBlock thisobj, coPlayer obj, string laststate)
     {
     RadiusDamage(obj, obj.getTransform().MPosition, 10, 25, "DetonadeDamage", 2000);
     }
 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 void TeleporterTriggerTeleFrag(coSimDataBlock thisobj, coPlayer player, coTrigger exit)
            {
            // When a telefrag happens, there are two cases we have to consider.
            // The first case occurs when the player's bounding box is much larger than the exit location, 
            // it is possible to have players colide even though a player is not within the bounds 
            // of the trigger Because of this we first check a radius the size of a player's bounding 
            // box around the exit location.

            // Get the bounding box of the player

            Point3F boundingBoxSize = new Point3F(((coPlayerData)player.getDataBlock())["boundingBox"]);
            float radius = boundingBoxSize.x;
            float boxSizeY = boundingBoxSize.y;
            float boxSizeZ = boundingBoxSize.z;

            // Use the largest dimention as the radius to check
            if (boxSizeY > radius)
                radius = boxSizeY;
            if (boxSizeZ > radius)
                radius = boxSizeZ;

            Point3F position = exit.getTransform().MPosition; // new TransformF(con.getTransform(exit));
            uint mask = (uint)SceneObjectTypesAsUint.PlayerObjectType;

            // Check all objects within the found radius of the exit location, and telefrag
            // any players that meet the conditions.

            Dictionary<uint, float> r = console.initContainerRadiusSearch(position, radius, mask);
            foreach (coShapeBase objectNearExit in r.Keys.Where(objectNearExit => ((coShapeBase)objectNearExit).isMemberOfClass("Player")).Where(objectNearExit => objectNearExit.AsString() != player))
                {
                ShapeBaseDamage(objectNearExit, player, exit.getTransform().MPosition, 10000, "Telefrag");
                }
            // The second case occurs when the bounds of the trigger are much larger
            // than the bounding box of the player. (So multiple players can exist within the
            // same trigger). For this case we check all objects contained within the trigger
            // and telefrag all players.

            int objectsInExit = exit.getNumObjects();
            // Loop through all objects in the teleporter exit
            // And kill any players
            for (int i = 0; i < objectsInExit; i++)
                {
                coShapeBase objectInTeleporter = console.Call(exit, "getObject", new[] { i.AsString() });
                if (objectInTeleporter.isMemberOfClass("Player"))
                    continue;
                // Avoid killing the player that is teleporting in the case of two
                // Teleporters near eachother.
                if (objectInTeleporter == player)
                    continue;

                ShapeBaseDamage(objectInTeleporter, player, exit.getTransform().MPosition, 10000, "Telefrag");
                }
            }
        public bool TeleporterTriggerVerifyObject(coSimDataBlock thisobj, coShapeBase obj, coSceneObject entrance, coSceneObject exit)
            {
            // Bail out early if we couldn't find an exit for this teleporter.
            if (!exit.isObject())
                {
                console.error(string.Format("Cound not find an exit for {0}", console.GetVarString(entrance + ".name")));
                return false;
                }


            if (!obj.isMemberOfClass("Player"))
                return false;

            // If the entrance is once sided, make sure the object
            // approached it from it's front.
            if (entrance["oneSided"].AsBool())
                {
                TransformF forwardvector = new TransformF(entrance.getForwardVector());

                Point3F velocity = obj.getVelocity();
                float dotProduct = TransformF.vectorDot(forwardvector, velocity);
                if (dotProduct > 0)
                    return false;
                // If we are coming directly from another teleporter and it happens
                // to be bidirectional, We need to avoid ending sending objects through
                // an infinite loop.

                if (obj["isTeleporting"].AsBool())
                    return false;
                // We only want to teleport players
                // So bail out early if we have found any 
                // other object.


                if (entrance["timeOfLastTeleport"].AsInt() > 0 && entrance["teleporterCooldown"].AsInt() > 0)
                    {
                    int currentTime = console.getSimTime();
                    int timedifference = currentTime - entrance["timeOfLastTeleport"].AsInt();
                    coSimDataBlock db = console.getDatablock(entrance);
                    if (timedifference <= db["teleporterCooldown"].AsInt())
                        return false;
                    }
                }
            return true;
            }
        public void TeleporterTriggerOnEnterTrigger(coSimDataBlock thisobj, coSceneObject entrance, coPlayer obj)
            {
            //if (!console.isMemberOfClass(obj, "Player"))
            //    return;

            if (obj["isTeleporting"].AsBool())
                return;
            // Get the location of our target position
            coTrigger exit = entrance["exit"];

            bool valid = TeleporterTriggerVerifyObject(thisobj, obj, entrance, exit);
            if (!valid)
                return;

            TeleporterTriggerTeleFrag(thisobj, obj, exit);
            // Create our entrance effects on all clients.



            coSimObject entranceeffect = entrance["entranceEffect"];
            if (entranceeffect.isObject())
                foreach (coGameConnection client in ClientGroup)
                    {
                    if (console.isObject(client))
                        console.commandToClient(client, "PlayTeleportEffect", new[] { entrance["position"], entranceeffect.getId().AsString() });
                    }


            TeleporterTriggerTeleportPlayer(thisobj, obj, exit);
            // Create our exit effects on all clients.

            coSimObject exitEffect = entrance["exitEffect"];
            if (exitEffect.isObject())
                foreach (coGameConnection client in ClientGroup)
                    {
                    if (console.isObject(client))
                        console.commandToClient(client, "PlayTeleportEffect", new[] { entrance["position"], exitEffect.getId().AsString() });
                    }

            // Record what time we last teleported so we can determine if enough
            // time has elapsed to teleport again
            int tolt = console.getSimTime();
            entrance["timeOfLastTeleport"] = tolt.AsString();

            // If this is a bidirectional teleporter, log it's exit too.
            if (exit["exit"] == entrance["name"])
                exit["timeOfLastTeleport"] = tolt.AsString();


            // Tell the client to play the 2D sound for the player that teleported.
            if (((coSimObject)thisobj["teleportSound"]).isObject() && ((coGameConnection)obj["client"]).isObject())
                {
                ((coGameConnection)obj["client"]).play2D(thisobj["teleportSound"]);
                //GameConnection.play2D(obj, thisobj["teleportSound"]);
                }
            }
 public void TeleporterTriggerOnLeaveTrigger(coSimDataBlock thisobj, coShapeBase trigger, coShapeBase obj)
     {
     obj["isTeleporting"] = false.AsString();
     }
 public void ClientCmdPlayTeleportEffect(Point3F position, coSimDataBlock effectDataBlock)
     {
     if (!effectDataBlock.isObject())
         return;
     Torque_Class_Helper tch = new Torque_Class_Helper("Explosion");
     tch.Props.Add("position", '"' + position.AsString() + '"');
     tch.Props.Add("datablock", effectDataBlock);
     tch.Create();
     }