コード例 #1
0
ファイル: AI.cs プロジェクト: Niezoor/ScriptsDemo
    private List <string> GetPossibleCardsFromHand()
    {
        List <string> rv = new List <string> ();

        if (AIHandCards.Count > 0)
        {
            foreach (string cardName in AIHandCards)
            {
                CardsBase.CardDescriptionClass cardDesc = GameplayComponent.CardsComp.FindCardDescByName(cardName);
                if (cardDesc != null)
                {
                    if (cardDesc.Cost <= (mana - spendMana))
                    {
                        rv.Add(cardName);
                    }
                }
            }
        }
        return(rv);
    }
コード例 #2
0
    private IEnumerator AddCardFromPack(GameObject card, GameObject panel, int i, CardsBase.CardDescriptionClass cardDesc)
    {
        SmothTransform ST = card.GetComponent <SmothTransform> ();

        yield return(new WaitForSeconds(0.5f));

        yield return(new WaitForSeconds(0.1f * i));

        card.transform.SetParent(panel.transform, true);
        ST.SmothTransformTo(new Vector3(0, 0, 0), Quaternion.identity, MovingSpeed);
        ST.SmoothScaleTo(new Vector3(CardReversEndScale, CardReversEndScale, CardReversEndScale), MovingSpeed);
        if (cardDesc != null)
        {
            if (cardDesc.Rarity == CardInteraction.CardRarityEnum.gold)
            {
                Instantiate(GoldCardRay, card.transform);
            }
            else if (cardDesc.Rarity == CardInteraction.CardRarityEnum.diamond)
            {
                Instantiate(DiamondCardRay, card.transform);
            }
        }
    }
コード例 #3
0
    public bool CheckCardQuantity(string CardName)
    {
        bool rv        = true;
        int  cardcount = 0;

        CardsBase.CardDescriptionClass desc = CardsBaseComponent.FindCardDescByName(CardName);
        if (desc != null)
        {
            foreach (string cardn in CardsInDeckNames)
            {
                if (cardn.Equals(desc.Name) || cardn.Equals(desc.CardID))
                {
                    cardcount++;
                }
            }

            if (cardcount >= desc.MaxQuantity)
            {
                rv = false;
            }
        }

        return(rv);
    }
コード例 #4
0
ファイル: AI.cs プロジェクト: Niezoor/ScriptsDemo
    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());
    }
コード例 #5
0
    private void GrantPackItems(List <ItemInstance> GrantedItems)
    {
        int i = 0;

        Debug.Log("Result open normal card pack:" + GrantedItems.Count);
        ButtonText.text = "ZGARNIJ";
        PackParticleEffect.Emit(1);
        RemoveItem(MainMenuComponent.CardsPacks[0]);
        foreach (ItemInstance item in GrantedItems)
        {
            int id = -1;
            Int32.TryParse(item.ItemId, out id);
            int quantity = item.RemainingUses.GetValueOrDefault(1);
            CardsBase.CardDescriptionClass cardDesc = MainMenuComponent.DeckBaseComponent.CardsBaseComponent.FindCardDescByID(id);
            Debug.Log("unlock card :" + item.DisplayName + " x" + item.RemainingUses.GetValueOrDefault(1) + " class:" + item.ItemClass);

            int maxCount   = 3;
            int givenMoney = 5;

            if (cardDesc.Rarity == CardInteraction.CardRarityEnum.common)
            {
                maxCount   = 3;
                givenMoney = 5;
            }
            else if (cardDesc.Rarity == CardInteraction.CardRarityEnum.gold)
            {
                maxCount   = 2;
                givenMoney = 10;
            }
            else if (cardDesc.Rarity == CardInteraction.CardRarityEnum.diamond)
            {
                maxCount   = 1;
                givenMoney = 20;
            }

            int cardNumber = cardDesc.Quantity;
            quantity -= cardDesc.Quantity;

            while (quantity > 0)
            {
                if (MainMenuComponent != null)
                {
                    cardDesc = MainMenuComponent.DeckBaseComponent.CardsBaseComponent.UnlockCard(id);
                }
                GameObject card = Instantiate(CardRevers);
                card.transform.position   = Package.transform.position;
                card.transform.rotation   = Package.transform.rotation;
                card.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
                if (card != null)
                {
                    GameObject panel     = Instantiate(CardPanel, CardsTable);
                    LootPanel  lootPanel = panel.GetComponent <LootPanel> ();
                    if ((quantity + cardNumber) > maxCount)
                    {
                        lootPanel.Duplicate          = true;
                        lootPanel.RewardForDuplicate = givenMoney;
                    }
                    lootPanel.Rarity = cardDesc.Rarity;
                    card.GetComponent <CardInteraction> ().SetCardOrder(2);
                    StartCoroutine(AddCardFromPack(card, panel, i, cardDesc));
                    lootPanel.RegisterListener(FlipCard, Int32.Parse(item.ItemId), i);

                    Cards.Add(card);
                    CardsPanels.Add(panel);
                    i++;
                }
                quantity--;
            }
        }
        PackAnimationController.SetTrigger("EndOpen");
        PackAudioSource.PlayOneShot(PackOpen);
        PackLoaded   = false;
        OpenFinished = true;
    }