Esempio n. 1
0
    IEnumerator CheckMatchStatus()
    {
        Action <bool, TurnBasedMatch, string> cb =
            (success, match, errors) =>
        {
            if (success)
            {
                Debug.Log("GridManager:CheckMatchStatus success");

                int turn = 0;
                int time = 90;
                int mana = 0;

                basicMatchUIView.SetTurnText("Turn: " + turn.ToString());
                basicMatchUIView.SetTimeText("Time: " + time.ToString());
                basicMatchUIView.SetManaText(mana.ToString() + "/10");
                basicMatchUIView.SetManaMeter(mana);

                string pendingParticipantId = match.PendingParticipantId;
                if (String.Compare(pendingParticipantId, GameManager.Instance.CurrentMatchPlayerId) == 0)
                {
                    Debug.Log("GridManager:Start() it's my turn: " + pendingParticipantId);
                    if (String.Compare(GameManager.Instance.CurrentMatchPlayerId, "player1") == 0)
                    {
                        currentPlayer = player1;
//						unitViews[player2].SetColor(Color.white);
                    }
                    else if (String.Compare(GameManager.Instance.CurrentMatchPlayerId, "player2") == 0)
                    {
                        currentPlayer = player2;
//						unitViews[player1].SetColor(Color.white);
                    }
                    else
                    {
                        Debug.Log("GridManager:Awake unknown player ID");
                    }

                    isPlayerTurn = true;
//					unitViews[currentPlayer].SetColor(Color.red);
                }
                else
                {
                    if (String.Compare(GameManager.Instance.CurrentMatchPlayerId, "player1") == 0)
                    {
//						unitViews[player2].SetColor(Color.red);
                    }
                    else if (String.Compare(GameManager.Instance.CurrentMatchPlayerId, "player2") == 0)
                    {
//						unitViews[player1].SetColor(Color.red);
                    }
                    else
                    {
                        Debug.Log("GridManager:Awake unknown player ID");
                    }
//					unitViews[currentPlayer].SetColor(Color.white);
                }

                string currentPlayerId = GameManager.Instance.CurrentMatchPlayerId;

                TurnBasedMatchData          d  = match.Data;
                TurnBasedMatchDataStructure ds = d.Data;

                try
                {
                    GameManager.Instance.CurrentMatchTurnNumber = ds.GetInt("turn");
                    basicMatchUIView.SetTurnText("Turn " + GameManager.Instance.CurrentMatchTurnNumber.ToString());

                    int manaPoints = ds.GetInt("mana");
                    basicMatchUIView.SetManaText(manaPoints.ToString() + "/10");
                    basicMatchUIView.SetManaMeter(manaPoints);

                    if (GameManager.Instance.CurrentMatchTurnNumber >= 5)
                    {
                        ResultsImage.SetActive(true);

                        if (GameManager.Instance.CurrentMatchPlayerId == "player2")
                        {
                            resultsText.text = "You Lose!";
                        }
                        else
                        {
                            resultsImage.color = Color.yellow;
                        }

                        // TODO: clone results image (you win/you lose) and attach to Canvas
                    }
                }
                catch (Exception e)
                {
                    Debug.Log("GridManager:CheckMatchStatus TurnNumber failure: " + e.ToString());
                }

                // update opponent position
                // TODO: update your own position as long as the player is not moving or selecting
                if (String.Compare(GameManager.Instance.CurrentMatchPlayerId, "player1") == 0 && !IsUnitMoving() && !map.DestinationSelected && map.OriginTile == null)
                {
                    Point p1;
                    try {
                        p1 = ds.GetPoint("position", GameManager.Instance.CurrentPlayerId);
                    }
                    catch (Exception e)
                    {
                        p1 = new Point(Player1StartX, Player1StartY);
                    }

                    Vector3 v = mapView.GetTileViewAt(p1).GetPosition();
//					unitViews[player1].SetPosition(v);
//					player1.Location = p1;

                    Point p2;
                    try {
                        p2 = ds.GetPoint("position", GameManager.Instance.CurrentMatchOpponentPlayerId);
                    }
                    catch (Exception e)
                    {
                        p2 = new Point(Player2StartX, Player2StartY);
                    }
                    Vector3 v2 = mapView.GetTileViewAt(p2).GetPosition();
//					unitViews[player2].SetPosition(v2);
//					player2.Location = p2;
                }
                else if (String.Compare(GameManager.Instance.CurrentMatchPlayerId, "player2") == 0 && !IsUnitMoving() && !map.DestinationSelected && map.OriginTile == null)
                {
                    Point point1;
                    try
                    {
                        point1 = ds.GetPoint("position", GameManager.Instance.CurrentMatchOpponentPlayerId);
                    }
                    catch (Exception e)
                    {
                        point1 = new Point(Player1StartX, Player1StartY);
                    }
                    Vector3 v = mapView.GetTileViewAt(point1).GetPosition();
//					unitViews[player1].SetPosition(v);
//					player1.Location = point1;

                    Point point2;

                    try
                    {
                        point2 = ds.GetPoint("position", GameManager.Instance.CurrentPlayerId);
                    }
                    catch (Exception e)
                    {
                        point2 = new Point(Player2StartX, Player2StartY);
                    }
                    Vector3 v2 = mapView.GetTileViewAt(point2).GetPosition();
//					unitViews[player2].SetPosition(v2);
//					player2.Location = point2;
                }
            }
            else
            {
                Debug.Log("GridManager:CheckMatchStatus failure");
            }
        };

        yield return(StartCoroutine(Platform.Instance.GetMatchInfo(GameManager.Instance.CurrentMatchId, cb)));
    }
