Exemple #1
0
 public void RemoveMatch(Match match = null, string matchID = "", bool completely = false, bool deleteInScene = false)
 {
     if (match == null)
     {
         if (matchID != "")
         {
             match = GetMatch(matchID);
         }
     }
     Debug.Log("Removing match");
     currentMatchID  = "";
     currentCategory = 0;
     matches.Remove(match);
     if (completely)
     {
         Debug.Log("Removing match completely");
         GamedoniaData.Delete("matches", match.m_ID, delegate(bool success){
             if (success)
             {
                 Debug.Log("Removed match!!");
             }
             else
             {
             }
         });
     }
     if (deleteInScene)
     {
         GameObject.FindObjectOfType <CurrentMatches> ().deleteRow(match.m_ID);
     }
     Save();
 }
 void removeEntity()
 {
     GamedoniaData.Delete("movies", "54d39884e4b0b94e5d240e3f", delegate(bool success){
         if (success)
         {
             printToConsole("Movie deleted successfully.");
         }
         else
         {
             printToConsole("Failed to delete the movie.");
         }
     });
 }
Exemple #3
0
    private void UpdateHoursRemaining(string LastTurnDate, GameObject row, string type, Match match)
    {
        if (LastTurnDate != "" && match != null)
        {
            float  timeLeft = getHoursRemaining(LastTurnDate);
            string oppId    = MatchManager.I.GetOppenentId(match);
            if (timeLeft <= 0)
            {
                if (type == "yourTurn")
                {
                    MatchManager.I.setWinner(match, oppId);
                }
                else if (type == "hisTurn")
                {
                    if (oppId != "")
                    {
                        MatchManager.I.setWinner(match, PlayerManager.I.player.playerID);
                        PlayerManager.I.UnlockNewAttribute(oppId);
                        Loader.I.showFinishedPopup("", PlayerManager.I.player.playerID, oppId);
                    }
                    else
                    {
                        MatchManager.I.RemoveMatch(match, "", true, true);
                        GamedoniaData.Delete("randomqueue", match.m_ID, null);
                    }
                }
                else if (type == "inviteTurn")
                {
                    MatchManager.I.DenyMatch(match);
                }
            }
            row.transform.GetChild(3).GetComponent <Text>().text = "nog " + timeLeft + " uur om te reageren";

            SetHourGlassImage(timeLeft, row.transform.GetChild(6).gameObject);
        }
    }
