Пример #1
0
    public void ComboCardPolymery()
    {
        //combine the card
        if (CombineCardLeft.transform.childCount > 0 && CombineCardRight.transform.childCount > 0)
        {
            GameObject          left         = CombineCardLeft.transform.GetChild(0).gameObject;
            GameObject          right        = CombineCardRight.transform.GetChild(0).gameObject;
            ElementCardInstance leftElement  = left.GetComponent <ElementCardUIController>().GetCardInstance();
            ElementCardInstance rightElement = right.GetComponent <ElementCardUIController>().GetCardInstance();
            if (ultimate.IsCardPlayable(leftElement, rightElement))
            {
                Destroy(CombineCardRight.transform.GetChild(0).gameObject);
                Destroy(CombineCardLeft.transform.GetChild(0).gameObject);
                PlayerPrefs.SetInt("ComboCardPanelState", 0);
                DataManager.Instance.BattleContext.UltimateCard.Property = ultimate;
                comboCardUIController.SetVisible(false);
                this.SetVisible(false);
                HoverPreview.PreviewsAllowed = true;
                Cursor.SetCursor(TargetCurse, Vector2.zero, CursorMode.Auto);
            }
        }

        //remove highlight card from hand
        GameObject[] highLight = GameObject.FindGameObjectsWithTag("CardHighlight");
        foreach (GameObject obj in highLight)
        {
            if (obj.transform.parent.parent.parent.parent.tag == "Card")
            {
                ElementCardInstance card = obj.transform.parent.parent.parent.parent.GetComponent <ElementCardUIController>().GetCardInstance();
                DataManager.Instance.BattleContext.Player.HandheldSet.RemoveItem(card);
            }
        }
    }
Пример #2
0
    public void Cancel()
    {
        //return the uncombine card to the handheld
        if (CombineCardRight.transform.childCount > 0)
        {
            ElementCardInstance tempInstance = CombineCardRight.transform.GetChild(0).GetComponent <ElementCardUIController>().GetCardInstance();
            DataManager.Instance.BattleContext.Player.HandheldSet.AddItem(tempInstance);
            Destroy(CombineCardRight.transform.GetChild(0).gameObject);
        }

        if (CombineCardLeft.transform.childCount > 0)
        {
            ElementCardInstance tempInstance = CombineCardLeft.transform.GetChild(0).GetComponent <ElementCardUIController>().GetCardInstance();
            DataManager.Instance.BattleContext.Player.HandheldSet.AddItem(tempInstance);
            Destroy(CombineCardLeft.transform.GetChild(0).gameObject);
        }

        //setvisible
        PlayerPrefs.SetInt("ComboCardPanelState", 0);
        comboCardUIController.SetVisible(false);
        this.SetVisible(false);

        //remove highlight
        GameObject[] highLight = GameObject.FindGameObjectsWithTag("CardHighlight");
        foreach (GameObject obj in highLight)
        {
            obj.SetActive(false);
        }

        HoverPreview.PreviewsAllowed = true;
    }
Пример #3
0
    /* 讀取用戶卡組,轉換成卡牌物件*/
    public List <ElementCardInstance> LoadUserCards(int[] ids)
    {
        //讀取所有卡組
        List <ElementCardInstance> userCardList = new List <ElementCardInstance>();
        string path = Application.dataPath + Constants.CardJsonPath;

        if (File.Exists(path))
        {
            JBasicCardListRoot cardSet = JsonUtility.FromJson <JBasicCardListRoot>(File.ReadAllText(path));
            Debug.Log("Load Card data Success.");


            //組成Default咭組
            foreach (int cardID in ids)
            {
                foreach (JElementCardProperties cardData in cardSet.Cards)
                {
                    if (cardData.ID == cardID)
                    {
                        ElementCardInstance cardInstance = new ElementCardInstance(Constants.language_zh_tw, cardData);
                        userCardList.Add(cardInstance);
                    }
                }
            }
        }
        else
        {
            Debug.LogError("Failed to load cards. The card json path cannot be found.");
        }

        return(userCardList);
    }
Пример #4
0
    // Load Data
    public void Bind(ElementCardInstance card)
    {
        UnBind();

        this._elementCard = card;
        SetStar(this._elementCard.Cost.Property);
        SetTitle(this._elementCard.Title.Property);
        SetDescription(this._elementCard.Description.Property);

        Sprite cardBody = Resources.Load <Sprite>(Constants.CardImagePath + Path.DirectorySeparatorChar + this._elementCard.Image);

        if (null == cardBody)
        {
            Debug.Log("Unable to load resource: " + Constants.CardImagePath + Path.DirectorySeparatorChar + this._elementCard.Image);
        }
        SetCardBody(cardBody);

        //Sprite cardImage = Resources.Load<Sprite>(Constants.CardImagePath + Path.DirectorySeparatorChar + this._elementCard.Image);
        //if (null == cardBody) Debug.Log("Unable to load resource: " + Constants.CardImagePath + Path.DirectorySeparatorChar + this._elementCard.Image);
        SetCardImage(null);

        //register data change listener
        this._elementCard.Cost.AddListener(this);
        this._elementCard.Title.AddListener(this);
        this._elementCard.Description.AddListener(this);
    }
