Beispiel #1
0
 public void RemoveCardValuesFromPlayer(MyPlayer player, List <byte> cardValuesToRemove)
 {
     protectedData.RemoveCardValuesFromPlayer(player, cardValuesToRemove);
 }
Beispiel #2
0
 public void RemoveCardValueFromPlayer(MyPlayer player, byte cardValueToRemove)
 {
     protectedData.RemoveCardValueFromPlayer(player, cardValueToRemove);
 }
        void OnGameStarted()
        {
            if (PhotonNetwork.IsMasterClient)
            {
                leastCountManager.Shuffle();
                Dictionary <string, byte[]> dict = new Dictionary <string, byte[]>();

                //distribute cards to players
                foreach (MyPlayer oplayer in MyPlayers.Values)
                {
                    List <byte> playerValues = leastCountManager.DealCardValuesToPlayer(oplayer, Constants.PLAYER_INITIAL_CARDS);
                    dict.Add(oplayer.PlayerId, playerValues.ToArray());
                    if (oplayer.IsLocalPlayer)
                    {
                        currentTurnPlayer = oplayer;
                    }
                }

                List <byte> poolOfCards      = leastCountManager.GetPoolOfCards();
                byte        droppedCardValue = leastCountManager.FirstDroppedCard();
                List <byte> droppedListValue = new List <byte>();
                droppedListValue.Add(droppedCardValue);
                dict.Add("poolOfCards", poolOfCards.ToArray());
                dict.Add(Constants.INITIALIZING_DROPPEDCARD, droppedListValue.ToArray());

                byte evCode = 1; // Custom Event 1: Used as "MoveUnitsToTargetPosition" event
                //object[] content = new object[] { dict }; // Array contains the target position and the IDs of the selected units
                RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
                    Receivers = ReceiverGroup.All
                };                                                                                             // You would have to set the Receivers to All in order to receive this event on the local client as well
                PhotonNetwork.RaiseEvent(evCode, dict, raiseEventOptions, SendOptions.SendReliable);
                Debug.Log("master onstarted");

                foreach (MyPlayer oplayer in MyPlayers.Values)
                {
                    if (!oplayer.IsLocalPlayer)
                    {
                        cardAnimator.DealDisplayingCards(oplayer, Constants.PLAYER_INITIAL_CARDS);
                    }
                    else
                    {
                        cardAnimator.DealDisplayingCardsToLocalPlayer(oplayer, Constants.PLAYER_INITIAL_CARDS);
                    }
                }
                Card firstDroppedCard = cardAnimator.DropFirstCard(droppedCardValue);
                leastCountManager.AddToDropCardsReference(firstDroppedCard);
            }
            else
            {
                if (intializing && !PhotonNetwork.IsMasterClient)
                {
                    foreach (MyPlayer oplayer in MyPlayers.Values)
                    {
                        if (!oplayer.IsLocalPlayer)
                        {
                            cardAnimator.DealDisplayingCards(oplayer, Constants.PLAYER_INITIAL_CARDS);
                        }
                        else
                        {
                            cardAnimator.DealDisplayingCardsToLocalPlayer(oplayer, Constants.PLAYER_INITIAL_CARDS);
                        }
                    }
                    Card firstDroppedCard = cardAnimator.DropFirstCard(leastCountManager.GetDroppedCardValues()[0]);
                    leastCountManager.AddToDropCardsReference(firstDroppedCard);
                    intializing = false;
                }
            }
        }
Beispiel #4
0
 public List <byte> PlayerCards(MyPlayer player)
 {
     return(protectedData.PlayerCards(player));
 }
 public OfflineCountManager(MyPlayer local, MyPlayer remote)
 {
     localPlayer   = local;
     remotePlayer  = remote;
     protectedData = new OfflineProtectedData(localPlayer.PlayerId, remotePlayer.PlayerId);
 }
 public void AddCardValueToPlayer(MyPlayer player, byte cardValue)
 {
     protectedData.AddCardValueToPlayer(player.PlayerId, cardValue);
 }
 public void AddCardValuesToPlayer(MyPlayer player, List <byte> cardValues)
 {
     protectedData.AddCardValuesToPlayer(player.PlayerId, cardValues);
 }