Exemple #4
0
    /********************************************************PUSH NOTIFICATIONS AREA ****************************************************************************/
    // Process incoming notification
    void OnGameUpdateNotification(Dictionary <string, object> notification)
    {
        Scene     currentScene = SceneManager.GetActiveScene();
        Hashtable payload      = notification["payload"] != null ? (Hashtable)notification["payload"] : new Hashtable();
        string    type         = payload.ContainsKey("type") ? payload["type"].ToString() : "";
        string    matchID      = payload.ContainsKey("notif_id") ? payload["notif_id"].ToString() : "";
        string    oppName      = payload.ContainsKey("notif_name") ? payload["notif_name"].ToString() : "";

        switch (type)
        {
        case "matchInvite":
            GamedoniaData.Search("matches", "{_id: { $oid: '" + matchID + "' } }", delegate(bool invitesuccess, IList data) {
                if (invitesuccess)
                {
                    if (data != null)
                    {
                        Dictionary <string, object> matchD = (Dictionary <string, object>)data[0];
                        Match match = MatchManager.I.GetMatch(matchID);
                        if (match == null)
                        {
                            match                 = new Match();
                            match.m_ID            = matchD["_id"].ToString();
                            List <string> uids    = JsonMapper.ToObject <List <string> > (JsonMapper.ToJson(matchD ["u_ids"]));
                            match.u_ids           = uids;
                            List <Turn> turns     = new List <Turn> ();
                            List <object> t_turns = new List <object> ();
                            t_turns               = (List <object>)matchD ["m_trns"];

                            foreach (Dictionary <string, object> t_turn  in t_turns)
                            {
                                Turn turn = new Turn(int.Parse(t_turn ["t_ID"].ToString()), t_turn ["p_ID"].ToString(), t_turn ["q_ID"].ToString(), int.Parse(t_turn ["c_ID"].ToString()), int.Parse(t_turn ["t_st"].ToString()));
                                turns.Add(turn);
                            }
                            match.m_cp     = matchD ["m_cp"].ToString();
                            match.m_trns   = turns;
                            match.m_date   = matchD ["m_date"].ToString();
                            match.m_status = matchD ["m_status"].ToString();
                            MatchManager.I.AddMatch(match, false, false);
                        }

                        if (currentScene.name == "Home")
                        {
                            //GameObject.FindObjectOfType<CurrentMatches>().showInvites();
                            GameObject.FindObjectOfType <CurrentMatches> ().updateMatches();
                            GameObject.FindObjectOfType <CurrentMatches> ().updateLives();
                        }
                    }
                }
            });
            break;

        case "matchTurn":

            //TODO: process the message
            Match match = MatchManager.I.GetMatch(matchID);
            if (match != null)
            {
                // Update match information
                // Get match from gamedonia server
                GamedoniaData.Search("matches", "{_id: { $oid: '" + matchID + "' } }", delegate(bool success, IList data) {
                    if (success)
                    {
                        if (data != null)
                        {
                            // *************** Server side match information ********************
                            Dictionary <string, object> matchD = (Dictionary <string, object>)data[0];
                            List <Turn> turns = new List <Turn>();
                            // Conver incoming turn data to Turn class
                            List <object> t_turns = new List <object>();
                            t_turns = (List <object>)matchD["m_trns"];
                            foreach (Dictionary <string, object> t_turn  in t_turns)
                            {
                                Turn turn = new Turn(int.Parse(t_turn["t_ID"].ToString()), t_turn["p_ID"].ToString(), t_turn["q_ID"].ToString(), int.Parse(t_turn["c_ID"].ToString()), int.Parse(t_turn["t_st"].ToString()));
                                turns.Add(turn);
                            }
                            List <string> uids = JsonMapper.ToObject <List <string> >(JsonMapper.ToJson(matchD["u_ids"]));
                            // Add friend to list
                            string oppId = MatchManager.I.GetOppenentId(match);
                            if (!PlayerManager.I.friends.ContainsKey(oppId) && oppId != "")
                            {
                                PlayerManager.I.AddFriend(oppId);
                            }
                            // *************** Update local match ********************
                            match.u_ids    = uids;
                            match.m_cc     = 0;
                            match.m_trns   = turns;
                            match.m_cp     = PlayerManager.I.player.playerID;
                            match.m_date   = matchD["m_date"].ToString();
                            match.m_status = matchD["m_status"].ToString();

                            if (currentScene.name == "Home")
                            {
                                GameObject.FindObjectOfType <CurrentMatches>().updateMatches();
                            }
                        }
                        else
                        {
                        }
                    }
                });
            }

            break;

        case "matchFinish":
            Match finishMatch = MatchManager.I.GetMatch(matchID);

            GamedoniaData.Search("matches", "{_id: { $oid: '" + matchID + "' } }", delegate(bool success, IList data) {
                if (success)
                {
                    if (data != null)
                    {
                        // *************** Server side match information ********************
                        Dictionary <string, object> matchD = (Dictionary <string, object>)data[0];
                        List <Turn> turns = new List <Turn>();
                        // Convert incoming turn data to Turn class
                        List <object> t_turns = new List <object>();
                        t_turns = (List <object>)matchD["m_trns"];
                        foreach (Dictionary <string, object> t_turn  in t_turns)
                        {
                            Turn turn = new Turn(int.Parse(t_turn["t_ID"].ToString()), t_turn["p_ID"].ToString(), t_turn["q_ID"].ToString(), int.Parse(t_turn["c_ID"].ToString()), int.Parse(t_turn["t_st"].ToString()));
                            turns.Add(turn);
                        }
                        List <string> uids = JsonMapper.ToObject <List <string> >(JsonMapper.ToJson(matchD["u_ids"]));
                        // *************** Update local match ********************
                        finishMatch.u_ids    = uids;
                        finishMatch.m_cc     = 0;
                        finishMatch.m_trns   = turns;
                        finishMatch.m_cp     = PlayerManager.I.player.playerID;
                        finishMatch.m_date   = matchD ["m_date"].ToString();
                        finishMatch.m_status = matchD["m_status"].ToString();
                        if (matchD["m_won"].ToString() == PlayerManager.I.player.playerID)
                        {
                            // Check if we can earn an attribute of our opponent
                            PlayerManager.I.UnlockNewAttribute(MatchManager.I.GetOppenentId(finishMatch));
                        }
                        if (currentScene.name == "Home")
                        {
                            Loader.I.showFinishedPopup(oppName, matchD["m_won"].ToString());
                        }
                        GameObject.FindObjectOfType <CurrentMatches> ().updateLives();
                    }
                }
            });



            break;

        case "matchDeny":
            GamedoniaData.Delete("matches", matchID);
            Match matchDeny = MatchManager.I.GetMatch(matchID);
            MatchManager.I.matches.Remove(matchDeny);
            MatchManager.I.Save();
            GameObject.FindObjectOfType <CurrentMatches> ().showInvites();
            GameObject.FindObjectOfType <CurrentMatches> ().deleteRow(matchDeny.m_ID);
            if (currentScene.name == "Home")
            {
                GameObject.FindObjectOfType <CurrentMatches> ().updateLives();
            }
            break;

        default:
            // Do nothing
            break;
        }
    }
