Esempio n. 1
0
        public override void onImpact(ShapeBase obj, SceneObject collObj, Point3F vec, float len)
        {
            Player     player = obj.getId();
            TransformF p      = player.getTransform() + new TransformF(vec);

            float speedDamageScale = len + this["speedDamageScale"].AsFloat();

            //Do not confuse the player.event_damage with the PlayerData.event_damage...
            player.damage(0, p.GetPosition(), speedDamageScale, "Impact");
        }
Esempio n. 2
0
        public virtual void throwObject(Item obj)
        {
            // Throw the given object in the direction the shape is looking.
            // The force value is hardcoded according to the current default
            // object mass and mission gravity (20m/s^2).

            float throwforce = ((SimDataBlock)getDataBlock())["throwForce"].AsFloat();

            if (throwforce == 0)
            {
                throwforce = 20;
            }

            // Start with the shape's eye vector...

            Point3F eye = getEyeVector();
            Point3F vec = eye.vectorScale(throwforce);

            // Add a vertical component to give the object a better arc
            double verticalForce = throwforce / 2.0;
            float  dot           = Point3F.vectorDot(new Point3F("0 0 1"), eye);

            if (dot < 0)
            {
                dot = dot * -1;
            }

            vec = vec + Point3F.vectorScale(new Point3F(string.Format("0 0 {0}", verticalForce)), 1 - dot);
            vec = vec + getVelocity();


            // Set the object's position and initial velocity


            TransformF pos = new TransformF(Util.getBoxCenter(getWorldBox()));


            obj.setTransform(pos);


            obj.applyImpulse(pos.GetPosition(), vec);

            // Since the object is thrown from the center of the shape,
            // the object needs to avoid colliding with it's thrower.

            obj.setCollisionTimeout(this);

            //todo Should we add this code in to destroy things after they have been thrown?
            if ((obj.getClassName() != "AITurretShape") && (obj.getClassName() != "ProximityMine"))
            {
                obj.schedule("2000", "delete");
            }
        }
Esempio n. 3
0
        public virtual TransformF PointInSpawnSphere(Player objectToSpawn, SpawnSphere spawnSphere)
        {
            bool spawnLocationFound = false;
            int  attemptsToSpawn    = 0;

            TransformF spherLocationP3F = new TransformF();


            while (!spawnLocationFound && attemptsToSpawn < 5)
            {
                spherLocationP3F = spawnSphere.getTransform();

                Random r = new Random();

                float angleY  = (float)tMath.mDegToRad((r.NextDouble() * 100) * tMath.M_2PI_F);
                float angleXZ = (float)tMath.mDegToRad((r.NextDouble() * 100) * tMath.M_2PI_F);

                int radius = spawnSphere["radius"].AsInt();
                spherLocationP3F.mPositionX += (float)(Math.Cos(angleY) * Math.Sin(angleXZ) * (r.Next(radius * -1, radius)));
                spherLocationP3F.mPositionY += (float)(Math.Cos(angleXZ) * (r.Next(radius * -1, radius)));
                spawnLocationFound           = true;

                // Now have to check that another object doesn't already exist at this spot.
                // Use the bounding box of the object to check if where we are about to spawn in is
                // clear.


                TransformF boundingboxsize =
                    new TransformF(((SimDataBlock)objectToSpawn.getDataBlock())["boundingBox"]);
                float searchRadius = boundingboxsize.mPositionX;
                float boxSizeY     = boundingboxsize.mPositionY;
                if (boxSizeY > searchRadius)
                {
                    searchRadius = boxSizeY;
                }
                List <UInt32> objectsfound = console.ContainerRadiusSearch(spherLocationP3F.GetPosition(), searchRadius,
                                                                           (UInt32)SceneObjectTypesAsUint.PlayerObjectType, false);
                if (objectsfound.Count > 0)
                {
                    spawnLocationFound = false;
                }

                attemptsToSpawn++;
            }
            if (!spawnLocationFound)
            {
                spherLocationP3F = spawnSphere.getTransform();
                console.warn("WARNING: Could not spawn player after 5 times");
            }
            return(spherLocationP3F);
        }