Beispiel #8
0
        // public void OnEvent(EventData photonEvent)
        // {
        //     byte eventCode = photonEvent.Code;

        //     if (eventCode == 1)
        //     {
        //         if (!PhotonNetwork.IsMasterClient)
        //         {

        //             Debug.Log(photonEvent.CustomData.GetType());
        //             Dictionary<string, byte[]> reply = (Dictionary<string, byte[]>)photonEvent.CustomData;

        //             //Dictionary<string, List<byte>> reply = data;

        //             if (reply.ContainsKey(localPlayer.PlayerId))
        //             {
        //                 foreach (int keys in MyPlayers.Keys) {
        //                     leastCountManager.AddCardValuesToPlayer(keys.ToString(), reply[keys.ToString()].ToList());
        //                 }
        //                 leastCountManager.SetPoolOfCards((List<byte>)reply["poolOfCards"].ToList());
        //                 leastCountManager.AddCardToDroppedCards(reply[Constants.INITIALIZING_DROPPEDCARD][0]);
        //                 intializing = true;
        //                 currentTurnPlayer = remotePlayer;
        //                 gameState = GameState.GameStarted;
        //                 GameFlow();
        //             }
        //         }
        //     }
        //     else if (eventCode == 2) {

        //         Dictionary<string, byte> move = (Dictionary<string, byte>)photonEvent.CustomData;
        //         int justPlayed = Convert.ToInt32(move["CurrentActorNumber"]);
        //         byte replyDroppedCards = move["droppedCards"];
        //         byte drawnCard = move["drawnCard"];
        //         byte drawnFromDeckOrDropped = move["drawnFromDeckOrDropped"];
        //         int currentPlayerId = Convert.ToInt32(move["NextActorNumber"]);
        //         startTime = PhotonNetwork.Time;
        //         if (justPlayed != PhotonNetwork.LocalPlayer.ActorNumber)
        //         {
        //             MoveAnimations(replyDroppedCards, drawnFromDeckOrDropped, drawnCard);
        //         }

        //         if (currentPlayerId == PhotonNetwork.LocalPlayer.ActorNumber)
        //         {
        //             currentTurnPlayer = localPlayer;
        //             gameState = GameState.TurnSelectingDroppingCard;
        //             GameFlow();

        //         }
        //         else {
        //             currentTurnPlayer = remotePlayer;
        //             gameState = GameState.TurnSelectingDroppingCard;
        //             GameFlow();
        //         }
        //     }

        // }

        public void OnEvent(EventData photonEvent)
        {
            byte eventCode = photonEvent.Code;

            //Event code 1-- initial distribution of cards

            if (eventCode == Constants.SHUFFLE_EVCODE)
            {
                if (!PhotonNetwork.IsMasterClient)
                {
                    Debug.Log(photonEvent.CustomData.GetType());
                    Dictionary <string, byte[]> reply = (Dictionary <string, byte[]>)photonEvent.CustomData;

                    //Dictionary<string, List<byte>> reply = data;

                    //correct  this BS
                    // if (reply.ContainsKey(localPlayer.PlayerId))

                    foreach (int keys in MyPlayers.Keys)
                    {
                        leastCountManager.AddCardValuesToPlayer(keys.ToString(), reply[keys.ToString()].ToList());
                    }
                    leastCountManager.SetPoolOfCards((List <byte>)reply["poolOfCards"].ToList());
                    leastCountManager.AddCardToDroppedCards(reply[Constants.INITIALIZING_DROPPEDCARD][0]);
                    intializing       = true;
                    currentTurnPlayer = MyPlayers[1];
                    gameState         = GameState.GameStarted;
                    GameFlow();
                }
            }
            else if (eventCode == Constants.DRAW_EVCODE)
            {
                Dictionary <string, byte> move = (Dictionary <string, byte>)photonEvent.CustomData;
                int  justPlayed             = Convert.ToInt32(move["CurrentActorNumber"]);
                byte drawnCard              = move["drawnCard"];
                byte drawnFromDeckOrDropped = move["drawnFromDeckOrDropped"];
                int  currentPlayerId        = Convert.ToInt32(move["NextActorNumber"]);
                if (justPlayed != PhotonNetwork.LocalPlayer.ActorNumber)
                {
                    DrawCardAnimations(drawnFromDeckOrDropped, drawnCard);
                }
                currentTurnPlayer = MyPlayers[currentPlayerId];
                startTime         = PhotonNetwork.Time;
                gameState         = GameState.TurnSelectingDroppingCard;
                GameFlow();
            }
            else if (eventCode == Constants.DROP_EVCODE)
            {
                Dictionary <string, byte> move = (Dictionary <string, byte>)photonEvent.CustomData;
                int justPlayed = Convert.ToInt32(move["CurrentActorNumber"]);
                if (justPlayed != PhotonNetwork.LocalPlayer.ActorNumber)
                {
                    var keyList = new List <string>(move.Keys);
                    for (int i = 0; i < keyList.Count; i++)
                    {
                        var key = keyList[i];
                        if (key.Contains("dropString"))
                        {
                            DroppedAnimations(move[key], MyPlayers[justPlayed]);
                        }
                    }
                }
            }
        }
 public void DrawDroppedCard(MyPlayer player, Card card)
 {
     player.ReceiveDisplayingCard(card);
     AddCardAnimation(card, player.NextCardPosition(), player.playerAngle, player.playerScale);
 }