예제 #1
0
        public void ShapeBaseDoRayCast(coShapeBase shapebase, float range, uint mask)
        {
            throw new Exception("Not Implemented.");

            //I didn't implement this because rarely would you call it from the script, and it would be
            //better implemented only in csharp.
        }
예제 #2
0
        public void WeaponImageReloadAmmoClip(coItemData thisobj, coShapeBase obj, int slot)
        {
            string ammoname = ((coItemData)thisobj["ammo"]).getName();

            if (thisobj != obj.getMountedImage(slot))
            {
                return;
            }

            if (!thisobj.isField("clip"))
            {
                return;
            }
            if (ShapeBaseShapeBaseGetInventory(obj, thisobj["clip"]) > 0)
            {
                ShapeBaseShapeBaseDecInventory(obj, thisobj["clip"], 1);

                ShapeBaseShapeBaseSetInventory(obj, thisobj["ammo"], thisobj["ammo.maxInventory"].AsInt());

                obj.setImageAmmo(slot, true);
            }
            else
            {
                int amountInPocket = obj["remaining" + ((coItem)thisobj["ammo"]).getName()].AsInt();
                if (amountInPocket > 0)
                {
                    obj["remaining" + ((coItem)thisobj["ammo"]).getName()] = "0";

                    ShapeBaseShapeBaseSetInventory(obj, thisobj["ammo"], amountInPocket);
                    obj.setImageAmmo(slot, true);
                }
            }
        }
예제 #3
0
        private void TurretShapeData_damage(coTurretShapeData thisobj, coTurretShape turret, TransformF position, coShapeBase sourceobject, float damage, string datatype)
        {
            if (turret.getDamageState() == "Dead")
            {
                return;
            }

            turret.applyDamage(damage);

            // Update the numerical Health HUD
            coShapeBase mountedobject = turret.getObjectMount();

            //if (mountedobject != 0)
            //    console.Call(mountedobject, "updateHealth");
            if (turret.getState() != "Dead")
            {
                return;
            }

            for (int i = 0; i < thisobj["numMountPoints"].AsInt(); i++)
            {
                coShapeBase player = turret.getMountNodeObject(i);
                if (player != 0)
                {
                    console.Call(player, "killWithSource", new[] { "sourceobject", "InsideTurret" });
                }
            }
        }
예제 #4
0
        public void ArmorOnImpact(coPlayerData datablock, coPlayer player, coShapeBase collidedObject, TransformF vec, float vecLen)
        {
            TransformF p = player.getTransform();

            p = p + vec;
            float speedDamageScale = vecLen + datablock["speedDamageScale"].AsFloat();

            ShapeBaseDamage(player, "0", p.MPosition, speedDamageScale, "Impact");
        }
예제 #5
0
        public int ShapeBaseShapeBaseMaxInventory(coShapeBase thisobj, coItemData data)
        {
            if (data.isField("clip"))
            {
                return(data["maxInventory"].AsInt());
            }

            return((( coSimDataBlock)thisobj.getDataBlock())["maxInv[" + data.getName() + "]"].AsInt());
        }
예제 #6
0
        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);
        }
예제 #7
0
        public bool ShapeBaseShapeBaseHasAmmo(coShapeBase thisob, coItem weapon)
        {
            coItemData weaponimageammo = weapon["image.ammo"];

            if (weaponimageammo == "")
            {
                return(true);
            }
            return(ShapeBaseShapeBaseGetInventory(thisob, weaponimageammo) > 0);
        }
예제 #8
0
        public void WeaponOnInventory(coScriptObject thisobj, coShapeBase obj, int amount)
        {
            if (amount != 0 || !obj.isMethod("getMountSlot"))
            {
                return;
            }
            int slot = obj.getMountSlot(thisobj["image"]);

            obj.unmountImage(slot);
        }
예제 #9
0
        public void DeployableTurretWeaponImageOnMount(coShapeBaseImageData thisobj, coShapeBase obj, int slot)
        {
            obj.setImageAmmo(slot, true);

            int numTurrets = ShapeBaseShapeBaseGetInventory(obj, thisobj["item"]);

            if (obj["client"] != "" && obj["isAiControlled"].AsBool() == false)
            {
                ((coGameConnection)obj["client"]).call("RefreshWeaponHud", "1", thisobj["item.previewImage"], thisobj["item.reticle"], thisobj["item.zoomReticle"], numTurrets.AsString());
            }
        }
