Beispiel #1
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);
                }
            }
        }
Beispiel #2
0
        public int WeaponImageStashSpareAmmo(coItemData thisobj, coPlayer player)
        {
            // If the amount in our pocket plus what we are about to add from the clip
            // Is over a clip, add a clip to inventory and keep the remainder
            // on the player
            coItemData ammo = thisobj["ammo"];

            if (ShapeBaseShapeBaseGetInventory(player, ammo) < thisobj["ammo.maxInventory"].AsInt())
            {
                string nameOfAmmoField = "remaining" + ammo.getName();


                int amountInPocket = player[nameOfAmmoField].AsInt();

                int amountIngun  = ShapeBaseShapeBaseGetInventory(player, thisobj["ammo"]);
                int combinedammo = amountInPocket + amountIngun;

                if (combinedammo >= thisobj["ammo.maxInventory"].AsInt())
                {
                    player[nameOfAmmoField] = (combinedammo - thisobj["ammo.maxInventory"].AsInt()).AsString();

                    ShapeBaseShapeBaseIncInventory(player, thisobj["clip"], 1);
                }
                else if (ShapeBaseShapeBaseGetInventory(player, thisobj["clip"]) > 0)
                {
                    player[nameOfAmmoField] = combinedammo.AsString();
                }

                return(player[nameOfAmmoField].AsInt());
            }

            return(0);
        }
Beispiel #3
0
        public int ShapeBaseShapeBaseMaxInventory(coShapeBase thisobj, coItemData data)
        {
            if (data.isField("clip"))
            {
                return(data["maxInventory"].AsInt());
            }

            return((( coSimDataBlock)thisobj.getDataBlock())["maxInv[" + data.getName() + "]"].AsInt());
        }
Beispiel #4
0
        public coItem ItemDataCreateItem(coItemData datablock)
        {
            Torque_Class_Helper tch = new Torque_Class_Helper("Item");

            tch.Props.Add("dataBlock", datablock);
            tch.Props.Add("static", "true");
            tch.Props.Add("rotate", "true");
            return(tch.Create());
        }
Beispiel #5
0
        public bool ShapeBaseShapeBaseHasAmmo(coShapeBase thisob, coItem weapon)
        {
            coItemData weaponimageammo = weapon["image.ammo"];

            if (weaponimageammo == "")
            {
                return(true);
            }
            return(ShapeBaseShapeBaseGetInventory(thisob, weaponimageammo) > 0);
        }
Beispiel #6
0
        public void AmmoOnInventory(coItemData thisobj, coPlayer player, int amount)
        {
            coGameConnection client = player["client"];

            for (int i = 0; i < 8; i++)
            {
                coItemData image = player.getMountedImage(i);
                if (image <= 0)
                {
                    continue;
                }

                if (!image["ammo"].isObject())
                {
                    continue;
                }
                if (console.Call(image["ammo"], "getID") != console.Call(thisobj, "getID"))
                {
                    continue;
                }


                player.setImageAmmo(i, amount != 0);

                int currentammo = ShapeBaseShapeBaseGetInventory(player, thisobj);

                if (player.getClassName() != "Player")
                {
                    continue;
                }

                int amountInClips;

                if (thisobj["clip"].isObject())
                {
                    amountInClips = ShapeBaseShapeBaseGetInventory(player, thisobj["clip"]);

                    amountInClips *= thisobj["maxInventory"].AsInt();

                    amountInClips += player["remaining" + thisobj.getName()].AsInt();
                }
                else
                {
                    amountInClips = currentammo;
                    currentammo   = 1;
                }
                if (player["client"] != "" && !player["isAiControlled"].AsBool())
                {
                    GameConnectionSetAmmoAmountHud(client, currentammo, amountInClips);
                }
            }
        }
Beispiel #7
0
        public void AmmoClipOnPickup(coItem thisobj, string obj, coPlayer shape, string amount, int nameSpaceDepth)
        {
            int nsd = nameSpaceDepth + 1;

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

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

            coItemData image = shape.getMountedImage(WeaponSlot);

            if (image == 0)
            {
                return;
            }

            if (!console.isField(image, "clip") || console.Call(string.Format("{0}.clip", image), "getID") != console.Call(thisobj, "getID"))
            {
                return;
            }

            bool outOfAmmo = !shape.getImageAmmo(WeaponSlot);

            int amountInClips = 0;

            int currentAmmo = ShapeBaseShapeBaseGetInventory(shape, image["ammo"]);

            if (console.isObject(image["clip"]))
            {
                amountInClips = ShapeBaseShapeBaseGetInventory(shape, image["clip"]);
            }

            int t = console.GetVarInt(string.Format("{0}.ammo.maxInventory", image));

            amountInClips *= t;

            int amountloadedingun = console.GetVarInt(string.Format("{0}.remaining{1}", obj, console.GetVarString(string.Format("{0}.ammo", this))));

            amountInClips += amountloadedingun;



            GameConnectionSetAmmoAmountHud(shape["client"], currentAmmo, amountInClips);

            if (outOfAmmo)
            {
                console.Call(image, "onClipEmpty", new string[] { shape, WeaponSlot.AsString() });
            }
        }
