public static bool AssignTargetLockToPair(Ship.GenericShip thisShip, Ship.GenericShip targetShip) { bool result = false; if (Letters.Count == 0) { InitializeTargetLockLetters(); } ShipDistanceInformation distanceInfo = new ShipDistanceInformation(thisShip, targetShip); if (distanceInfo.Range < 4) { Tokens.GenericToken existingBlueToken = thisShip.GetToken(typeof(Tokens.BlueTargetLockToken), '*'); if (existingBlueToken != null) { if ((existingBlueToken as Tokens.BlueTargetLockToken).LockedShip != null) { (existingBlueToken as Tokens.BlueTargetLockToken).LockedShip.RemoveToken(typeof(Tokens.RedTargetLockToken), (existingBlueToken as Tokens.BlueTargetLockToken).Letter); } thisShip.RemoveToken(typeof(Tokens.BlueTargetLockToken), (existingBlueToken as Tokens.BlueTargetLockToken).Letter); } Tokens.BlueTargetLockToken tokenBlue = new Tokens.BlueTargetLockToken(); Tokens.RedTargetLockToken tokenRed = new Tokens.RedTargetLockToken(); char letter = GetFreeTargetLockLetter(); tokenBlue.Letter = letter; tokenBlue.LockedShip = targetShip; tokenRed.Letter = letter; TakeTargetLockLetter(letter); Selection.ThisShip.AssignToken(tokenBlue); targetShip.AssignToken(tokenRed); result = true; } else { Messages.ShowErrorToHuman("Target is out of range of Target Lock"); } return(result); }
public static void AssignTargetLockToPair(Ship.GenericShip thisShip, Ship.GenericShip targetShip, Action successCallback, Action failureCallback) { if (Letters.Count == 0) { InitializeTargetLockLetters(); } ShipDistanceInformation distanceInfo = new ShipDistanceInformation(thisShip, targetShip); if (distanceInfo.Range >= thisShip.TargetLockMinRange && distanceInfo.Range <= thisShip.TargetLockMaxRange) { Tokens.GenericToken existingBlueToken = thisShip.GetToken(typeof(Tokens.BlueTargetLockToken), '*'); if (existingBlueToken != null) { thisShip.RemoveToken(typeof(Tokens.BlueTargetLockToken), (existingBlueToken as Tokens.BlueTargetLockToken).Letter); } Tokens.BlueTargetLockToken tokenBlue = new Tokens.BlueTargetLockToken(); Tokens.RedTargetLockToken tokenRed = new Tokens.RedTargetLockToken(); char letter = GetFreeTargetLockLetter(); tokenBlue.Letter = letter; tokenBlue.OtherTokenOwner = targetShip; tokenRed.Letter = letter; tokenRed.OtherTokenOwner = Selection.ThisShip; TakeTargetLockLetter(letter); targetShip.AssignToken( tokenRed, delegate { thisShip.AssignToken(tokenBlue, successCallback); }); } else { Messages.ShowErrorToHuman("Target is out of range of Target Lock"); failureCallback(); } }