Exemple #5
0
    public void StartRandomMatch()
    {
        Loader.I.CheckInternetConnection();
        if (!Loader.I.noInternet)
        {
            currentMatchID  = "";
            currentCategory = 0;
            // Enable Loader
            Loader.I.enableLoader();

            // Search for random fame in random queue tabel

            GamedoniaData.Search("randomqueue", "{'uid': {$nin:['" + PlayerManager.I.player.playerID + "'" + getPlayingFriendsIds() + "]}}", delegate(bool success, IList data){
                if (success)
                {
                    // If there isnt anyone waiting for a game we start a match then send it as an option to others
                    if (data == null || data.Count == 0)
                    {
                        Debug.Log("not matches available");

                        Match match = new Match();
                        // Add empty player since we dont know against we play yet
                        match.AddPlayer("");
                        // Set match status to playing
                        match.m_status = "waiting";
                        // Add ourself
                        match.AddPlayer(PlayerManager.I.player.playerID);
                        // We are the current player
                        match.m_cp = PlayerManager.I.player.playerID;
                        // Set current Date
                        match.m_date = RuntimeData.I.getCorrectDateTime(System.DateTime.Now);
                        //Debug.Log(match.m_date);
                        //Debug.Log("random"+DateTime.Parse(match.m_date));
                        //string myDate = "30-12-2016 07:50:00:AM";
                        //DateTime dt1 = DateTime.ParseExact(myDate, "dd-MM-yyyy hh:mm:ss:tt", System.Globalization.CultureInfo.InvariantCulture);
                        // Add match to local list and gamedonia server
                        AddMatch(match, true, false, true);
                    }
                    else
                    {
                        // We found a random player, delete entry from randomqueue
                        GamedoniaData.Delete("randomqueue", ((IDictionary)data[0])["_id"].ToString(), null);

                        // Add player to friend list
                        if (!PlayerManager.I.friends.ContainsKey(((IDictionary)data[0])["uid"].ToString()) && ((IDictionary)data[0])["uid"].ToString() != "")
                        {
                            PlayerManager.I.AddFriend(((IDictionary)data[0])["uid"].ToString());
                        }

                        GamedoniaData.Search("matches", "{_id: { $oid: '" + ((IDictionary)data[0])["m_ID"].ToString() + "' } }", 1, "{m_trns:1}", delegate(bool _success, IList match) {
                            if (success)
                            {
                                if (data != null)
                                {
                                    Dictionary <string, object> matchD = (Dictionary <string, object>)match[0];

                                    List <Turn> turns = new List <Turn>();
                                    // Convert incoming turn data to Turn class
                                    List <object> t_turns = new List <object>();
                                    t_turns = (List <object>)matchD["m_trns"];
                                    foreach (Dictionary <string, object> t_turn  in t_turns)
                                    {
                                        Turn turn = new Turn(int.Parse(t_turn["t_ID"].ToString()), t_turn["p_ID"].ToString(), t_turn["q_ID"].ToString(), int.Parse(t_turn["c_ID"].ToString()), int.Parse(t_turn["t_st"].ToString()));
                                        turns.Add(turn);
                                    }

                                    List <string> uids     = JsonMapper.ToObject <List <string> >(JsonMapper.ToJson(matchD["u_ids"]));
                                    uids[0]                = PlayerManager.I.player.playerID;
                                    Match existingMatch    = new Match(matchD ["_id"].ToString(), uids, "", "", matchD ["m_status"].ToString(), 0, matchD ["m_cp"].ToString(), 0, matchD ["m_date"].ToString());
                                    existingMatch.m_trns   = turns;
                                    existingMatch.m_cp     = PlayerManager.I.player.playerID;
                                    existingMatch.m_status = "playing";
                                    currentMatchID         = existingMatch.m_ID;
                                    AddMatch(existingMatch, false, false, true);
                                }
                            }
                        });
                    }
                }
            });
        }
    }
