Traveller/scripts/map/roomInjectionProcessor/TimeIntervalRoomInjectorProcessor.cs
Cold-Mint a957c91ffe
Add probability-based and time-interval based room injection processors.
加入基于概率的和基于时间间隔的房间注入处理器。
2024-05-30 22:49:54 +08:00

84 lines
3.4 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;
using System.Threading.Tasks;
using ColdMint.scripts.utils;
using Godot;
namespace ColdMint.scripts.map.roomInjectionProcessor;
/// <summary>
/// <para>Time interval for room injection processor</para>
/// <para>时间区间的房间注入处理器</para>
/// </summary>
/// <remarks>
///<para>This processor allows you to specify a time range and allows room generation within the specified time range.</para>
///<para>此处理器允许指定一个时间范围,并在指定的时间范围内允许生成房间。</para>
/// </remarks>
public class
TimeIntervalRoomInjectorProcessor : RoomInjectionProcessorTemplate<TimeIntervalRoomInjectorProcessor.ConfigData>
{
public override string GetId()
{
return Config.RoomInjectionProcessorId.TimeInterval;
}
protected override Task<bool> OnCreateConfigData(RandomNumberGenerator randomNumberGenerator, ConfigData configData)
{
if (configData.StartTime == null)
{
return Task.FromResult(false);
}
if (configData.EndTime == null)
{
//If no end time is specified, the default end time is the start time
//如果未指定结束时间,则默认结束时间为开始时间
configData.EndTime = configData.StartTime;
}
var now = DateTime.Now;
if (!configData.SpecifiedYear)
{
//If no year is specified, it is automatically added to the current year
//若未指定年份,则自动补充为当前年份
var nowYear = now.Year;
configData.StartTime = $"{nowYear}-{configData.StartTime}";
configData.EndTime = $"{nowYear}-{configData.EndTime}";
}
return Task.FromResult(TimeUtils.IsBetweenTimeSpan(now, configData.StartTime, configData.EndTime));
}
public class ConfigData
{
/// <summary>
/// <para>Whether to specify a year</para>
/// <para>是否指定年份</para>
/// </summary>
/// <remarks>
///<para>If true, then Year can be specified in StartTime and EndTime. The specified year is used to be executed only once in a given year, while configurations that do not specify a year are automatically replenished with the current year (performed annually).</para>
///<para>如果为true那么可以在StartTime和EndTime内指定Year。指定年份被用于在特定的年份仅执行一次而未指定年份的配置会自动补充为当前年份每年执行。</para>
/// </remarks>
public bool SpecifiedYear { get; set; }
/// <summary>
/// <para>Start time</para>
/// <para>起始时间</para>
/// </summary>
/// <remarks>
///<para>If the year is not specified, enter data in the format MM-DD hh:mm:ss. If the year is specified, enter data in the format yyyy-MM-dd hh:mm:ss.</para>
///<para>若未指定年份则可填入格式为MM-dd hh:mm:ss的数据若指定了年份那么请填入yyyy-MM-dd hh:mm:ss格式数据。</para>
/// </remarks>
public string? StartTime { get; set; }
/// <summary>
/// <para>End time</para>
/// <para>结束时间</para>
/// </summary>
/// <remarks>
///<para>See StartTime</para>
///<para>同StartTime</para>
/// </remarks>
public string? EndTime { get; set; }
}
}