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

53 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.Threading.Tasks;
using Godot;
namespace ColdMint.scripts.map.roomInjectionProcessor;
/// <summary>
/// <para>Probabilistic room injection processor</para>
/// <para>概率的房间注入处理器</para>
/// </summary>
/// <remarks>
///<para>This processor allows you to specify a probability and then decide whether to generate a room based on that probability.</para>
///<para>此处理器允许指定一个概率,然后根据概率来决定是否生成房间。</para>
/// </remarks>
public class ChanceRoomInjectionProcessor : RoomInjectionProcessorTemplate<ChanceRoomInjectionProcessor.ConfigData>
{
public override string GetId()
{
return Config.RoomInjectionProcessorId.Chance;
}
protected override Task<bool> OnCreateConfigData(RandomNumberGenerator randomNumberGenerator, ConfigData configData)
{
if (configData.Chance == null)
{
return Task.FromResult(false);
}
//Generate a random number between 1 and 10000.
//生成1-10000的随机数。
var round = randomNumberGenerator.Randi() % 10000 + 1;
//If the random number is less than or equal to the probability, the room is generated.
//如果随机数小于等于概率,则生成房间。
return Task.FromResult(round <= configData.Chance * 100);
}
/// <summary>
/// <para>Configuration Data</para>
/// <para>配置数据</para>
/// </summary>
public class ConfigData
{
/// <summary>
/// <para>The probability of generating this room</para>
/// <para>生成此房间的概率</para>
/// </summary>
/// <para>
///<para>The value ranges from 1 to 100. For example, if it is set to 1.5, it means that there is a 1.5% probability of generating this room.</para>
///<para>支持小数范围为1-100。例如如果设置为1.5则表示1.5%的概率生成此房间。</para>
/// </para>
public float? Chance { get; set; }
}
}