Exemple #6
0
 private void setChildInformation(string oppId, string matchId, GameObject parent, string listname, int i = 0)
 {
     if (oppId != "")
     {
         float timeLeft = 0;
         Match match    = MatchManager.I.GetMatch(matchId);
         GamedoniaUsers.GetUser(oppId, delegate(bool success, GDUserProfile data) {
             if (success)
             {
                 Dictionary <string, object> oppProfile = new Dictionary <string, object> ();
                 oppProfile = data.profile;
                 foreach (Transform child in parent.transform)
                 {
                     if (child.name == "playerName")
                     {
                         if (oppId != "")
                         {
                             string extraText = "";
                             if (match.m_status == "invite" && match.m_cp == oppId)
                             {
                                 extraText = " (wachten op acceptatie)";
                             }
                             child.GetComponent <Text> ().text = oppProfile ["name"].ToString() + extraText;
                         }
                     }
                     if (child.name == "Score")
                     {
                         if (listname != "inviteTurn")
                         {
                             string _score = MatchManager.I.getMatchScore(matchId, oppId);
                             child.GetComponent <Text> ().text = MatchManager.I.getMatchScore(matchId, oppId);
                         }
                     }
                     if (child.name == "line")
                     {
                         if (listname == "yourTurn")
                         {
                             if (yourTurn.Count == 1 || (yourTurn.Count - 1) == i)
                             {
                                 child.gameObject.SetActive(false);
                             }
                         }
                         else if (listname == "hisTurn")
                         {
                             if (hisTurn.Count == 1 || (hisTurn.Count - 1) == i)
                             {
                                 child.gameObject.SetActive(false);
                             }
                         }
                         else if (listname == "finished")
                         {
                             if (finishedMatches.Count == 1 || (finishedMatches.Count - 1) == i)
                             {
                                 child.gameObject.SetActive(false);
                             }
                         }
                     }
                     if (child.name == "rankImg")
                     {
                         if (oppId != "")
                         {
                             child.GetComponent <Image> ().sprite = PlayerManager.I.GetRankSprite(int.Parse(oppProfile ["lvl"].ToString()));
                         }
                     }
                     if (child.name == "TimeRemaining")
                     {
                         timeLeft = getHoursRemaining(match.m_date);
                         if (listname == "finished")
                         {
                             child.GetComponent <Text>().text = Mathf.Abs(timeLeft) + " uur geleden beëindigd";
                         }
                         else if (listname == "inviteTurn")
                         {
                             child.GetComponent <Text>().text = "nog " + timeLeft + " uur";
                         }
                         else if (listname == "yourTurn")
                         {
                             child.GetComponent <Text>().text = "nog " + timeLeft + " uur om te reageren";
                         }
                         else if (listname == "hisTurn")
                         {
                             child.GetComponent <Text>().text = "heeft nog " + timeLeft + " uur om te reageren";
                         }
                         if (timeLeft <= 0)
                         {
                             if (listname == "yourTurn")
                             {
                                 MatchManager.I.setWinner(match, oppId);
                                 StartCoroutine(waitBeforeUpdateMatches(1f));
                             }
                             else if (listname == "hisTurn")
                             {
                                 if (oppId != "")
                                 {
                                     MatchManager.I.setWinner(match, PlayerManager.I.player.playerID);
                                     PlayerManager.I.UnlockNewAttribute(oppId);
                                     Loader.I.showFinishedPopup(oppProfile ["name"].ToString(), PlayerManager.I.player.playerID);
                                 }
                                 else
                                 {
                                     MatchManager.I.RemoveMatch(match, "", true, true);
                                     GamedoniaData.Delete("randomqueue", match.m_ID, null);
                                 }
                             }
                             else if (listname == "inviteTurn")
                             {
                                 MatchManager.I.DenyMatch(match);
                             }
                         }
                     }
                     if (child.name == "HourGlass")
                     {
                         SetHourGlassImage(timeLeft, child.gameObject);
                     }
                 }
                 parent.SetActive(true);
             }
         });
     }
     else
     {
         foreach (Transform child in parent.transform)
         {
             if (child.name == "Score")
             {
                 if (listname != "inviteTurn")
                 {
                     string _score = MatchManager.I.getMatchScore(matchId, oppId);
                     child.GetComponent <Text> ().text = (_score == "" ? "0-0" : _score);
                 }
             }
         }
         parent.SetActive(true);
     }
 }