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 void ReassignTargetLockToken(Type type, char letter, GenericShip newOwner, Action callback) { Tokens.GenericTargetLockToken assignedToken = GetToken(type, letter) as Tokens.GenericTargetLockToken; if (assignedToken != null) { AssignedTokens.Remove(assignedToken); if (AfterTokenIsRemoved != null) { AfterTokenIsRemoved(this, type); } var oppositeType = (assignedToken.GetType() == typeof(Tokens.BlueTargetLockToken)) ? typeof(Tokens.RedTargetLockToken) : typeof(Tokens.BlueTargetLockToken); var otherToken = assignedToken.OtherTokenOwner.GetToken(oppositeType, letter) as Tokens.GenericTargetLockToken; otherToken.OtherTokenOwner = newOwner; newOwner.AssignToken(assignedToken, callback, letter); } }
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(); } }