示例#1
0
        /// <summary>
        /// Release all the locks you have based by type
        /// </summary>
        public void ReleasePlayerLocks(LockType type)
        {
            var playerName = SettingsSystem.CurrentSettings.PlayerName;
            IEnumerable <LockDefinition> locksToRelease;

            switch (type)
            {
            case LockType.Asteroid:
                locksToRelease = LockQuery.AsteroidLockOwner() == playerName ?
                                 new[] { LockQuery.AsteroidLock() } : new LockDefinition[0];
                break;

            case LockType.Control:
                locksToRelease = LockQuery.GetAllControlLocks(SettingsSystem.CurrentSettings.PlayerName);
                break;

            case LockType.Kerbal:
                locksToRelease = LockQuery.GetAllKerbalLocks(SettingsSystem.CurrentSettings.PlayerName);
                break;

            case LockType.Update:
                locksToRelease = LockQuery.GetAllUpdateLocks(SettingsSystem.CurrentSettings.PlayerName);
                break;

            case LockType.UnloadedUpdate:
                locksToRelease = LockQuery.GetAllUnloadedUpdateLocks(SettingsSystem.CurrentSettings.PlayerName);
                break;

            case LockType.Spectator:
                locksToRelease = LockQuery.SpectatorLockExists(SettingsSystem.CurrentSettings.PlayerName) ?
                                 new[] { LockQuery.GetSpectatorLock(SettingsSystem.CurrentSettings.PlayerName) } : new LockDefinition[0];
                break;

            case LockType.Contract:
                locksToRelease = LockQuery.ContractLockOwner() == playerName ?
                                 new[] { LockQuery.ContractLock() } : new LockDefinition[0];
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            //Serialize to array as it's a concurrent collection
            foreach (var lockToRelease in locksToRelease.ToArray())
            {
                ReleaseLock(lockToRelease);
            }
        }