예제 #1
0
            public async Task SegmentAsync()
            {
                var segmentId = await GetSegmentSelectionAsync().ConfigureAwait(false);

                if (segmentId.HasValue)
                {
                    await _tacZapController.ShowSegmentAsync(Context, segmentId.Value).ConfigureAwait(false);
                }
            }
예제 #2
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);
        }
예제 #3
0
        public async Task ApplyTemplateCommandAsync()
        {
            var userId = await _userRepository.GetUserIdAsync(Context.User).ConfigureAwait(false);

            var selectedSegment  = _gameState.GetUserSegmentSelection(userId);
            var selectedTemplate = _gameState.GetUserTemplateSelection(userId);

            if (!selectedSegment.HasValue)
            {
                await ReplyAsync(Responses.SelectSegmentMessage).ConfigureAwait(false);

                return;
            }

            if (!selectedTemplate.HasValue)
            {
                await ReplyAsync(Responses.SelectTemplateMessage).ConfigureAwait(false);

                return;
            }

            var segmentId  = selectedSegment.Value;
            var templateId = selectedTemplate.Value;

            var inventory = await _inventoryRepository.GetInventoryAsync(Context.User).ConfigureAwait(false);

            foreach (var block in await _segmentRepository.ResetSegmentAsync(segmentId).ConfigureAwait(false))
            {
                inventory.AddBlocks(block.Key, block.Value);
            }

            var template = await _templateRepository.GetTemplateAsync(templateId).ConfigureAwait(false);

            var templateBlocks = new Dictionary <BlockType, int>();

            for (var y = 0; y < template.Blocks.GetLength(1); y++)
            {
                for (var x = 0; x < template.Blocks.GetLength(0); x++)
                {
                    var block = template.Blocks[x, y];
                    if (block == null || block.BlockType == BlockType.Controller)
                    {
                        continue;
                    }

                    if (!templateBlocks.ContainsKey(block.BlockType))
                    {
                        templateBlocks.Add(block.BlockType, 0);
                    }
                    templateBlocks[block.BlockType]++;
                }
            }

            var buy       = true;
            var notEnough = new Dictionary <BlockType, int>();

            foreach (var templateblock in templateBlocks)
            {
                if (inventory.Blocks.ContainsKey(templateblock.Key) &&
                    inventory.Blocks[templateblock.Key] - templateblock.Value >= 0)
                {
                    continue;
                }

                buy = false;
                notEnough.Add(templateblock.Key, templateblock.Value - inventory.Blocks[templateblock.Key]);
            }

            if (!buy)
            {
                var message = "You don't have enough blocks, you are missing:" + Environment.NewLine;
                foreach (var block in notEnough)
                {
                    message += $"{block.Key} x{block.Value}";
                }

                await ReplyAsync(message).ConfigureAwait(false);

                return;
            }

            var segment = await _segmentRepository.GetSegmentAsync(segmentId).ConfigureAwait(false);

            for (var y = 0; y < template.Blocks.GetLength(1); y++)
            {
                for (var x = 0; x < template.Blocks.GetLength(0); x++)
                {
                    var block = template.Blocks[x, y];
                    if (block == null || block.BlockType == BlockType.Controller)
                    {
                        continue;
                    }

                    inventory.RemoveBlocks(block.BlockType, 1);
                    segment.AddBlock(x, y, block.BlockType);
                }
            }

            await _segmentRepository.SetSegmentAsync(segmentId, segment).ConfigureAwait(false);

            await _inventoryRepository.SaveInventoryAsync(Context.User, inventory).ConfigureAwait(false);

            await _tacZapController.ShowSegmentAsync(Context, segmentId).ConfigureAwait(false);
        }