Exemplo n.º 1
0
    public void AddCardToHand(Card_Data cardToCreate)
    {
        GameObject newCard = Instantiate(cardPrefab, transform);

        newCard.GetComponent <Card_Behaviour>().SetCard(cardToCreate);
        cardObjects.Add(newCard);
    }
Exemplo n.º 2
0
    public void RemoveCardFromHand(GameObject cardObject)
    {
        Card_Data tempCard = cardObject.GetComponent <Card_Behaviour>().myCard;

        cardObjects.Remove(cardObject);
        Destroy(cardObject);
        myPlayer.cardsInHand.Remove(tempCard);
        myPlayer.cardsInGraveyard.Add(tempCard);
    }
Exemplo n.º 3
0
 public void SetCard(Card_Data _card)
 {
     myCard         = _card;
     cost_text.text = _card.cost.ToString();
     name_text.text = _card.cardName;
     type_text.text = _card.type.ToString();
     //abilities_text.text = _card.
     flavor_text.text = _card.flavor_text;
     picture.sprite   = _card.card_image;
 }
Exemplo n.º 4
0
    public IEnumerator PlayCard(GameObject pCard)
    {
        // Get the card_data
        Card_Data tCardData = pCard.GetComponent <CardController> ().Card;

        // Remove the card from the hand
        CardsInHand.Remove(pCard);

        // Pay the cost of the card
        Player.PayManaCost(tCardData.manaCost);

        // TODO Check effects that activate on card activation

        // Toss the card template back to factory
        StartCoroutine(MatchHelper.RecycleCardTemplate(pCard));

        // Set card being play
        CardBeingPlay = tCardData;

        // Get all the effects of the card
        List <_Effect> tEffects = pCard.GetComponent <CardController>().GetEffects();

        // Resolve the card effects
        for (int i = 0; i < tEffects.Count; i++)
        {
            string        Result;
            CoroutineData EffectCoroutine = new CoroutineData(this, tEffects [i].ResolveEffect());

            yield return(EffectCoroutine.coroutine);

            Result = null;
            Result = (string)EffectCoroutine.result;

            yield return(new WaitUntil(() => Result == "Finished"));
        }

        // Decrement card_data charge
        tCardData.charge--;
        Debug.Log("Charge: " + tCardData.charge);

        // Put the card back into the deck or discard pile
        if (tCardData.charge > 0)
        {
            Deck.AddCardToDeck(tCardData);
        }
        else
        {
            DiscardPile.Add(tCardData);
        }

        AlignHand();
        CardBeingPlay = null;
        yield return("Finished");
    }
    /// <summary>
    /// Fisher-Yates shuffle implementation
    /// Shuffle the current deck
    /// </summary>
    public void Shuffle()
    {
        var randomSeed = new System.Random();
        int cardNum    = CardsInDeck.Count;

        while (cardNum > 1)
        {
            cardNum--;
            int       randomCard = randomSeed.Next(cardNum + 1);
            Card_Data card       = CardsInDeck[randomCard];
            CardsInDeck[randomCard] = CardsInDeck[cardNum];
            CardsInDeck[cardNum]    = card;
        }
    }
Exemplo n.º 6
0
    public IEnumerator DrawTopCardFromDeck()
    {
        // Set magnify on hover off
        InputController.CanMagnify = false;
        InputController.UnmagnifyCard();

        string Result;

        // Get the card_data from the deck
        Card_Data tCardData = Deck.DrawTopCard();

        // Wait until the deck return a card_data
        yield return(new WaitUntil(() => tCardData != null));

        // Set the card data into a template
        GameObject tCard = null;

        tCard = MatchHelper.SetCardData(tCardData);

        yield return(new WaitUntil(() => tCard != null));

        // Show the card draw from the top of the deck
        CoroutineData DrawingCoroutine = new CoroutineData(this, MatchHelper.RenderCardFromDeck(tCard));

        // Wait for Card to be drew from the deck
        yield return(DrawingCoroutine.coroutine);

        Result = null;
        Result = (string)DrawingCoroutine.result;

        yield return(new WaitUntil(() => Result == "Finished"));

        // Put the card in the player hand
        CoroutineData PutCardInHandCoroutine = new CoroutineData(this, PutCardInHand(tCard));

        yield return(PutCardInHandCoroutine.coroutine);

        Result = null;
        Result = (string)PutCardInHandCoroutine.result;

        yield return(new WaitUntil(() => Result == "Finished"));

        // Set magnify on hover on
        InputController.CanMagnify = true;

        yield return("Finished");
    }
