예제 #1
0
파일: Block.cs 프로젝트: LeGaryGary/Stupify
        private async Task AddBlockCommandAsync(int segmentId, int x, int y, string type)
        {
            var blockType = Enum.Parse <BlockType>(type, true);

            if (await _inventoryRepository.RemoveFromInventoryAsync(blockType, 1, Context.User).ConfigureAwait(false))
            {
                if (!await _segmentRepository.AddBlockAsync(segmentId, x - 1, y - 1, blockType).ConfigureAwait(false))
                {
                    await _inventoryRepository.AddToInventoryAsync(blockType, 1, Context.User).ConfigureAwait(false);
                }
                await _tacZapController.ShowSegmentAsync(Context, segmentId).ConfigureAwait(false);

                return;
            }

            await ReplyAsync(Responses.ShopAdvisoryMessage).ConfigureAwait(false);
        }
예제 #2
0
            public async Task ResetSegmentAsync()
            {
                var segmentId = await GetSegmentSelectionAsync().ConfigureAwait(false);

                if (segmentId.HasValue)
                {
                    var blocks = await _segmentRepository.ResetSegmentAsync(segmentId.Value).ConfigureAwait(false);

                    foreach (var type in blocks)
                    {
                        if (type.Value > 0)
                        {
                            await _inventoryRepository.AddToInventoryAsync(type.Key, type.Value, Context.User).ConfigureAwait(false);
                        }
                    }

                    await ReplyAsync($"segment {segmentId} was reset!").ConfigureAwait(false);
                }
            }
예제 #3
0
        public async Task BuyFromShopAsync(BlockType block, int quantity)
        {
            var total = _tacZapController.Shop.GetBuyTotal(block, quantity);

            if (!total.HasValue)
            {
                await ReplyAsync("The shop doesn't sell this type of block.").ConfigureAwait(false);

                return;
            }

            if (!await _userRepository.UserToBankTransferAsync(Context.User, total.Value).ConfigureAwait(false))
            {
                await ReplyAsync(Responses.NotEnoughUnits(total.Value)).ConfigureAwait(false);

                return;
            }

            await _inventoryRepository.AddToInventoryAsync(block, quantity, Context.User).ConfigureAwait(false);

            await ShowInventoryAsync().ConfigureAwait(false);
        }