Exemplo n.º 1
0
    public override double GetMinCost()
    {
        UpToXTargetDescription desc = new UpToXTargetDescription(targetType, alignment);

        desc.amount = 1;
        return(desc.PowerLevel());
    }
Exemplo n.º 2
0
    public bool CanSelectMoreTargets()
    {
        if (selectableTargetDescriptions != null)
        {
            ITargettingDescription desc = selectableTargetDescriptions[allSelectedTargets.Count];
            if (desc.targettingType == TargettingType.EXCEPT)
            {
                ExceptTargetDescription exceptDesc = (ExceptTargetDescription)desc;
                desc = exceptDesc.targetDescription;
            }

            switch (desc.targettingType)
            {
            case TargettingType.TARGET:
            case TargettingType.TARGET_ALLY:
            case TargettingType.TARGET_ENEMY:
                TargetXDescription targetDesc = (TargetXDescription)desc;
                return(selectedTargets.Count < targetDesc.amount);

            case TargettingType.UP_TO_TARGET:
            case TargettingType.UP_TO_TARGET_ALLY:
            case TargettingType.UP_TO_TARGET_ENEMY:
                UpToXTargetDescription upToTargetDesc = (UpToXTargetDescription)desc;
                return(selectedTargets.Count < upToTargetDesc.amount);
            }
        }
        return(false);
    }
Exemplo n.º 3
0
    public override ITargettingDescription Generate()
    {
        UpToXTargetDescription desc = new UpToXTargetDescription(targetType, alignment);

        // Find the bounds of card amounts
        int max = ProceduralUtils.GetUpperBound(desc, ref desc.amount, MinTargets(), MaxTargets(), maxAllocatedBudget);
        int min = ProceduralUtils.GetLowerBound(desc, ref desc.amount, MinTargets(), max, minAllocatedBudget);

        Assert.IsTrue(max >= min);
        desc.amount = random.Next(min, max);

        return(desc);
    }
Exemplo n.º 4
0
    private void HandleTargetEvent(TargetSelectionEvent targetEvent)
    {
        // Validate all targets
        Card card = gameSession.GetPendingCard(targetEvent.playerId.GetComponent <PlayerController>());

        bool isValid = false;

        if (card != null && targetEvent.playerId == gameSession.GetWaitingOnPlayer().netIdentity)
        {
            PlayerController    player           = gameSession.GetWaitingOnPlayer();
            TriggerCondition    triggerCondition = gameSession.GetPendingTriggerCondition();
            NetworkIdentity[][] targets          = targetEvent.ReconstructTargets();

            List <ITargettingDescription> selectableTargetDescriptions = null;
            GameSession.PendingType       pendingType = gameSession.GetPendingActionType();

            if (pendingType == GameSession.PendingType.REPLACE_CREATURE)
            {
                selectableTargetDescriptions = GameUtils.ReplaceCreatureTargetDescriptions();
            }
            else
            {
                switch (card.cardData.GetCardType())
                {
                case CardType.CREATURE:
                    selectableTargetDescriptions = card.cardData.GetSelectableTargets(triggerCondition);
                    break;

                case CardType.SPELL:
                case CardType.TRAP:
                    selectableTargetDescriptions = card.cardData.GetSelectableTargets(TriggerCondition.NONE);
                    break;
                }
            }

            if (selectableTargetDescriptions != null && selectableTargetDescriptions.Count == targets.Length)
            {
                isValid = true;
                for (int i = 0; i < selectableTargetDescriptions.Count; i++)
                {
                    ITargettingDescription desc = selectableTargetDescriptions[i];
                    if (desc.targettingType == TargettingType.EXCEPT)
                    {
                        ExceptTargetDescription exceptDesc = (ExceptTargetDescription)desc;
                        desc = exceptDesc.targetDescription;
                    }

                    switch (desc.targettingType)
                    {
                    case TargettingType.TARGET:
                    {
                        TargetXDescription targetDesc = (TargetXDescription)desc;
                        if (targetDesc.amount == targets[i].Length)
                        {
                            TargettingQuery query = new TargettingQuery(targetDesc, player, pendingType != GameSession.PendingType.REPLACE_CREATURE);
                            for (int j = 0; j < targets[i].Length; j++)
                            {
                                Targettable targettable = targets[i][j].GetComponent <Targettable>();
                                if (!targettable.IsTargettable(query))
                                {
                                    isValid = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            isValid = false;
                        }
                        break;
                    }

                    case TargettingType.UP_TO_TARGET:
                    {
                        UpToXTargetDescription targetDesc = (UpToXTargetDescription)desc;
                        if (targetDesc.amount >= targets[i].Length)
                        {
                            TargettingQuery query = new TargettingQuery(targetDesc, player, pendingType != GameSession.PendingType.REPLACE_CREATURE);
                            for (int j = 0; j < targets[i].Length; j++)
                            {
                                Targettable targettable = targets[i][j].GetComponent <Targettable>();
                                if (!targettable.IsTargettable(query))
                                {
                                    isValid = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            isValid = false;
                        }
                        break;
                    }
                    }

                    if (!isValid)
                    {
                        break;
                    }
                }
            }

            if (isValid)
            {
                switch (pendingType)
                {
                case GameSession.PendingType.PLAY_CARD:
                    PlayCardEvent playCardEvent = new PlayCardEvent(player, card, targetEvent.flattenedTargets, targetEvent.indexes);
                    gameSession.HandleEvent(playCardEvent);
                    gameSession.ServerPopState();
                    break;

                case GameSession.PendingType.TRIGGER_EFFECT:
                    gameSession.ServerAddEffectToStack(gameSession.GetPendingCreature(player), card, triggerCondition, targetEvent.flattenedTargets, targetEvent.indexes);
                    gameSession.ResetPendingCreature();
                    gameSession.ServerPopState();
                    break;

                case GameSession.PendingType.USE_TRAP:
                    UseTrapEvent trapEvent = new UseTrapEvent(player, card, targetEvent.flattenedTargets, targetEvent.indexes);
                    gameSession.HandleEvent(trapEvent);
                    gameSession.ServerPopState();
                    break;

                case GameSession.PendingType.REPLACE_CREATURE:
                    // Replace creature should only have one target
                    Creature creatureToReplace = targets[0][0].GetComponent <Creature>();

                    // Destroying the creature makes it so we can't target it for the on enter effect of the replacing creature which is what we want
                    creatureToReplace.GetCreatureState().ServerDestroyCard();
                    gameSession.SetPendingCreature(creatureToReplace);

                    PlayCardEvent playReplaceCreatureEvent = new PlayCardEvent(player, card);
                    gameSession.HandleEvent(playReplaceCreatureEvent);
                    gameSession.ServerPopState();
                    break;
                }
            }
            else
            {
                CancelPlayCard();
            }
        }
    }