Пример #1
0
    private void RPC_MasterDealCardToPlayer(string rank, string suit, string playerId)
    {
        CardSerializer datas = new CardSerializer(rank, suit);

        Card card = new Card(datas);

        PlayerCards playerCards = PlayerFunctions.GetPlayer(playerId, dataManager.GetPlayerFromPlayerCards()); //GetPlayer(playerId);

        playerCards.AddCards(card);

        Debug.Log("Using this RPC");

        // Set next turn
        playerCards.UnSetTurn();

        Player nextPlayer = playerCards.player.GetNext();

        PlayerCards nextPlayerPlayerCards = PlayerFunctions.GetPlayer(nextPlayer.NickName, dataManager.GetPlayerFromPlayerCards());

        nextPlayerPlayerCards.SetToTurn();
        // End set turn

        card = PlayerFunctions.GetSameCard(card, GetAllCards());

        dataManager.RemoveCardsFromAllCards(card);

        CardAnimator.GetComponent <CardAnimator>().AddCardToPlayerDeck(card, playerId);

        // show animation for market
        CardAnimator.GetComponent <CardAnimator>().ShowNextPlayerGeneric(nextPlayer.NickName + " plays next");
    }
Пример #2
0
    public static object Deserialize(byte[] bytes)
    {
        CardSerializer data = new CardSerializer();

        //RANK.
        byte[] RankBytes = new byte[4];

        Array.Copy(bytes, 0, RankBytes, 0, RankBytes.Length);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(RankBytes);
        }
        data.Rank = Encoding.UTF8.GetString(RankBytes);


        //SUIT.
        byte[] SuitBytes = new byte[bytes.Length - 4];

        if (SuitBytes.Length > 0)
        {
            Array.Copy(bytes, 4, SuitBytes, 0, SuitBytes.Length);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(SuitBytes);
            }
            data.Suit = Encoding.UTF8.GetString(SuitBytes);
        }
        else
        {
            data.Suit = string.Empty;
        }

        return(data);
    }
Пример #3
0
    private void RPC_PlayCard(string rank, string suit, string playerId)
    {
        CardSerializer datas = new CardSerializer(rank, suit);

        Card card = new Card(datas);

        PlayerCards playerCards = PlayerFunctions.GetPlayer(playerId, dataManager.GetPlayerFromPlayerCards());

        List <Card> allCards = playerCards.GetAllCards();

        // Set next turn
        playerCards.UnSetTurn();

        Player nextPlayer = playerCards.player.GetNext();

        PlayerCards nextPlayerPlayerCards = PlayerFunctions.GetPlayer(nextPlayer.NickName, dataManager.GetPlayerFromPlayerCards());

        card = PlayerFunctions.GetSameCard(card, allCards);

        dataManager.AddCardsToPlayingDeck(card);

        playerCards.RemoveCards(card);

        CardAnimator.GetComponent <CardAnimator>().AddCardtoPlayingDeck(card, playerId);

        CarryCardActionAsync(card, playerCards.player);
    }
Пример #4
0
    public void DealACard(string playerId)
    {
        Card           card  = cardFunctions.PickSingleCard(dataManager);
        CardSerializer datas = card.ConvertCardToCardSerializer();

        photonView.RPC("RPC_MasterDealCard", RpcTarget.AllBuffered, datas.Rank, datas.Suit, playerId);
    }
Пример #5
0
    public void DealCardToPlayer(Card card, string playerId)
    {
        CardSerializer datas = card.ConvertCardToCardSerializer();

        RPC_Manager.DealCardToPlayer(datas, playerId);

        //photonView.RPC("RPC_DealCardToPlayer", RpcTarget.AllBuffered, datas.Rank, datas.Suit, playerId);
    }
Пример #6
0
        public void CardData_SerializationWorksBothWays()
        {
            var json = CardSerializer.SerializeCardData(cardData);

            var cardData2 = CardSerializer.DeserializeCardJson(json);

            Assert.AreEqual(cardData.GetHashCode(), cardData2.GetHashCode());
        }
Пример #7
0
    public void InitilizeAllCards()
    {
        CardSerializer datas = cardFunctions.PickSingleCard(dataManager).ConvertCardToCardSerializer();

        RPC_Manager.SetPlayinCard(datas);

        //photonView.RPC("RPC_SetPlayinCard", RpcTarget.AllBuffered, datas.Rank, datas.Suit);
    }
Пример #8
0
    private void RPC_SetPlayinCard(string rank, string suit)
    {
        CardSerializer datas = new CardSerializer(rank, suit);

        Card card = new Card(datas);

        dataManager.AddCardsToPlayingDeck(card);

        card = PlayerFunctions.GetSameCard(card, GetAllCards());

        dataManager.RemoveCardsFromAllCards(card);
    }
Пример #9
0
    private void SetAllPlayersAllCards()
    {
        List <Card> InstalizedCards = cardFunctions.InitializeCards();

        foreach (Card card in InstalizedCards)
        {
            CardSerializer datas = card.ConvertCardToCardSerializer();

            RPC_Manager.SetAllPlayerAllCards(datas);

            //photonView.RPC("RPC_SetAllPlayerAllCards", RpcTarget.AllBuffered, datas.Rank, datas.Suit);
        }
    }
