void InternalSort() { if (_sortActions == null) { _sortActions = new List <Action>(); } _sortActions.Clear(); _sortIndex = 0; string[] slotOrder = new string[_slotOrder.Length]; _slotOrder.CopyTo(slotOrder, 0); for (int i = 0; i < slotOrder.Length; i++) { ISlot userSlot = _data.GetSlot(slotOrder[i]); //User already at correct position if (userSlot.Id == i + 1) { continue; } ISlot destSlot = _data.GetSlot(i); //Slot is free, only move player if (!destSlot.IsUsed) { _sortActions.Add(new Action(() => _lobby.SetSlot(userSlot.Nickname, destSlot.Id))); } //Slot is not free, move player out of the way and then move player in else { ISlot freeSlot = _data.GetFirstUnusedSlot(); _sortActions.Add(new Action(() => _lobby.SetSlot(destSlot.Nickname, freeSlot.Id))); _sortActions.Add(new Action(() => _lobby.SetSlot(userSlot.Nickname, destSlot.Id))); } } }