supervisor-simulator/scripts/Models/StatusValue.cs
wjsjwr b8fecd080f 已把模型层改成组合式结构并补齐 MVC/内容配置骨架:Unit/任务/运行时状态现在通过组件组合,GameManager 作为桥接层改为驱动 GameSession/Controller;同时新增学科/羁绊/装备/任务/肉鸽等定义结构,预留 i18n 与 Mod 内容加载接口。
- 组合式单位与数值基础重构:scripts/Models/UnitModel.cs, scripts/Models/UnitComponents.cs, scripts/Models/StudentModel.cs, scripts/Models/MentorModel.cs, scripts/Models/StaffModel.cs, scripts/Models/PropertyValue.cs, scripts/Models/StatusValue.cs
  - 任务与运行时状态骨架:scripts/Models/Task.cs, scripts/Models/TaskDefinitions.cs, scripts/Models/GameState.cs
  - 配置与规则定义骨架:scripts/Models/DefinitionSupport.cs, scripts/Models/DomainEnums.cs, scripts/Models/Modifiers.cs, scripts/Models/DisciplineDefinitions.cs, scripts/Models/SynergyDefinitions.cs, scripts/Models/ItemDefinitions.cs, scripts/Models/PaperDefinitions.cs, scripts/Models/RogueliteDefinitions.cs, scripts/Models/GameContentDatabase.cs, scripts/Models/CoreIds.cs
  - MVC/会话/系统/i18n/Mod 支撑:scripts/Core/GameSession.cs, scripts/Core/GameSystems.cs, scripts/Core/GameController.cs, scripts/Core/Mvc.cs, scripts/Core/LocalizationService.cs, scripts/Core/ContentRegistry.cs, scripts/Core/ModManifest.cs, scripts/Core/EventBus.cs
  - 主控流程衔接:scripts/GameManager.cs
2025-12-31 23:54:31 +08:00

85 lines
2.0 KiB
C#
Raw 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;
namespace Models;
/// <summary>
/// 状态值 (StatusValue)
/// 设计说明:
/// 1) 这是“带阈值的数值”,用于压力、体力、忠诚等需要触发事件的状态。
/// 2) 当前值由 PropertyValue 承担“范围约束”,阈值只负责触发行为。
/// 3) 事件由 Model 层抛出Controller/系统层订阅View 不直接耦合。
/// 注意事项:
/// - Upper/Lower 默认等于当前范围的上/下限,保持语义直观。
/// - 如果需要“软阈值”,请在系统中根据 Normalized 手动判断。
/// 未来扩展:
/// - 可增加“阈值触发冷却/抑制器”,避免频繁触发。
/// - 可加入“变化速率”以支持回合/时间驱动的增减。
/// </summary>
public sealed class StatusValue
{
private PropertyValue _current;
public event Action OnUpperThresholdReached;
public event Action OnLowerThresholdReached;
public PropertyValue Current
{
get => _current;
set
{
_current = value;
CheckThresholds();
}
}
public float UpperThreshold { get; set; }
public float LowerThreshold { get; set; }
public StatusValue(int current = 0, int upper = 100, int lower = 0)
{
_current = new PropertyValue(current, lower, upper);
UpperThreshold = upper;
LowerThreshold = lower;
}
public StatusValue(float current, float upper, float lower)
{
_current = new PropertyValue(current, lower, upper);
UpperThreshold = upper;
LowerThreshold = lower;
}
public StatusValue(PropertyValue current, float upperThreshold, float lowerThreshold)
{
_current = current ?? new PropertyValue(0);
UpperThreshold = upperThreshold;
LowerThreshold = lowerThreshold;
CheckThresholds();
}
private void CheckThresholds()
{
if (_current.Value >= UpperThreshold)
{
OnUpperThresholdReached?.Invoke();
}
if (_current.Value <= LowerThreshold)
{
OnLowerThresholdReached?.Invoke();
}
}
public void Add(float value)
{
_current.Add(value);
CheckThresholds();
}
public void Subtract(float value)
{
_current.Subtract(value);
CheckThresholds();
}
}