public void RemoveToken(GenericToken tokenToRemove, Action callback) { if (Host.CanRemoveToken(tokenToRemove)) { AssignedTokens.Remove(tokenToRemove); if (tokenToRemove.GetType().BaseType == typeof(GenericTargetLockToken)) { ITargetLockable otherTokenOwner = (tokenToRemove as GenericTargetLockToken).OtherTargetLockTokenOwner; ActionsHolder.ReleaseTargetLockLetter((tokenToRemove as GenericTargetLockToken).Letter); Type oppositeType = (tokenToRemove.GetType() == typeof(BlueTargetLockToken)) ? typeof(RedTargetLockToken) : typeof(BlueTargetLockToken); char letter = (tokenToRemove as GenericTargetLockToken).Letter; GenericToken otherTargetLockToken = otherTokenOwner.GetAnotherToken(oppositeType, letter); if (otherTargetLockToken != null) { otherTokenOwner.RemoveToken(otherTargetLockToken); if (otherTokenOwner is GenericShip) { (otherTokenOwner as GenericShip).CallOnRemoveTokenEvent(otherTargetLockToken); } } } tokenToRemove.WhenRemoved(); Host.CallOnRemoveTokenEvent(tokenToRemove); } Triggers.ResolveTriggers(TriggerTypes.OnTokenIsRemoved, callback); }
public void RemoveToken(GenericToken tokenToRemove, Action callback) { AssignedTokens.Remove(tokenToRemove); if (tokenToRemove.GetType().BaseType == typeof(GenericTargetLockToken)) { GenericShip otherTokenOwner = (tokenToRemove as GenericTargetLockToken).OtherTokenOwner; Actions.ReleaseTargetLockLetter((tokenToRemove as GenericTargetLockToken).Letter); Type oppositeType = (tokenToRemove.GetType() == typeof(BlueTargetLockToken)) ? typeof(RedTargetLockToken) : typeof(BlueTargetLockToken); char letter = (tokenToRemove as GenericTargetLockToken).Letter; GenericToken otherTargetLockToken = otherTokenOwner.Tokens.GetToken(oppositeType, letter); if (otherTargetLockToken != null) { otherTokenOwner.Tokens.GetAllTokens().Remove(otherTargetLockToken); otherTokenOwner.CallOnRemoveTokenEvent(otherTargetLockToken.GetType()); } } Host.CallOnRemoveTokenEvent(tokenToRemove.GetType()); Triggers.ResolveTriggers(TriggerTypes.OnTokenIsRemoved, callback); }