Esempio n. 4
0
        public string doRayCast(float range, UInt32 mask)
        {
            Point3F    eyeVec  = getEyeVector();
            TransformF eyeTran = getEyeTransform();

            Point3F eyePos = eyeTran.GetPosition();

            Point3F nEyeVec = Util.VectorNormalize(eyeVec);

            Point3F scEyeVec = Util.VectorScale(nEyeVec, range);

            Point3F eyeEnd = Util.VectorAdd(eyePos, scEyeVec);

            return(Util.containerRayCast(eyePos, eyeEnd, mask, this, false));
        }
Esempio n. 5
0
        public string tossPatch()
        {
            if (!isObject())
            {
                return(string.Empty);
            }

            Item item = ItemData.createItem("HealthKitPatch");

            item["istemp"] = true.AsString();

            item["sourceObject"] = this;
            item["static"]       = false.AsString();

            ((SimSet)"MissionCleanup").pushToBack(item);

            Random r = new Random();

            Point3F vec = new Point3F(-1 + (float)r.NextDouble() * 2, -1 * (float)r.NextDouble() * 2, (float)r.NextDouble());

            vec = vec.vecotrScale(10);
            Point3F eye = getEyeVector();
            float   dot = new Point3F("0 0 1 ").vectorDot(eye);

            if (dot < 0)
            {
                dot = -dot;
            }

            vec = vec + new Point3F("0 0 8").vecotrScale(1 - dot);
            vec = vec + getVelocity();

            TransformF pos = new TransformF(getWorldBox().Get_MinExtents());

            item.setTransform(pos);
            item.applyImpulse(pos.GetPosition(), vec);
            item.setCollisionTimeout(this);

            item.SchedulePop();

            return(item);
        }
