Ejemplo n.º 1
0
        public override void onImageMount(ShapeBase obj, int slot, float dt)
        {
            GameConnection client = obj["client"];

            string ammoName = string.Empty;
            ammoName = this["ammo"].getName();

            int currentammo = 0;
            int ammountinClips = 0;
            if (isField("clip"))
                {
                if (obj.getInventory(this["ammo"]).AsBool())
                    {
                    obj.setImageAmmo(slot, true);
                    currentammo = obj.getInventory(this["ammo"]);
                    }
                else if (obj.getInventory(this["clip"]) > 0)
                    {
                    obj.setInventory(this["ammo"], this["ammo.maxInventory"].AsInt());
                    obj.setImageAmmo(slot, true);
                    currentammo = this["ammo.maxInventory"].AsInt();
                    ammountinClips += obj["remaining" + ammoName].AsInt();
                    }
                else
                    currentammo = obj["remaining" + ammoName].AsInt();

                ammountinClips = obj.getInventory(this["clip"]);
                ammountinClips *= this["ammo.maxInventory"].AsInt();

                if ((obj["client"] != string.Empty) && !obj["isAiControlled"].AsBool())
                    client.refreshWeaponHud(currentammo, this["item.previewImage"], this["item.reticle"], this["item.zoomReticle"], ammountinClips);
                }
            else if (this["ammo"] != string.Empty)
                {
                if (obj.getInventory(this["ammo"]).AsBool())
                    {
                    obj.setImageAmmo(slot, true);
                    currentammo = obj.getInventory(this["ammo"]);
                    }
                else
                    currentammo = 0;

                if (obj["client"] != string.Empty && !obj["isAiControlled"].AsBool())
                    client.refreshWeaponHud(1, this["item.previewImage"], this["item.reticle"], this["item.zoomReticle"], currentammo);
                }
        }
        public override void onImageMount(ShapeBase obj, int slot, float dt)
        {
            obj.setImageAmmo(slot, true);

            int numTurrets = obj.getInventory(this["item"]);

            if (obj["client"] != string.Empty && obj.isAiControlled == false)
                ((GameConnection) obj["client"]).refreshWeaponHud(1, this["item.previewImage"], this["item.reticle"], this["item.zoomReticle"], numTurrets);
        }
Ejemplo n.º 3
0
        public override void onImageMount(ShapeBase obj, int slot, float dt)
        {
            obj.setImageAmmo(slot, true);
            int numofmines = obj.getInventory(this["item"]);

            string previewImage = this["item.previewImage"];
            string reticle = this["item.reticle"];
            string zoomReticle = this["item.zoomReticle"];

            GameConnection client = obj["client"];
            client.refreshWeaponHud(1, previewImage, reticle, zoomReticle, numofmines);
        }
Ejemplo n.º 4
0
        public override bool onPickup(Item obj, ShapeBase user, int amount)
        {
            if (!base.onPickup(obj, user, amount))
                return false;

            Audio.AudioServerPlay3D("WeaponPickupSound", user.getTransform());

            ShapeBaseImageData image = user.getMountedImage(Constants.WeaponSlot);

            if (image == 0)
                return false;

            if (!console.isField(image, "clip") || image["clip"].getID() != getId())
                return false;

            bool outOfAmmo = !user.getImageAmmo(Constants.WeaponSlot);

            int amountInClips = 0;

            int currentAmmo = user.getInventory(image["ammo"]);

            if (console.isObject(image["clip"]))
                amountInClips = user.getInventory(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;

            GameConnection client = user["client"];
            client.setAmmoAmountHud(currentAmmo, amountInClips);

            if (outOfAmmo)
                ((WeaponImage) image.ID).onClipEmpty(user, Constants.WeaponSlot);

            return true;
        }
Ejemplo n.º 5
0
        public override void onInventory(ShapeBase user, int value)
        {
            //Player can be either a player object or a aiturret...

            GameConnection client = user["client"];
            for (int i = 0; i < 8; i++)
                {
                if (user.GetType() == typeof (Player))
                    {
                    ShapeBaseImageData image = (user).getMountedImage(i);
                    if (image <= 0)
                        continue;

                    if (!image["ammo"].isObject())
                        continue;
                    if (((SimObject) image["ammo"]).getId() != this.getId())
                        continue;

                    (user).setImageAmmo(i, value != 0);
                    }
                else if (user.GetType() == typeof (AITurretShape))
                    {
                    ShapeBaseImageData image = (user).getMountedImage(i);
                    if (image <= 0)
                        continue;

                    if (!image["ammo"].isObject())
                        continue;
                    if (((SimObject) image["ammo"]).getId() != getId())
                        continue;

                    (user).setImageAmmo(i, value != 0);
                    }

                int currentammo = user.getInventory(this); // ShapeBaseShapeBaseGetInventory(player, thisobj);

                if (user.getClassName() != "Player")
                    continue;

                int amountInClips;

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

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

                    amountInClips += user["remaining" + getName()].AsInt();
                    }
                else
                    {
                    amountInClips = currentammo;
                    currentammo = 1;
                    }
                if (user["client"] != string.Empty && !user["isAiControlled"].AsBool())
                    client.setAmmoAmountHud(currentammo, amountInClips);
                }
        }
Ejemplo n.º 6
0
        public virtual int stashSpareAmmo(ShapeBase obj)
        {
            // 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
            ShapeBaseData ammo = this["ammo"];

            if (obj.getInventory(ammo) < this["ammo.maxInventory"].AsInt())
                {
                string nameOfAmmoField = "remaining" + ammo.getName();

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

                int amountIngun = obj.getInventory(this["ammo"]);
                int combinedammo = amountInPocket + amountIngun;

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

                    obj.incInventory(this["clip"], 1);
                    }
                else if (obj.getInventory(this["clip"]) > 0)
                    obj[nameOfAmmoField] = combinedammo.AsString();

                return obj[nameOfAmmoField].AsInt();
                }

            return 0;
        }
Ejemplo n.º 7
0
        public virtual void clearAmmoClip(ShapeBase 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 (!this["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 = stashSpareAmmo(obj);

            if (obj.getInventory(this["clip"]) > 0 || pocketAmount != 0)
                obj.setImageAmmo(slot, false);
        }
Ejemplo n.º 8
0
        public virtual void reloadAmmoClip(ShapeBase obj, int slot)
        {
            if (this != obj.getMountedImage(slot))
                return;

            if (!this.isField("clip"))
                return;

            if (obj.getInventory(this["clip"]) > 0)
                {
                obj.decInventory(this["clip"], 1);
                obj.setInventory(this["ammo"], this["ammo.maxInventory"].AsInt());

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

                    obj.setInventory(this["ammo"], amountInPocket);
                    obj.setImageAmmo(slot, true);
                    }
                }
        }