189 lines
7.1 KiB
C#
189 lines
7.1 KiB
C#
using System.Threading.Tasks;
|
|
using asap.core;
|
|
using EventPartnerGatherRequests;
|
|
using System;
|
|
using UnityEngine;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace EventPartner
|
|
{
|
|
public class RequestSystem
|
|
{
|
|
private readonly string DetailUrl = "detail", InviteUrl = "invite", RefuseUrl = "refuse", AcceptUrl = "accept", BuildUrl = "build";
|
|
private const string AutoMatchControlUrl = "automatch/toggle";
|
|
private const string AutoMatchStatusUrl = "automatch/status";
|
|
private readonly ICustomServerMgr _customServerMgr = GContext.container.Resolve<ICustomServerMgr>();
|
|
private int _eventId;
|
|
|
|
public void Init(IEventPartnerArchitecture arc)
|
|
{
|
|
_eventId = arc.Ctx.EventId;
|
|
}
|
|
|
|
public void Init(int eventId)
|
|
{
|
|
_eventId = eventId;
|
|
}
|
|
|
|
public async Task<EventPartnerGatherDetail> GetDetail()
|
|
{
|
|
var request = new EventPartnerGatherDetailRequest
|
|
{
|
|
EventId = _eventId
|
|
};
|
|
var respString = await _customServerMgr.EventPartnerRequest(DetailUrl, request);
|
|
try
|
|
{
|
|
var res = JsonConvert.DeserializeObject<EventPartnerGatherDetailResp>(respString);
|
|
if (res.State != EEventBuildState.Success)
|
|
{
|
|
Debug.Log($"<color=#2d7cee>[EventPartner] GetDetail Failed with Code {res.State}: {res.Message}</color>");
|
|
return null;
|
|
}
|
|
Debug.Log($"[EventPartnerStatue]: Detail response:\n {respString}");
|
|
return res.Detail;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<EventPartnerGatherOperationResp> Invite(string partnerId)
|
|
{
|
|
var request = new EventPartnerGatherPartnerRequest
|
|
{
|
|
PartnerId = partnerId,
|
|
EventId = _eventId
|
|
};
|
|
var respString = await _customServerMgr.EventPartnerRequest(InviteUrl, request);
|
|
try
|
|
{
|
|
var res = JsonConvert.DeserializeObject<EventPartnerGatherOperationResp>(respString);
|
|
if (res.State != EEventBuildState.Success)
|
|
{
|
|
Debug.Log($"<color=#2d7cee>[EventPartner] Invite Failed with Code {res.State}: {res.ErrorMessage}</color>");
|
|
return null;
|
|
}
|
|
return res;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<EventPartnerGatherOperationResp> Refuse(string partnerId)
|
|
{
|
|
var request = new EventPartnerGatherPartnerRequest
|
|
{
|
|
PartnerId = partnerId,
|
|
EventId = _eventId
|
|
};
|
|
var respStr = await _customServerMgr.EventPartnerRequest(RefuseUrl, request);
|
|
try
|
|
{
|
|
var res = JsonConvert.DeserializeObject<EventPartnerGatherOperationResp>(respStr);
|
|
if (res.State != EEventBuildState.Success)
|
|
{
|
|
Debug.Log($"<color=#2d7cee>[EventPartner] Refuse Failed with Code {res.State}: {res.ErrorMessage}</color>");
|
|
return null;
|
|
}
|
|
return res;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<EventPartnerGatherAcceptResponse> Accept(string partnerId)
|
|
{
|
|
var request = new EventPartnerGatherPartnerRequest
|
|
{
|
|
PartnerId = partnerId,
|
|
EventId = _eventId
|
|
};
|
|
var respStr = await _customServerMgr.EventPartnerRequest(AcceptUrl, request);
|
|
try
|
|
{
|
|
var res = JsonConvert.DeserializeObject<EventPartnerGatherAcceptResponse>(respStr);
|
|
if (res.State != EEventBuildState.Success)
|
|
{
|
|
Debug.Log($"<color=#2d7cee>[EventPartner] Accept Failed with Code {res.State}: {res.Message}</color>");
|
|
return null;
|
|
}
|
|
return res;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<EventPartnerGatherBuildResponse> Build(string partnerId, int score)
|
|
{
|
|
var request = new EventPartnerGatherBuildRequest
|
|
{
|
|
PartnerId = partnerId,
|
|
NewScore = score,
|
|
EventId = _eventId
|
|
};
|
|
var respStr = await _customServerMgr.EventPartnerRequest(BuildUrl, request);
|
|
try
|
|
{
|
|
var res = JsonConvert.DeserializeObject<EventPartnerGatherBuildResponse>(respStr);
|
|
if (res.State != EEventBuildBuildState.Success)
|
|
{
|
|
Debug.Log($"<color=#2d7cee>[EventPartner] Build Failed with Code {res.State}: {res.Message}</color>");
|
|
return null;
|
|
}
|
|
return res;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<AutoMatchToggleResponse> ControlAutoMatch(bool enable)
|
|
{
|
|
try
|
|
{
|
|
var request = new AutoMatchToggleRequest { EventId = _eventId, Enabled = enable };
|
|
var response = await _customServerMgr.EventPartnerRequest(AutoMatchControlUrl, request);
|
|
if (string.IsNullOrEmpty(response))
|
|
return new AutoMatchToggleResponse { State = EEventBuildState.Failed, Message = "Network error" };
|
|
return JsonConvert.DeserializeObject<AutoMatchToggleResponse>(response);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError($"[EventPartner] ControlAutoMatch error: {e.Message}");
|
|
return new AutoMatchToggleResponse { State = EEventBuildState.Failed, Message = e.Message };
|
|
}
|
|
}
|
|
|
|
public async Task<AutoMatchStatusResponse> GetAutoMatchStatus()
|
|
{
|
|
try
|
|
{
|
|
var request = new AutoMatchStatusRequest { EventId = _eventId };
|
|
var response = await _customServerMgr.EventPartnerRequest(AutoMatchStatusUrl, request);
|
|
if (string.IsNullOrEmpty(response))
|
|
return new AutoMatchStatusResponse { State = EEventBuildState.Failed, Message = "Network error", IsInMatching = false };
|
|
return JsonConvert.DeserializeObject<AutoMatchStatusResponse>(response);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError($"[EventPartner] GetAutoMatchStatus error: {e.Message}");
|
|
return new AutoMatchStatusResponse { State = EEventBuildState.Failed, Message = e.Message, IsInMatching = false };
|
|
}
|
|
}
|
|
}
|
|
}
|