LootBoxGenerator/LootBoxSimulator/Program.cs

44 lines
1.2 KiB
C#
Raw Normal View History

2024-12-18 09:33:25 +00:00
using LootBoxSimulator.Models.DAO;
2024-12-18 12:17:24 +00:00
RemoteDatabaseContext databaseContext = new RemoteDatabaseContext();
2024-12-05 11:29:52 +00:00
2024-12-18 12:17:24 +00:00
var result = RandomizeRate();
var item = RandomizeItem(result);
Console.WriteLine($"{item?.Name} {item?.Id}");
2024-12-16 13:07:23 +00:00
2024-12-18 12:17:24 +00:00
ItemDao? RandomizeItem(RateDao? rateDao){
if(rateDao == null) return null;
var items = databaseContext.Items
.Where(item =>
item.Rate.Id == rateDao.Id
).ToList();
if(items.Count == 0) return null;
Random random = new Random();
int randomIndex = random.Next(0, items.Count);
return items[randomIndex];
2024-12-17 06:38:50 +00:00
}
2024-12-17 12:43:34 +00:00
2024-12-18 12:17:24 +00:00
RateDao? RandomizeRate()
{
var rates = databaseContext
.Rates
.OrderByDescending(item => item.Rate).ToList();
if (rates.Count == 0) return null;
decimal start = 0;
decimal end = rates[0].Rate;
Random random = new Random();
decimal number = Convert.ToDecimal(random.NextDouble());
for (var i = 0; i < rates.Count; i++)
{
if (number >= start && number <= end)
{
Console.WriteLine($"{number} {start} {end}");
return rates[i];
}
start = end;
end += rates[i].Rate;
}
return null;
}