//override public IEnumerator ConcludePutAfterTurn(AWebCoroutine a) { //Finished, update the client player WWW www = WWWX.Get(WebRequests.urlGetUserPlayers(),WebRequests.authenticatedParameters); while (!www.isDone) { yield return 0; } Debug.Log(www.text); PlayersData playersData = JSONDecoder.Decode<PlayersData>(www.text); if( playersData == null ) { yield break; } PlayerData d = playersData.GetPlayerWithWorldId(GameManager.worldData.id); if( d == null ) { yield break; } player.data = d; yield break; }
static IEnumerator PutWorldData(WorldData data, AWebCoroutine handler) { string json = "{\"world\":{\"timber_count\":"+data.timber_count+"}"; handler.Request = new HTTP.Request( "Put", WWWX.AppendParametersToUrl(WebRequests.urlGetWorld, WebRequests.authenticatedGodModeParameters) ); handler.Request.SetText( json ); handler.Request.Send(); while(!handler.IsDone) { yield return 0; } Debug.Log(handler.ResponseText); }
protected IEnumerator ChangePlayerData(Player.CharacterClass role, int amount, PlayerDataHandler DataHandler, AWebCoroutine handler) { while(GameManager.worldData == null){ WWW www2 = WWWX.Get(WebRequests.urlGetWorld, WebRequests.authenticatedParameters); while(!www2.isDone){www2 = WWWX.Get(WebRequests.urlGetWorld, WebRequests.authenticatedParameters);} GameManager.worldData = JSONDecoder.Decode<WorldData>(www2.text); } //string url = WebRequests.urlGetUserPlayerId(GameManager.worldData.GetUserIdFromRole(role),GameManager.worldData.GetPlayerIdFromRole(role)); string url = WebRequests.urlGetUserPlayers(GameManager.worldData.GetUserIdFromRole(role)); WWW www = WWWX.Get(url,WebRequests.authenticatedGodModeParameters); while(!www.isDone) { yield return www; } Debug.Log(www.text); //Does not contains balance and pending balance.....check wat server returns //Get the specific role we want PlayersData playersData = JSONDecoder.Decode<PlayersData>(www.text); PlayerData data = playersData.GetPlayerWithWorldId(GameManager.worldData.id); //Adjust the balance DataHandler(ref data,amount); string json = "{\"player\":{\"balance\":" + data.balance +",\"pending_balance\":" + data.pending_balance +"}}"; Debug.Log(json); Debug.Log(WebRequests.urlGetUserPlayerId(data.user_id,data.id)); www = WWWX.Put(WebRequests.urlGetUserPlayerId(data.user_id,data.id),json,WebRequests.authenticatedGodModeParameters); while(!www.isDone) { yield return 0; } //Conclude the Put IEnumerator e = ConcludePut(handler); yield return e.Current; while(e.MoveNext()) yield return e.Current; }
protected IEnumerator ChangeTimberCount(int amount, AWebCoroutine handler) { WWW www = WWWX.Get(WebRequests.urlGetWorld,WebRequests.authenticatedParameters); while(!www.isDone) { yield return 0; } WorldData data = JSONDecoder.Decode<WorldsData>(www.text).world; data.timber_count += amount; //Send new timber count string json = "{\"world\":{\"timber_count\":" + data.timber_count +"}}"; www = WWWX.Put(WebRequests.urlGetWorld,json,WebRequests.authenticatedGodModeParameters); while(!www.isDone) { yield return 0; } //Refresh World Data GameManager.worldData.timber_count = data.timber_count; GameManager.use.worldDataIsValid = false; }
public static IEnumerator GetPlayerData( AWebCoroutine handler ) { // get world list //loginStatus = ""; handler.Request = new HTTP.Request( "Get", urlGetUserPlayers() ); handler.Request.acceptGzip = false; handler.Request.AddParameters( authenticatedGodModeParameters ); handler.Request.Send(); while( !handler.Request.isDone ) { Debug.Log( "GetPlayerData: " + handler.Request.isDone ); yield return 0; } Func<string, PlayersData> playersDataDecodeDelegate = JSONDecoder.Decode<PlayersData>; IAsyncResult ar = playersDataDecodeDelegate.BeginInvoke( handler.ResponseText, null, null ); while( !ar.IsCompleted ) { yield return 0; } LoginGUI.playerData = playersDataDecodeDelegate.EndInvoke( ar ); }
public static IEnumerator RefreshWorldData(AWebCoroutine handler) { handler.Request = new HTTP.Request( "Get", urlGetWorld ); handler.Request.AddParameters( authenticatedParameters ); handler.Request.Send(); while( !handler.RequestIsDone ) { yield return 0; } if( handler.Request.ProducedError ) { Debug.LogError( handler.Request.Error ); yield break; } Func<string, WorldsData> asyncDelegate = JSONDecoder.Decode<WorldsData>; IAsyncResult ar = asyncDelegate.BeginInvoke( handler.ResponseText, null, null ); while( !ar.IsCompleted ) { yield return 0; } WorldsData worlds = asyncDelegate.EndInvoke( ar ); GameManager.worldData = worlds.world; }
public static IEnumerator GetWorldList( AWebCoroutine handler ) { loginStatus = ""; handler.Request = new HTTP.Request( "Get", urlGetWorldList ); handler.Request.AddParameters( WebRequests.authenticatedParameters ); handler.Request.Send(); while( !handler.IsDone ) { yield return 0; } Func<string, WorldsData> worldsDataDecodeDelegate = JSONDecoder.Decode<WorldsData>; IAsyncResult ar = worldsDataDecodeDelegate.BeginInvoke( handler.ResponseText, null, null ); while( !ar.IsCompleted ) { yield return 0; } LoginGUI.worlds = worldsDataDecodeDelegate.EndInvoke( ar ); }
protected void OnComplete( AWebCoroutine self ) { //OnResponse( JSONDeserializer.Deserialize(self.ResponseText) ); }
/// <summary> /// Gets the turn time left. /// </summary> /// <returns> /// The turn time left. /// </returns> protected IEnumerator GetTurnTimeLeft(AWebCoroutine a) { WWW www = WWWX.Get(WebRequests.urlGetTurnState,WebRequests.authenticatedParameters); while (!www.isDone) { TimeIsRunning = true; yield return www; } yield return new WaitForSeconds(5); m_TimeState = JSONDecoder.Decode<TimeState>(www.text); timer = m_TimeState.time_left; TimeIsRunning = false; if(timer <= 0){ isTurnOver = true; } yield break; }
/// <summary> /// Starts the new turn. /// </summary> /// <returns> /// The new turn. /// </returns> protected IEnumerator startNewTurn(AWebCoroutine a){ WWW www = WWWX.Get(WebRequests.urlGetTurnState,WebRequests.authenticatedParameters); while (!www.isDone) { ProcessIsRunning = true; yield return www; } yield return new WaitForSeconds(5); m_TimeState = JSONDecoder.Decode<TimeState>(www.text); timer = m_TimeState.time_left; string state = m_TimeState.state; if(state == "processing"){ //make sure that the game had passed through "processing phase" isPutting = true; } if(state == "playing" && isPutting == true){ isAfterProcessing = true; } ProcessIsRunning = false; Debug.Log ("New Turn"); TimeIsRunning = false; yield break; }
/// <summary> /// Sends a turn over message to the server (coroutine) /// </summary> /// <returns> /// what to do /// </returns> protected IEnumerator PutTurnOver(AWebCoroutine a) { WWW www = WWWX.Put(WebRequests.urlPutPlayerTurnDone,WebRequests.authenticatedParameters); while (!www.isDone) { isPutting = true; yield return www; } isAfterPut = true; Messenger.Broadcast("TurnOver"); Debug.Log("Put Turn over message to the server"); isPutting = false; yield break; }