Esempio n. 1
0
    private IEnumerator PlayRandomCardFromHand()
    {
        List <string> skipCard = new List <string> ();

        while (true)
        {
            List <string> cardsToPlay = GetPossibleCardsFromHand();
            if (skipCard.Count > 0)
            {
                foreach (string card in skipCard)
                {
                    cardsToPlay.Remove(card);
                }
            }
            if (cardsToPlay.Count > 0)
            {
                string cardToPlayName = cardsToPlay[Random.Range(0, cardsToPlay.Count)];
                int    handIndex;
                int    boardPosIndex = 0;
                bool   playcard      = true;

                handIndex = AIHandCards.IndexOf(cardToPlayName);
                if (GameplayComponent.IsFreePosision(17))
                {
                    boardPosIndex = 17;
                }
                else if (GameplayComponent.IsFreePosision(18))
                {
                    boardPosIndex = 18;
                }
                else if (GameplayComponent.IsFreePosision(21))
                {
                    boardPosIndex = 21;
                }
                else
                {
                    playcard = false;
                    break;
                }
                if (playcard)
                {
                    CardsBase.CardDescriptionClass cardDesc = GameplayComponent.CardsComp.FindCardDescByName(cardToPlayName);
                    if (cardDesc != null)
                    {
                        yield return(new WaitForSeconds(1f));

                        if (cardDesc.CardMode == CardsBase.CardTypesEnum.Pawn)
                        {
                            GameObject pawnObject = GameplayComponent.PutEnemyPawnOnBoard(cardToPlayName, AIPawnIDNext, 3, handIndex, boardPosIndex);
                            yield return(new WaitForSeconds(1f));

                            GameplayComponent.ConfirmEnemyPawnPos(cardToPlayName, AIPawnIDNext, 3, boardPosIndex);
                            spendMana += cardDesc.Cost;
                            AIHandCards.Remove(cardToPlayName);
                            if (pawnObject != null)
                            {
                                Pawn pawnComp = pawnObject.GetComponent <Pawn> ();
                                pawnComp.isFirstPlay = true;
                                if (pawnComp.AITriggerEffectCallback != null)
                                {
                                    List <int> targets = pawnComp.AITriggerEffectCallback(pawnComp.boardPosisionIndex);
                                    if (targets != null)
                                    {
                                        if (targets.Count > 0)
                                        {
                                            ShooseRandomTarget(cardToPlayName, pawnComp.boardPosisionIndex, -1, targets);
                                            yield return(new WaitForSeconds(1f));
                                        }
                                        else
                                        {
                                            skipCard.Add(cardToPlayName);
                                        }
                                    }
                                    else
                                    {
                                        skipCard.Add(cardToPlayName);
                                    }
                                }
                            }
                        }
                        else if (cardDesc.CardMode == CardsBase.CardTypesEnum.Effect)
                        {
                            //GameObject pawnObject = GameplayComponent.PutEnemyCardOnBoard (cardToPlayName, -1, 0, -1, -1).gameObject;
                            GameObject cardObject = GameplayComponent.CardsComp.SpawnCardByName(cardToPlayName);
                            GameObject pawnObject = cardObject.transform.Find("Pawn").gameObject;
                            cardObject.transform.localPosition = new Vector3(1000, 1000, 1000);
                            if (pawnObject != null)
                            {
                                Pawn pawnComp = pawnObject.GetComponent <Pawn> ();
                                pawnComp.gamePlayComp = GameplayComponent;
                                List <int> targets = pawnComp.AITriggerEffectCallback(pawnComp.boardPosisionIndex);
                                if (targets != null)
                                {
                                    if (cardDesc.EffectComponent.Equals("VerticalLineAttack"))
                                    {
                                        if (targets.Count > 0)
                                        {
                                            GameplayComponent.PlayEnemyEffectOnBoard(pawnComp.Name, Random.Range(0, 5), targets [Random.Range(0, targets.Count)], handIndex);
                                            yield return(new WaitForSeconds(1f));
                                        }
                                        else
                                        {
                                            skipCard.Add(cardToPlayName);
                                        }
                                    }
                                    else
                                    {
                                        if (targets.Count > 0)
                                        {
                                            ShooseRandomTarget(pawnComp.Name, -1, handIndex, targets);
                                            yield return(new WaitForSeconds(1f));
                                        }
                                        else
                                        {
                                            skipCard.Add(cardToPlayName);
                                        }
                                    }
                                    spendMana += cardDesc.Cost;
                                    AIHandCards.Remove(cardToPlayName);
                                }
                                else
                                {
                                    skipCard.Add(cardToPlayName);
                                }
                            }
                            Destroy(cardObject, 10);
                        }
                        else if (cardDesc.CardMode == CardsBase.CardTypesEnum.Weapon)
                        {
                            GamePlay.TargetSettings settings = GamePlay.TargetSettings.WithEnemyPawn;
                            GameplayComponent.SetTargetsOnBoard(settings, null, null);
                            List <int> targets = GameplayComponent.TargetsList;
                            if (targets != null)
                            {
                                if (targets.Count > 0)
                                {
                                    int target = targets [Random.Range(0, targets.Count)];
                                    GameplayComponent.PutEnemyWeaponOnBoard(cardToPlayName, 3, handIndex, target);
                                    yield return(new WaitForSeconds(1f));

                                    GameplayComponent.GiveWeaponToEnemyPawn(cardToPlayName, target, 3);
                                    spendMana += cardDesc.Cost;
                                    AIHandCards.Remove(cardToPlayName);
                                    yield return(new WaitForSeconds(1f));
                                }
                                else
                                {
                                    skipCard.Add(cardToPlayName);
                                }
                            }
                            else
                            {
                                skipCard.Add(cardToPlayName);
                            }
                        }

                        AIPawnIDNext++;
                    }
                }
            }
            else
            {
                break;
            }
            if ((mana - spendMana) <= 1)
            {
                break;
            }
        }
        StartCoroutine(RandomMoves());
    }