feat: 完善,调整矿物刷新
This commit is contained in:
@@ -33,9 +33,40 @@ public class CollectiblesService : ApplicationService
|
|||||||
public async Task<CollectiblesAccountInfoDto> GetAccountInfoAsync()
|
public async Task<CollectiblesAccountInfoDto> GetAccountInfoAsync()
|
||||||
{
|
{
|
||||||
var userId = CurrentUser.GetId();
|
var userId = CurrentUser.GetId();
|
||||||
var totalValue = await _collectiblesUserStoreRepository._DbQueryable.Where(store => store.UserId == userId)
|
var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable
|
||||||
|
.Where(store => store.UserId == userId)
|
||||||
.LeftJoin<CollectiblesAggregateRoot>((store, c) => store.CollectiblesId == c.Id)
|
.LeftJoin<CollectiblesAggregateRoot>((store, c) => store.CollectiblesId == c.Id)
|
||||||
.SumAsync((store, c) => c.ValueNumber);
|
.Select((store, c) =>
|
||||||
|
new
|
||||||
|
{
|
||||||
|
c.Id,
|
||||||
|
c.ValueNumber
|
||||||
|
}
|
||||||
|
).ToListAsync();
|
||||||
|
var groupBy = collectiblesList.GroupBy(x => x.Id);
|
||||||
|
decimal totalValue = 0;
|
||||||
|
|
||||||
|
//首个价值百分之百,后续每个只有百分之40,最大10个
|
||||||
|
foreach (var groupByItem in groupBy)
|
||||||
|
{
|
||||||
|
foreach (var item in groupByItem.Select((value, index) => new { value, index }))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (item.index == 0)
|
||||||
|
{
|
||||||
|
totalValue += item.value.ValueNumber;
|
||||||
|
}
|
||||||
|
else if (item.index == 10)
|
||||||
|
{
|
||||||
|
//到第11个,直接跳出循环
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
totalValue += item.value.ValueNumber * 0.4m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return new CollectiblesAccountInfoDto
|
return new CollectiblesAccountInfoDto
|
||||||
{
|
{
|
||||||
TotalValue = totalValue
|
TotalValue = totalValue
|
||||||
@@ -56,7 +87,7 @@ public class CollectiblesService : ApplicationService
|
|||||||
var userId = CurrentUser.GetId();
|
var userId = CurrentUser.GetId();
|
||||||
RefAsync<int> total = 0;
|
RefAsync<int> total = 0;
|
||||||
var output = await _collectiblesUserStoreRepository._DbQueryable
|
var output = await _collectiblesUserStoreRepository._DbQueryable
|
||||||
.Where(x=>x.UserId==userId)
|
.Where(x => x.UserId == userId)
|
||||||
.WhereIF(
|
.WhereIF(
|
||||||
input.StartTime is not null && input.EndTime is not null,
|
input.StartTime is not null && input.EndTime is not null,
|
||||||
u => u.CreationTime >= input.StartTime && u.CreationTime <= input.EndTime)
|
u => u.CreationTime >= input.StartTime && u.CreationTime <= input.EndTime)
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ namespace Yi.Framework.DigitalCollectibles.Domain.Shared.Etos;
|
|||||||
public class SuccessMiningEto
|
public class SuccessMiningEto
|
||||||
{
|
{
|
||||||
public Guid CollectiblesId { get; set; }
|
public Guid CollectiblesId { get; set; }
|
||||||
|
|
||||||
|
public Guid UserId{ get; set; }
|
||||||
}
|
}
|
||||||
@@ -19,16 +19,25 @@ namespace Yi.Abp.Domain.Shared.Settings
|
|||||||
new SettingDefinition("MaxPoolLimit", "100"),
|
new SettingDefinition("MaxPoolLimit", "100"),
|
||||||
|
|
||||||
//每日挖矿最大上限--控制无限挖矿
|
//每日挖矿最大上限--控制无限挖矿
|
||||||
new SettingDefinition("MiningMaxLimit", "36"),
|
// new SettingDefinition("MiningMaxLimit", "36"),
|
||||||
|
new SettingDefinition("MiningMaxLimit", "999"),
|
||||||
|
|
||||||
//每次挖矿最小间隔(秒)--控制暴力挖矿
|
//每次挖矿最小间隔(秒)--控制暴力挖矿
|
||||||
new SettingDefinition("MiningMinIntervalSeconds", "3"),
|
new SettingDefinition("MiningMinIntervalSeconds", "3"),
|
||||||
|
|
||||||
//每次挖到矿的概率--控制爆率
|
//每次挖到矿的概率--控制爆率
|
||||||
new SettingDefinition("MiningMinProbability", "0.06"),
|
// new SettingDefinition("MiningMinProbability", "0.06"),
|
||||||
|
new SettingDefinition("MiningMinProbability", "0.6"),
|
||||||
|
|
||||||
//交易税率--控制频繁交易
|
//交易税率--控制频繁交易
|
||||||
new SettingDefinition("MarketTaxRate", "0.2")
|
new SettingDefinition("MarketTaxRate", "0.02"),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//矿池刷新内容
|
||||||
|
new SettingDefinition("PoolData", "60,24,10,3,1")
|
||||||
|
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,13 @@ public class SuccessMiningEventHandler : ILocalEventHandler<SuccessMiningEto>, I
|
|||||||
{
|
{
|
||||||
private MiningPoolManager _miningPoolManager;
|
private MiningPoolManager _miningPoolManager;
|
||||||
private ISqlSugarRepository<CollectiblesAggregateRoot> _repository;
|
private ISqlSugarRepository<CollectiblesAggregateRoot> _repository;
|
||||||
|
private readonly ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> _userStoreRepository;
|
||||||
public SuccessMiningEventHandler(MiningPoolManager miningPoolManager,
|
public SuccessMiningEventHandler(MiningPoolManager miningPoolManager,
|
||||||
ISqlSugarRepository<CollectiblesAggregateRoot> repository)
|
ISqlSugarRepository<CollectiblesAggregateRoot> repository, ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> userStoreRepository)
|
||||||
{
|
{
|
||||||
_miningPoolManager = miningPoolManager;
|
_miningPoolManager = miningPoolManager;
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
|
_userStoreRepository = userStoreRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleEventAsync(SuccessMiningEto eventData)
|
public async Task HandleEventAsync(SuccessMiningEto eventData)
|
||||||
@@ -32,5 +33,13 @@ public class SuccessMiningEventHandler : ILocalEventHandler<SuccessMiningEto>, I
|
|||||||
//新增全世界发现
|
//新增全世界发现
|
||||||
currentCollectibles.FindTotal += 1;
|
currentCollectibles.FindTotal += 1;
|
||||||
await _repository.UpdateAsync(currentCollectibles);
|
await _repository.UpdateAsync(currentCollectibles);
|
||||||
|
|
||||||
|
//使用结果新增给对应的用户
|
||||||
|
await _userStoreRepository.InsertAsync(new CollectiblesUserStoreAggregateRoot
|
||||||
|
{
|
||||||
|
UserId = eventData.UserId,
|
||||||
|
CollectiblesId = eventData.CollectiblesId,
|
||||||
|
IsRead = false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,14 @@
|
|||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
using Volo.Abp.Caching;
|
using Volo.Abp.Caching;
|
||||||
using Volo.Abp.Domain.Services;
|
using Volo.Abp.Domain.Services;
|
||||||
|
using Volo.Abp.EventBus.Local;
|
||||||
using Volo.Abp.Settings;
|
using Volo.Abp.Settings;
|
||||||
using Volo.Abp.Threading;
|
using Volo.Abp.Threading;
|
||||||
using Yi.Framework.DigitalCollectibles.Domain.Dtos;
|
using Yi.Framework.DigitalCollectibles.Domain.Dtos;
|
||||||
using Yi.Framework.DigitalCollectibles.Domain.Entities;
|
using Yi.Framework.DigitalCollectibles.Domain.Entities;
|
||||||
using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts;
|
using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts;
|
||||||
using Yi.Framework.DigitalCollectibles.Domain.Shared.Enums;
|
using Yi.Framework.DigitalCollectibles.Domain.Shared.Enums;
|
||||||
|
using Yi.Framework.DigitalCollectibles.Domain.Shared.Etos;
|
||||||
using Yi.Framework.SettingManagement.Domain;
|
using Yi.Framework.SettingManagement.Domain;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ public class MiningPoolManager : DomainService
|
|||||||
private readonly IDistributedCache<UserMiningLimitCacheDto?> _userMiningLimitCache;
|
private readonly IDistributedCache<UserMiningLimitCacheDto?> _userMiningLimitCache;
|
||||||
private readonly ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> _userStoreRepository;
|
private readonly ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> _userStoreRepository;
|
||||||
private IRedisClient RedisClient => LazyServiceProvider.LazyGetRequiredService<IRedisClient>();
|
private IRedisClient RedisClient => LazyServiceProvider.LazyGetRequiredService<IRedisClient>();
|
||||||
|
private ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetRequiredService<ILocalEventBus>();
|
||||||
|
|
||||||
public MiningPoolManager(ISettingProvider settingProvider, IDistributedCache<MiningPoolContent> miningPoolCache,
|
public MiningPoolManager(ISettingProvider settingProvider, IDistributedCache<MiningPoolContent> miningPoolCache,
|
||||||
ISqlSugarRepository<CollectiblesAggregateRoot> collectiblesRepository,
|
ISqlSugarRepository<CollectiblesAggregateRoot> collectiblesRepository,
|
||||||
@@ -66,6 +69,7 @@ public class MiningPoolManager : DomainService
|
|||||||
pool.I4_LegendNumber -= 1;
|
pool.I4_LegendNumber -= 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//重新设置
|
//重新设置
|
||||||
await SetMiningPoolAsync(pool);
|
await SetMiningPoolAsync(pool);
|
||||||
}
|
}
|
||||||
@@ -89,7 +93,7 @@ public class MiningPoolManager : DomainService
|
|||||||
{
|
{
|
||||||
var onHook = await _onHookRepository._DbQueryable.Where(x => x.UserId == userId)
|
var onHook = await _onHookRepository._DbQueryable.Where(x => x.UserId == userId)
|
||||||
.Where(x => x.IsActive == true)
|
.Where(x => x.IsActive == true)
|
||||||
.Where(x => x.EndTime <= DateTime.Now)
|
.Where(x => x.EndTime > DateTime.Now)
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
|
|
||||||
if (onHook is not null)
|
if (onHook is not null)
|
||||||
@@ -198,51 +202,54 @@ public class MiningPoolManager : DomainService
|
|||||||
{
|
{
|
||||||
poolState = false;
|
poolState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case RarityEnum.Senior:
|
case RarityEnum.Senior:
|
||||||
if (pool.I1_SeniorNumber <= 0)
|
if (pool.I1_SeniorNumber <= 0)
|
||||||
{
|
{
|
||||||
poolState = false;
|
poolState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case RarityEnum.Rare:
|
case RarityEnum.Rare:
|
||||||
if (pool.I2_RareNumber <= 0)
|
if (pool.I2_RareNumber <= 0)
|
||||||
{
|
{
|
||||||
poolState = false;
|
poolState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case RarityEnum.Gem:
|
case RarityEnum.Gem:
|
||||||
if (pool.I3_GemNumber <= 0)
|
if (pool.I3_GemNumber <= 0)
|
||||||
{
|
{
|
||||||
poolState = false;
|
poolState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case RarityEnum.Legend:
|
case RarityEnum.Legend:
|
||||||
if (pool.I4_LegendNumber <= 0)
|
if (pool.I4_LegendNumber <= 0)
|
||||||
{
|
{
|
||||||
poolState = false;
|
poolState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poolState==false)
|
if (poolState == false)
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException($"超级可惜!真的真的只差最后一点就挖到了");
|
throw new UserFriendlyException($"超级可惜!真的真的只差最后一点就挖到了");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int randomIndex = new Random().Next(collectiblesList.Count);
|
int randomIndex = new Random().Next(collectiblesList.Count);
|
||||||
var currentCollectibles = collectiblesList[randomIndex];
|
var currentCollectibles = collectiblesList[randomIndex];
|
||||||
|
|
||||||
result.Collectibles = currentCollectibles;
|
result.Collectibles = currentCollectibles;
|
||||||
|
|
||||||
//使用结果新增给对应的用户
|
await LocalEventBus.PublishAsync(new SuccessMiningEto
|
||||||
await _userStoreRepository.InsertAsync(new CollectiblesUserStoreAggregateRoot
|
|
||||||
{
|
{
|
||||||
UserId = userId,
|
CollectiblesId = currentCollectibles.Id,
|
||||||
CollectiblesId = result.Collectibles.Id,
|
UserId = userId
|
||||||
IsRead = false
|
}, false);
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -316,22 +323,22 @@ public class MiningPoolManager : DomainService
|
|||||||
{
|
{
|
||||||
//获取当前最大的限制
|
//获取当前最大的限制
|
||||||
var maximumPoolLimit = int.Parse(await _settingProvider.GetOrNullAsync("MaxPoolLimit"));
|
var maximumPoolLimit = int.Parse(await _settingProvider.GetOrNullAsync("MaxPoolLimit"));
|
||||||
|
var poolData = (await _settingProvider.GetOrNullAsync("PoolData")).Split(',').Select(x=>int.Parse(x)).ToList();
|
||||||
DateTime startTime = DateTime.Today.AddHours(10);
|
DateTime startTime = DateTime.Today.AddHours(10);
|
||||||
DateTime endTime = startTime.AddDays(1);
|
DateTime endTime = startTime.AddDays(1);
|
||||||
var probabilityValues = RarityEnumExtensions.GetProbabilityArray();
|
// var probabilityValues = RarityEnumExtensions.GetProbabilityArray();
|
||||||
var result = GenerateDistribution(maximumPoolLimit, probabilityValues);
|
// var result = GenerateDistribution(maximumPoolLimit, probabilityValues);
|
||||||
|
|
||||||
//根据配置,将不同比例的矿,塞入矿池,
|
//根据配置,将不同比例的矿,塞入矿池,
|
||||||
//矿池,交给redis
|
//矿池,交给redis
|
||||||
|
|
||||||
await SetMiningPoolAsync(new MiningPoolContent(startTime, endTime)
|
await SetMiningPoolAsync(new MiningPoolContent(startTime, endTime)
|
||||||
{
|
{
|
||||||
I0_OrdinaryNumber = result[0],
|
I0_OrdinaryNumber = poolData[0],
|
||||||
I1_SeniorNumber = result[1],
|
I1_SeniorNumber = poolData[1],
|
||||||
I2_RareNumber = result[2],
|
I2_RareNumber = poolData[2],
|
||||||
I3_GemNumber = result[3],
|
I3_GemNumber = poolData[3],
|
||||||
I4_LegendNumber = result[4]
|
I4_LegendNumber = poolData[4]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user