TaskManager中LoadPlayerTasksFromServer()

This commit is contained in:
YiHan0621
2025-09-08 16:18:10 +08:00
parent 409883801b
commit 3467536386

View File

@@ -136,7 +136,7 @@ namespace TcgEngine.Gameplay
// 从服务器API获取任务配置
string url = ApiClient.ServerURL + "/api/tasks";
WebResponse res = await ApiClient.Get().SendGetRequest(url);
Debug.LogError("从服务器API获取任务配置"+res.data);
Debug.LogError("从服务器API获取任务配置" + res.data);
if (res.success)
{
// 解析任务配置数据
@@ -176,6 +176,7 @@ namespace TcgEngine.Gameplay
private async Task LoadPlayerTasksFromServer()
{
Debug.LogError(ApiClient.Get() + "" + ApiClient.Get().IsLoggedIn());
if (ApiClient.Get() != null && ApiClient.Get().IsLoggedIn())
{
// 从服务器获取玩家任务数据
@@ -183,7 +184,7 @@ namespace TcgEngine.Gameplay
WebResponse res = await ApiClient.Get().SendGetRequest(url);
Debug.Log($"<color=red>{url}</color>");
Debug.LogWarning($"从服务器获取玩家任务数据res_data--:{res.data}");
Debug.LogWarning($"从服务器获取玩家任务数据res_data--:{res.data},{res.status}");
if (res.success)
{
// 解析玩家任务数据
@@ -225,11 +226,9 @@ namespace TcgEngine.Gameplay
public async void SavePlayerData()
{
Debug.LogError("------Get():"+ApiClient.Get()+"------.IsLoggedIn():"+ ApiClient.Get().IsLoggedIn());
// 将玩家任务数据保存到服务器
if (ApiClient.Get() != null)
{
Debug.Log("<color=red> GO GO GO </color>");
// 准备要发送的数据
PlayerTasksResponse saveData = new PlayerTasksResponse();
// 转换任务数据
@@ -240,6 +239,7 @@ namespace TcgEngine.Gameplay
}
Debug.Log($"<color=red>{taskResponses.Length}</color>");
saveData.tasks = taskResponses;
saveData.lastDailyTaskAssigned = lastDailyTaskAssigned.Ticks;
@@ -247,20 +247,14 @@ namespace TcgEngine.Gameplay
string url = ApiClient.ServerURL + $"/api/tasks/{userID}";
WebResponse res = await ApiClient.Get().SendPostRequest(url, json);
Debug.Log($"1111<color=red>{url}</color>");
Debug.Log($"2222<color=red>{json}</color>");
if (res.success)
{
Debug.Log("--Player tasks saved to server");
Debug.Log("玩家任务已保存到服务器");
}
else
{
Debug.LogWarning("Failed to save player tasks to server: " + res.error);
Debug.LogWarning("未能将玩家任务保存到服务器:" + res.error);
}
Debug.LogWarning($"res_data--:{res.data}");
Debug.LogWarning($"res.success--:{res.success}");
}
}
@@ -331,7 +325,7 @@ namespace TcgEngine.Gameplay
// 检查并更新过期任务
public void CheckExpiredTasks()
{
DateTime now = DateTime.Now;
long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); // 当前时间戳(秒)
foreach (var task in playerTasks)
{
if (task.status == TaskStatus.Active && now > task.expireTime)