示例#1
0
    public void CreateCard(ActionCardData data, bool isEmergency = false)
    {
        if (data.Location == LocationType.Null)
        {
            Debug.LogWarning($"Wrong {nameof(LocationType)} passed to {nameof(CreateCard)}");
            return;
        }

        var cardController = DrawCard(data, isEmergency);

        cardController.OnClick += () => {
            if (!Operatable || GameMaster.Instance.IsGameOver)
            {
                return;
            }

            if (data.Cost)
            {
                StatusManager.Instance.ApplyStatusChange(data.Cost);
            }

            foreach (var ev in data.TriggerEvents)
            {
                ProcessEvent(ev);
            }
        };
    }
示例#2
0
    // This method create a card on the scene during the runtime
    // The card will be initialize with the id took from the deck.
    public void InstantiateActionCard()
    {
        int PlayerAction = Player.GetPlayerAction();

        if (PlayerTurn1 == true && PlayerAction > 0)
        {
            int nbCardsDeck = currentActionDeck.ActionCardsList.Count;

            if (nbCardsDeck > 0)
            {
                GameObject newCard = Instantiate(cardPrefab, handPlayer.transform.position, handPlayer.transform.rotation);

                int index = (int)(Random.value * nbCardsDeck);

                ActionCardData myCard = currentActionDeck.ActionCardsList[index];
                currentActionDeck.ActionCardsList.Remove(myCard);

                var script = newCard.GetComponent <DisplayActionCard>();
                script.card = myCard;

                var scriptDrag = newCard.GetComponent <Drag>();
                scriptDrag.typeOfAction     = (Drag.Action)myCard.TypeOfAction;
                scriptDrag.parentToReturnTo = handPlayer.transform;

                newCard.transform.SetParent(handPlayer.transform);
                Player.SpendAction();
            }

            numberCardText.text = "Deck Action : " + currentActionDeck.ActionCardsList.Count.ToString() + " cartes";
        }
    }
 public bool Verif(ActionCardData c)
 {
     int nb = 0;
     bool test = true;
     foreach (ActionCardData card in myDeck.ActionCardsList)
     {
         if (card.Id == myCard.Id)
         {
             nb++;
         }
     }
     if (nb == 3)
     {
         test = false;
     }
     return test;
 }
示例#4
0
    public void Update()
    {
        if (i > myActionDeck.ActionCardsList.Count)
        {
            i = 0;
        }

        if (i < myActionDeck.ActionCardsList.Count)
        {
            GameObject copy = Instantiate(myTemplate);
            //On copy itemTemplate qui est un bouton

            //on transform le content pour y ajouter le bouton  // copy.transform.parent = content.transform; Vielle Version

            copy.transform.SetParent(myContent.transform);

            ActionCardData c = myActionDeck.ActionCardsList[i];
            copy.GetComponentInChildren <Text>().text = c.Name;

            copy.GetComponentInChildren <Image>().sprite = c.Artwork;
            int copyIndex = i;
            copy.GetComponent <Button>().onClick.AddListener(

                () =>
            {
                ActionCardData d = myActionDeck.ActionCardsList[copyIndex];
                myActionDeck.ActionCardsList.Remove(d);
                Destroy(copy);

                //On detruit tous les boutons puis on recommence la liste à 0 pour faire basculer les id.
                foreach (Transform child in myContent.transform)
                {
                    GameObject.Destroy(child.gameObject);
                }
                i = 0;
            }
                );
            i++;
        }
        myNumberCards.text = myActionDeck.ActionCardsList.Count + "/15";
    }
示例#5
0
    private CardController DrawCard(ActionCardData data, bool isEmergency)
    {
        var panel           = _dicLocationPanel[data.Location];
        var pos             = _dicRefPos[$"{panel}CardRefPos"].position;
        var parentTransform = _dicRefPos[$"{panel}CardContainer"];
        var cardIndex       = _listActionCards.Count;

        pos += new Vector3(0f, -Config.CardVerticalStep * cardIndex, 0f);

        var newCard        = Instantiate(CardPrefab, pos, Quaternion.identity, parentTransform);
        var cardController = newCard.GetComponent <CardController>();

        cardController.DetailOffset      = new Vector2(0f, 100f);
        cardController.name              = data.name;
        cardController.BelongingLocation = data.Location;
        cardController.PinPos            = pos;
        cardController.GetComponentInChildren <TextMeshProUGUI>().text = data.Name;
        _listActionCards.Add(cardController);

        return(cardController);
    }
示例#6
0
    public void DeleteCard(ActionCardData data)
    {
        CardController toRemove = null;

        foreach (var card in _listActionCards)
        {
            if (card.name == data.name)
            {
                toRemove = card;
            }
        }

        Debug.Log($"To remove : {toRemove}");

        if (!toRemove)
        {
            return;
        }
        OnCardDestroyed?.Invoke(toRemove);
        _listActionCards.Remove(toRemove);
        Destroy(toRemove.gameObject);
    }
