Beispiel #1
0
    public IEnumerator LoadPlayer()
    {
        var url = new DungeonUrl("create_player.php");
        var www = UnityWebRequest.Get(url.ToString());

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.LogError(www.error);
            yield break;
        }

        var result = www.downloadHandler.text;

        if (result.StartsWith("ERR"))
        {
            url.Error(result);
            yield break;
        }

        var playerData = JsonUtility.FromJson <PlayerData>(result);

        m_id            = playerData.id;
        m_nameText.text = "Player " + m_id;
    }
    private IEnumerator CreateMapCoroutine()
    {
        var url = new DungeonUrl("create_map.php");

        url.AddGet("x", m_mapCoordinate.x);
        url.AddGet("y", m_mapCoordinate.y);
        url.AddGet("width", 10);
        url.AddGet("height", 9);
        url.AddGet("owner_id", PlayerCharacter.instance.Id);
        var www = UnityWebRequest.Get(url.ToString());

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.LogError(www.error);
            yield break;
        }

        var resultText = www.downloadHandler.text.Trim();

        if (resultText.StartsWith("ERR"))
        {
            url.Error(resultText);
            yield break;
        }

        m_mapId = int.Parse(resultText);
        Debug.LogFormat("[Tile Map] Created new map {0}", m_mapId);

        m_isLocked = true;

        JimJamManager.instance.ShowNowhere();
    }
    private IEnumerator UnlockMapCoroutine()
    {
        Debug.LogFormat("[Tile Map] Unlock map {0}", m_mapId);

        var url = new DungeonUrl("unlock_map.php");

        url.AddGet("id", m_mapId);
        var www = UnityWebRequest.Get(url.ToString());

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.LogError(www.error);
            yield break;
        }

        var resultText = www.downloadHandler.text.Trim();

        if (resultText.StartsWith("ERR"))
        {
            url.Error(resultText);
            yield break;
        }

        m_isLocked = false;
        if (s_isUnlocking)
        {
            Application.Quit();
        }
    }
    private IEnumerator GetMapIdList()
    {
        var url = new DungeonUrl("get_map_id_list.php");
        var www = UnityWebRequest.Get(url.ToString());

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.LogError(www.error);
            yield break;
        }

        var resultText = www.downloadHandler.text.Trim();

        if (resultText.StartsWith("ERR"))
        {
            url.Error(resultText);
            yield break;
        }

        var splitResult = resultText.Split(',');

        if (splitResult.Length == 0)
        {
            Debug.LogError("[Tile Map] No map IDs returned");
            yield break;
        }

        m_mapIdList = new List <int>();
        foreach (var valStr in splitResult)
        {
            var val = 0;
            if (int.TryParse(valStr, out val) == false)
            {
                Debug.LogFormat("[Tile Map] Failed to parse '{0}' as int; aborting load", valStr);
                yield break;
            }
            m_mapIdList.Add(val);
        }

        Debug.LogFormat("[Tile Map] Received {0} map ID values", m_mapIdList.Count);
    }
    private IEnumerator UploadEnemyData(EnemyData a_data)
    {
        if (JimJamManager.instance.IsLoaded == false)
        {
            yield break;
        }

        a_data.mapId = TileMap.instance.CurrentId;

        Debug.LogFormat("[Create Enemy] Uploading enemy data to server: {0}", a_data);
        var mapId = TileMap.instance.CurrentId;
        var url   = new DungeonUrl("create_enemy.php");

        url.AddGet("map_id", a_data.mapId);
        url.AddGet("power_level", a_data.powerLevel);
        url.AddGet("crystals", a_data.crystals);
        url.AddGet("x", a_data.x);
        url.AddGet("y", a_data.y);
        url.AddGet("owner_id", a_data.ownerId);
        var www = UnityWebRequest.Get(url.ToString());

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.LogError(www.error);
            yield break;
        }

        var result = www.downloadHandler.text.Trim();

        if (result.StartsWith("ERR"))
        {
            url.Error(result);
            yield break;
        }

        Debug.Log("Upload success!");
    }
    private IEnumerator LoadCoroutine(int a_mapId)
    {
        //Debug.LogFormat( "[Tile Map] Retrieving map at ({0}, {1})", m_x, m_y );

        var url = new DungeonUrl("get_map.php");

        url.AddGet("id", a_mapId);
        var www = UnityWebRequest.Get(url.ToString());

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.LogError(www.error);
            yield break;
        }

        var resultText = www.downloadHandler.text.Trim();

        if (string.IsNullOrEmpty(resultText) || resultText.StartsWith("ERR"))
        {
            url.Error(resultText);
            yield break;
        }

        /*
         * m_isNowhere = resultText == "0";
         *
         * if( m_isNowhere ) {
         *  JimJamManager.instance.StartCreateMode();
         *  yield break;
         * }
         */

        var mapData = JsonUtility.FromJson <TileMapData>(resultText);

        m_mapDataDict.Add(new Vector2Int(mapData.x, mapData.y), mapData);
    }
    public IEnumerator CheckLockedCoroutine(int a_curRoomX, int a_curRoomY)
    {
        var dirVec = m_direction.ToVector2();
        var x      = a_curRoomX + Mathf.FloorToInt(dirVec.x);
        var y      = a_curRoomY + Mathf.FloorToInt(dirVec.y);

        ///Debug.LogFormat( "[Exit] Checking lock to ({0}, {1})", x, y );

        {
            var url = new DungeonUrl("is_map_locked.php");
            url.AddGet("x", x);
            url.AddGet("y", y);
            var www = UnityWebRequest.Get(url);
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.LogError(www.error);
                yield break;
            }

            var resultText = www.downloadHandler.text.Trim();

            if (string.IsNullOrEmpty(resultText) || resultText.StartsWith("ERR"))
            {
                url.Error(resultText);
                yield break;
            }

            var prevLocked = m_isLocked;
            m_isLocked = int.Parse(resultText) == 1;

            if (prevLocked != m_isLocked)
            {
                if (m_isLocked)
                {
                    m_onLocked.Invoke();
                }
                else
                {
                    m_onUnlocked.Invoke();
                }
            }
        }

        if (PlayerCharacter.instance.CharacterClass == CharacterClass.Destroyer)
        {
            var url = new DungeonUrl("get_map.php");
            url.AddGet("x", x);
            url.AddGet("y", y);
            var www = UnityWebRequest.Get(url);
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.LogError(www.error);
                yield break;
            }

            var resultText = www.downloadHandler.text.Trim();

            if (string.IsNullOrEmpty(resultText) || resultText.StartsWith("ERR"))
            {
                url.Error(resultText);
                yield break;
            }

            var prevLocked = m_isLocked;
            m_isLocked = resultText == "0";

            if (prevLocked != m_isLocked)
            {
                if (m_isLocked)
                {
                    m_onLocked.Invoke();
                }
                else
                {
                    m_onUnlocked.Invoke();
                }
            }
        }

        if (m_recurseCheck && gameObject.activeSelf)
        {
            StartCoroutine(CheckLockedCoroutine(a_curRoomX, a_curRoomY));
        }
    }