示例#1
0
        public virtual bool hasAmmo(Item weapon)
        {
            ShapeBaseImageData weaponimageammo = weapon["image.ammo"];

            if (weaponimageammo == string.Empty)
            {
                return(true);
            }
            return(getInventory(weaponimageammo) > 0);
        }
示例#2
0
        public virtual void cycleWeapon(string direction)
        {
            //I sure seem to retrieve "thisobj.totalCycledWeapons" alot,
            //So to save so work, I'm just gonna grab it here.
            int totalCycledWeapons = this["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;

            ShapeBaseImageData mountedimage = this.getMountedImage(Constants.WeaponSlot);

            if (mountedimage.isObject())
            {
                string curWeapon = mountedimage["item"];
                for (int i = 0; i < totalCycledWeapons; i++)
                {
                    if (this["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;
            ItemData weapon = null;

            for (int i = 0; i < totalCycledWeapons; i++)
            {
                weapon = this["cycleWeapon[" + i + "]"];
                if ((weapon != 0) && (hasInventory(weapon)))
                {
                    found = true;
                    break;
                }
                nextIndex = nextIndex + dir;
                if (nextIndex < 0)
                {
                    nextIndex = totalCycledWeapons - 1;
                }
                else if (nextIndex >= totalCycledWeapons)
                {
                    nextIndex = 0;
                }
            }
            if (!found)
            {
                return;
            }
            weapon = this["cycleWeapon[" + nextIndex + "]"];

            Use(weapon);
        }