예제 #10
0
        public void ShapeBaseClearDamageDt(coShapeBase shapebase)
        {
            //I could think of soo much better ways of doing this... even if my grammar blows.

            if (shapebase["damageSchedule"] == "")
            {
                return;
            }

            Util._cancel(shapebase["damageSchedule"]);
            shapebase["damageSchedule"] = "";
        }
예제 #11
0
        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);
        }
예제 #12
0
        public void TurretShapeData_OnAdd(coTurretShapeData thisobj, coShapeBase obj)
        {
            obj.setRechargeRate(thisobj["rechargeRate"].AsFloat());
            obj.setEnergyLevel(thisobj["MaxEnergy"].AsFloat());
            obj.setRepairRate(0);


            if (obj["mountable"] == "1" || obj["mountable"] == "")
            {
                thisobj.call("isMountable", obj, true.AsString());
            }
            else
            {
                thisobj.call("isMountable", obj, false.AsString());
            }

            if (thisobj["nameTag"] != "")
            {
                obj.setShapeName(thisobj["nameTag"]);
            }
            for (int i = 0; i < thisobj["numWeaponMountPoints"].AsInt(); i++)
            {
                ShapeBaseShapeBaseIncInventory(obj, thisobj["weapon[" + i + "]"], 1);

                coItemData weaponAmmo = thisobj["weaponAmmo[" + i + "]"];


                string weaponAmmoAmount = thisobj["weaponAmmoAmount[" + i + "]"];
                ShapeBaseShapeBaseIncInventory(obj, weaponAmmo, weaponAmmoAmount.AsInt());


                bool startLoaded = thisobj["startLoaded"].AsBool();

                obj.mountImage(thisobj["weapon[" + i + "].Image"], i, startLoaded, "");
                obj.setImageGenericTrigger(i, 0, false);
            }
            if (thisobj["enterSequence"] != "")
            {
                obj["entranceThread"] = "0";
                int    et = obj["entranceThread"].AsInt();
                string es = thisobj["enterSequence"];
                obj.playThread(et, es);
                obj.pauseThread(et);
            }
            else
            {
                obj["entranceThread"] = "-1";
            }
        }
예제 #13
0
        public void ShapeBaseDamage(coShapeBase shapebase, coShapeBase sourceobject, Point3F position, float damage, string damagetype)
        {
            // All damage applied by one object to another should go through this method.
            // This function is provided to allow objects some chance of overriding or
            // processing damage values and types.  As opposed to having weapons call
            // ShapeBase::applyDamage directly. Damage is redirected to the datablock,
            // this is standard procedure for many built in callbacks.


            if (shapebase.isObject())
            {
                coShapeBaseData datablock = shapebase.getDataBlock();
                datablock.call("damage", shapebase, position.AsString(), sourceobject, damage.AsString(), damagetype);
            }
        }
예제 #14
0
        public void TurretShapeData_OnRemove(coTurretShapeData thisobj, coShapeBase obj)
        {
            for (int i = 0; i < thisobj["numMountPoints"].AsInt(); i++)
            {
                if (obj.getMountNodeObject(i) == 0)
                {
                    continue;
                }

                coPlayer passenger = obj.getMountNodeObject(i).AsString();


                ((coTurretShapeData)passenger.getDataBlock()).call("doDismount", true.AsString());
            }
        }
예제 #15
0
        public void ShapeBaseShapeBaseThrowObject(coShapeBase thisobj, coItem 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 = (( coSimDataBlock)thisobj.getDataBlock())["throwForce"].AsFloat();

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

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

            Point3F eye = thisobj.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 + thisobj.getVelocity();

            // Set the object's position and initial velocity
            TransformF pos = new TransformF(Util.getBoxCenter(thisobj.getWorldBox()));

            obj.setTransform(pos);

            obj.applyImpulse(pos.MPosition, vec);

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

            obj.setCollisionTimeout(thisobj);


            if ((obj.getClassName() != "AITurretShape") && (obj.getClassName() != "ProximityMine"))
            {
                obj.schedule(ItemPopTime.AsString(), "delete");
            }
        }
