天梯UI补充
This commit is contained in:
@@ -28,8 +28,11 @@ namespace TcgEngine.Gameplay
|
||||
|
||||
private GameClient gameClient;
|
||||
|
||||
public string userID;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
@@ -43,6 +46,7 @@ namespace TcgEngine.Gameplay
|
||||
|
||||
private void Start()
|
||||
{
|
||||
userID = ApiClient.Get().UserID;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -56,6 +60,7 @@ namespace TcgEngine.Gameplay
|
||||
LoadPlayerData();
|
||||
gameClient.onGameStart += OnGameStart;
|
||||
gameClient.onGameEnd += OnGameEnd;
|
||||
// gameClient.onConnectServer?.Invoke();
|
||||
}
|
||||
|
||||
// 移除对GameLogic.Instance的错误引用,改为检查gameLogic变量
|
||||
@@ -63,6 +68,13 @@ namespace TcgEngine.Gameplay
|
||||
{
|
||||
SubscribeToGameEvents();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@@ -122,16 +134,16 @@ namespace TcgEngine.Gameplay
|
||||
if (ApiClient.Get() != null && ApiClient.Get().IsLoggedIn())
|
||||
{
|
||||
// 从服务器API获取任务配置
|
||||
string url = ApiClient.ServerURL + "/tasks";
|
||||
string url = ApiClient.ServerURL + "/api/tasks";
|
||||
WebResponse res = await ApiClient.Get().SendGetRequest(url);
|
||||
|
||||
Debug.LogError("从服务器API获取任务配置"+res.data);
|
||||
if (res.success)
|
||||
{
|
||||
// 解析任务配置数据
|
||||
try
|
||||
{
|
||||
TaskDataResponse[] taskResponses = ApiTool.JsonToObject<TaskDataResponse[]>(res.data);
|
||||
Debug.Log("Loaded " + taskResponses.Length + " tasks from server");
|
||||
Debug.Log("<color=red>Loaded </color>" + taskResponses.Length + " tasks from server");
|
||||
// 在实际项目中,这里应该将服务器数据转换为TaskData对象并存储在内存中
|
||||
// 供后续使用,而不是每次都从Resources加载
|
||||
|
||||
@@ -156,24 +168,6 @@ namespace TcgEngine.Gameplay
|
||||
Debug.Log("Loaded " + localTasks.Length + " tasks from local resources as fallback");
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.K))
|
||||
{
|
||||
LoadTasks();
|
||||
LoadPlayerData();
|
||||
SavePlayerData();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.U))
|
||||
{
|
||||
UpdateTaskProgress(TaskConditionType.WinGames, "YiYongJun", "YiYongJun");
|
||||
UpdateTaskProgress(TaskConditionType.SummonHeroWithAttributes, "WangGuoJun", "YiYongJun");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private async void LoadPlayerData()
|
||||
{
|
||||
// 从服务器加载玩家任务数据
|
||||
@@ -185,11 +179,11 @@ namespace TcgEngine.Gameplay
|
||||
if (ApiClient.Get() != null && ApiClient.Get().IsLoggedIn())
|
||||
{
|
||||
// 从服务器获取玩家任务数据
|
||||
string url = ApiClient.ServerURL + "/users/" + ApiClient.Get().UserID + "/tasks";
|
||||
string url = ApiClient.ServerURL + $"/api/tasks/{userID}";
|
||||
WebResponse res = await ApiClient.Get().SendGetRequest(url);
|
||||
|
||||
Debug.Log($"<color=red>{url}</color>");
|
||||
|
||||
Debug.LogWarning($"从服务器获取玩家任务数据res_data--:{res.data}");
|
||||
if (res.success)
|
||||
{
|
||||
// 解析玩家任务数据
|
||||
@@ -231,28 +225,31 @@ namespace TcgEngine.Gameplay
|
||||
|
||||
public async void SavePlayerData()
|
||||
{
|
||||
Debug.LogError("------Get():"+ApiClient.Get()+"------.IsLoggedIn():"+ ApiClient.Get().IsLoggedIn());
|
||||
// 将玩家任务数据保存到服务器
|
||||
if (ApiClient.Get() != null && ApiClient.Get().IsLoggedIn())
|
||||
if (ApiClient.Get() != null)
|
||||
{
|
||||
Debug.Log("<color=red> GO GO GO </color>");
|
||||
// 准备要发送的数据
|
||||
PlayerTasksResponse saveData = new PlayerTasksResponse();
|
||||
|
||||
// 转换任务数据
|
||||
PlayerTaskResponse[] taskResponses = new PlayerTaskResponse[playerTasks.Count];
|
||||
for (int i = 0; i < playerTasks.Count; i++)
|
||||
{
|
||||
taskResponses[i] = playerTasks[i].ToResponse();
|
||||
}
|
||||
|
||||
|
||||
Debug.Log($"<color=red>{taskResponses.Length}</color>");
|
||||
saveData.tasks = taskResponses;
|
||||
saveData.lastDailyTaskAssigned = lastDailyTaskAssigned.Ticks;
|
||||
|
||||
string json = ApiTool.ToJson(saveData);
|
||||
string url = ApiClient.ServerURL + "/users/" + ApiClient.Get().UserID + "/tasks";
|
||||
string url = ApiClient.ServerURL + $"/api/tasks/{userID}";
|
||||
WebResponse res = await ApiClient.Get().SendPostRequest(url, json);
|
||||
|
||||
Debug.Log($"<color=red>{res}</color>");
|
||||
Debug.Log($"1111<color=red>{url}</color>");
|
||||
Debug.Log($"2222<color=red>{json}</color>");
|
||||
|
||||
|
||||
if (res.success)
|
||||
{
|
||||
@@ -262,6 +259,8 @@ namespace TcgEngine.Gameplay
|
||||
{
|
||||
Debug.LogWarning("Failed to save player tasks to server: " + res.error);
|
||||
}
|
||||
Debug.LogWarning($"res_data--:{res.data}");
|
||||
Debug.LogWarning($"res.success--:{res.success}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +325,7 @@ namespace TcgEngine.Gameplay
|
||||
lastDailyTaskAssigned = now;
|
||||
SavePlayerData();
|
||||
|
||||
Debug.Log($"Assigned daily task: {selectedTask.name}");
|
||||
Debug.Log($"分配任务: {selectedTask.name}");
|
||||
}
|
||||
|
||||
// 检查并更新过期任务
|
||||
@@ -463,6 +462,7 @@ namespace TcgEngine.Gameplay
|
||||
|
||||
if (progressUpdated)
|
||||
{
|
||||
Debug.LogError("读到了");
|
||||
SavePlayerData();
|
||||
}
|
||||
}
|
||||
@@ -470,6 +470,7 @@ namespace TcgEngine.Gameplay
|
||||
// 事件处理方法
|
||||
private void OnGameStart()
|
||||
{
|
||||
|
||||
// 进行对战任务进度+1
|
||||
UpdateTaskProgress(TaskConditionType.PlayGames);
|
||||
}
|
||||
@@ -549,6 +550,19 @@ namespace TcgEngine.Gameplay
|
||||
// 玩家登录时检查任务
|
||||
public void OnPlayerLogin()
|
||||
{
|
||||
// 检查是否已有登录任务
|
||||
bool hasLoginTask = playerTasks.Any(t =>
|
||||
{
|
||||
TaskData config = GetTaskConfig(t.taskId);
|
||||
return config != null && config.condition == TaskConditionType.LoginGame;
|
||||
});
|
||||
|
||||
// 如果没有登录任务,就分配一个
|
||||
if (!hasLoginTask)
|
||||
{
|
||||
AssignLoginTask();
|
||||
}
|
||||
|
||||
// 登录任务完成
|
||||
UpdateTaskProgress(TaskConditionType.LoginGame);
|
||||
|
||||
@@ -558,6 +572,29 @@ namespace TcgEngine.Gameplay
|
||||
// 分配每日任务(如果需要)
|
||||
AssignDailyTaskIfNeeded();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 专门分配一个登录任务
|
||||
/// </summary>
|
||||
private void AssignLoginTask()
|
||||
{
|
||||
TaskData[] allTasks = Resources.LoadAll<TaskData>("Tasks");
|
||||
var loginTask = allTasks.FirstOrDefault(t => t.isDailyTask && t.condition == TaskConditionType.LoginGame);
|
||||
|
||||
if (loginTask != null)
|
||||
{
|
||||
PlayerTask playerTask = new PlayerTask(loginTask);
|
||||
playerTasks.Add(playerTask);
|
||||
lastDailyTaskAssigned = DateTime.Now;
|
||||
SavePlayerData();
|
||||
Debug.Log($"分配登录任务: {loginTask.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("未找到登录任务配置!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取活跃任务
|
||||
public List<PlayerTask> GetActiveTasks()
|
||||
|
||||
31
Assets/TcgEngine/Scripts/GameLogic/TaskManagerGx.cs
Normal file
31
Assets/TcgEngine/Scripts/GameLogic/TaskManagerGx.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using TcgEngine;
|
||||
using TcgEngine.Gameplay;
|
||||
using TcgEngine.Client;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TcgEngine.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务管理器,负责任务的分配、进度追踪和奖励发放等功能
|
||||
/// </summary>
|
||||
public class TaskManagerGx : MonoBehaviour
|
||||
{
|
||||
public List<PlayerTask> PlayerTasks = new List<PlayerTask>();
|
||||
|
||||
public async void SavePayerData()
|
||||
{
|
||||
PlayerTasksResponse saveData = new PlayerTasksResponse();
|
||||
// PlayerTaskResponse[] taskResponses = new PlayerTaskResponse[ taskResponses.taskId="login_task_1",
|
||||
// assignedTime=1757067900,
|
||||
// taskResponses.expireTime=1757154300,
|
||||
// taskResponses.status=2,
|
||||
// taskResponses.progress=1]
|
||||
;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/TcgEngine/Scripts/GameLogic/TaskManagerGx.cs.meta
Normal file
3
Assets/TcgEngine/Scripts/GameLogic/TaskManagerGx.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d388b20392c45e6b37f010373e2c729
|
||||
timeCreated: 1757061071
|
||||
@@ -48,7 +48,7 @@ namespace TcgEngine.UI
|
||||
RankMedalShow(ranking);
|
||||
this.playerName.text = username;
|
||||
this.rankScore.text = rankScore.ToString();
|
||||
this.stars.text = "星×" + stars;
|
||||
this.stars.text = "×" + stars;
|
||||
this.avatar.sprite = avatar;
|
||||
|
||||
PlayerRank pr = PlayerRank.Bronze; // 默认
|
||||
@@ -74,6 +74,7 @@ namespace TcgEngine.UI
|
||||
{
|
||||
this.rankId.sprite = null; // 或者默认图
|
||||
}
|
||||
this.rankId.SetNativeSize();
|
||||
|
||||
if (rankScore != 0)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace TcgEngine.UI
|
||||
public GameObject[] hideGameObject;
|
||||
private bool isHideObject = false;
|
||||
|
||||
public List<string> Usersid = new List<string>();
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -248,6 +249,8 @@ namespace TcgEngine.UI
|
||||
rankData.rankScore, rankData.stars, false);
|
||||
previous_rank = rankData.position;
|
||||
previous_index = rank_order;
|
||||
Usersid.Add(rankData.playerId);
|
||||
//68a6ca87c1f7ac52b66ef8dc
|
||||
}
|
||||
index++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user