using System.Collections.Generic; using System.Linq; using ColdMint.scripts.utils; namespace ColdMint.scripts.loot; /// /// Loot entry /// 战利品条目 /// public readonly struct LootEntry(string itemId, int minQuantity = 1, int maxQuantity = 1, int weight = 1) { /// /// ID of item /// 物品ID /// public string ItemId { get; init; } = itemId; /// /// Minimum number of generated /// 最小生成多少个 /// public int MinQuantity { get; init; } = minQuantity; /// /// The maximum number of files to be generated /// 最多生成多少个 /// public int MaxQuantity { get; init; } = maxQuantity; /// /// Weight of probability within the drop group /// 在掉落组内的生成权重 /// public int Weight { get; init; } = weight; } /// /// Loot Group /// 战利品分组 /// /// ///Chance ///概率 /// /// ///Entries ///条目列表 /// public readonly record struct LootGroup(float Chance, IEnumerable Entries) { private int WeightSum { get; } = Entries.Sum(entry => entry.Weight); public LootDatum GenerateLootData() { var random = RandomUtils.Instance; var w = random.Next(WeightSum); LootEntry entry = default; foreach (var e in Entries) { w -= e.Weight; if (w >= 0) continue; entry = e; break; } var quantity = random.Next(entry.MinQuantity, entry.MaxQuantity + 1); return new LootDatum(entry.ItemId, quantity); } }