调试日志

This commit is contained in:
YiHan0621
2025-09-08 18:28:21 +08:00
parent 29ba23403b
commit f550a87d81
2 changed files with 35 additions and 18 deletions

View File

@@ -18,7 +18,8 @@ namespace TcgEngine.Gameplay
[Header("Player Data")]
public List<PlayerTask> playerTasks = new List<PlayerTask>();
public DateTime lastDailyTaskAssigned;
public long lastDailyTaskAssigned = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
public int maxTasks = 5; // 玩家最多持有任务数
private GameLogic gameLogic;
@@ -68,13 +69,6 @@ namespace TcgEngine.Gameplay
{
SubscribeToGameEvents();
}
}
private void Update()
{
}
private void OnDisable()
@@ -136,6 +130,7 @@ namespace TcgEngine.Gameplay
// 从服务器API获取任务配置
string url = ApiClient.ServerURL + "/api/tasks";
WebResponse res = await ApiClient.Get().SendGetRequest(url);
Debug.Log($"<color=red>LoadTasksFromServer:{url}</color>");
Debug.LogError("从服务器API获取任务配置" + res.data + res.status);
Debug.LogError(res.success);
if (res.success)
@@ -177,14 +172,13 @@ namespace TcgEngine.Gameplay
private async Task LoadPlayerTasksFromServer()
{
Debug.LogError(ApiClient.Get() + "" + ApiClient.Get().IsLoggedIn());
if (ApiClient.Get() != null && ApiClient.Get().IsLoggedIn())
{
// 从服务器获取玩家任务数据
string url = ApiClient.ServerURL + $"/api/tasks/{userID}";
string url = ApiClient.ServerURL + $"/api/tasks/"+ApiClient.Get().UserID;
WebResponse res = await ApiClient.Get().SendGetRequest(url);
Debug.Log($"<color=red>{url}</color>");
Debug.Log($"<color=red>LoadPlayerTasksFromServer:{url}</color>");
Debug.LogWarning($"从服务器获取玩家任务数据res_data--:{res.data},{res.status}");
if (res.success)
{
@@ -192,7 +186,7 @@ namespace TcgEngine.Gameplay
try
{
PlayerTasksResponse response = ApiTool.JsonToObject<PlayerTasksResponse>(res.data);
lastDailyTaskAssigned = new DateTime(response.lastDailyTaskAssigned);
lastDailyTaskAssigned = response.lastDailyTaskAssigned;
// 清除现有任务
playerTasks.Clear();
@@ -237,24 +231,42 @@ namespace TcgEngine.Gameplay
for (int i = 0; i < playerTasks.Count; i++)
{
taskResponses[i] = playerTasks[i].ToResponse();
Debug.Log($"数据[{i}]:{taskResponses[i].taskId}");
}
foreach (PlayerTaskResponse item in taskResponses)
{
Debug.Log($"<color=red>id:{item.taskId}" +
$"开始时间:{item.assignedTime}" +
$"结束时间:{item.expireTime}" +
$"状态:{item.status}" +
$"进度:{item.progress}" +
$"</color>");
}
Debug.Log($"<color=red>{taskResponses.Length}</color>");
saveData.tasks = taskResponses;
saveData.lastDailyTaskAssigned = lastDailyTaskAssigned.Ticks;
saveData.lastDailyTaskAssigned = lastDailyTaskAssigned;
Debug.Log($"saveData.tasks---{saveData.tasks.Length}");
string json = ApiTool.ToJson(saveData);
string url = ApiClient.ServerURL + $"/api/tasks/{userID}";
WebResponse res = await ApiClient.Get().SendPostRequest(url, json);
Debug.Log(json);
Debug.Log($"<color=red>SavePlayerData:{url}</color>");
if (res.success)
{
Debug.Log("玩家任务已保存到服务器");
}
else
{
Debug.LogWarning("未能将玩家任务保存到服务器:" + res.error);
Debug.LogWarning("未能将玩家任务保存到服务器:" + res.error+"错误码:"+res.status);
}
}
}
@@ -262,9 +274,13 @@ namespace TcgEngine.Gameplay
// 每日任务分配
public void AssignDailyTaskIfNeeded()
{
// 检查是否应该分配新任务(每日一次)
DateTime now = DateTime.Now;
if ((now - lastDailyTaskAssigned).TotalHours < 24)
long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
long secondsSinceLastTask = now - lastDailyTaskAssigned;
// 转换为小时
double hoursSinceLastTask = secondsSinceLastTask / 3600.0;
if (hoursSinceLastTask < 24)
return;
// 检查玩家是否已达到最大任务数
@@ -580,7 +596,7 @@ namespace TcgEngine.Gameplay
{
PlayerTask playerTask = new PlayerTask(loginTask);
playerTasks.Add(playerTask);
lastDailyTaskAssigned = DateTime.Now;
lastDailyTaskAssigned = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
SavePlayerData();
Debug.Log($"分配登录任务: {loginTask.name}");
}

View File

@@ -57,6 +57,7 @@ namespace TcgEngine
{
string url = ApiClient.ServerURL + "/users/" + tuser;
WebResponse res = await ApiClient.Get().SendGetRequest(url);
Debug.LogError($"ID{res.data}");
UserData udata = ApiTool.JsonToObject<UserData>(res.data);
if (!res.success)
error.text = res.error;