Esempio n. 1
0
 private void RegisterTrigger(ITargetLockable target)
 {
     if (target is GenericShip)
     {
         RegisterAbilityTrigger(TriggerTypes.OnTargetLockIsAcquired, delegate { GenesisRedAbilityEffect(target as GenericShip); });
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 private void RegisterHobbieKlivianPilotAbility(ITargetLockable ship)
 {
     if (HostShip.Tokens.HasToken(typeof(StressToken)))
     {
         RegisterAbilityTrigger(TriggerTypes.OnTargetLockIsAcquired, AskToRemoveStress);
     }
 }
        public void CallOnTargetLockIsAcquiredEvent(ITargetLockable target, Action callback)
        {
            OnTargetLockIsAcquired?.Invoke(target);
            OnTargetLockIsAcquiredGlobal?.Invoke(this, target);

            Triggers.ResolveTriggers(TriggerTypes.OnTargetLockIsAcquired, callback);
        }
Esempio n. 5
0
 private void CheckAbility(ITargetLockable ship)
 {
     if (!IsAbilityUsed)
     {
         RegisterAbilityTrigger(TriggerTypes.OnActionIsPerformed, AcquireSecondTargetLock);
     }
 }
Esempio n. 6
0
        public void CanPerformTargetLock(ref bool result, GenericShip attacker, ITargetLockable defender)
        {
            bool abilityIsActive = false;

            if (defender is GenericShip)
            {
                if ((defender as GenericShip).ShipId != HostShip.ShipId)
                {
                    if ((defender as GenericShip).Owner.PlayerNo == HostShip.Owner.PlayerNo)
                    {
                        BoardTools.DistanceInfo positionInfo = new BoardTools.DistanceInfo(attacker, HostShip);
                        if (positionInfo.Range >= attacker.TargetLockMinRange && positionInfo.Range <= attacker.TargetLockMaxRange)
                        {
                            abilityIsActive = true;
                        }
                    }
                }

                if (abilityIsActive)
                {
                    if (Roster.GetPlayer(Phases.CurrentPhasePlayer).GetType() == typeof(Players.HumanPlayer))
                    {
                        Messages.ShowErrorToHuman("Captain Kagi: You cannot target lock that ship");
                    }
                    result = false;
                }
            }
        }
Esempio n. 7
0
    private static void FinishAcquireTargetLock(GenericShip thisShip, ITargetLockable targetShip, Action callback)
    {
        BlueTargetLockToken tokenBlue = new BlueTargetLockToken(thisShip);
        RedTargetLockToken  tokenRed  = new RedTargetLockToken(targetShip);

        char letter = GetFreeTargetLockLetter();

        tokenBlue.Letter = letter;
        tokenBlue.OtherTargetLockTokenOwner = targetShip;

        tokenRed.Letter = letter;
        tokenRed.OtherTargetLockTokenOwner = thisShip;

        TakeTargetLockLetter(letter);

        targetShip.AssignToken(
            tokenRed,
            delegate
        {
            thisShip.Tokens.AssignToken(tokenBlue, delegate
            {
                thisShip.CallOnTargetLockIsAcquiredEvent(targetShip, callback);
            });
        }
            );
    }
Esempio n. 8
0
        private void RemoveTargetLock(System.Object sender, EventArgs e)
        {
            BlueTargetLockToken tlock   = HostShip.Tokens.GetToken(typeof(BlueTargetLockToken), '*') as BlueTargetLockToken;
            ITargetLockable     tlocked = tlock.OtherTargetLockTokenOwner;

            HostShip.Tokens.RemoveToken(tlock, delegate { (tlocked as GenericShip).Damage.ExposeRandomFacedownCard(DecisionSubPhase.ConfirmDecision); });
        }
Esempio n. 9
0
 public List <char> GetTargetLockLetterPairsOn(ITargetLockable targetShip)
 {
     return(Tokens
            .Where(t => (t as RedTargetLockToken).OtherTargetLockTokenOwner == targetShip)
            .Select(t => (t as RedTargetLockToken).Letter)
            .ToList());
 }
Esempio n. 10
0
 private void CheckAbility(ITargetLockable target)
 {
     if (target is GenericObstacle)
     {
         Messages.ShowInfo("Qi'Ra: While you move or perform attack, you ignore this obstacle");
         HostShip.IgnoreObstaclesList.Add(target as GenericObstacle);
     }
 }
Esempio n. 11
0
        private void CanPerformJam(ref bool result, GenericShip ship, ITargetLockable defender)
        {
            if (ship.Owner.PlayerNo != HostShip.Owner.PlayerNo) return;

            if (defender.GetRangeToShip(HostShip) < 2)
            {
                result = true;
                return;
            }
        }
Esempio n. 12
0
 private void CheckAbility(GenericShip activeShip, ITargetLockable lockedShip)
 {
     if (lockedShip == HostShip && lockedShip is GenericShip)
     {
         if (!activeShip.SectorsInfo.IsShipInSector(lockedShip as GenericShip, Arcs.ArcType.Bullseye))
         {
             RegisterAbilityTrigger(TriggerTypes.OnTargetLockIsAcquired, delegate { AssignStress(activeShip); });
         }
     }
 }
Esempio n. 13
0
        private void UseAbility(object sender, System.EventArgs e)
        {
            DecisionSubPhase.ConfirmDecisionNoCallback();

            IsAbilityUsed = true;

            BlueTargetLockToken existingToken    = HostShip.Tokens.GetToken <BlueTargetLockToken>('*');
            ITargetLockable     TargetLockTarget = existingToken.OtherTargetLockTokenOwner;

            ActionsHolder.AcquireTargetLock(HostShip, TargetLockTarget, FinishAbility, FinishAbility);
        }
Esempio n. 14
0
        public RedTargetLockToken(ITargetLockable host) : base(null)
        {
            Name       = ImageName = "Red Target Lock Token";
            TokenColor = TokenColors.Red;
            PriorityUI = 20;

            HostTargetable = host;
            if (host is GenericShip)
            {
                Host = host as GenericShip;
            }
        }
Esempio n. 15
0
        private ITargetLockable GetLockedShip()
        {
            ITargetLockable result = null;

            BlueTargetLockToken blueTargetLock = HostShip.Tokens.GetToken <BlueTargetLockToken>(letter: '*');

            if (blueTargetLock != null)
            {
                result = blueTargetLock.OtherTargetLockTokenOwner;
            }

            return(result);
        }
Esempio n. 16
0
        private void CanPerformTargetLock(ref bool result, GenericShip ship, ITargetLockable defender)
        {
            if (ship.Owner.PlayerNo != HostShip.Owner.PlayerNo)
            {
                return;
            }

            foreach (GenericShip friendlyShip in HostShip.Owner.Ships.Values)
            {
                if (defender.GetRangeToShip(friendlyShip) < 4)
                {
                    result = true;
                    return;
                }
            }
        }
Esempio n. 17
0
    public static void AcquireTargetLock(GenericShip thisShip, ITargetLockable targetShip, Action successCallback, Action failureCallback, bool ignoreRange = false)
    {
        if (Letters.Count == 0)
        {
            InitializeTargetLockLetters();
        }

        if (ignoreRange || Rules.TargetLocks.TargetLockIsAllowed(thisShip, targetShip))
        {
            List <BlueTargetLockToken> existingBlueTokens = thisShip.Tokens.GetTokens <BlueTargetLockToken>('*');

            GetTokensToRemoveThenAssign(existingBlueTokens, thisShip, targetShip, successCallback);
        }
        else
        {
            Messages.ShowErrorToHuman("The target is out of range of Target Lock");
            failureCallback();
        }
    }
Esempio n. 18
0
        public List <char> GetTargetLockLetterPairsOn(ITargetLockable targetShip)
        {
            List <char> result = new List <char>();

            List <BlueTargetLockToken> blueTokens = GetTokens <BlueTargetLockToken>('*');

            foreach (BlueTargetLockToken blueToken in blueTokens)
            {
                char foundLetter = (blueToken as BlueTargetLockToken).Letter;

                GenericToken redToken = targetShip.GetAnotherToken(typeof(RedTargetLockToken), foundLetter);
                if (redToken != null)
                {
                    result.Add(blueToken.Letter);
                }
            }

            return(result);
        }
Esempio n. 19
0
        private void StartAbility(object sender, EventArgs e)
        {
            LockedShip = GetLockedShip();
            if (LockedShip == null)
            {
                Messages.ShowError(HostShip.PilotInfo.PilotName + " doesn't have any locked targets!");
                Triggers.FinishTrigger();
                return;
            }

            SelectTargetForAbility(
                GetTargetLockOnSameTarget,
                AnotherFriendlyShipInRange,
                AiPriority,
                HostShip.Owner.PlayerNo,
                HostShip.PilotInfo.PilotName,
                "Choose a ship, that ship will acquire a lock on the object you locked",
                HostShip
                );
        }
Esempio n. 20
0
        public bool TargetLockIsAllowed(GenericShip ship, ITargetLockable target)
        {
            bool result = true;

            int rangeBetween = target.GetRangeToShip(ship);

            if (rangeBetween > ship.TargetLockMaxRange || rangeBetween < ship.TargetLockMinRange)
            {
                result = false;
            }

            if (result != true)
            {
                OnCheckTargetLockIsAllowed?.Invoke(ref result, ship, target);
            }
            if (result == true)
            {
                OnCheckTargetLockIsDisallowed?.Invoke(ref result, ship, target);
            }

            return(result);
        }
Esempio n. 21
0
        private void UseZertikStromAbility()
        {
            BlueTargetLockToken tlock = HostShip.Tokens.GetToken(typeof(BlueTargetLockToken), '*') as BlueTargetLockToken;

            // Do we have a target lock?
            if (tlock != null)
            {
                ITargetLockable tlocked = tlock.OtherTargetLockTokenOwner;

                if (tlocked is GenericShip)
                {
                    if (!(tlocked as GenericShip).Damage.HasFacedownCards)
                    {
                        return;
                    }

                    Triggers.RegisterTrigger(
                        new Trigger()
                    {
                        Name         = "Zertik Strom's Ability",
                        TriggerOwner = HostShip.Owner.PlayerNo,
                        TriggerType  = TriggerTypes.OnEndPhaseStart,
                        EventHandler = delegate
                        {
                            AskToUseAbility(
                                HostShip.PilotInfo.PilotName,
                                AlwaysUseByDefault,
                                RemoveTargetLock,
                                descriptionLong: "Do you want to spend a lock you have on an enemy ship to expose 1 of that ship's damage cards?",
                                imageHolder: HostShip
                                );
                        }
                    }
                        );
                }
            }
        }
Esempio n. 22
0
 private bool FilterTargetLockTargets(ITargetLockable target)
 {
     // Don't include targets that are owned by the target locking player or ships that can't get target locks
     return(Rules.TargetLocks.TargetLockIsAllowed(Selection.ThisShip, target));
 }
Esempio n. 23
0
    public static bool HasTargetLockOn(GenericShip attacker, ITargetLockable defender)
    {
        List <char> letter = GetTargetLocksLetterPairs(attacker, defender);

        return(letter.Count > 0);
    }
Esempio n. 24
0
 public static List <char> GetTargetLocksLetterPairs(ITargetLockable thisShip, ITargetLockable targetShip)
 {
     return(thisShip.GetTargetLockLetterPairsOn(targetShip));
 }
Esempio n. 25
0
 private static void AssignNewTargetLockToken(List <GenericToken> tokensToRemove, GenericShip thisShip, ITargetLockable targetShip, Action successCallback)
 {
     if (tokensToRemove.Count != 0)
     {
         thisShip.Tokens.RemoveTokens(
             tokensToRemove,
             delegate { FinishAcquireTargetLock(thisShip, targetShip, successCallback); }
             );
     }
     else
     {
         FinishAcquireTargetLock(thisShip, targetShip, successCallback);
     }
 }
Esempio n. 26
0
    private static void GetTokensToRemoveThenAssign(List <BlueTargetLockToken> existingBlueTokens, GenericShip thisShip, ITargetLockable targetShip, Action successCallback)
    {
        TokensToRemove = new List <GenericToken>();
        List <GenericToken> tokensAskToRemove = new List <GenericToken>();

        foreach (BlueTargetLockToken existingBlueToken in existingBlueTokens)
        {
            bool tokenMustBeRemoved      = false;
            bool tokenMaybeWillBeRemoved = false;

            //Two TLs on the same target AND on different targets are allowed
            if (thisShip.TwoTargetLocksOnSameTargetsAreAllowed.Count > 0 && thisShip.TwoTargetLocksOnDifferentTargetsAreAllowed.Count > 0)
            {
                //If target is different
                if (existingBlueToken.OtherTargetLockTokenOwner != targetShip)
                {
                    //If already >1 of tokens, then ask to remove
                    int alreadyAssignedSameTokens = thisShip.Tokens.GetTokens <BlueTargetLockToken>('*').Count;
                    if (alreadyAssignedSameTokens > 1 && TokensToRemove.Count < alreadyAssignedSameTokens - 1)
                    {
                        tokenMaybeWillBeRemoved = true;
                    }
                }
                else //If target is the same
                {
                    //If already >1 of tokens, then remove all except one
                    int alreadyAssignedSameTokens = thisShip.Tokens.GetTokens <BlueTargetLockToken>('*').Count(t => t.OtherTargetLockTokenOwner == targetShip);
                    if (alreadyAssignedSameTokens > 1 && TokensToRemove.Count < alreadyAssignedSameTokens - 1)
                    {
                        tokenMustBeRemoved = true;
                    }
                }
            }
            //Two TLs on the different targets are allowed
            else if (thisShip.TwoTargetLocksOnSameTargetsAreAllowed.Count == 0 && thisShip.TwoTargetLocksOnDifferentTargetsAreAllowed.Count > 0)
            {
                //Remove if token is on the same target
                if (existingBlueToken.OtherTargetLockTokenOwner == targetShip)
                {
                    tokenMustBeRemoved = true;
                }
                else //If target is different
                {
                    //If already >1 of tokens, then ask to remove
                    int alreadyAssignedSameTokens = thisShip.Tokens.GetTokens <BlueTargetLockToken>('*').Count;
                    if (alreadyAssignedSameTokens > 1 && TokensToRemove.Count < alreadyAssignedSameTokens - 1)
                    {
                        tokenMaybeWillBeRemoved = true;
                    }
                }
            }
            //Two TLs on the same target are allowed
            else if (thisShip.TwoTargetLocksOnSameTargetsAreAllowed.Count > 0 && thisShip.TwoTargetLocksOnDifferentTargetsAreAllowed.Count == 0)
            {
                //Remove all if new target is another
                if (existingBlueToken.OtherTargetLockTokenOwner != targetShip)
                {
                    tokenMustBeRemoved = true;
                }
                else //If target is the same
                {
                    //If already >1 of tokens, then remove all except one
                    int alreadyAssignedSameTokens = thisShip.Tokens.GetTokens <BlueTargetLockToken>('*').Count(t => t.OtherTargetLockTokenOwner == targetShip);
                    if (alreadyAssignedSameTokens > 1 && TokensToRemove.Count < alreadyAssignedSameTokens - 1)
                    {
                        tokenMustBeRemoved = true;
                    }
                }
            }
            //Always remove if only 1 token is allowed
            else if (thisShip.TwoTargetLocksOnSameTargetsAreAllowed.Count == 0 && thisShip.TwoTargetLocksOnDifferentTargetsAreAllowed.Count == 0)
            {
                tokenMustBeRemoved = true;
            }

            if (tokenMustBeRemoved)
            {
                TokensToRemove.Add(existingBlueToken);
            }
            else if (tokenMaybeWillBeRemoved)
            {
                tokensAskToRemove.Add(existingBlueToken);
            }
        }

        if (tokensAskToRemove.Count > 0)
        {
            Triggers.RegisterTrigger(new Trigger()
            {
                Name         = "Select token to remove",
                TriggerOwner = thisShip.Owner.PlayerNo,
                TriggerType  = TriggerTypes.OnAbilityDirect,
                EventHandler = StartSelectTokenToRemoveSubPhase,
                Sender       = thisShip,
                EventArgs    = new EventArgsTokensList()
                {
                    List = tokensAskToRemove
                }
            });
        }

        Triggers.ResolveTriggers(
            TriggerTypes.OnAbilityDirect,
            delegate { AssignNewTargetLockToken(TokensToRemove, thisShip, targetShip, successCallback); }
            );
    }
 public List <char> GetTargetLockLetterPairsOn(ITargetLockable targetShip)
 {
     return(Tokens.GetTargetLockLetterPairsOn(targetShip));
 }