Esempio n. 6
0
        public static void RadiusDamage(GameBase sourceobject, Point3F position, float radius, float damage, string damageType, float impulse)
        {
            // Use the container system to iterate through all the objects
            // within our explosion radius.  We'll apply damage to all ShapeBase
            // objects.
            Dictionary <uint, float> r = tst.console.initContainerRadiusSearch(position, radius, (uint)SceneObjectTypesAsUint.ShapeBaseObjectType);
            float halfRadius           = radius / (float)2.0;

            foreach (ShapeBase targetObject in r.Keys)
            {
                // Calculate how much exposure the current object has to
                // the explosive force.  The object types listed are objects
                // that will block an explosion.  If the object is totally blocked,
                // then no damage is applied.

                UInt32 mask = (uint)SceneObjectTypesAsUint.TerrainObjectType | (uint)SceneObjectTypesAsUint.StaticShapeObjectType | (uint)SceneObjectTypesAsUint.VehicleObjectType;

                float coverage = tst.Util.calcExplosionCoverage(new Point3F(position), targetObject, mask);
                if (!coverage.AsBool())
                {
                    continue;
                }
                float dist = r[targetObject];
                // Calculate a distance scale for the damage and the impulse.
                // Full damage is applied to anything less than half the radius away,
                // linear scale from there.
                float distScale = (float)((dist < halfRadius) ? 1.0 : 1 - ((dist - halfRadius) / halfRadius));
                // Apply the damage

                targetObject.damage(sourceobject, position, (((damage) * coverage * distScale)), damageType);

                // Apply the impulse
                if (!impulse.AsBool())
                {
                    continue;
                }
                TransformF impulseVec = new TransformF(targetObject.getWorldBoxCenter()) - new TransformF(position);
                impulseVec = impulseVec.normalizeSafe();
                impulseVec = impulseVec.vectorScale(impulse * distScale);
                targetObject.applyImpulse(new Point3F(position), impulseVec.GetPosition());
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public void setDamageDirection(GameBase sourceObject, TransformF damagePos)
        {
            if (sourceObject.isObject())
            {
                damagePos = console.isField(sourceObject, "initialPosition") ? new TransformF(sourceObject["initialPosition"]) : sourceObject.getTransform();
            }

            TransformF dp  = damagePos;
            Point3F    wbc = getWorldBoxCenter();

            TransformF damagevec = dp - new TransformF(wbc);

            damagevec = damagevec.normalizeSafe();

            GameConnection client = this["client"];

            if (!client.isObject())
            {
                return;
            }

            ShapeBase cameraobject = client.getCameraObject();

            TransformF inverseTransform = cameraobject.getInverseTransform();

            damagevec = math.MatrixMulVector(inverseTransform, damagevec.GetPosition());

            float[]  components = new float[6];
            string[] directions = new string[6];
            directions[0] = "Left";
            directions[1] = "Right";
            directions[2] = "Bottom";
            directions[3] = "Front";
            directions[4] = "Bottom";
            directions[5] = "Top";

            components[0] = -damagevec.mPositionX;
            components[1] = damagevec.mPositionX;
            components[2] = -damagevec.mPositionY;
            components[3] = damagevec.mPositionY;
            components[4] = -damagevec.mPositionZ;
            components[5] = damagevec.mPositionZ;
            string damagedirection = string.Empty;
            float  max             = 0;

            for (int i = 0; i < 6; i++)
            {
                if (components[i] <= max)
                {
                    continue;
                }
                damagedirection = directions[i];
                max             = components[i];
            }

            if (console.isObject(client))
            {
                // Util._commandToClient(client, console.addTaggedString("setDamageDirection"), damagedirection);
                console.commandToClient(client, console.addTaggedString("setDamageDirection"), new[] { damagedirection });
            }
        }
Esempio n. 9
0
        public virtual bool CheckForEnemy()
        {
            if (!isObject())
            {
                return(false);
            }
            int nearestplayer = GetNearestPlayerTarget();

            if (nearestplayer != -1)
            {
                float      dist = GetTargetDistance(nearestplayer);
                TransformF t    = ((Player)nearestplayer).getTransform();
                if (dist < 30)
                {
                    setAimObject(nearestplayer.AsString());
                    string currentweapon = ((SimObject)getMountedImage(0))["name"];

                    if (dist > 25)
                    {
                        if (currentweapon != "LurkerGrenadeLauncherImage")
                        {
                            if (hasInventory("LurkerGrenadeAmmo"))
                            {
                                mountImage("LurkerGrenadeLauncherImage", 0, true, "");
                            }
                            else if (currentweapon != "LurkerWeaponImage")
                            {
                                mountImage("LurkerWeaponImage", 0, true, "");
                            }
                        }
                    }
                    else if (dist > 10)
                    {
                        if (currentweapon != "LurkerWeaponImage")
                        {
                            mountImage("LurkerWeaponImage", 0, true, "");
                        }
                    }
                    else
                    {
                        //if (ShapeBaseShapeBaseHasInventory(npc, "ProxMine"))
                        //    {
                        //    ShapeBaseShapeBaseThrow(npc, "ProxMine", 1);
                        //    }
                        if (currentweapon != "LurkerWeaponImage")
                        {
                            mountImage("LurkerWeaponImage", 0, true, "");
                        }
                    }

                    if (holdcount == -1)
                    {
                        holdcount++;
                    }
                    this["HoldAndFire"] = true.AsString();

                    if (holdcount == 5)
                    {
                        holdcount           = -1;
                        this["HoldAndFire"] = false.AsString();
                        clearAim();
                        MoveToNode(this["currentNode"].AsUint());
                    }

                    if (TargetIsInLos(nearestplayer))
                    {
                        setImageTrigger(0, true);
                        setImageTrigger(0, false);
                    }
                    else
                    {
                        if (currentweapon == "LurkerGrenadeLauncherImage")
                        {
                            setImageTrigger(0, true);
                            setImageTrigger(0, false);
                        }
                    }

                    if (dist < 10)
                    {
                        stop();
                    }
                    else
                    {
                        setMoveDestination(t.GetPosition(), false);
                    }
                    return(false);
                }

                setMoveDestination(t.GetPosition(), false);
                return(false);
            }
            setImageTrigger(0, false);
            this["HoldAndFire"] = false.AsString();

            clearAim();
            MoveToNode(this["currentNode"].AsUint());
            return(true);
        }
Esempio n. 10
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"));
            }
        }