public Team Reward(int teamId, string difficulty, bool answer, bool gotIngredient, List <string> missingIngredients) { Team team = context.Teams.Include(t => t.Inventory).ThenInclude(i => i.Ingredients).ThenInclude(i => i.Item).SingleOrDefault(t => t.Id == teamId); List <Item> missingIngredientsList = new List <Item>(); Random r = new Random(); foreach (string m in missingIngredients) { missingIngredientsList.Add(context.Items.SingleOrDefault(i => i.Name == m)); } if (team != null) { if (answer) { switch (difficulty.ToLower()) { case "high": inventoryService.addIngredient(team.Inventory.Id, missingIngredientsList[r.Next(missingIngredientsList.Count)].Id); team.Money += r.Next(40, 50); break; case "medium": if (!gotIngredient) { if (r.Next(1, 2) == 1) { inventoryService.addIngredient(team.Inventory.Id, missingIngredientsList[r.Next(missingIngredientsList.Count)].Id); } else { team.Money += r.Next(30, 40); } } else { team.Money += r.Next(30, 40); } break; case "low": team.Money += r.Next(20, 30); break; default: break; } } else { team.Money -= 10; } context.SaveChanges(); } return(team); }
public Inventory buyShopItem(int shopItemId, int teamId) { ShopItem shopItem = GetShopItemById(shopItemId); Item item = null; if (shopItem != null) { item = shopItem.Item; } else { return(null); } Team team = context.Teams.Include(t => t.Inventory).SingleOrDefault(t => t.Id == teamId); if (team != null) { if (team.Money - shopItem.Price >= 0) { team.Money -= shopItem.Price; if (shopItem.Item.Type == Item.TYPE_INGREDIENT) { team.Inventory = inventoryService.addIngredient(team.Inventory.Id, shopItem.Item.Id); } if (shopItem.Item.Type == Item.TYPE_ITEM) { team.Inventory = inventoryService.addItem(team.Inventory.Id, shopItem.Item.Id); } context.SaveChanges(); return(team.Inventory); } else { return(null); } } else { return(null); } }