Exemplo n.º 7
0
    /// <summary>
    /// Set Card_data into a card template and return the card template
    /// </summary>
    /// <returns>The card.</returns>
    /// <param name="tCardData">T card data.</param>
    public GameObject SetCard(Card_Data tCardData)
    {
        // Create the card
        if (CardTemplates.Count == 0)
        {
            CardTemplates.Add(Instantiate(instance.CardPrefab));
        }

        GameObject tCard = CardTemplates[0];

        CardTemplates.RemoveAt(0);

        // Set the card data
        tCard.GetComponent <CardController> ().SetCardData(tCardData);
        tCard.transform.Rotate(new Vector3(-90, 0, 0));

        return(tCard);
    }
Exemplo n.º 8
0
    /// <summary>
    /// Discards the card.
    /// </summary>
    /// <returns>The card.</returns>
    /// <param name="pCard">P card.</param>
    public IEnumerator DiscardCard(GameObject pCard)
    {
        string Result;

        // Put the card_data into discard list
        Card_Data tCardData = pCard.GetComponent <CardController> ().GetCardData();

        DiscardPile.Add(tCardData);

        CoroutineData DiscardingCoroutine = new CoroutineData(this, MatchHelper.RenderCardToRightSide(pCard));

        yield return(DiscardingCoroutine.coroutine);

        Result = null;
        Result = (string)DiscardingCoroutine.result;

        // Wait for Card to be render moving to the right side
        yield return(new WaitUntil(() => Result == "Finished"));

        yield return("Finished");
    }
Exemplo n.º 9
0
    public void Init(string deckName)
    {
        Object masterCard = Resources.Load("Prefabs/Cards/Pf_Card_Game") as GameObject;

        scr_Deck_Data.Save_Data deckSave = Database.Instance.decks.LoadDeck(deckName);

        // Make cards
        foreach (scr_Deck_Data.Card_Entry card in deckSave.cardList)
        {
            //Get Card Data from ID in savefile
            Card_Data cardData = Database.Instance.GetInventoryCard(card.ID).card;

            //Create correct number of cards
            for (int i = 0; i < card.count; i++)
            {
                GameObject cardCopy = Instantiate(masterCard) as GameObject;
                cardCopy.GetComponent <Card_Game>().InitData(cardData);

                cardCopy.transform.SetParent(gameObject.transform);
                cardCopy.SetActive(false);
                cards.Add(cardCopy);
            }
        }
    }
Exemplo n.º 10
0
 public void InitData(Card_Data data, int count)
 {
     base.InitData(data);
     numBank = count;
     AddUseCount(0);
 }