Beispiel #8
0
        public bool ItemDataOnPickUp(coItemData datablock, coItem item, coPlayer player, string amount)
        {
            int count = item["count"].AsInt();

            //string count = console.GetVarString(item + ".count");

            if (count == 0)
            {
                count = datablock["count"].AsInt();
                if (count == 0)
                {
                    if (datablock["maxInventory"] != "")
                    {
                        if (count != datablock["maxInventory"].AsInt())
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        count = 1;
                    }
                }
            }
            ShapeBaseShapeBaseIncInventory(player, (((coItemData)datablock).getName()), count);


            coGameConnection client = player["client"];

            if (client.isObject())
            {
                MessageClient(client, "MsgItemPickup", console.ColorEncode(@"\c0You picked up %1"), datablock["pickupName"]);
            }


            // If the item is a static respawn item, then go ahead and
            // respawn it, otherwise remove it from the world.
            // Anything not taken up by inventory is lost.

            if (item.isStatic())
            {
                item.call("respawn");
            }
            else
            {
                item.delete();
            }


            return(true);
        }
Beispiel #9
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";
            }
        }
Beispiel #10
0
        public void ServerCmdReloadWeapon(coGameConnection client)
        {
            coPlayer player = client.getControlObject();

            coItemData image = player.getMountedImage(iGlobal["$WeaponSlot"]);

            if (ShapeBaseShapeBaseGetInventory(player, image["ammo"]) == image["ammo.maxInventory"].AsInt())
            {
                return;
            }

            if (image > 0)
            {
                WeaponImageClearAmmoClip(image, player, sGlobal["$WeaponSlot"].AsInt());
            }
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
0
        public string ProximityMineDataOnThrow(coItemData datablock, coPlayer player, int amount)
        {
            ShapeBaseShapeBaseDecInventory(player, datablock, 1);

            Torque_Class_Helper tch = new Torque_Class_Helper("ProximityMine", "");

            tch.Props.Add("datablock", datablock);
            tch.Props.Add("sourceObject", player);
            tch.Props.Add("rotation", string.Format("\"0 0 1 {0} \"", new Random().NextDouble() * 360));
            tch.Props.Add("static", "false");
            tch.Props.Add("client", player["client"]);
            coProximityMine pm = (tch.Create());

            ((coSimSet)"MissionCleanup").pushToBack(pm);

            return(pm);
        }
Beispiel #14
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);
        }
Beispiel #15
0
        public void ServerCmdThrow(coGameConnection client, string data)
        {
            coPlayer player = client["player"];

            if (!player.isObject() || (player.getState() == "Dead") || !Game_Running)
            {
                return;
            }

            coSimObject mountedimage = player.getMountedImage(iGlobal["$WeaponSlot"]);

            switch (data)
            {
            case "Weapon":
            {
                if (mountedimage != "0")
                {
                    coItemData item = mountedimage["item"];
                    ShapeBaseShapeBaseThrow(player, item);
                }
            }
            break;

            case "Ammo":
            {
                if (mountedimage != "0")
                {
                    coSimObject item = mountedimage;
                    if (item["ammo"] != "")
                    {
                        ShapeBaseShapeBaseThrow(player, item["ammo"]);
                    }
                }
            }
            break;

            default:
                if (ShapeBaseShapeBaseHasInventory(player, data.getName()))
                {
                    ShapeBaseShapeBaseThrow(player, data);
                }
                break;
            }
        }
Beispiel #16
0
        public void WeaponImageClearAmmoClip(coItemData thisobj, coPlayer obj, int slot)
        {
            //echo("WeaponImage::clearAmmoClip: " SPC %this SPC %obj SPC %slot);

            // if we're not empty put the remaining bullets from the current clip
            // in to the player's "pocket".

            if (!thisobj["clip"].isObject())
            {
                return;
            }
            // Commenting out this line will use a "hard clip" system, where
            // A player will lose any ammo currently in the gun when reloading.
            int pocketAmount = WeaponImageStashSpareAmmo(thisobj, obj);

            if (ShapeBaseShapeBaseGetInventory(obj, thisobj["clip"]) > 0 || pocketAmount != 0)
            {
                obj.setImageAmmo(slot, false);
            }
        }
