private void UpdatePlayerScore(bool win) { attack.EndGame(); defense.EndGame(); float ratingDiff = UIManager.CurrentRival.score - UIManager.CurrentUser.score; float den = 1 + (float)Math.Pow(10, ratingDiff / 400); float exp = 1.0f / den; float ratingChange = win?1:0; ratingChange = (ratingChange - exp) * 32; req = new ScoreUpdateRequest() { Username = UIManager.CurrentUser.user_id, Score = ratingChange, SessionToken = UIManager.CurrentUser.session_tk }; StartCoroutine("PostScoreUpdate"); }
private IEnumerator PostScore() { var requestBody = new ScoreUpdateRequest() { Username = currentPlayer.user_id, SessionToken = currentPlayer.session_tk, top_score = currentPlayer.top_score, top_rounds = currentPlayer.top_rounds, top_time = currentPlayer.top_time, total_matches = currentPlayer.total_matches, user_id_match = latestPlay.player_id_match, score = latestPlay.score, rounds = latestPlay.rounds, time = latestPlay.time, bonus = latestPlay.bonus, }; var postData = JsonUtility.ToJson(requestBody); using (UnityWebRequest www = UnityWebRequest.Put(urlBase + "BTUsrMgm", postData)) { www.method = UnityWebRequest.kHttpVerbPUT; www.SetRequestHeader("Content-Type", "application/json"); www.SetRequestHeader("Accept", "application/json"); yield return(www.SendWebRequest()); if (www.isNetworkError) { Debug.Log("Error: " + www.error); } else { Debug.Log("Yay! " + www.downloadHandler.text); } if (ScoreRegisteredEvent != null) { ScoreRegisteredEvent.Invoke(); } } }