예제 #1
0
    protected override void OnTransformChildrenChanged()
    {
        base.OnTransformChildrenChanged();

        //print("New Card Position: " + newCardPosition);

        //Check if a card was added to the Zone
        bool hasNewChild = false;

        if (transform.childCount > childCount)
        {
            hasNewChild = true;
        }
        childCount = transform.childCount;

        //CardGO cardGO = (newCardPosition == -1) ? zone.Cards[zone.Cards.Count - 1] : zone.Cards[newCardPosition];
        CardGO cardGO = null;

        if (hasNewChild) //If a card was added, get that card
        {
            if (newCardPosition == -1)
            {
                if (zone.Cards.Count >= 1)
                {
                    cardGO = zone.Cards[zone.Cards.Count - 1];
                }
                else
                {
                    cardGO = zone.Cards[0];
                }
            }
            else
            {
                cardGO = zone.Cards[newCardPosition];
            }
            print("New Card: " + cardGO + " in Zone: " + zone);
        }
        if (zone.Type == Zone.Types.Hand)
        {
            if (zone.Cards.Count > Zone.MAX_CARDS_HAND)
            {
                float width     = 40 * Zone.MAX_CARDS_HAND; //GetComponent<RectTransform>().rect.width;
                float cardAlloc = width / (zone.Cards.Count);
                spacing = cardAlloc - 35.66666f;            // + ((Cards.Count - MAX_CARDS_HAND) * 0.25f);
            }
            //
            if (hasNewChild)
            {
                cardGO.ApplyEffects(zone, false);
            }
        }
        else if (zone.Type == Zone.Types.Melee || zone.Type == Zone.Types.Ranged ||
                 zone.Type == Zone.Types.Siege)
        {
            if (zone.Cards.Count > Zone.MAX_CARDS_BATTLEFIELD)
            {
                float width     = 40 * Zone.MAX_CARDS_BATTLEFIELD; //GetComponent<RectTransform>().rect.width;
                float cardAlloc = width / (zone.Cards.Count);
                spacing = cardAlloc - 40f;                         // + ((Cards.Count - MAX_CARDS_HAND) * 0.25f);
            }
            if (hasNewChild)
            {
                ApplyAllCardEffects();
            }
            //if (ability != Card.Abilities.Avenger)
            //Trigger card ability
        }
        else if (zone.Type == Zone.Types.Discard)
        {
            //trigger Avenger ability
            CardGO go = zone.Cards[zone.Cards.Count - 1];
            if (go.Card.Ability == Card.Abilities.Avenger)
            {
                print("Avenger on " + go.Card.Name);
            }
        }

        newCardPosition = -1;
    }
예제 #2
0
    public override void OnPointerClick(PointerEventData eventData)
    {
        base.OnPointerClick(eventData);

        if (eventData.button == PointerEventData.InputButton.Left)
        {
            if (Highlighted)
            {
                //If no card is selected, select this one
                if (selectedCard == null)
                {
                    Select(this);
                }
                //If this card is already selected, deselect it then unhighlight all selected zones
                else if (IsSelectedCard)
                {
                    if (specialHighlight.Count != 0)
                    {
                        UnHighlightAllSpecial();
                    }
                    Select(null);
                }
                //If another card (in the player's hand) is already selected,
                //deselect that one and select this one
                else
                {
                    if (specialHighlight.Count != 0)
                    {
                        UnHighlightAllSpecial();
                    }
                    Deselect(SelectedCard);
                    Select(this);
                }

                if (IsSelectedCard) //card is being selected
                {
                    Card c = cardGO.Card;
                    //print(GetComponent<CardGO>().InZone);


                    //highlight zones depending on who's turn it is
                    //if it's a spy, reverse
                    //TODO
                    //add enum for P1, P2, and Both (for scorch special cards)
                    bool highlightPlayerOne;
                    if (!c.Special)
                    {
                        if (((UnitCard)c).Ability == Card.Abilities.Spy)
                        {
                            highlightPlayerOne = (Manager.manager.PlayerOnesTurn) ? false : true;
                        }
                        else
                        {
                            highlightPlayerOne = (Manager.manager.PlayerOnesTurn) ? true : false;
                        }
                    }
                    else
                    {
                        highlightPlayerOne = (Manager.manager.PlayerOnesTurn) ? true : false;
                    }

                    //Highlight relevant Zone(s) for Card c
                    Manager.manager.HighlightNewZone(cardGO.Card, highlightPlayerOne);
                    //UnHighlight(this);
                }
                else //card is being deselected
                {
                    Highlight(this);
                }
            }
            else if (SpecialHighlighted)
            {
                if (SelectedCard.cardGO.Card.Ability == Card.Abilities.Decoy)
                {
                    print("DECOY: " + gameObject.name);
                    //play the decoy card in this card's slot, and return this card to hand

                    //print(cardGO.Zone.Cards.IndexOf(cardGO) + ", " + cardGO.Zone.Cards.Count);
                    int index = cardGO.Zone.Cards.IndexOf(cardGO);
                    SelectedCard.cardGO.MoveTo(cardGO.Zone, index);
                    SelectedCard.transform.SetSiblingIndex(index);
                    Battlefield old = (Battlefield)cardGO.Zone;
                    cardGO.ApplyEffects(old, false);
                    ((UnitCard)cardGO.Card).CalcStats(old, cardGO, false);
                    cardGO.MoveTo(Manager.manager.GetZone(Zone.Types.Hand));
                    StartCoroutine(old.RecalcStatsAtEndOfFrame());
                    //reset card effects
                    UnHighlightAllSpecial();
                    Deselect(this);
                }
            }
        }
        else if (eventData.button == PointerEventData.InputButton.Right)
        {
            //display big version of card.
            //set examiningCard = true;
            //lock out highlighting/selecting cards
        }
    }