예제 #1
0
        /**
         * Returns true if the given player has any of the given item types in thier inventory.
         * index : Is set to the index of the item found. If it isn't found, it is set to -1.
         * counts : the minimum stack per item needed for HasItem to return true.
         * includeAmmo : true if you wish to include the ammo slots.
         * includeCoins : true if you wish to include the coin slots.
         */
        public static bool HasItem(Player player, int[] types, ref int index, int[] counts = default(int[]), bool includeAmmo = false, bool includeCoins = false)
        {
            if (types == null || types.Length == 0)
            {
                return(false);                                               //no types to check!
            }
            if (counts == null || counts.Length == 0)
            {
                counts = BaseUtility.FillArray(new int[types.Length], 1);
            }
            int countIndex = -1;

            if (includeCoins)
            {
                for (int m = 50; m < 54; m++)
                {
                    Item item = player.inventory[m];
                    if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex])
                    {
                        index = m; return(true);
                    }
                }
            }
            if (includeAmmo)
            {
                for (int m = 54; m < 58; m++)
                {
                    Item item = player.inventory[m];
                    if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex])
                    {
                        index = m; return(true);
                    }
                }
            }
            for (int m = 0; m < 50; m++)
            {
                Item item = player.inventory[m];
                if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex])
                {
                    index = m; return(true);
                }
            }
            return(false);
        }
예제 #2
0
 public static bool HasAllItems(Player player, int[] types, ref int[] indicies, int[] counts = default(int[]), bool includeAmmo = false, bool includeCoins = false)
 {
     if (types == null || types.Length == 0)
     {
         return(false);                                               //no types to check!
     }
     if (counts == null || counts.Length == 0)
     {
         counts = BaseUtility.FillArray(new int[types.Length], 1);
     }
     int[]  indexArray = new int[types.Length];
     bool[] foundItem  = new bool[types.Length];
     if (includeCoins)
     {
         for (int m = 50; m < 54; m++)
         {
             for (int m2 = 0; m2 < types.Length; m2++)
             {
                 if (foundItem[m2])
                 {
                     continue;
                 }
                 Item item = player.inventory[m];
                 if (item != null && item.type == types[m2] && item.stack >= counts[m2])
                 {
                     foundItem[m2] = true; indexArray[m2] = m;
                 }
             }
         }
     }
     if (includeAmmo)
     {
         for (int m = 54; m < 58; m++)
         {
             for (int m2 = 0; m2 < types.Length; m2++)
             {
                 if (foundItem[m2])
                 {
                     continue;
                 }
                 Item item = player.inventory[m];
                 if (item != null && item.type == types[m2] && item.stack >= counts[m2])
                 {
                     foundItem[m2] = true; indexArray[m2] = m;
                 }
             }
         }
     }
     for (int m = 0; m < 50; m++)
     {
         for (int m2 = 0; m2 < types.Length; m2++)
         {
             if (foundItem[m2])
             {
                 continue;
             }
             Item item = player.inventory[m];
             if (item != null && item.type == types[m2] && item.stack >= counts[m2])
             {
                 foundItem[m2] = true; indexArray[m2] = m;
             }
         }
     }
     foreach (bool f in foundItem)
     {
         if (!f)
         {
             return(false);
         }
     }
     return(true);
 }