Esempio n. 1
0
    // Functions
    public void DrawCards(int numCards)
    {
        Debug.Log("Drawing " + numCards + " cards");

        for (int i = 0; i < numCards; i++)
        {
            CGCardObject card = m_deck.GetTopCard();
            if (card == null)
            {
                // This player loses the game
                return;
            }

            m_hand.MoveCardToHere(card);

            // Create the 'card draw' client command
            if (m_ID == 0)
            {
                CGC_PlayerDrawCard command = new CGC_PlayerDrawCard(card.m_data, card.m_cardID);
                CGVisualManager.instance.AddCommand(command);
            }
            else
            {
                CGC_OpponentDrawCard command = new CGC_OpponentDrawCard();
                CGVisualManager.instance.AddCommand(command);
            }
        }
    }
Esempio n. 2
0
    public void PlayRandomCardFromHand()
    {
        CGCardObject card = m_hand.GetRandomPlayableCard();

        if (card != null)
        {
            card.PlayFromHand(this);

            if (m_ID == 0)
            {
                CGC_PlayerPlayCardFromHand command = new CGC_PlayerPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining());
                CGVisualManager.instance.AddCommand(command);
            }
            else
            {
                CGC_OpponentPlayCardFromHand command = new CGC_OpponentPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining());
                CGVisualManager.instance.AddCommand(command);
            }

            Debug.Log("Played card: " + card.m_cardName);

            // Add any "OnPlay" effect to the stack
            m_cgManager.AddEffectToStack(card.GetEffect(CGEffectType.ON_PLAY));
        }
    }
Esempio n. 3
0
 public void SetScriptData(CardData data, CardGameManager cgManager, CGCardObject card)
 {
     m_data       = data;
     m_cgManager  = cgManager;
     m_card       = card;
     m_attributes = m_data.cardAttributes;
 }
Esempio n. 4
0
    /** Create a spell from the card in the player's hand, adding any "OnPlay" effect to the stack */
    public void PlayCardFromHand(int cardID)
    {
        // Create a spell from the chosen card
        CGCardObject card = m_hand.GetCardWithID(cardID);

        if (card != null)
        {
            card.PlayFromHand(this);

            if (m_ID == 0)
            {
                CGC_PlayerPlayCardFromHand command = new CGC_PlayerPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining());
                m_cgManager.m_connection.TransmitStream(command.PackCommand(), 0);
                CGC_OpponentPlayCardFromHand oppCommand = new CGC_OpponentPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining());
                m_cgManager.m_connection.TransmitStream(oppCommand.PackCommand(), 1);
            }
            else
            {
                CGC_PlayerPlayCardFromHand command = new CGC_PlayerPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining());
                m_cgManager.m_connection.TransmitStream(command.PackCommand(), 1);
                CGC_OpponentPlayCardFromHand oppCommand = new CGC_OpponentPlayCardFromHand(card.m_data, card.m_cardID, card.GetTimeRemaining());
                m_cgManager.m_connection.TransmitStream(oppCommand.PackCommand(), 0);
            }

            Debug.Log("Played card: " + card.m_cardName);

            // Add any "OnPlay" effect to the stack
            m_cgManager.AddEffectToStack(card.GetEffect(CGEffectType.ON_PLAY));
        }
    }
Esempio n. 5
0
 void FizzleSpell(CGCardObject spell)
 {
     // CGC_FizzleSpell(spell.m_cardID);
     m_spellsCastThisTurn++;
     spell.Remove();
     ResolveStack();
 }
Esempio n. 6
0
    /************************
    ** DEFAULT BEHAVIOURS **
    ************************/

    /** Called when playing the card from hand to put the spell into play */
    public void PlayFromHand(CGCardObject card, CGPlayerLogic player)
    {
        m_owner = player;

        card.SetTimeRemaining(m_data.channelCost);
        player.m_spells.MoveCardToHere(card);
        m_cgManager.AddEffectToStack(OnPlay);
    }
