Ejemplo n.º 1
0
    // Playing element card
    private void OnElementCardPlayed(System.Object arg)
    {
        if (arg is ElementCardPlayEvent)
        {
            Debug.Log("on card played received");
            ElementCardPlayEvent playEvent = (ElementCardPlayEvent)arg;
            List <Actor>         targets   = new List <Actor>();
            if (null != playEvent.Targets)
            {
                targets.AddRange(playEvent.Targets);
            }
            else
            {
                //debug
                if (playEvent.Card.IsAgainstEnemy)
                {
                    if (playEvent.Card.IsAOE)
                    {
                        foreach (Actor actor in _battleContext.EnemyList.GetAll())
                        {
                            targets.Add(actor);
                        }
                    }
                    else
                    {
                        targets.Add(_battleContext.EnemyList.Get(0));
                    }
                }
                else
                {
                    targets.Add(_battleContext.Player);
                }
            }

            // 減少Power
            _battleContext.Player.Power.Property -= playEvent.Card.Cost.Property;

            // 使用卡牌
            playEvent.Card.Play(_battleContext.Player, targets, _battleContext);

            /*
             * // debug
             * _battleContext.PrintData();
             * foreach (Actor actor in _battleContext.ActorList.GetAll())
             * {
             *  actor.PrintData();
             * }*/

            _battleContext.Player.HandheldSet.RemoveItem(playEvent.Card);
            _battleContext.Player.Graveyard.AddItem(playEvent.Card);

            // 檢查角色HP值
            CheckGameEnded();
        }
    }
Ejemplo n.º 2
0
    public void TestCard()
    {
        BattleContext context = DataManager.Instance.BattleContext;

        if (null != context && context.Player.Power.Property >= _elementCard.Cost.Property)
        {
            Debug.Log("testing card");
            ElementCardPlayEvent cardEvent = new ElementCardPlayEvent();
            cardEvent.Card    = _elementCard;
            cardEvent.Targets = null;
            EventManager.TriggerEvent(BattleManager.PLAY_ELEMENT_CARD, cardEvent);
        }
    }
Ejemplo n.º 3
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();
        }
    }