예제 #16
0
        public void WeaponOnPickup(coScriptObject thisobj, string obj, coShapeBase shape, int amount, int nameSpaceDepth)
        {
            int nsd = (nameSpaceDepth + 1);

            if (!console.ParentExecute(thisobj, "onPickup", nsd, new string[] { thisobj, obj, shape, amount.AsString() }).AsBool())
            {
                return;
            }


            AudioServerPlay3D("WeaponPickupSound", shape.getTransform());

            if (shape.getClassName() == "Player" && shape.getMountedImage(WeaponSlot) == 0)
            {
                shape.call("use", thisobj);
            }
        }
예제 #17
0
        public void ShapeBaseSetDamageDT(coShapeBase shapebase, float damageAmount, string damageType)
        {
            // This function is used to apply damage over time.  The damage is applied
            // at a fixed rate (50 ms).  Damage could be applied over time using the
            // built in ShapBase C++ repair functions (using a neg. repair), but this
            // has the advantage of going through the normal script channels.

            if (shapebase.getDamageState() != "Dead")
            {
                ShapeBaseDamage(shapebase, 0, new Point3F("0 0 0"), damageAmount, damageType);
                shapebase["damageSchedule"] = shapebase.schedule("50", "setDamageDt", damageAmount.AsString(), damageType).AsString();
            }
            else
            {
                shapebase["damageSchedule"] = "";
            }
        }
예제 #18
0
        public int ShapeBaseShapeBaseDecInventory(coShapeBase shapebase, coItemData data, int amount = 0)
        {
            int total = shapebase["inv[" + data.getName() + "]"].AsInt();


            if (total > 0)
            {
                if (total < amount)
                {
                    amount = total;
                }

                ShapeBaseShapeBaseSetInventory(shapebase, data, (total - amount));
                return(amount);
            }
            return(0);
        }
예제 #19
0
        public int ShapeBaseShapeBaseIncInventory(coShapeBase player, coItemData datablock, int amount)
        {
            int maxamount = ShapeBaseShapeBaseMaxInventory(player, datablock);

            int total = player["inv[" + datablock.getName() + "]"].AsInt();

            if (total < maxamount)
            {
                if (total + amount > maxamount)
                {
                    amount = (maxamount - total);
                }
                ShapeBaseShapeBaseSetInventory(player, datablock, (total + amount));
                return(amount);
            }
            return(0);
        }
예제 #20
0
        public bool ShapeBaseShapeBaseThrow(coShapeBase thisobj, coItemData data, int amount = 1)
        {
            bool functionresult = false;

            if (ShapeBaseShapeBaseGetInventory(thisobj, data) > 0)
            {
                coSimObject objectid = data.call("onThrow", thisobj, amount.AsString());
                {
                    if (objectid != 0)
                    {
                        thisobj.call("throwObject", objectid);
                        AudioServerPlay3D("ThrowSnd", thisobj.getTransform());
                        functionresult = true;
                    }
                }
            }
            return(functionresult);
        }
예제 #21
0
        public void ServerCmdDropPlayerAtCamera(coGameConnection client)
        {
            // If the player is mounted to something (like a vehicle) drop that at the
            // camera instead. The player will remain mounted.
            coPlayer    player = client["player"];
            coShapeBase obj    = null;

            obj = player.getObjectMount();
            if (!console.isObject(obj))
            {
                obj = client["player"];
            }

            obj.setTransform(((coCamera)client["Camera"]).getTransform());
            obj.setVelocity(new Point3F("0 0 0"));
            client.setControlObject(player);
            console.Call("clientCmdSyncEditorGui");
        }
예제 #22
0
        public void ArmorOnCollision(coPlayerData datablock, coPlayer player, coShapeBase col)
        {
            if (player.getState() == "Dead")
            {
                return;
            }
            // Try and pickup all items
            if (col.getClassName() == "Item")
            {
                player.call("pickup", col);
                return;
            }
            //AI are not allowed to drive they are lousey drivers....
            coGameConnection client = player["client"];

            if (!client.isObject())
            {
                return;
            }
            //Mount Vehicle.
            if ((console.getTypeMask(col) & (UInt32)SceneObjectTypesAsUint.GameBaseObjectType) != (UInt32)SceneObjectTypesAsUint.GameBaseObjectType)
            {
                return;
            }
            coVehicleData db = col.getDataBlock();

            if (((db.getClassName() == "WheeledVehicleData") || player["mountVehicle"].AsBool() || player.getState() == "Move" || col["mountable"].AsBool()))
            {
                return;
            }
            // Only mount drivers for now.
            ((coGameConnection)player["client"]).setFirstPerson(false);
            // For this specific example, only one person can fit
            // into a vehicle
            int mount = col.getMountNodeObject(0);

            if (mount > 0)
            {
                return;
            }
            // For this specific FPS Example, always mount the player to node 0
            col.mountObject(player, 0, new TransformF(true));
            player["mVehicle"] = col;
        }
