supervisor-simulator/scripts/Models/Task.cs
2026-01-18 20:05:23 +08:00

71 lines
2.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
namespace Models;
/// <summary>
/// 任务运行时模型 (TaskModel)
/// 设计说明:
/// 1) TaskDefinition 描述“配置”TaskModel 描述“运行时进度”。二者分离利于 Mod 追加内容。
/// 2) 任务状态只保存必要字段,展示文本统一由 Definition + i18n 输出。
/// 3) 任务参与单位只记录 Id避免模型直接引用 Node。
/// 注意事项:
/// - 如果没有 DefinitionId可使用 Name 作为临时演示数据。
/// - Deadline 语义是“剩余回合数”,由 TurnSystem 递减。
/// 未来扩展:
/// - 可加入阶段状态(灵感/写作/实验/审核),与 UI 进度条分段对应。
/// - 可加入失败原因/完成评级,用于结算与肉鸽评分。
/// </summary>
public sealed class TaskModel {
public TaskModel(string name, TaskKind kind, float workload, int deadline) {
Name = name;
Kind = kind;
Track = TaskTrack.LabProject;
Difficulty = TaskDifficulty.Standard;
Runtime = new TaskRuntime(workload, deadline);
}
public Guid Id { get; } = Guid.NewGuid();
public string DefinitionId { get; set; }
public string Name { get; set; }
public TaskTrack Track { get; set; }
public TaskKind Kind { get; set; }
public TaskDifficulty Difficulty { get; set; }
public TaskRuntime Runtime { get; }
public TaskRewardSnapshot Reward { get; set; } = new();
public List<Guid> AssignedUnitIds { get; } = new();
public bool IsCompleted => Runtime.CurrentProgress >= Runtime.TotalWorkload;
public bool IsFailed => Runtime.RemainingTurns <= 0 && !IsCompleted;
public void AddProgress(float amount) {
Runtime.CurrentProgress += amount;
if (Runtime.CurrentProgress > Runtime.TotalWorkload) Runtime.CurrentProgress = Runtime.TotalWorkload;
}
}
/// <summary>
/// 任务运行参数(进度与截止)
/// </summary>
public sealed class TaskRuntime {
public TaskRuntime(float totalWorkload, int remainingTurns) {
TotalWorkload = totalWorkload;
RemainingTurns = remainingTurns;
}
public float TotalWorkload { get; set; }
public float CurrentProgress { get; set; }
public float DifficultyScale { get; set; } = 1.0f;
public int RemainingTurns { get; set; }
}
/// <summary>
/// 运行时奖励快照(避免 Definition 被动态修改)
/// </summary>
public sealed class TaskRewardSnapshot {
public int Money { get; set; }
public int Reputation { get; set; }
public List<string> PaperIds { get; } = new();
public List<string> ItemIds { get; set; }
}