Exemplo n.º 1
0
        async Task <IonicMessage> PurchaseBackgroundInternalAsync(ulong userId, uint itemId)
        {
            var item = GetBackgroundById(itemId);

            if (item is null)
            {
                return(await messageService.GetMessageAsync("store-wrongnumber", new FormatData(userId)));
            }

            if (!await CanBuyBackAsync(userId))
            {
                return(await messageService.GetMessageAsync("backstore-cooldown", new FormatData(userId)));
            }

            var backInventory = await DB.BackgroundInventory.GetAsync(userId);

            if (!(backInventory is null) && backInventory.Count > 0)
            {
                if (backInventory.Any(x => x.BackgroundId == item.Id))
                {
                    return(await messageService.GetMessageAsync("backstore-hasback", new FormatData(userId)));
                }
            }

            if (!await TryWithdrawAsync(userId, item))
            {
                switch (item.Currency)
                {
                case Currency.Coins: return(await messageService.GetMessageAsync("store-nocoins", new FormatData(userId)));

                case Currency.Tokens:
                    return(await messageService.GetMessageAsync("store-notokens", new FormatData(userId)));
                }
            }

            var reward = new BackgroundReward().SetId((int)item.Id);

            try
            {
                await rewardService.DeliverToAsync(userId, reward);
            }
            catch (Exception ex)
            {
                RiftBot.Log.Error(ex, $"An error occured while delivering reward to {userId.ToString()}");
                return(MessageService.Error);
            }

            await DB.Cooldowns.SetLastBackgroundStoreTimeAsync(userId, DateTime.UtcNow);

            RiftBot.Log.Information($"Background purchased: #{item.Id.ToString()} by {userId.ToString()}.");

            return(await messageService.GetMessageAsync("store-success", new FormatData(userId)
            {
                Reward = reward
            }));
        }
Exemplo n.º 2
0
        public override async Task <RiftMessage> ApplyAsync(RiftMessage message, FormatData data)
        {
            var rewardString = data.Reward switch
            {
                ItemReward itemReward => data.RewardService.Format(itemReward),
                RoleReward roleReward => await data.RewardService.FormatAsync(roleReward),
                BackgroundReward backgroundReward => await data.RewardService.FormatAsync(backgroundReward),
                _ => "Пусто :("
            };

            return(await ReplaceDataAsync(message, rewardString));
        }
    }
Exemplo n.º 3
0
        public async Task <string> FormatAsync(BackgroundReward reward)
        {
            var text   = "фон ";
            var dbBack = await DB.ProfileBackgrounds.GetAsync(reward.BackgroundId);

            if (dbBack is null)
            {
                RiftBot.Log.Error($"Background ID \"{nameof(reward.BackgroundId)}\" does not exist!");
                text += "не найден";
                return(text);
            }

            text += dbBack.Name;
            return(text);
        }
Exemplo n.º 4
0
 async Task DeliverBackgroundAsync(ulong userId, BackgroundReward reward)
 {
     await DB.BackgroundInventory.AddAsync(userId, reward.BackgroundId);
 }