Exemplo n.º 11
0
 public void Load(Card_Data c)
 {
     description.text = c.description;
     image.sprite     = c.image;
     cardData         = c;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Adds the card to deck and shuffle.
 /// </summary>
 /// <param name="pCardData">P card data.</param>
 public void AddCardToDeck(Card_Data pCardData)
 {
     CardsInDeck.Add(pCardData);
     Shuffle();
 }
Exemplo n.º 13
0
    public void InitData(Card_Data baseData)
    {
        data.name = baseData.name;
        data.info = baseData.info;
        data.AP   = baseData.AP;
        data.HP   = baseData.HP;
        data.TP   = baseData.TP;
        data.MV   = baseData.MV;
        data.ID   = baseData.ID;
        data.Cost = baseData.Cost;
        foreach (int i in baseData.leftCon)
        {
            data.leftCon.Add(i);
        }
        data.leftCon.Sort();
        foreach (int i in baseData.rightCon)
        {
            data.rightCon.Add(i);
        }
        data.rightCon.Sort();

        visuals = (GameObject)Instantiate(Resources.Load("Prefabs/Cards/Pf_Card_Visuals"), transform);
        Transform visualsT = visuals.transform;

        visualsT.SetSiblingIndex(0);

        //Connection markers
        List <int>[] connection = new List <int>[2] {
            data.leftCon, data.rightCon
        };
        Transform[] conPanels = new Transform[2] {
            visualsT.Find("Con_Left"), visualsT.Find("Con_Right")
        };
        for (int j = 0; j < 2; j++)
        {
            float panelHeight = conPanels[j].GetComponent <RectTransform>().sizeDelta.y;
            int   conIndex    = 0;
            foreach (int color in connection[j])
            {
                //Create new marker
                GameObject newColor = new GameObject("Color_" + color);
                newColor.transform.SetParent(conPanels[j]);
                //Position marker correctly
                RectTransform rect = newColor.AddComponent <RectTransform>();
                rect.anchorMin        = new Vector2(0, 0);
                rect.anchorMax        = new Vector2(1, 0);
                rect.pivot            = new Vector2(0.5f, 0);
                rect.sizeDelta        = new Vector2(0, panelHeight / connection[j].Count - (connection[j].Count - 1) * 10);
                rect.localScale       = new Vector3(1, 1, 1);
                rect.anchoredPosition = new Vector2(0, conIndex * panelHeight / connection[j].Count);
                conIndex++;

                //Set correct color
                UnityEngine.UI.Image image = newColor.AddComponent <UnityEngine.UI.Image>();
                image.color = colors[color];
            }
        }

        //Data text
        visualsT.Find("Name").GetComponent <UnityEngine.UI.Text>().text                = data.name;
        visualsT.Find("CardInfo").GetComponent <UnityEngine.UI.Text>().text            = data.info;
        visualsT.Find("AP_Panel").Find("AP").GetComponent <UnityEngine.UI.Text>().text = "AP: " + data.AP.ToString();
        visualsT.Find("HP_Panel").Find("HP").GetComponent <UnityEngine.UI.Text>().text = "HP: " + data.HP.ToString();
        visualsT.Find("TP_Panel").Find("TP").GetComponent <UnityEngine.UI.Text>().text = "TP: " + data.TP.ToString();
        visualsT.Find("MV_Panel").Find("MV").GetComponent <UnityEngine.UI.Text>().text = "MV: " + data.MV.ToString();

        //Card art
        Sprite cardArt = (Sprite)(Resources.Load("Cards/" + data.ID, typeof(Sprite)));

        if (cardArt == null)
        {
            cardArt = (Sprite)(Resources.Load("Cards/Card", typeof(Sprite)));
        }
        visualsT.Find("CardArt").GetComponent <UnityEngine.UI.Image>().sprite = cardArt;

        //Cost Markers
        Transform costPanel = visualsT.Find("Cost_Panel");

        UnityEngine.UI.Image[] costMarkers = new UnityEngine.UI.Image[7] {
            costPanel.Find("CM1").GetComponent <UnityEngine.UI.Image>(),
            costPanel.Find("CM2").GetComponent <UnityEngine.UI.Image>(),
            costPanel.Find("CM3").GetComponent <UnityEngine.UI.Image>(),
            costPanel.Find("CM4").GetComponent <UnityEngine.UI.Image>(),
            costPanel.Find("CM5").GetComponent <UnityEngine.UI.Image>(),
            costPanel.Find("CM6").GetComponent <UnityEngine.UI.Image>(),
            costPanel.Find("CM7").GetComponent <UnityEngine.UI.Image>()
        };
        for (int i = 0; i < data.Cost; i++)
        {
            costMarkers[i].color = new Color(1, 1, 0);
        }
        for (int i = data.Cost; i < 7; i++)
        {
            costMarkers[i].color = new Color(0.2f, 0.2f, 0.2f);
        }
    }
    public GameObject SetCardData(Card_Data pCardData)
    {
        GameObject tCard = CardFactory.SetCard(pCardData);

        return(tCard);
    }
Exemplo n.º 15
0
 public void SetCardData(Card_Data pCardData)
 {
     Card = pCardData;
     InitializeCard();
 }
Exemplo n.º 16
0
 void Awake()
 {
     ChargeHidden     = false;
     Card             = null;
     mMatchController = GameObject.Find("Match Controller").GetComponent <MatchController> ();
 }