using System.Threading.Tasks;
using Godot;
namespace ColdMint.scripts.map.roomInjectionProcessor;
///
/// Probabilistic room injection processor
/// 概率的房间注入处理器
///
///
///This processor allows you to specify a probability and then decide whether to generate a room based on that probability.
///此处理器允许指定一个概率,然后根据概率来决定是否生成房间。
///
public class ChanceRoomInjectionProcessor : RoomInjectionProcessorTemplate
{
public override string GetId()
{
return Config.RoomInjectionProcessorId.Chance;
}
protected override Task 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);
}
///
/// Configuration Data
/// 配置数据
///
public class ConfigData
{
///
/// The probability of generating this room
/// 生成此房间的概率
///
///
///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.
///支持小数,范围为1-100。例如,如果设置为1.5,则表示1.5%的概率生成此房间。
///
// ReSharper disable UnusedAutoPropertyAccessor.Global
public float? Chance { get; set; }
// ReSharper restore UnusedAutoPropertyAccessor.Global
}
}