Esempio n. 2
0
 public TurnBasedMatchData(string kind, bool dataAvailable, TurnBasedMatchDataStructure data)
 {
     Kind          = kind;
     DataAvailable = dataAvailable;
     Data          = data;
 }
Esempio n. 3
0
    private TurnBasedMatch ParseMatch(string results)
    {
        string matchKind       = "";
        string id              = "";
        string applicationId   = "";
        string variant         = "";
        string status          = "";
        string userMatchStatus = "";
        List <TurnBasedMatchParticipant> ppp = new List <TurnBasedMatchParticipant>();

        string creationDetailsKind                    = "";
        string creationDetailsParticipantId           = "";
        long   creationDetailsModifiedTimestampMillis = 0;
        TurnBasedMatchModification creationDetails    = new TurnBasedMatchModification(creationDetailsKind, creationDetailsParticipantId,
                                                                                       creationDetailsModifiedTimestampMillis);
        string lastUpdateDetailsKind                 = "";
        string lastUpdateParticipantId               = "";
        long   lastUpdateModifiedTimestampMillis     = 0;
        TurnBasedMatchModification lastUpdateDetails = new TurnBasedMatchModification(lastUpdateDetailsKind, lastUpdateParticipantId,
                                                                                      lastUpdateModifiedTimestampMillis);
        string autoMatchingCriteriaKind = "";
        int    autoMatchingCriteriaMinAutoMatchingPlayers  = 0;
        int    autoMatchingCriteriaMaxAutoMatchingPlayers  = 0;
        int    autoMatchingCriteriaExclusiveBitmask        = 0;
        TurnBasedAutoMatchingCriteria autoMatchingCriteria = new TurnBasedAutoMatchingCriteria(autoMatchingCriteriaKind,
                                                                                               autoMatchingCriteriaMinAutoMatchingPlayers,
                                                                                               autoMatchingCriteriaMaxAutoMatchingPlayers,
                                                                                               autoMatchingCriteriaExclusiveBitmask);
        string dataKind                      = "";
        bool   dataDataAvailable             = false;
        TurnBasedMatchDataStructure dataData = new TurnBasedMatchDataStructure(null);
        TurnBasedMatchData          data     = new TurnBasedMatchData(dataKind, dataDataAvailable, dataData);

        string            myResultsKind          = "";
        string            myResultsParticipantId = "";
        string            myResultsResult        = "";
        string            myResultsPlacing       = "";
        ParticipantResult myResults            = new ParticipantResult(myResultsKind, myResultsParticipantId, myResultsResult, myResultsPlacing);
        string            inviterId            = "";
        string            withParticipantId    = "";
        string            description          = "";
        string            pendingParticipantId = "";
        string            matchVersion         = "";
        string            rematchId            = "";
        string            matchNumber          = "";

        string previousMatchDataKind                      = "";
        bool   previousMatchDataDataAvailable             = false;
        TurnBasedMatchDataStructure previousMatchDataData = new TurnBasedMatchDataStructure(null);
        TurnBasedMatchData          previousMatchData     = new TurnBasedMatchData(previousMatchDataKind, previousMatchDataDataAvailable,
                                                                                   previousMatchDataData);

        Dictionary <string, System.Object> resp = MiniJSON.Json.Deserialize(results) as Dictionary <string, System.Object>;

        System.Object ooo;
        resp.TryGetValue("match", out ooo);
        Dictionary <string, System.Object> ddd = (Dictionary <string, System.Object>)ooo;

        Debug.Log(ddd.ToString());
        foreach (KeyValuePair <string, System.Object> matchData in ddd)
        {
            if (matchData.Key == "kind")
            {
                if (matchData.Value != null)
                {
                    matchKind = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "matchId")
            {
                if (matchData.Value != null)
                {
                    id = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "applicationId")
            {
                if (matchData.Value != null)
                {
                    applicationId = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "variant")
            {
                if (matchData.Value != null)
                {
                    variant = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "status")
            {
                if (matchData.Value != null)
                {
                    status = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "userMatchStatus")
            {
                if (matchData.Value != null)
                {
                    userMatchStatus = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "participants")
            {
                ppp = new List <TurnBasedMatchParticipant>();

                List <System.Object> participants = new List <System.Object>();              // = matchData.Value as List<System.Object>;
                if (matchData.Value != null)
                {
                    participants = matchData.Value as List <System.Object>;
                }
                foreach (System.Object o in participants)
                {
                    Dictionary <string, System.Object> participantData = (Dictionary <string, System.Object>)o;
                    System.Object v;
                    participantData.TryGetValue("id", out v);
                    string playerId = "";
                    if (v != null)
                    {
                        playerId = (string)v;
                    }

                    participantData.TryGetValue("kind", out v);
                    string k = "";
                    if (v != null)
                    {
                        k = (string)v;
                    }

                    participantData.TryGetValue("autoMatched", out v);
                    bool autoMatched = false;
                    if (v != null)
                    {
                        autoMatched = bool.Parse((string)v);
                    }

                    participantData.TryGetValue("status", out v);
                    string playerStatus = "";
                    if (v != null)
                    {
                        playerStatus = (string)v;
                    }

                    participantData.TryGetValue("player", out v);
                    Dictionary <string, System.Object> playerD = new Dictionary <string, System.Object>();                  // = (Dictionary<string, System.Object>) v;
                    if (v != null)
                    {
                        playerD = (Dictionary <string, System.Object>)v;
                    }

                    string kind           = "";
                    string participantId  = "";
                    string avatarImageUrl = "";
                    foreach (KeyValuePair <string, System.Object> playerData in playerD)
                    {
                        if (playerData.Key == "kind")
                        {
                            if (playerData.Value != null)
                            {
                                kind = (string)playerData.Value;
                            }
                        }
                        else if (playerData.Key == "participantId")
                        {
                            if (playerData.Value != null)
                            {
                                participantId = (string)playerData.Value;
                            }
                        }
                        else if (playerData.Key == "avatarImageUrl")
                        {
                            if (playerData.Value != null)
                            {
                                avatarImageUrl = (string)playerData.Value;
                            }
                        }
                    }
                    Player player = new Player("player", participantId, avatarImageUrl);
                    TurnBasedMatchParticipant p = new TurnBasedMatchParticipant(k, playerId, player, autoMatched, playerStatus);
                    ppp.Add(p);
                }
            }
            else if (matchData.Key == "creationDetails")
            {
                string kind                    = "";
                string participantId           = "";
                long   modifiedTimestampMillis = 0;

                Dictionary <string, System.Object> details = new Dictionary <string, System.Object>();              // = matchData.Value as Dictionary<string, System.Object>;

                if (matchData.Value != null)
                {
                    details = matchData.Value as Dictionary <string, System.Object>;
                }

                foreach (KeyValuePair <string, System.Object> p in details)
                {
                    if (p.Key == "kind")
                    {
                        if (p.Value != null)
                        {
                            kind = (string)p.Value;
                        }
                    }
                    else if (p.Key == "participantId")
                    {
                        if (p.Value != null)
                        {
                            participantId = (string)p.Value;
                        }
                    }
                    else if (p.Key == "modifiedTimeStampMillis")
                    {
                        if (p.Value != null)
                        {
                            modifiedTimestampMillis = (long)p.Value;
                        }
                    }
                }
                creationDetails = new TurnBasedMatchModification(kind, participantId, modifiedTimestampMillis);
            }
            else if (matchData.Key == "lastUpdateDetails")
            {
                string kind                    = "";
                string participantId           = "";
                long   modifiedTimestampMillis = 0;

                Dictionary <string, System.Object> details = new Dictionary <string, System.Object>();              // = matchData.Value as Dictionary<string, System.Object>;
                if (matchData.Value != null)
                {
                    details = matchData.Value as Dictionary <string, System.Object>;
                }

                foreach (KeyValuePair <string, System.Object> p in details)
                {
                    if (p.Key == "kind")
                    {
                        if (p.Value != null)
                        {
                            kind = (string)p.Value;
                        }
                    }
                    else if (p.Key == "participantId")
                    {
                        if (p.Value != null)
                        {
                            participantId = (string)p.Value;
                        }
                    }
                    else if (p.Key == "modifiedTimeStampMillis")
                    {
                        if (p.Value != null)
                        {
                            modifiedTimestampMillis = (long)p.Value;
                        }
                    }
                }
                lastUpdateDetails = new TurnBasedMatchModification(kind, participantId, modifiedTimestampMillis);
            }
            else if (matchData.Key == "autoMatchingCriteria")
            {
                string kind = "";
                int    minAutoMatchingPlayers = 0;
                int    maxAutoMatchingPlayers = 0;
                int    exclusiveBitmask       = 0;

                Dictionary <string, System.Object> criteria = new Dictionary <string, System.Object>();              // = matchData.Value as Dictionary<string, System.Object>;
                if (matchData.Value != null)
                {
                    criteria = matchData.Value as Dictionary <string, System.Object>;
                }
                foreach (KeyValuePair <string, System.Object> p in criteria)
                {
                    if (p.Key == "kind")
                    {
                        if (String.Compare((string)p.Value, "\"null\"") == 0)
                        {
                            kind = (string)p.Value;
                        }
                    }
                    else if (p.Key == "minAutoMatchingPlayers")
                    {
                        if (String.Compare((string)p.Value, "\"null\"") == 0)
                        {
                            minAutoMatchingPlayers = int.Parse((string)p.Value);
                        }
                    }
                    else if (p.Key == "maxAutoMatchingPlayers")
                    {
                        if (String.Compare((string)p.Value, "\"null\"") == 0)
                        {
                            maxAutoMatchingPlayers = int.Parse((string)p.Value);
                        }
                    }
                    else if (p.Key == "exclusiveBitmask")
                    {
                        if (String.Compare((string)p.Value, "\"null\"") == 0)
                        {
                            exclusiveBitmask = int.Parse((string)p.Value);
                        }
                    }
                }
                autoMatchingCriteria = new TurnBasedAutoMatchingCriteria(kind, minAutoMatchingPlayers, maxAutoMatchingPlayers,
                                                                         exclusiveBitmask);
            }
            else if (matchData.Key == "data")
            {
                string kind          = "";
                bool   dataAvailable = false;
                TurnBasedMatchDataStructure theData = new TurnBasedMatchDataStructure(null);

                if (matchData.Value != null)
                {
                    Dictionary <string, System.Object> d = matchData.Value as Dictionary <string, System.Object>;

                    foreach (KeyValuePair <string, System.Object> p in d)
                    {
                        if (p.Key == "kind")
                        {
                            if (String.Compare((string)p.Value, "\"null\"") == 0)
                            {
                                kind = (string)p.Value;
                            }
                        }
                        else if (p.Key == "dataAvailable")
                        {
                            if (String.Compare((string)p.Value, "\"null\"") == 0)
                            {
                                dataAvailable = bool.Parse((string)p.Value);
                            }
                        }
                        else if (p.Key == "data")
                        {
                            if (p.Value != null)
                            {
                                theData = new TurnBasedMatchDataStructure((Dictionary <string, System.Object>)p.Value);
                            }
                        }
                    }
                }

                data = new TurnBasedMatchData(kind, dataAvailable, theData);
            }
            else if (matchData.Key == "results")
            {
                string kind          = "";
                string participantId = "";
                string result        = "";
                string placing       = "";

                if (matchData.Value != null)
                {
                    List <System.Object> l = matchData.Value as List <System.Object>;
                    if (l != null)
                    {
                        foreach (System.Object o in l)
                        {
                            Dictionary <string, System.Object> d = o as Dictionary <string, System.Object>;
                            if (d != null)
                            {
                                foreach (KeyValuePair <string, System.Object> p in d)
                                {
                                    if (p.Key == "kind")
                                    {
                                        if (p.Value != null)
                                        {
                                            kind = (string)p.Value;
                                        }
                                    }
                                    else if (p.Key == "participantId")
                                    {
                                        if (p.Value != null)
                                        {
                                            participantId = (string)p.Value;
                                        }
                                    }
                                    else if (p.Key == "result")
                                    {
                                        if (p.Value != null)
                                        {
                                            result = (string)p.Value;
                                        }
                                    }
                                    else if (p.Key == "placing")
                                    {
                                        if (p.Value != null)
                                        {
                                            placing = (string)p.Value;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                myResults = new ParticipantResult(kind, participantId, result, placing);
            }
            else if (matchData.Key == "inviterId")
            {
                if (matchData.Value != null)
                {
                    inviterId = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "withParticipantId")
            {
                if (matchData.Value != null)
                {
                    withParticipantId = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "description")
            {
                if (matchData.Value != null)
                {
                    description = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "pendingParticipantId")
            {
                if (matchData.Value != null)
                {
                    pendingParticipantId = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "matchVersion")
            {
                if (matchData.Value != null)
                {
                    matchVersion = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "rematchId")
            {
                if (matchData.Value != null)
                {
                    rematchId = matchData.Key.ToString();
                }
            }
            else if (matchData.Key == "matchNumber")
            {
                if (matchData.Value != null)
                {
                    matchNumber = matchData.Key.ToString();
                }
            }
            else if (matchData.Key == "previousMatchData")
            {
                string kind          = "";
                bool   dataAvailable = false;
                TurnBasedMatchDataStructure theData = new TurnBasedMatchDataStructure(null);

                Dictionary <string, System.Object> d = new Dictionary <string, System.Object>();              // = matchData.Value as Dictionary<string, System.Object>;
                if (matchData.Value != null)
                {
                    d = matchData.Value as Dictionary <string, System.Object>;
                }
                foreach (KeyValuePair <string, System.Object> p in d)
                {
                    if (p.Key == "kind")
                    {
                        kind = (string)p.Value;
                    }
                    else if (p.Key == "dataAvailable")
                    {
                        dataAvailable = bool.Parse((string)p.Value);
                    }
                    else if (p.Key == "data")
                    {
                        theData = new TurnBasedMatchDataStructure((Dictionary <string, System.Object>)p.Value);
                    }
                }

                previousMatchData = new TurnBasedMatchData(kind, dataAvailable, theData);
            }
        }

        return(new TurnBasedMatch(matchKind, id, applicationId, variant, status, userMatchStatus,
                                  ppp, creationDetails, lastUpdateDetails, autoMatchingCriteria,
                                  data, myResults, inviterId, withParticipantId, description, pendingParticipantId,
                                  matchVersion, rematchId, matchNumber, previousMatchData));
    }