Esempio n. 7
0
 protected bool IsCardASpell(CGCardObject card)
 {
     if (card.m_isSpell)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 8
0
 void CastSpell(CGCardObject spell)
 {
     spell.Cast();
     m_spellsCastThisTurn++;
     ResolveStack();
     spell.Remove();
     ResolveStack();
 }
Esempio n. 9
0
 public void Populate(CardData[] cards)
 {
     foreach (CardData data in cards)
     {
         CGCardObject card = new CGCardObject(data, m_cgManager, m_player);
         MoveCardToHere(card);
     }
     Shuffle();
 }
Esempio n. 10
0
 public CGCardObject GetTopCard()
 {
     if (m_cards.Count > 0)
     {
         CGCardObject card = m_cards[0];
         return(card);
     }
     return(null);
 }
Esempio n. 11
0
    public CGSpellObject(CGCardObject card, int playerID)
    {
        m_turnsRemaining = card.m_channelCost;
        m_card           = card;
        m_playerID       = playerID;

        m_spellID = m_allSpellIDs.Count;
        m_allSpellIDs.Add(m_spellID);
    }
Esempio n. 12
0
    public bool CanPlayCard(int cardID)
    {
        CGCardObject card = m_hand.GetCardWithID(cardID);

        if (card != null)
        {
            //if (CardGameManager.IsCardPlayable(card)
            return(true);
        }
        return(false);
    }
Esempio n. 13
0
 public override bool CheckValidTarget(CGCardObject thisCard, CGCardObject target)
 {
     if (IsCardASpell(target))
     {
         if (target.m_controller != thisCard.m_controller)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 14
0
    public void CastSpellFromChannel0(int spellCardID, int targetCardID)
    {
        // Ideally this would only listen to requests from the active player

        if (m_turnState == CGTurnState.WAIT_FOR_CAST_ORDER)
        {
            CGCardObject spell = m_activePlayer.GetSpell(spellCardID);
            if (spell == null)
            {
                Debug.LogError("Requested spell not found!");
                m_turnState = TellClientToCastSpell();
                return;
            }
            if (!spell.m_data.hasTargets)
            {
                // Cast spell with no targets
                CastSpell(spell);
            }
            else if (!SpellHasValidTargets(spell))
            {
                // Spell with no valid targets fizzles
                FizzleSpell(spell);
            }
            else if (IsTargetValid(spell, targetCardID))
            {
                // Cast spell with target
                CGCardObject target = FindCard(targetCardID);
                if (target != null)
                {
                    spell.SetTarget(target);
                }
                CastSpell(spell);
            }
            else
            {
                Debug.LogError("Requested spell not given valid target when at least one exists");
                m_turnState = TellClientToCastSpell();
                return;
            }

            // Spell has been cast, continue gameplay
            if (m_activePlayerID == 0)   // @TODO: Update this for multiplayer
            {
                m_turnState = TellClientToCastSpell();

                if (m_turnState == CGTurnState.ALL_SPELLS_CAST)
                {
                    RunGameLogic();
                }
            }
        }
    }
Esempio n. 15
0
    protected override void OnCardEnter(CGCardObject card)
    {
        if (card.m_isSpell)
        {
            m_cgManager.AddEffectToStack(card.GetEffect(CGEffectType.ON_REMOVE));
            m_cgManager.TriggerEvent("SpellRemoved");

            CGC_MoveCardToGraveyard command = new CGC_MoveCardToGraveyard(card.m_owner.m_ID, card.m_cardID);
            m_cgManager.m_connection.TransmitStream(command.PackCommand(), 0);
            m_cgManager.m_connection.TransmitStream(command.PackCommand(), 1);
        }
        card.SetIsSpell(false);
    }
Esempio n. 16
0
    public void MoveCardToHere(CGCardObject card)
    {
        if (card.m_currentZone != null)
        {
            // Remove the card from its last zone's list
            card.m_currentZone.MoveCardFromZone(card);
            card.m_currentZone.OnCardExit(card);
        }

        card.m_currentZone = this;
        // Add the card to this zone's list
        m_cards.Add(card);
        OnCardEnter(card);

        return;
    }
Esempio n. 17
0
    public CGCardObject RemoveCardWithID(int cardID)
    {
        int i = 0;

        foreach (CGCardObject card in m_cards)
        {
            if (card.m_cardID == cardID)
            {
                break;
            }
            i++;
        }

        CGCardObject removedCard = m_cards[i];

        m_cards.RemoveAt(i);

        return(removedCard);
    }
Esempio n. 18
0
    /*************
    * Targeting *
    *************/

    List <int> GetAllValidTargetsForSpell(CGCardObject spell)
    {
        List <int> targetIDs = new List <int>();

        // Check every card in every zone for targets

        int controllerID = spell.m_controller.m_ID;
        int opponentID   = (controllerID + 1) % 2;

        // Controller's hand
        foreach (CGCardObject target in m_players[controllerID].m_hand.m_cards)
        {
            if (target != spell && spell.m_script.CheckValidTarget(spell, target))
            {
                targetIDs.Add(target.m_cardID);
            }
        }

        // Controller's spells
        foreach (CGCardObject target in m_players[controllerID].m_spells.m_cards)
        {
            if (target != spell && spell.m_script.CheckValidTarget(spell, target))
            {
                targetIDs.Add(target.m_cardID);
            }
        }

        // Opponent's spells
        foreach (CGCardObject target in m_players[opponentID].m_spells.m_cards)
        {
            if (target != spell && spell.m_script.CheckValidTarget(spell, target))
            {
                targetIDs.Add(target.m_cardID);
            }
        }

        return(targetIDs);
    }
Esempio n. 19
0
    // Functions
    public void DrawCards(int numCards)
    {
        Debug.Log("Drawing " + numCards + " cards");

        for (int i = 0; i < numCards; i++)
        {
            CGCardObject card = m_deck.GetTopCard();
            if (card == null)
            {
                // This player loses the game
                return;
            }

            m_hand.MoveCardToHere(card);

            // Create the 'card draw' client command
            if (m_ID == 0)
            {
                // Tell player 0 what card they drew
                CGC_PlayerDrawCard command = new CGC_PlayerDrawCard(card.m_data, card.m_cardID);
                m_cgManager.m_connection.TransmitStream(command.PackCommand(), 0);
                // Tell player 1 that player 0 drew a card
                CGC_OpponentDrawCard oppCommand = new CGC_OpponentDrawCard();
                m_cgManager.m_connection.TransmitStream(oppCommand.PackCommand(), 1);
            }
            else
            {
                // Tell player 1 what card they drew
                CGC_PlayerDrawCard command = new CGC_PlayerDrawCard(card.m_data, card.m_cardID);
                m_cgManager.m_connection.TransmitStream(command.PackCommand(), 1);
                // Tell player 0 that player 1 drew a card
                CGC_OpponentDrawCard oppCommand = new CGC_OpponentDrawCard();
                m_cgManager.m_connection.TransmitStream(oppCommand.PackCommand(), 0);
            }
        }
    }
Esempio n. 20
0
 protected override void OnCardEnter(CGCardObject card)
 {
     card.SetIsSpell(true);
 }
Esempio n. 21
0
 public override bool CheckValidTarget(CGCardObject thisCard, CGCardObject target)
 {
     return(IsCardASpell(target));
 }
Esempio n. 22
0
 public void SetTarget(CGCardObject target)
 {
     m_script.SetTarget(target);
 }
Esempio n. 23
0
 public void AddCard(CGCardObject card)
 {
     m_cards.Add(card);
 }
Esempio n. 24
0
 /** A check on a given card, returning true if it is a valid target */
 public virtual bool CheckValidTarget(CGCardObject thisCard, CGCardObject target)
 {
     return(false);
 }
Esempio n. 25
0
 /** Called at the start of the "Channel phase" to decrease the time remaining on the spell */
 public void ChannelSpell(CGCardObject card)
 {
     card.DecreaseTimeRemaining(1);
     m_cgManager.AddEffectToStack(OnChannel);
 }
Esempio n. 26
0
 /** Called when the spell is to be removed from the board */
 public void RemoveSpell(CGCardObject card, CGPlayerLogic owner)
 {
     owner.m_graveyard.MoveCardToHere(card);
 }
Esempio n. 27
0
 public void CastSpell(CGCardObject card)
 {
     card.Cast();
 }
Esempio n. 28
0
 protected virtual void OnCardExit(CGCardObject card)
 {
 }
Esempio n. 29
0
 protected virtual void OnCardEnter(CGCardObject card)
 {
 }
Esempio n. 30
0
 /** Called when a card moves from this zone to remove it from the cards list */
 private void MoveCardFromZone(CGCardObject card)
 {
     m_cards.Remove(card);
 }