add random functions
This commit is contained in:
parent
be164d5afe
commit
26e4077197
@ -1,38 +1,44 @@
|
||||
using LootBoxSimulator.Models.DAO;
|
||||
|
||||
RemoteDatabaseContext db = new RemoteDatabaseContext();
|
||||
decimal [] test = [0.25M, 0.5M, 0.125M , 0.125M];
|
||||
Dictionary<int, (decimal, decimal)> rareDictionary = new Dictionary<int, (decimal, decimal)>();
|
||||
var rates = db.Rates.OrderByDescending(it => it.Rate).ToList();
|
||||
RemoteDatabaseContext databaseContext = new RemoteDatabaseContext();
|
||||
|
||||
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();
|
||||
decimal number = Convert.ToDecimal(Math.Round(random.NextDouble(),2));
|
||||
Console.WriteLine($"Random number: {number}");
|
||||
decimal startRange = 0;
|
||||
decimal endRange = rates[0].Rate;
|
||||
rareDictionary.Add(rates[0].Id, (startRange, endRange));
|
||||
for (int i = 1; i < rates.Count; i++)
|
||||
{
|
||||
startRange = endRange;
|
||||
endRange = startRange + rates[i].Rate;
|
||||
rareDictionary.Add(rates[i].Id, (startRange, endRange));
|
||||
if (number >= startRange && number <= endRange)
|
||||
{
|
||||
Console.WriteLine(rates[i].Id);
|
||||
};
|
||||
int randomIndex = random.Next(0, items.Count);
|
||||
return items[randomIndex];
|
||||
}
|
||||
|
||||
foreach (var keyValuePair in rareDictionary)
|
||||
|
||||
RateDao? RandomizeRate()
|
||||
{
|
||||
Console.WriteLine($"{keyValuePair.Key}: {keyValuePair.Value}");
|
||||
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];
|
||||
}
|
||||
|
||||
var items = db.Items.Where(it => it.Rate.Rate == 3).ToList();
|
||||
Random randomInt = new Random();
|
||||
int randomIndex = randomInt.Next(0,items.Count);
|
||||
Console.WriteLine(items[randomIndex].Name);
|
||||
//вынести попадание в диапазон в отдельную функцию, которая возвращает айди редкость
|
||||
//сделать ролл по предметам с условием выпавшей редкости и вернуть случайную вещь
|
||||
//сгенерировать случайное число от 0 до кол-во вещей после фильтра и выдать случайный
|
||||
//предмет по выпавшему индексу
|
||||
start = end;
|
||||
end += rates[i].Rate;
|
||||
}
|
||||
return null;
|
||||
}
|
Loading…
Reference in New Issue
Block a user