Пример #5
0
 private void UnBind()
 {
     if (null != this._elementCard)
     {
         this._elementCard.Cost.RemoveListener(this);
         this._elementCard.Title.RemoveListener(this);
         this._elementCard.Description.RemoveListener(this);
         this._elementCard = null;
     }
 }
Пример #6
0
    private void OnItemCard(ElementCardInstance card, Vector3 pos)
    {
        GameObject newCard = Instantiate(CardPrefab, pos, colObj.transform.localRotation) as GameObject;

        newCard.transform.localScale = new Vector3(CardScale, CardScale, 1);
        newCard.transform.SetParent(colObj.transform);
        ElementCardUIController controller = newCard.GetComponent <ElementCardUIController>();

        controller.Bind(card);
        DataManager.Instance.BattleContext.Player.HandheldSet.RemoveItem(card);
    }
Пример #7
0
    public bool IsCardPlayable(ElementCardInstance left, ElementCardInstance right)
    {
        if (left.Element.Equals(_jUltimateCardProperties.LeftCard.Element) && right.Element.Equals(_jUltimateCardProperties.RightCard.Element))
        {
            if (left.Cost.Property >= _jUltimateCardProperties.LeftCard.Cost && right.Cost.Property >= _jUltimateCardProperties.RightCard.Cost)
            {
                return(true);
            }
        }

        return(false);
    }
Пример #8
0
    void OnMouseUp()
    {
        //check col gameobject
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit[] hits = Physics.RaycastAll(ray);
        for (int i = 0; i < hits.Length; i++)
        {
            Debug.Log(hits[i].collider.name);
            if (hits[i].collider.tag == "CombineCard")
            {
                colObj  = hits[i].collider.gameObject;
                coltype = 3;
                break;
            }
            if (hits[i].collider.tag == "Monster")
            {
                colObj  = hits[i].collider.gameObject;
                coltype = 1;
                break;
            }
            if (hits[i].collider.tag == "Player")
            {
                colObj  = hits[i].collider.gameObject;
                coltype = 2;
                break;
            }
        }


        //if is combinecard
        if (coltype == 3)
        {
            ElementCardInstance card = this.GetComponent <ElementCardUIController>().GetCardInstance();

            //at the combineCard position instantiate this card
            Vector3 pos = new Vector3();


            if (colObj.name == "CombineCardRight")
            {
                if (GameObject.Find("CombineCardRight").transform.childCount > 0)
                {
                    ElementCardInstance tempInstance = GameObject.Find("CombineCardRight").transform.GetChild(0).GetComponent <ElementCardUIController>().GetCardInstance();
                    DataManager.Instance.BattleContext.Player.HandheldSet.AddItem(tempInstance);
                    Destroy(GameObject.Find("CombineCardRight").transform.GetChild(0).gameObject);
                }
                pos = CobineRightPos;
                OnItemCard(card, pos);
            }
            else
            {
                if (GameObject.Find("CombineCardLeft").transform.childCount > 0)
                {
                    ElementCardInstance tempInstance = GameObject.Find("CombineCardLeft").transform.GetChild(0).GetComponent <ElementCardUIController>().GetCardInstance();
                    DataManager.Instance.BattleContext.Player.HandheldSet.AddItem(tempInstance);
                    Destroy(GameObject.Find("CombineCardLeft").transform.GetChild(0).gameObject);
                }
                pos = CobineLeftPos;
                OnItemCard(card, pos);
            }
        }

        //if is player or monster, play effect
        if (coltype < 3 && PlayerPrefs.GetInt("ComboCardPanelState") != 1)
        {
            ElementCardPlayEvent playEvent = new ElementCardPlayEvent();
            playEvent.Card = this.GetComponent <ElementCardUIController>().GetCardInstance();
            Actor[] targetList = new Actor[1];
            if (colObj.tag == "Monster")
            {
                targetList[0] = colObj.GetComponent <MonsterUIController>().EnemyInstance;
            }
            if (colObj.tag == "Player")
            {
                targetList[0] = colObj.GetComponent <PlayerUIController>().PlayerInstance;
            }
            playEvent.Targets = targetList;
            EventManager.TriggerEvent(BattleManager.PLAY_ELEMENT_CARD, playEvent);
        }


        if (dragging)
        {
            dragging = false;
            HoverPreview.PreviewsAllowed = true;
            colObj  = null;
            coltype = 99;
            da.OnEndDrag();
        }
    }