Files
ft/Client/Assets/Scripts/Services/EventPartnerService.cs
2026-06-29 21:18:33 +08:00

284 lines
10 KiB
C#

using asap.core;
using System;
using System.Threading.Tasks;
using EventPartnerGatherRequests;
using Newtonsoft.Json;
using UnityEngine;
//Event
using EventPartnerGatherBuildRequest = EventPartnerGatherRequests.EventPartnerGatherBuildRequest;
using EventPartnerGatherBuildResponse = EventPartnerGatherRequests.EventPartnerGatherBuildResponse;
using EventPartnerGatherDetailRequest = EventPartnerGatherRequests.EventPartnerGatherDetailRequest;
using EventPartnerGatherDetailResp = EventPartnerGatherRequests.EventPartnerGatherDetailResp;
using EventPartnerGatherPartnerRequest = EventPartnerGatherRequests.EventPartnerGatherPartnerRequest;
using EventPartnerGatherOperationResp = EventPartnerGatherRequests.EventPartnerGatherOperationResp;
using EventPartnerGatherAcceptResponse = EventPartnerGatherRequests.EventPartnerGatherAcceptResponse;
using AutoMatchToggleRequest = EventPartnerGatherRequests.AutoMatchToggleRequest;
using AutoMatchToggleResponse = EventPartnerGatherRequests.AutoMatchToggleResponse;
// using EEventBuildState = Eventpartnergathermo EEventBuildBuildState;
namespace game
{
public class EventPartnerService
{
[Inject]
public ICustomServerMgr customServerMgr { get; set; }
[Inject]
public cfg.Tables tables { get; set; }
[Inject]
public FriendService FriendService { get; set; }
#region URL
// 推荐
public const string RecommendUrl = "recommend";
// 详情,
public const string DetailUrl = "detail";
// 邀请
public const string InviteUrl = "invite";
//
public const string IgnoreUrl = "refuse";
//
public const string AcceptUrl = "accept";
private const string BuildUrl = "build";
// 自动匹配控制(开始/取消)
public const string AutoMatchControlUrl = "automatch/toggle";
// 获取匹配结果
public const string GetAutoMatchResultUrl = "automatch/status";
#endregion
#region
public async Task<EventPartnerGatherDetailResp> GetEventDetail(int eventId)
{
try
{
ELog($"GetEventDetail eventId = {eventId}");
var detailRequest = new EventPartnerGatherDetailRequest { EventId = eventId};
var response = await customServerMgr.EventPartnerRequest(DetailUrl, detailRequest);
if (string.IsNullOrEmpty(response))
{
return new EventPartnerGatherDetailResp
{
State = EventPartnerGatherRequests.EEventBuildState.Failed
};
}
// return null;
// var result = JObject.Parse(response);
ELog($"response = {response}");
// return result;
return JsonConvert.DeserializeObject<EventPartnerGatherDetailResp>(response);
}
catch (Exception e)
{
LogError(e.Message);
throw;
}
}
// 邀请Partner
public async Task<EventPartnerGatherOperationResp> InvitePartner(string partnerId,int eventId)
{
try
{
ELog($"InvitePartner partnerId = {partnerId}");
var request = new EventPartnerGatherPartnerRequest { PartnerId = partnerId, EventId = eventId };
var response = await customServerMgr.EventPartnerRequest(InviteUrl, request);
if (string.IsNullOrEmpty(response))
{
return new EventPartnerGatherOperationResp
{
State = EventPartnerGatherRequests.EEventBuildState.Failed
};
}
ELog($"InvitePartner response = {response}");
return JsonConvert.DeserializeObject<EventPartnerGatherOperationResp>(response);
}
catch (Exception e)
{
LogError(e.Message);
return new EventPartnerGatherOperationResp
{
State = EventPartnerGatherRequests.EEventBuildState.Failed
};
}
}
// 拒绝Id
public async Task<EventPartnerGatherOperationResp> RefusePartner(string partnerId, int eventId)
{
try
{
ELog($"RefusePartner {partnerId}");
var request = new EventPartnerGatherPartnerRequest { PartnerId = partnerId, EventId = eventId };
var response = await customServerMgr.EventPartnerRequest(IgnoreUrl,request);
if (string.IsNullOrEmpty(response))
{
return new EventPartnerGatherOperationResp
{
State = EventPartnerGatherRequests.EEventBuildState.Failed
};
}
// return null;
ELog($"RefusePartner response = {response}");
return JsonConvert.DeserializeObject<EventPartnerGatherOperationResp>(response);
}
catch (Exception e)
{
LogError(e);
// throw;
return new EventPartnerGatherOperationResp
{
State = EventPartnerGatherRequests.EEventBuildState.Failed
};
}
}
// 同意Id
public async Task<EventPartnerGatherAcceptResponse> AcceptPartner(string partnerId, int eventId)
{
ELog($"AcceptPartner -> {partnerId} {eventId}");
try
{
var request = new EventPartnerGatherPartnerRequest { PartnerId = partnerId, EventId = eventId };
var response = await customServerMgr.EventPartnerRequest(AcceptUrl,request);
if (string.IsNullOrEmpty(response))
{
return new EventPartnerGatherAcceptResponse
{
State = EventPartnerGatherRequests.EEventBuildState.Failed
};
}
ELog($"AcceptPartner response = {response}");
return JsonConvert.DeserializeObject<EventPartnerGatherAcceptResponse>(response);
}
catch (Exception e)
{
LogError(e);
// throw;
return new EventPartnerGatherAcceptResponse
{
State = EventPartnerGatherRequests.EEventBuildState.Failed
};
}
}
// 构建活动
public async Task<EventPartnerGatherBuildResponse> BuildWorks(string partnerId,int newScore,int eventId)
{
ELog($"BuildWorks-> {partnerId} {newScore} {eventId}");
var buildRequest = new EventPartnerGatherBuildRequest
{
PartnerId = partnerId,
NewScore = newScore,
EventId = eventId
};
var response = await customServerMgr.EventPartnerRequest(BuildUrl, buildRequest);
if (string.IsNullOrEmpty(response))
{
return new EventPartnerGatherBuildResponse
{
State = EventPartnerGatherRequests.EEventBuildBuildState.Failed
};
}
// return null;
ELog($"response = {response}");
return JsonConvert.DeserializeObject<EventPartnerGatherBuildResponse>(response);
}
// 控制自动匹配(开始或取消)
public async Task<AutoMatchToggleResponse> ControlAutoMatch(int eventId, bool enable)
{
try
{
ELog($"ControlAutoMatch eventId={eventId} enable={enable} ");
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"
};
}
ELog($"ControlAutoMatch response = {response}");
return JsonConvert.DeserializeObject<AutoMatchToggleResponse>(response);
}
catch (Exception e)
{
LogError(e.Message);
return new AutoMatchToggleResponse
{
State = EEventBuildState.Failed,
Message = e.Message
};
}
}
// 获取匹配结果
public async Task<AutoMatchStatusResponse> GetAutoMatchResult(int eventId)
{
try
{
ELog($"GetAutoMatchResult eventId={eventId}");
var request = new AutoMatchStatusRequest { EventId = eventId };
var response = await customServerMgr.EventPartnerRequest(GetAutoMatchResultUrl, request);
if (string.IsNullOrEmpty(response))
{
return new AutoMatchStatusResponse
{
State = EEventBuildState.Failed,
Message = "Network error"
};
}
ELog($"GetAutoMatchResult response = {response}");
return JsonConvert.DeserializeObject<AutoMatchStatusResponse>(response);
}
catch (Exception e)
{
LogError(e.Message);
return new AutoMatchStatusResponse
{
State = EEventBuildState.Failed,
Message = e.Message
};
}
}
#endregion
public static void LogError(object message)
{
Debug.Log($"<color=red>EventPartnerService => {message} </color>");
}
//
public static void ELog(object message)
{
#if UNITY_EDITOR
Debug.Log($"<color=cyan>EventPartnerService => {message} </color>");
#endif
}
public static void Log(object message)
{
Debug.Log($"<color=cyan>EventPartnerService => {message} </color>");
}
}
}