Beispiel #17
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);
        }
Beispiel #18
0
        public void HealthPatchOnCollision(coItemData healthkit_datablock, coSceneObject healthkit_instance, coPlayer player)
        {
            if (player.getDamageLevel() <= 0.00 || player.getState() == "Dead")
            {
                return;
            }

            player.applyRepair(healthkit_datablock["repairAmount"].AsFloat());

            healthkit_instance.call("schedulePop");


            //coGameConnection client = player["client"];
            //if (!client.isObject())
            //    return;
            //using (BackgroundWorker bwr = new BackgroundWorker())
            //    {
            //    bwr.DoWork += bwr_UpdateHealth;
            //    bwr.RunWorkerAsync(new HealthKitHelper(player, healthkit_instance));
            //    }

            AudioServerPlay3D("HealthUseSound", player.getTransform());
        }
Beispiel #19
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);
        }
Beispiel #20
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);
        }
Beispiel #21
0
        public string ItemDataOnThrow(coItemData datablock, coPlayer player, int amount)
        {
            if (amount == 0)
            {
                amount = 1;
            }

            if (amount > datablock["maxInventory"].AsInt())
            {
                amount = datablock["maxInventory"].AsInt();
            }

            if (!amount.AsBool())
            {
                return("0");
            }


            ShapeBaseShapeBaseDecInventory(player, datablock, amount);

            // Construct the actual object in the world, and add it to
            // the mission group so it's cleaned up when the mission is
            // done.  The object is given a random z rotation.
            Torque_Class_Helper tch = new Torque_Class_Helper("Item", "");

            tch.Props.Add("datablock", datablock);
            tch.Props.Add("rotation", @"""0 0 1 " + (new Random().Next(0, 360)) + @"""");
            tch.Props.Add("count", amount.AsString());

            coItem item = tch.Create();

            ((coSimSet)"MissionGroup").pushToBack(item);

            ItemschedulePop(item);
            return(item);
        }
Beispiel #22
0
 public int ShapeBaseShapeBaseGetInventory(coShapeBase thisobj, coItemData data)
 {
     return(thisobj.isObject() ? thisobj["inv[" + data.getName() + "]"].AsInt() : 0);
 }
Beispiel #23
0
        public void ShapeBaseCycleWeapon(coShapeBase thisobj, string direction)
        {
            //I sure seem to retrieve "thisobj.totalCycledWeapons" alot,
            //So to save so work, I'm just gonna grab it here.
            int totalCycledWeapons = thisobj["totalCycledWeapons"].AsInt();


            // Can't cycle what we don't have
            if (totalCycledWeapons == 0)
            {
                return;
            }
            // Find out the index of the current weapon, if any (not all
            // available weapons may be part of the cycle)
            int currentIndex = -1;


            coItemData mountedimage = thisobj.getMountedImage(WeaponSlot);

            if (mountedimage.isObject())
            {
                string curWeapon = mountedimage["item"];
                for (int i = 0; i < totalCycledWeapons; i++)
                {
                    if (thisobj["cycleWeapon[" + i + "]"] != curWeapon)
                    {
                        continue;
                    }
                    currentIndex = i;
                    break;
                }
            }



            int nextIndex = 0;
            int dir       = 1;

            if (currentIndex != -1)
            {
                if (direction == "prev")
                {
                    dir       = -1;
                    nextIndex = currentIndex - 1;
                    if (nextIndex < 0)
                    {
                        nextIndex = totalCycledWeapons - 1;
                    }
                }
                else
                {
                    nextIndex = currentIndex + 1;
                    if (nextIndex >= totalCycledWeapons)
                    {
                        nextIndex = 0;
                    }
                }
            }
            bool       found  = false;
            coItemData weapon = null;

            for (int i = 0; i < totalCycledWeapons; i++)
            {
                weapon = thisobj["cycleWeapon[" + i + "]"];
                if ((weapon != 0) && (ShapeBaseShapeBaseHasInventory(thisobj, weapon)))
                {
                    found = true;
                    break;
                }
                nextIndex = nextIndex + dir;
                if (nextIndex < 0)
                {
                    nextIndex = totalCycledWeapons - 1;
                }
                else if (nextIndex >= totalCycledWeapons)
                {
                    nextIndex = 0;
                }
            }
            if (!found)
            {
                return;
            }
            weapon = thisobj["cycleWeapon[" + nextIndex + "]"];
            ShapeBaseShapeBaseUse(thisobj, weapon);
        }
Beispiel #24
0
        public bool ShapeBaseShapeBaseHasInventory(coShapeBase thisobj, coItemData data)
        {
            int amount = thisobj["inv[" + data.getName() + "]"].AsInt();

            return(amount > 0);
        }