Example #1
0
    public static void BattlePVPServerConnect(BattlePvPServerConnectType type, System.Action <bool> result)
    {
        if (battlePVPServerConnectCoroutine != null)
        {
            return;
        }

        battlePVPServerConnectCoroutine = Instance.StartCoroutine(Instance.BattlePVPServerConnectCoroutine(type, result));
    }
Example #2
0
    IEnumerator BattlePVPServerConnectCoroutine(BattlePvPServerConnectType type, System.Action <bool> result)
    {
        string  php  = "BattlePvP.php";
        WWWForm form = new WWWForm();

        form.AddField("type", (int)type);
        form.AddField("userID", User.Instance.userID);

        if (string.IsNullOrEmpty(opponentPvPUserID) == false)
        {
            form.AddField("opponentID", opponentPvPUserID);
        }

        if (Battle.currentBattleGroup.redTeamList.Count > 0)
        {
            List <string> heroIDList = new List <string>();
            for (int i = 0; i < Battle.currentBattleGroup.redTeamList.Count; i++)
            {
                string heroID = Battle.currentBattleGroup.redTeamList[i].heroData.id;
                heroIDList.Add(heroID);
            }
            string json = JsonMapper.ToJson(heroIDList);
            form.AddField("heroIDList", json);
        }
        if (type == BattlePvPServerConnectType.PvPResult)
        {
            form.AddField("isWin", BattlePvP.Instance.isWin.ToString());
        }

        string data  = "";
        string error = "";

        yield return(StartCoroutine(WebServerConnectManager.Instance.WWWCoroutine(php, form, x => data = x, x => error = x)));

        battlePVPServerConnectCoroutine = null;

        bool isResult = false;

        isResult = string.IsNullOrEmpty(data) == false;

        if (string.IsNullOrEmpty(error) == false)
        {
            isResult = false;
            Debug.Log(error);
        }

        // 서버 연결 결과
        if (result != null)
        {
            result(isResult);
        }
    }