Пример #1
0
 private void Start()
 {
     if (cardGO == null)
     {
         cardGO = GetComponent <CardGO>();
     }
     specialHighlight = new List <CardEventTrigger>();
 }
Пример #2
0
 public void AddCard(CardGO cardGO)
 {
     if (Cards == null)
     {
         Cards = new List <CardGO>();
     }
     Cards.Add(cardGO);
     //cardGO.transform.SetParent(transform);
 }
Пример #3
0
 public bool checkForDuplicateCardGO(CardGO cardGO)
 {
     for (int i = 0; i < cards.Count; i++)
     {
         if (cards [i].IsActive)
         {
             if (cards [i].parentCard == cardGO.parentCard && cards [i] != cardGO)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #4
0
    public CardGO getCardGO()
    {
        //check if we have any inactive in the list
        for (int i = 0; i < cards.Count; i++)
        {
            if (cards [i].IsActive == false)
            {
                return(cards [i]);
            }
        }

        //otherwise make one
        GameObject obj = Instantiate(cardPrefab) as GameObject;
        CardGO     GO  = obj.GetComponent <CardGO> ();

        cards.Add(GO);
        return(GO);
    }
Пример #5
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;
    }
Пример #6
0
    public void OnPointerClick(PointerEventData eventData)
    {
        if (Highlighted)
        {
            print("CLICK: " + gameObject + " CARD: " + CardEventTrigger.SelectedCard);
            //play selected card
            CardGO cardGO = CardEventTrigger.SelectedCard.GetComponent <CardGO>();

            if (cardGO.Card.Ability == Card.Abilities.Scorch)
            {
                if (cardGO.Card.Special)
                {
                    //scorch highest str card(s)
                    Zone[] zones = new Zone[] {
                        Manager.manager.GetZone(Zone.Types.Melee),
                        Manager.manager.GetZone(Zone.Types.Ranged),
                        Manager.manager.GetZone(Zone.Types.Siege),
                        Manager.manager.GetZone(Zone.Types.Melee, false),
                        Manager.manager.GetZone(Zone.Types.Ranged, false),
                        Manager.manager.GetZone(Zone.Types.Siege, false)
                    };

                    /*
                     * List<CardGO> strongest = new List<CardGO>();
                     * foreach (Zone zone in zones)
                     * {
                     *  foreach (CardGO c in zone.Cards)
                     *  {
                     *      if (!c.Card.Special && !((UnitCard)c.Card).Hero)
                     *      {
                     *          if (strongest.Count == 0)
                     *              strongest.Add(c);
                     *          else if (((UnitCard)c.Card).Strength > ((UnitCard)strongest[0].Card).Strength)
                     *          {
                     *              strongest.Clear();
                     *              strongest.Add(c);
                     *          }
                     *          else if (((UnitCard)c.Card).Strength == ((UnitCard)strongest[0].Card).Strength)
                     *              strongest.Add(c);
                     *      }
                     *  }
                     * }
                     * //move strongest to discard
                     * foreach (CardGO go in strongest)
                     * {
                     *  go.Discard();
                     *  print(go.name);
                     * }
                     */
                    ScorchZone(zones);
                }
                else
                {
                    //scorch highest str card(s) in opponents zone
                }
            }
            //else if (cardGO.Card.Ability == Card.Abilities.Bond)

            CardEventTrigger.UnHighlight(CardEventTrigger.SelectedCard.GetComponent <CardEventTrigger>());
            Zone z = GetComponent <Zone>();
            if (cardGO.Card.Ability == Card.Abilities.Bond && z.Cards.Count > 0)
            {
                for (int i = 0; i < z.Cards.Count; i++)
                {
                    if (z.Cards[i].Card.Name == cardGO.Card.Name)
                    {
                        cardGO.MoveTo(z, z.Cards.IndexOf(z.Cards[i]));
                        break;
                    }
                    else if (i == z.Cards.Count - 1)
                    {
                        cardGO.MoveTo(z);
                    }
                }
            }
            else
            {
                cardGO.MoveTo(z);
            }
            Manager.manager.UnHighlightZones();
            if (z.Type == Zone.Types.Melee || z.Type == Zone.Types.Ranged || z.Type == Zone.Types.Siege)
            {
                ((Battlefield)z).RecalcStatsAtEndOfFrame();
            }
            else if (z.Type == Zone.Types.Horn)
            {
                ((HornZone)z).SpecialHorn = cardGO;
                //recalc stats for associated battlefield
                StartCoroutine(((HornZone)z).Battlefield.RecalcStatsAtEndOfFrame());
            }

            //if Cards.count > MAX_CARDS_WITHOUT_OVERLAP
            //change layout group spacing by -10 * (Cards.Count - MAX_CARDS_WITHOUT_OVERLAP)
            //GetComponent<HorizontalLayoutGroup>().spacing = z.RecalcSpacing();
            CardEventTrigger.Deselect(CardEventTrigger.SelectedCard);
        }
    }
Пример #7
0
    public void CalcStats(Battlefield bf, CardGO cardGO, bool apply = true)
    {
        if (!apply)
        {
            Strength = GetBaseStrength();
            ClearBonds();
            Morale = 0;
            Horn   = false;
            cardGO.GetComponent <CardGO>().UpdateStrengthText();
        }
        else if (!Hero)
        {
            //1. apply Weather effects
            if (bf.Weather)
            {
                Strength = 1;
            }
            else
            {
                Strength = GetBaseStrength();
            }
            //2. apply Bond effects
            if (Ability == Abilities.Bond)
            {
                ClearBonds();
                int index     = bf.Cards.IndexOf(cardGO);
                int tempindex = -1;
                while (index + tempindex >= 0 &&
                       bf.Cards[index + tempindex].GetComponent <CardGO>().Card.Name == cardGO.Card.Name)
                {
                    AddBond();
                    tempindex--;
                }

                tempindex = 1;
                while (index + tempindex <= bf.Cards.Count - 1 &&
                       bf.Cards[index + tempindex].GetComponent <CardGO>().Card.Name == cardGO.Card.Name)
                {
                    AddBond();
                    tempindex++;
                }

                for (int i = 0; i < Bond; i++)
                {
                    Strength += GetBaseStrength();
                }
            }
            //3. apply Morale effects
            if (bf.Morale > 0 && Ability != Abilities.Morale)
            {
                Morale    = bf.Morale;
                Strength += Morale;
            }
            else if (bf.Morale > 1 && Ability == Abilities.Morale)
            {
                Morale    = bf.Morale;
                Strength += Morale - 1;
            }
            //4.1 apply Horn effect from Horn unit cards
            Horn = false;
            if (bf.ZoneHorn.HasHorn)
            {
                HornZone hz = bf.ZoneHorn;
                if (hz.SpecialHorn != null)
                {
                    Strength += Strength;
                    Horn      = true;
                }
                //check to see this card is not doubling itself
                else if ((Ability == Abilities.Horn && hz.UnitHorns.Count > 1) ||
                         (Ability != Abilities.Horn && hz.UnitHorns.Count > 0))
                {
                    Strength += Strength;
                    Horn      = true;
                }
            }
            //update Strength text
            cardGO.GetComponent <CardGO>().UpdateStrengthText();
        }
    }
Пример #8
0
 private void Reset()
 {
     cardGO = GetComponent <CardGO>();
 }
Пример #9
0
    void Start()
    {
        if (manager == null)
        {
            DontDestroyOnLoad(gameObject);
            manager = this;
        }
        else
        {
            Destroy(gameObject);
        }
        TextAssets         = Resources.LoadAll <TextAsset>("Factions/");
        FactionGameObjects = new List <GameObject>();

        GameObject UnitPrefab    = Resources.Load <GameObject>("Prefabs/UnitPrefab");
        GameObject HeroPrefab    = Resources.Load <GameObject>("Prefabs/HeroPrefab");
        GameObject SpecialPrefab = Resources.Load <GameObject>("Prefabs/SpecialPrefab");

        foreach (TextAsset t in TextAssets)
        {
            List <GameObject> g = TextParsing.ParseText(t.text);
            for (int i = 0; i < 1; i++)
            {
                foreach (GameObject go in g)
                {
                    FactionGameObjects.Add(go);
                    Faction f = go.GetComponent <Faction>();
                    foreach (Card c in f.Cards)
                    {
                        GameObject wrapper;
                        GameObject wrapper2;
                        if (c.Special)
                        {
                            //instantiate special prefab
                            wrapper  = Instantiate(SpecialPrefab, player1Half.Deck.transform);
                            wrapper2 = Instantiate(SpecialPrefab, player2Half.Deck.transform);
                        }
                        else if (((UnitCard)c).Hero)
                        {
                            //instantiate hero prefab
                            wrapper  = Instantiate(HeroPrefab, player1Half.Deck.transform);
                            wrapper2 = Instantiate(HeroPrefab, player2Half.Deck.transform);
                        }
                        else //regular unit
                        {
                            //instantiate unit prefab
                            wrapper  = Instantiate(UnitPrefab, player1Half.Deck.transform);
                            wrapper2 = Instantiate(UnitPrefab, player2Half.Deck.transform);
                        }
                        //CardGO wrapper = new GameObject().AddComponent<CardGO>();
                        CardGO cardGO  = wrapper.GetComponent <CardGO>();
                        CardGO cardGO2 = wrapper2.GetComponent <CardGO>();
                        cardGO.SetCard(c);
                        cardGO2.SetCard(c);
                        //RectTransform rect = wrapper.GetComponent<RectTransform>();
                        //rect.pivot = new Vector2(0.5f, 0.5f);
                        //rect.anchoredPosition = new Vector2(0.5f, 0.5f);
                        //rect.offsetMax = new Vector2(0.5f, 0.5f);
                        //rect.offsetMin = new Vector2(0.5f, 0.5f);
                        //rect.position = Vector2.zero;
                        player1Half.Deck.AddCard(cardGO);
                        player2Half.Deck.AddCard(cardGO2);
                        wrapper.SetActive(false);
                        wrapper2.SetActive(false);
                    }
                    Faction.CloneTo(f, gameObject);
                }
            }
            foreach (GameObject go in g)
            {
                Destroy(go);
            }
        }

        int[] deck = new int[] { 1, 3, 6, 9, 10, 14, 18, 11, 11, 12, 12, 13,
                                 100, 101, 101, 102, 102, 102, 103, 103, 106, 107, 108, 109, 119, 121, 122, 122 };

        //PlayerOnesTurn = (Random.Range(0, 2) == 1) ? true : false;
        PlayerOnesTurn = true;


        //set up board
        InitialiseZone(player1Half, true);
        InitialiseZone(player2Half, false);
        weather.Type      = Zone.Types.Weather;
        weather.VisibleTo = Zone.IsVisibleTo.Both;
        highlightedZones  = new List <Zone>();

        StartCoroutine(DrawCards());
    }