public static void ClearRandomQuickSlot() { QuickSlots quickSlots = Inventory.main.quickSlots; // Find all slots which have items in them List <int> activeSlots = new List <int>(); for (int i = 0; i < quickSlots.slotCount; i++) { if (quickSlots.GetSlotItem(i) != null) { activeSlots.Add(i); } } if (activeSlots.Count == 0) { // Prevent OutOfBounds errors return; } System.Random random = new System.Random(); int randomSlotID = activeSlots[random.Next(0, activeSlots.Count)]; quickSlots.Unbind(randomSlotID); }
public static void RandomizeQuickSlots() { QuickSlots quickSlots = Inventory.main.quickSlots; // Make a list of all slots (including empty slots) List <InventoryItem> allSlots = new List <InventoryItem>(); for (int i = 0; i < quickSlots.slotCount; i++) { allSlots.Add(quickSlots.GetSlotItem(i)); } // Shuffle the list System.Random random = new System.Random(); int n = allSlots.Count; while (n > 1) { n--; int k = random.Next(n + 1); InventoryItem value = allSlots[k]; allSlots[k] = allSlots[n]; allSlots[n] = value; } // Set the quick slots for (int i = 0; i < quickSlots.slotCount; i++) { quickSlots.binding[i] = allSlots[i]; } // Notify the game that the slots have changed for (int i = 0; i < quickSlots.slotCount; i++) { quickSlots.NotifyBind(i, allSlots[i] != null); } }