/// <inheritdoc /> public async ValueTask <LocalExperience> GetLocalExperienceAsync(GuildUserReference guildUser) { var localExperience = await localExperienceRepository.GetAsync(guildUser.GuildId, guildUser.UserId); if (localExperience == null) { throw new EntityNullException <LocalExperience>(); } return(localExperience); }
/// <inheritdoc /> public async ValueTask <Timer> GetTimerAsync(GuildUserReference guildUserReference) { var timer = await timerRepository.GetAsync(guildUserReference.GuildId, guildUserReference.UserId); if (timer == null) { throw new EntityNullException <Timer>(); } return(timer); }
/// <inheritdoc /> public async ValueTask <WeeklyResponse> ClaimWeeklyAsync(GuildUserReference guildUserReference) { var guild = await GetGuildAsync(guildUserReference.GuildId); var rival = await GetRivalAsync(guild); if (rival.Experience > guild.Experience) { return(new WeeklyResponse( WeeklyStatus.GuildInsufficientExp, 0, DateTime.Now)); } var localExperience = await this.GetOrCreateLocalExperienceAsync(guildUserReference); if (localExperience.Experience < guild.MinimalExperienceToGetRewards) { return(new WeeklyResponse( WeeklyStatus.UserInsufficientExp, 0, DateTime.Now, guild.MinimalExperienceToGetRewards - localExperience.Experience)); } var timer = await this.GetOrCreateTimerAsync(guildUserReference); if (timer.Value.AddDays(7) > DateTime.UtcNow) { return(new WeeklyResponse( WeeklyStatus.NotReady, 0, timer.Value)); } var amountClaimed = CalculateWeeklyClaimAmount( guild.GuildHouseMultiplier, guild.CalculateLevel(guild.Experience)); await transactionService.CreateTransactionAsync( new TransactionRequest.Builder() .WithAmount(amountClaimed) .WithReceiver(guildUserReference.UserId) .WithSender(AppProps.Currency.BankId) .Build()); timer.Value = DateTime.UtcNow; await UpdateTimerAsync(timer); await SaveAsync(); return(new WeeklyResponse(WeeklyStatus.Success, amountClaimed, timer.Value)); }
/// <inheritdoc /> public async ValueTask <Timer> CreateTimerAsync(GuildUserReference guildUser) { var timer = new Timer { GuildId = guildUser.GuildId, UserId = guildUser.UserId, Value = DateTime.UtcNow.AddDays(-30) }; await timerRepository.AddAsync(timer); await unitOfWork.CommitAsync(); return(timer); }
/// <inheritdoc /> public async ValueTask <LocalExperience> CreateLocalExperienceAsync(GuildUserReference guildUser) { var localExperience = new LocalExperience { ServerId = guildUser.GuildId, UserId = guildUser.UserId, Experience = 0 }; await localExperienceRepository.AddAsync(localExperience); await unitOfWork.CommitAsync(); return(localExperience); }