/// <summary> /// Fills the rounds from Match Accounts. /// </summary> void FillRounds() { _rounds.Clear(); for (int i = 0; i < roundsCount; ++i) { _rounds.Add(new MatchRoundData()); } // Fill the rounds for each user foreach (MatchAccount user in _users) { for (int i = 0; i < roundsCount; ++i) { _rounds[i].users.Add(user); MatchRound round; if (i < user.rounds.Count) { round = user.rounds[i]; } else { round = new MatchRound(); round.idMatchAccount = user.id; } _rounds[i].scores.Add(round); } } }
/// <summary> /// Send the specified score. /// </summary> /// <param name="score">Score.</param> /// <param name="callback">Callback.</param> public void Score(float score, Action <bool, string> callback) { if (_finished) { if (callback != null) { callback(false, "This Match is already finished"); } return; } long myId = CombuManager.localUser.idLong; MatchAccount matchAccount = _users.Find(u => u.idAccount.Equals(myId)); MatchRound round = null; if (matchAccount != null) { round = matchAccount.rounds.Find(r => !r.hasScore); } if (round == null) { if (callback != null) { callback(false, "Cannot send score to this Match or it has been already sent"); } return; } var form = CombuManager.instance.CreateForm(); form.AddField("action", "match_score"); form.AddField("Id", round.id.ToString()); form.AddField("Score", score.ToString()); form.AddField("CustomData", customData.toJson()); CombuManager.instance.CallWebservice(CombuManager.instance.GetUrl("match.php"), form, (string text, string error) => { bool success = false; if (string.IsNullOrEmpty(error)) { Hashtable result = text.hashtableFromJson(); if (result != null) { bool.TryParse(result["success"].ToString(), out success); if (success) { matchAccount.FromJson(result["message"].ToString()); FillRounds(); } else { error = result["message"].ToString(); } } } if (callback != null) { callback(success, error); } }); }