Ejemplo n.º 1
0
        public async Task <ActionResult <Inventory> > CraftItem(Guid id, [FromBody] CraftItemRequest craftItem)
        {
            var factory = _factoryManager.GetFactory(id);

            if (factory == null)
            {
                return(NotFound());
            }
            var itemToCraft = RecipesDatabase.GetRecipe(craftItem.Name);

            if (itemToCraft == null)
            {
                await _hubContext.Clients.Group(factory.Id.ToString()).SendNotification("Error",
                                                                                        $"Couldn't find item to craft named {craftItem.Name}", "danger");

                return(NotFound());
            }

            if (!_craftingService.CanCraftItem(factory, itemToCraft, craftItem.Count))
            {
                await _hubContext.Clients.Group(factory.Id.ToString())
                .SendNotification("Error", "Not enough items to make crafting", "danger");

                return(NotFound());
            }

            _craftingService.AddItemToCraftQueue(factory, itemToCraft, craftItem.Count);
            await _hubContext.Clients.Group(factory.Id.ToString()).UpdateFactoryCraftingQueue(factory.Id, factory.CraftingQueue);

            return(new JsonResult(factory.Inventory));
        }
Ejemplo n.º 2
0
 public Factory(Guid id, string displayName)
 {
     Id            = id;
     DisplayName   = displayName;
     CreatedAt     = DateTime.Now;
     Inventory     = new FactoryInventoryCreateService().CreateDefaultInventory(new Random().Next(100, 300));
     Recipes       = RecipesDatabase.GetRandomRecipes(new Random().Next(2, 5));
     CraftingQueue = new List <CraftItem>();
 }