Пример #10
0
    private void RPC_DealCardToPlayer(string rank, string suit, string playerId)
    {
        CardSerializer datas = new CardSerializer(rank, suit);

        PlayerCards playerCards = PlayerFunctions.GetPlayer(playerId, GetAllPlayerCards());

        Card card = new Card(datas);

        playerCards.AddCards(card);

        card = PlayerFunctions.GetSameCard(card, playerCards.GetAllCards());

        dataManager.RemoveCardsFromAllCards(card);
    }
Пример #11
0
 public GameManagementService(
     RandomGenerator randomGenerator,
     DeckService deckService,
     MainDbContext context,
     CardSerializer cardSerializer,
     Mapper mapper,
     ITransactionManager transactionManager
     )
 {
     _context            = context;
     _randomGenerator    = randomGenerator;
     _deckService        = deckService;
     _cardSerializer     = cardSerializer;
     _mapper             = mapper;
     _transactionManager = transactionManager;
 }
Пример #12
0
    private void RPC_PlayCard(string rank, string suit, string playerId)
    {
        CardSerializer datas = new CardSerializer(rank, suit);

        Card card = new Card(datas);

        PlayerCards playerCards = PlayerFunctions.GetPlayer(playerId, dataManager.GetPlayerFromPlayerCards());

        card = PlayerFunctions.GetSameCard(card, playerCards.GetAllCards());

        dataManager.AddCardsToPlayingDeck(card);

        playerCards.RemoveCards(card);

        cardAnimator.AddCardtoPlayingDeck(card, playerId);
    }
Пример #13
0
    private void RPC_MasterDealCard(string rank, string suit, string playerId)
    {
        CardSerializer datas = new CardSerializer(rank, suit);

        Card card = new Card(datas);

        PlayerCards playerCards = PlayerFunctions.GetPlayer(playerId, dataManager.GetPlayerFromPlayerCards()); //GetPlayer(playerId);

        playerCards.AddCards(card);

        card = PlayerFunctions.GetSameCard(card, GetAllCards());

        dataManager.RemoveCardsFromAllCards(card);

        CardAnimator.GetComponent <CardAnimator>().AddCardToPlayerDeck(card, playerId);
    }
Пример #14
0
    public void PlayCard(Card card)
    {
        PlayerCards playerCards = PlayerFunctions.GetPlayer(PhotonNetwork.NickName, dataManager.GetPlayerFromPlayerCards()); //GetPlayer(playerId);

        if (!playerCards.isTurn)
        {
            return;
        }

        playerCards.UnSetTurn();

        CardSerializer datas = card.ConvertCardToCardSerializer();

        RPC_Manager.PlayCard(datas);

        //photonView.RPC("RPC_PlayCard", RpcTarget.AllBuffered, datas.Rank, datas.Suit, PhotonNetwork.LocalPlayer.NickName);
    }
Пример #15
0
        /// <summary>
        /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
        /// </summary>
        /// <typeparam name="T">The type being serialized.</typeparam>
        /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
        /// <param name="writer">The destination XmlWriter to write to.</param>
        public static void Serialize <T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            using (MemoryStream ms = new MemoryStream())
            {
                CardSerializer.Serialize(ms, instance);
                writer.WriteBase64(ms.GetBuffer(), 0, (int)ms.Length);
            }
        }
Пример #16
0
 public GameService(
     MainDbContext context,
     CardSerializer cardSerializer,
     Mapper mapper,
     GameManagementService gameManagementService,
     ITransactionManager transactionManager,
     GameLogicService gameLogicService,
     DeckService deckService
     )
 {
     _context               = context;
     _cardSerializer        = cardSerializer;
     _mapper                = mapper;
     _gameManagementService = gameManagementService;
     _transactionManager    = transactionManager;
     _gameLogicService      = gameLogicService;
     _deckService           = deckService;
 }
Пример #17
0
    public static byte[] Serialize(object obj)
    {
        CardSerializer data = (CardSerializer)obj;

        //RANK.
        byte[] RankBytes = Encoding.ASCII.GetBytes(data.Rank);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(RankBytes);
        }

        //SUIT.
        byte[] SuitBytes = Encoding.ASCII.GetBytes(data.Suit);
        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(SuitBytes);
        }

        return(JoinBytes(RankBytes, SuitBytes));
    }
Пример #18
0
        /// <summary>
        /// Applies a protocol-buffer from an XmlReader to an existing instance.
        /// </summary>
        /// <typeparam name="T">The type being merged.</typeparam>
        /// <param name="instance">The existing instance to be modified (cannot be null).</param>
        /// <param name="reader">The XmlReader containing the data to apply to the instance (cannot be null).</param>
        public static void Merge <T>(System.Xml.XmlReader reader, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            const int LEN = 4096;

            byte[] buffer = new byte[LEN];
            int    read;

            using (MemoryStream ms = new MemoryStream())
            {
                int depth = reader.Depth;
                while (reader.Read() && reader.Depth > depth)
                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Text)
                    {
                        while ((read = reader.ReadContentAsBase64(buffer, 0, LEN)) > 0)
                        {
                            ms.Write(buffer, 0, read);
                        }
                        if (reader.Depth <= depth)
                        {
                            break;
                        }
                    }
                }
                ms.Position = 0;
                CardSerializer.Merge(ms, instance);
            }
        }
