Example #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);
            }
        }
    }
Example #2
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);
            }
        }
    }
Example #3
0
    public static CGCommand CreateCommandFromPacket(BKSystem.IO.BitStream packet)
    {
        if (packet.Length < 0)
        {
            return(null);
        }

        ushort commandID;

        packet.Position = 0;
        packet.Read(out commandID, 0, 16);
        Debug.Log("Read packet with command ID: " + commandID);

        CGCommand command;

        switch (commandID)
        {
        case (ushort)CGCommandID.CAST_SPELL:
            command = new CGC_CastSpell(packet);
            break;

        case (ushort)CGCommandID.CHANNEL_SPELL:
            command = new CGC_ChannelSpell(packet);
            break;

        case (ushort)CGCommandID.MOVE_CARD_TO_GRAVEYARD:
            command = new CGC_MoveCardToGraveyard(packet);
            break;

        case (ushort)CGCommandID.OPPONENT_DRAW_CARD:
            command = new CGC_OpponentDrawCard(packet);
            break;

        case (ushort)CGCommandID.OPPONENT_PLAY_CARD_FROM_HAND:
            command = new CGC_OpponentPlayCardFromHand(packet);
            break;

        case (ushort)CGCommandID.PLAYER_DRAW_CARD:
            command = new CGC_PlayerDrawCard(packet);
            break;

        case (ushort)CGCommandID.PLAYER_PLAY_CARD_FROM_HAND:
            command = new CGC_PlayerPlayCardFromHand(packet);
            break;

        case (ushort)CGCommandID.SET_LIFE:
            command = new CGC_SetLife(packet);
            break;

        case (ushort)CGCommandID.WAIT_FOR_CAST_SELECTION:
            command = new CGC_WaitForCastSelection(packet);
            break;

        case (ushort)CGCommandID.WAIT_FOR_PLAY_FROM_HAND:
            command = new CGC_WaitForPlayFromHand(packet);
            break;

        case (ushort)CGCommandID.SET_PLAYER_ID:
            command = new CGC_SetPlayerID(packet);
            break;

        case (ushort)CGCommandID.PHASE_TRANSITION:
            command = new CGC_PhaseTransition(packet);
            break;

        case (ushort)CGCommandID.REQUEST_DECK:
            command = new CGC_RequestDeck(packet);
            break;

        case (ushort)CGCommandID.REFRESH_TIMEOUT:
            command = new CGC_RefreshTimeout(packet);
            break;

        default:
            command = null;
            break;
        }

        return(command);
    }