From 34675363868c4d618eccf1fd482aac792ebf82fa Mon Sep 17 00:00:00 2001 From: YiHan0621 <2857295085@qq.com> Date: Mon, 8 Sep 2025 16:18:10 +0800 Subject: [PATCH] =?UTF-8?q?TaskManager=E4=B8=ADLoadPlayerTasksFromServer()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/GameLogic/TaskManager.cs | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Assets/TcgEngine/Scripts/GameLogic/TaskManager.cs b/Assets/TcgEngine/Scripts/GameLogic/TaskManager.cs index 06fb6fa..a630f39 100644 --- a/Assets/TcgEngine/Scripts/GameLogic/TaskManager.cs +++ b/Assets/TcgEngine/Scripts/GameLogic/TaskManager.cs @@ -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($"{url}"); - 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(" GO GO GO "); // 准备要发送的数据 PlayerTasksResponse saveData = new PlayerTasksResponse(); // 转换任务数据 @@ -240,6 +239,7 @@ namespace TcgEngine.Gameplay } Debug.Log($"{taskResponses.Length}"); + 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{url}"); - Debug.Log($"2222{json}"); - - 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)