private static void FinishReassignToken(char letter, GenericShip oldOwner, GenericShip newOwner, Action callback) { GenericTargetLockToken assignedTargetLockToken = oldOwner.Tokens.GetTargetLockToken(letter); Type oppositeType = (assignedTargetLockToken is BlueTargetLockToken) ? typeof(RedTargetLockToken) : typeof(BlueTargetLockToken); oldOwner.Tokens.RemoveCondition(assignedTargetLockToken); var otherToken = assignedTargetLockToken.OtherTokenOwner.Tokens.GetToken(oppositeType, letter) as GenericTargetLockToken; otherToken.OtherTokenOwner = newOwner; newOwner.Tokens.AssignToken(assignedTargetLockToken, callback, letter); }
public static void ReassignTargetLockToken(char letter, GenericShip oldOwner, GenericShip newOwner, Action callback) { GenericTargetLockToken assignedTargetLockToken = oldOwner.Tokens.GetTargetLockToken(letter); if (assignedTargetLockToken != null) { if (assignedTargetLockToken.GetType() == typeof(BlueTargetLockToken)) { char existingTlOnSameTarget = GetTargetLocksLetterPair(newOwner, assignedTargetLockToken.OtherTokenOwner); if (existingTlOnSameTarget != ' ') { newOwner.Tokens.RemoveToken( typeof(BlueTargetLockToken), delegate { FinishReassignToken(letter, oldOwner, newOwner, callback); }, existingTlOnSameTarget ); } else { FinishReassignToken(letter, oldOwner, newOwner, callback); } } else { char existingTlOnSameTarget = GetTargetLocksLetterPair(assignedTargetLockToken.OtherTokenOwner, newOwner); if (existingTlOnSameTarget != ' ') { newOwner.Tokens.RemoveToken( typeof(RedTargetLockToken), delegate { FinishReassignToken(letter, oldOwner, newOwner, callback); }, existingTlOnSameTarget ); } else { FinishReassignToken(letter, oldOwner, newOwner, callback); } } } else { Messages.ShowError("ERROR: No such token to reassign!"); callback(); } }