Пример #19
0
    private void RPC_SetAllPlayerAllCards(string rank, string suit)
    {
        CardSerializer datas = new CardSerializer(rank, suit);

        dataManager.AddCardsToAllCards(new Card(datas));
    }
Пример #20
0
        protected override BaseSerializer PerformAction(ClientConnection conn, BaseSerializer requestData)
        {
            RequestSerializer  data = (RequestSerializer)requestData;
            ResponseSerializer resp = (ResponseSerializer)InitializeResponseSerializer();

            resp.Status = "OK";

            Lobby lobby = (Lobby)conn.Session.Get("joined-lobby");
            Match game  = lobby.Game;

            if (
                game.GameState != GameState.BIDDING &&
                game.GameState != GameState.PLAYING &&
                game.GameState != GameState.PAUSED
                )
            {
                data.AddError(null, "INVALID_GAME_STATE", "W tym stanie gry nie można pobrać kart");
                data.ThrowException();
            }

            // Przypadek jeśli karty dziadka nie są jeszcze publiczne
            if (!(
                    game.GameState == GameState.PLAYING &&
                    (
                        game.CurrentGame.TrickList.Count > 0 ||
                        (game.CurrentGame.TrickList.Count == 0 && game.CurrentGame.currentTrick.CardList.Count > 0)
                    )
                    ))
            {
                if (!conn.Session.Has("player"))
                {
                    data.AddError(null, "INVALID_USER", "Nie masz uprawnień do pobrania kart tego gracza");
                    data.ThrowException();
                }

                var player = conn.Session.Get <Player>("player");
                if ((int)player.Tag != data.PlayerTag)
                {
                    if (game.GameState != GameState.PLAYING)
                    {
                        data.AddError(null, "INVALID_USER", "Nie masz uprawnień do pobrania kart tego gracza");
                        data.ThrowException();
                    }
                    if (
                        game.CurrentBidding.Declarer != player.Tag ||
                        ((int)player.Tag + 2) % 4 != data.PlayerTag
                        )
                    {
                        data.AddError(null, "INVALID_USER", "Nie masz uprawnień do pobrania kart tego gracza");
                        data.ThrowException();
                    }
                }
            }

            int playerId = game.PlayerList.FindIndex((p) => {
                return((int)p.Tag == data.PlayerTag);
            });

            if (playerId == -1)
            {
                data.AddError(null, "INTERNAL_SERVER_ERROR", "Wystąpił błąd wewnętrzny serwera");
                data.ThrowException();
            }

            CardSerializer[] cards = new CardSerializer[13];

            for (int i = 0; i < game.PlayerList[playerId].Hand.Length; i++)
            {
                cards[i]        = new CardSerializer();
                cards[i].Figure = (int)game.PlayerList[playerId].Hand[i].Figure;
                cards[i].Color  = (int)game.PlayerList[playerId].Hand[i].Color;
                cards[i].State  = (int)game.PlayerList[playerId].Hand[i].CurrentState;
            }

            resp.Cards = cards;
            return(resp);
        }
Пример #21
0
 public void SetAllPlayerAllCards(CardSerializer datas)
 {
     photonView.RPC("RPC_SetAllPlayerAllCards", RpcTarget.AllBuffered, datas.Rank, datas.Suit);
 }
Пример #22
0
 public void SetPlayinCard(CardSerializer datas)
 {
     photonView.RPC("RPC_SetPlayinCard", RpcTarget.AllBuffered, datas.Rank, datas.Suit);
 }
Пример #23
0
 public void DealCardToPlayer(CardSerializer datas, string playerId)
 {
     photonView.RPC("RPC_DealCardToPlayer", RpcTarget.AllBuffered, datas.Rank, datas.Suit, playerId);
 }
Пример #24
0
 public void SetCardFromCardSerializer(CardSerializer _cardSerializer)
 {
     SetCardRank(_cardSerializer.Rank);
     SetCardSuit(_cardSerializer.Suit);
 }
Пример #25
0
 public void PlayCard(CardSerializer datas)
 {
     photonView.RPC("RPC_PlayCard", RpcTarget.AllBuffered, datas.Rank, datas.Suit, PhotonNetwork.LocalPlayer.NickName);
 }
Пример #26
0
 public void AddToPlayerCards(CardSerializer _cardSerializer)
 {
     playerCards.Add(new Card(_cardSerializer));
 }
Пример #27
0
 public Card(CardSerializer _cardSerializer)
 {
     Rank = SetCardRank(_cardSerializer.Rank);
     Suit = SetCardSuit(_cardSerializer.Suit);
 }