コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <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);
        }