예제 #23
0
        public string ShapeBaseTossPatch(coShapeBase thisobj)
        {
            if (!thisobj.isObject())
            {
                return(string.Empty);
            }

            coItem item = console.Call_Classname("ItemData", "CreateItem", new[] { "HealthKitPatch" });

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

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

            (( coSimSet)"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 = thisobj.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 + thisobj.getVelocity();

            TransformF pos = new TransformF(thisobj.getWorldBox().minExtents);

            item.setTransform(pos);
            item.applyImpulse(pos.MPosition, vec);
            item.setCollisionTimeout(thisobj);

            item.call("schedulePop");

            return(item);
        }
예제 #24
0
        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"] = "";
        }
예제 #25
0
        public void RadiusDamage(coShapeBase 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 = console.initContainerRadiusSearch(new Point3F(position), radius, (uint)SceneObjectTypesAsUint.ShapeBaseObjectType);
            float halfRadius           = radius / (float)2.0;

            foreach (coPlayer 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 = 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
                ShapeBaseDamage(targetObject, 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.MPosition);
            }
        }
예제 #26
0
        public bool ShapeBaseShapeBasePickup(coShapeBase thisobj, coItem obj, int amount)
        {
            coItemData data = obj.getDataBlock();

            if (amount == 0)
            {
                int maxamount = ShapeBaseShapeBaseMaxInventory(thisobj, data);

                int curamount = ShapeBaseShapeBaseGetInventory(thisobj, data);

                amount = (maxamount - curamount);
            }

            if (amount > 0)
            {
                return(data.call("onPickUp", obj, thisobj, amount.AsString()).AsBool());
            }

            return(false);
        }
예제 #27
0
        public bool ShapeBaseShapeBaseUse(coShapeBase thisobj, coItemData data)
        {
            coGameConnection client = thisobj.getControllingClient();

            if (client.isObject())
            {
                double defaultfov = client.getControlCameraDefaultFov();
                double fov        = client.getControlCameraFov();
                if (defaultfov != fov)
                {
                    return(false);
                }
            }



            if (ShapeBaseShapeBaseGetInventory(thisobj, data) > 0)
            {
                return(data.call("onUse", thisobj).AsBool());
            }

            return(false);
        }
예제 #28
0
        public int ShapeBaseShapeBaseSetInventory(coShapeBase thisobj, coItemData data, int value = 0)
        {
            if (thisobj == "")
            {
                return(0);
            }
            int max = 0;


            max = ShapeBaseShapeBaseMaxInventory(thisobj, data);
            if (value > max)
            {
                value = max;
            }

            int amount = thisobj["inv[" + data.getName() + "]"].AsInt();


            if (amount != value)
            {
                thisobj["inv[" + data.getName() + "]"] = value.AsString();


                if (console.isMethodInNamespace(data, "onInventory"))
                {
                    data.call("onInventory", thisobj, value.AsString());
                }

                //string datablock = console.getDatablock(thisobj).AsString();

                if (console.isObject((( coSimDataBlock)thisobj.getDataBlock())) && console.isMethodInNamespace((( coSimDataBlock)thisobj.getDataBlock()), "onInventory"))
                {
                    (( coSimDataBlock)thisobj.getDataBlock()).call("onInventory", data, value.AsString());
                }
            }
            return(value);
        }
예제 #29
0
 public int ShapeBaseShapeBaseGetInventory(coShapeBase thisobj, coItemData data)
 {
     return(thisobj.isObject() ? thisobj["inv[" + data.getName() + "]"].AsInt() : 0);
 }
예제 #30
0
 public void ShapeBaseShapeBaseClearInventory(coShapeBase thisobj)
 {
 }