Beispiel #1
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);
        }