using System.Collections.Generic;
using Godot;
namespace ColdMint.scripts.inventory;
///
/// Loot list
/// 战利品表
///
public class LootList
{
///
/// Id
/// 战利品表的Id
///
public string? Id { get; set; }
private List? _lootEntrieList;
///
/// Add loot entry
/// 添加战利品条目
///
///
public void AddLootEntry(LootEntry lootEntry)
{
if (_lootEntrieList == null)
{
_lootEntrieList = new List();
}
_lootEntrieList.Add(lootEntry);
}
///
/// GenerateLootData
/// 生成战利品数据
///
///
public List GenerateLootData()
{
var lootDataList = new List();
if (_lootEntrieList == null)
{
return lootDataList;
}
foreach (var lootEntry in _lootEntrieList)
{
var chance = GD.Randf();
if (chance > lootEntry.Chance)
{
//If the random number is greater than the generation probability, skip the current loop.
//如果随机数大于生成概率,则跳过当前循环。
continue;
}
//We generate a loot data for each loot entry.
//我们为每个战利品条目生成一个战利品数据。
var quantity = GD.RandRange(lootEntry.MinQuantity, lootEntry.MaxQuantity);
var lootData = new LootData
{
ResPath = lootEntry.ResPath,
Quantity = quantity
};
lootDataList.Add(lootData);
}
return lootDataList;
}
///
/// Remove loot entry
/// 移除战利品条目
///
///
///
public bool RemoveLootEntry(LootEntry lootEntry)
{
if (_lootEntrieList == null)
{
return false;
}
return _lootEntrieList.Remove(lootEntry);
}
}