LootBoxGenerator/LootBoxSimulator/Program.cs
2024-12-19 13:19:53 +03:00

52 lines
1.4 KiB
C#

using LootBoxSimulator.Models.DAO;
RemoteDatabaseContext databaseContext = new RemoteDatabaseContext();
var sum = databaseContext.Rates.Select(dsadsa => dsadsa.Rate).Sum();
var result = RandomizeRate();
var item = RandomizeItem(result);
Console.WriteLine($"{item?.Name} {item?.Id}");
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];
}
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;
}
//lootbox -> id, name, desc
//lootbobx and item -> itemID, lootboxID
//func openLootbox() - сдедать и добавить в меню
//dotnet ef migrations add [EnterName]
//dotnet ef database