示例#7
0
    void SetupIcon()
    {
        CardViewData viewData = Resources.Load("Card Icons Data/" + actionCard.owner.staticData.characterName + "/" + actionCard.data.cardName) as CardViewData;

        iconRenderer.material.mainTexture = viewData.iconTexture;

        DamageTypeTextureData damageTypeData = Resources.Load("Damage Type Data") as DamageTypeTextureData;

        ActionCardData data = actionCard.data;

        if (data.isPositive)
        {
            if (data.damageValues[(int)ParameterType.ManaPoints] > 0)
            {
                cardRenderer.material.mainTexture = damageTypeData.healingMP;
            }
            else if (data.damageValues[(int)ParameterType.PowerPoints] > 0)
            {
                cardRenderer.material.mainTexture = damageTypeData.healingSP;
            }
            else
            {
                cardRenderer.material.mainTexture = damageTypeData.healing;
            }
        }
        else
        {
            if (data.damageValues[(int)ParameterType.PowerPoints] > 0)
            {
                cardRenderer.material.mainTexture = damageTypeData.damagingSP;
            }
            else
            {
                cardRenderer.material.mainTexture = damageTypeData.damaging;
            }
        }

//		damageTypeData
    }
示例#8
0
    public void Start()
    {
        currentActionDeck.ActionCardsList = new List <ActionCardData>();

        playerActionDeck.text = PlayerPrefs.GetString("ActionDeck");
        Debug.Log(playerActionDeck.text);

        string path = Application.persistentDataPath + "/" + playerActionDeck.text + ".json";
        // string path = Application.persistentDataPath + "/deck.json";
        //On lit tout le fichier json
        string contents = System.IO.File.ReadAllText(path);

        //On recupère les objets dans le fichier .json à l'aide de la classe JsonHelper et on les stocks dans un Array de Card
        string[] card = JsonHelper.FromJson <string>(contents);

        for (int i = 0; i < card.Length; i++)
        {
            ActionCardData c = myDataBase.Get(card[i]);
            currentActionDeck.ActionCardsList.Add(c);
        }

        numberCardText.text = "Deck Action : " + currentActionDeck.ActionCardsList.Count.ToString() + " cartes";
    }
示例#9
0
    // Update is called once per frame
    void Update()
    {
        if (i < myDecksList.myActionDecks.Count)
        {
            GameObject copy    = Instantiate(itemTemplate);
            GameObject copydel = Instantiate(itemTemplate2);

            //On copy itemTemplate qui est un bouton

            //on transform le content pour y ajouter le bouton  // copy.transform.parent = content.transform; Vielle Version

            copy.transform.SetParent(content.transform);
            copydel.transform.SetParent(content.transform);

            string s = myDecksList.myActionDecks[i];
            copy.GetComponentInChildren <Text>().text = s;
            int copyIndex = i;

            copydel.GetComponent <Button>().onClick.AddListener(

                () =>
            {
                string path = Application.persistentDataPath + "/" + myDecksList.myActionDecks[copyIndex] + ".json";

                // On retire l'élement de la liste
                myDecksList.myActionDecks.Remove(myDecksList.myActionDecks[copyIndex]);
                // On supprime le fichier ayant pour nom liste.deckls[copyIndex]
                File.Delete(path);
                //On détruit tous les boutons dans content puis on fait recommencer i à 0 pour qu'il recharge la liste avec les nouveaux id;
                foreach (Transform child in content.transform)
                {
                    GameObject.Destroy(child.gameObject);
                }
                i = 0;


                // sauvegarde

                string[] fis;

                fis = new string[myDecksList.myActionDecks.Count];

                int j = 0;
                foreach (string str in myDecksList.myActionDecks)
                {
                    fis[j] = str;
                    j++;
                }

                string fi = JsonHelper.ToJson(fis, true);
                path      = Application.persistentDataPath + "/dataActionDecks.json";
                System.IO.File.WriteAllText(path, fi);
            }

                );



            copy.GetComponent <Button>().onClick.AddListener(

                () =>
            {
                myDeck.ActionCardsList.Clear();

                string d = myDecksList.myActionDecks[copyIndex];
                copy.GetComponentInChildren <Text>().text = d;
                nameDeck.text = d.Replace("_Action", "");

                string path = Application.persistentDataPath + "/" + d + ".json";
                // string path = Application.persistentDataPath + "/deck.json";
                //On lit tout le fichier json
                string contents = System.IO.File.ReadAllText(path);

                //On recupère les objets dans le fichier .json à l'aide de la classe JsonHelper et on les stocks dans un Array de Card
                string[] card = JsonHelper.FromJson <string>(contents);

                for (int i = 0; i < card.Length; i++)
                {
                    ActionCardData c = myDataBase.Get(card[i]);
                    Debug.Log(c.name);
                    myDeck.ActionCardsList.Add(c);
                }
            }
                );
            i++;
        }
    }