Ejemplo n.º 1
0
    void HandlePlayer(int id)
    {
        SGCommand playerCommand = m_connection.ReceiveStream(id);

        if (playerCommand != null)
        {
            // Execute the command
            if (playerCommand.GetID() == SGCommandID.REFRESH_TIMEOUT)
            {
                m_playerTimeouts[id] = CONNECTION_TIMEOUT_LOOPS;
            }
            else
            {
                playerCommand.ExecuteCommand(m_cgManager);
                m_playerTimeouts[id]--;
            }
        }
        else
        {
            // Ask player for a no-timeout packet
            CGC_RefreshTimeout timeout = new CGC_RefreshTimeout(id);
            m_connection.TransmitStream(timeout.PackCommand(), id);
            m_playerTimeouts[id]--;
        }
    }
Ejemplo n.º 2
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);
    }