public static bool AcquireLock(LockDefinition lockDef, bool force, out bool repeatedAcquire) { repeatedAcquire = false; //Player tried to acquire a lock that they already own if (LockQuery.LockBelongsToPlayer(lockDef.Type, lockDef.VesselId, lockDef.KerbalName, lockDef.PlayerName)) { repeatedAcquire = true; return(true); } if (force || !LockQuery.LockExists(lockDef)) { if (lockDef.Type == LockType.Control) { //If they acquired a control lock they probably switched vessels or something like that and they can only have one control lock. //So remove the other control locks just for safety... var controlLocks = LockQuery.GetAllPlayerLocks(lockDef.PlayerName).Where(l => l.Type == LockType.Control); foreach (var control in controlLocks) { ReleaseLock(control); } } LockStore.AddOrUpdateLock(lockDef); return(true); } return(false); }
public static bool AcquireLock(LockDefinition lockDef, bool force, out bool repeatedAcquire) { repeatedAcquire = false; //Player tried to acquire a lock that he already owns if (LockQuery.LockBelongsToPlayer(lockDef.Type, lockDef.VesselId, lockDef.PlayerName)) { repeatedAcquire = true; return(true); } if (force || !LockQuery.LockExists(lockDef)) { if (GeneralSettings.SettingsStore.DropControlOnVesselSwitching && lockDef.Type == LockType.Control) { //If he acquired a control lock he probably switched vessels or smth like that and he can only have 1 control lock. //So remove the other control locks just for safety... var controlLocks = LockQuery.GetAllPlayerLocks(lockDef.PlayerName).Where(l => l.Type == LockType.Control); foreach (var control in controlLocks) { ReleaseLock(control); } } LockStore.AddOrUpdateLock(lockDef); return(true); } return(false); }
//Lock types //control-vessel-(vesselid) - Replaces the old "inUse" messages, the active pilot will have the control-vessel lock. //update-vessel-(vesselid) - Replaces the "only the closest player can update a vessel" code, //Now you acquire locks to update crafts around you. //asteroid - Held by the player that can spawn asteroids into the game. public static bool AcquireLock(LockDefinition lockDef, bool force) { if (force || !LockQuery.LockExists(lockDef)) { LockStore.AddOrUpdateLock(lockDef); return(true); } return(false); }
/// <summary> /// Acquire the specified lock by sending a message to the server. /// </summary> /// <param name="lockDefinition">The definition of the lock to acquire</param> /// <param name="force">Force the acquire. Usually false unless in dockings.</param> /// <param name="immediate">Acquire the lock immediately without waiting confirmation from the server</param> private void AcquireLock(LockDefinition lockDefinition, bool force = false, bool immediate = false) { var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <LockAcquireMsgData>(); msgData.Lock = lockDefinition; msgData.Force = force; MessageSender.SendMessage(msgData); if (force && immediate) { LockStore.AddOrUpdateLock(lockDefinition); } }
public static bool AcquireLock(LockDefinition lockDef, bool force, out bool repeatedAcquire) { repeatedAcquire = false; //Player tried to acquire a lock that he already owns if (LockQuery.LockBelongsToPlayer(lockDef.Type, lockDef.VesselId, lockDef.PlayerName)) { repeatedAcquire = true; return(true); } if (force || !LockQuery.LockExists(lockDef)) { LockStore.AddOrUpdateLock(lockDef); return(true); } return(false); }