125 lines
4.3 KiB
C#
125 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace TcgEngine
|
|
{
|
|
/// <summary>
|
|
/// 任务配置数据,用于定义各种任务的属性和条件
|
|
/// </summary>
|
|
[CreateAssetMenu(fileName = "TaskData", menuName = "TcgEngine/TaskData")]
|
|
public class TaskData : ScriptableObject
|
|
{
|
|
public string id;
|
|
public string name;
|
|
public string desc;
|
|
public TaskConditionType condition;
|
|
public int value1; // 任务进度上限
|
|
public string value2; // 边界条件1
|
|
public string value3; // 边界条件2
|
|
public TaskRewardType[] rewardTypes;
|
|
public int[] rewardNums;
|
|
public bool isDailyTask = true; // 是否为每日任务
|
|
public int durationHours = 24; // 任务有效期(小时)
|
|
|
|
// 从服务器响应数据创建任务配置
|
|
public static TaskData CreateFromResponse(TaskDataResponse response)
|
|
{
|
|
TaskData taskData = ScriptableObject.CreateInstance<TaskData>();
|
|
taskData.id = response.id;
|
|
taskData.name = response.name;
|
|
taskData.desc = response.desc;
|
|
taskData.condition = (TaskConditionType)response.condition;
|
|
taskData.value1 = response.value1;
|
|
taskData.value2 = response.value2;
|
|
taskData.value3 = response.value3;
|
|
|
|
// 转换奖励类型数组
|
|
taskData.rewardTypes = new TaskRewardType[response.rewardTypes.Length];
|
|
for (int i = 0; i < response.rewardTypes.Length; i++)
|
|
{
|
|
taskData.rewardTypes[i] = (TaskRewardType)response.rewardTypes[i];
|
|
}
|
|
|
|
taskData.rewardNums = response.rewardNums;
|
|
taskData.isDailyTask = response.isDailyTask;
|
|
taskData.durationHours = response.durationHours;
|
|
|
|
return taskData;
|
|
}
|
|
}
|
|
|
|
public enum TaskConditionType
|
|
{
|
|
LoginGame = 1, // 登入游戏
|
|
PlayGames = 2, // 进行X场对战
|
|
WinGames = 3, // 胜利X场
|
|
DefeatHeroWithAttributes = 4, // 击败Y属性和Z属性的英雄X次
|
|
SummonHeroWithAttributes = 5, // 召唤Y属性和Z属性的英雄X次
|
|
UseHeroSkillWithAttributes = 6 // 使用Y属性和Z属性英雄的技能X次
|
|
}
|
|
|
|
public enum TaskRewardType
|
|
{
|
|
Coins = 0, // 金币
|
|
// 后续可扩展其他奖励类型
|
|
}
|
|
|
|
[Serializable]
|
|
public class PlayerTask
|
|
{
|
|
public string taskId;
|
|
public long assignedTime;
|
|
public long expireTime;
|
|
public TaskStatus status;
|
|
public int progress; // 当前进度
|
|
|
|
public PlayerTask(TaskData taskConfig)
|
|
{
|
|
taskId = taskConfig.id;
|
|
assignedTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
expireTime = DateTimeOffset.UtcNow.AddHours(taskConfig.durationHours).ToUnixTimeSeconds();
|
|
Debug.Log($"<color=red>" +
|
|
$"任务获取时间=={assignedTime}" +
|
|
$"任务结束时间=={expireTime}" +
|
|
$"</color>");
|
|
status = TaskStatus.Active;
|
|
progress = 0;
|
|
}
|
|
|
|
|
|
// 从服务器响应数据创建玩家任务
|
|
public PlayerTask(PlayerTaskResponse response)
|
|
{
|
|
taskId = response.taskId;
|
|
assignedTime = response.assignedTime;
|
|
expireTime = response.expireTime;
|
|
Debug.Log($"<color=red>" +
|
|
$"任务获取时间=={assignedTime}" +
|
|
$"任务结束时间=={expireTime}" +
|
|
$"</color>");
|
|
status = (TaskStatus)response.status;
|
|
progress = response.progress;
|
|
}
|
|
|
|
// 转换为服务器响应数据
|
|
public PlayerTaskResponse ToResponse()
|
|
{
|
|
PlayerTaskResponse response = new PlayerTaskResponse();
|
|
response.taskId = taskId;
|
|
response.assignedTime = assignedTime;
|
|
response.expireTime = expireTime;
|
|
response.status = (int)status;
|
|
response.progress = progress;
|
|
return response;
|
|
}
|
|
}
|
|
|
|
public enum TaskStatus
|
|
{
|
|
Active = 0, // 激活
|
|
Completed = 1, // 完成
|
|
Expired = 2, // 过期
|
|
Claimed = 3 // 已领取
|
|
}
|
|
} |