public async Task BuyInnovation(int userId, InnovationTypes innovationType) { var player = await _dbContext.Players .Include(p => p.Stock) .Include(p => p.Laboratory) .ThenInclude(l => l.CurrentInnovation) .Include(p => p.Laboratory) .ThenInclude(l => l.LaboratoryInnovations) .ThenInclude(li => li.Innovation) .Where(p => p.UserId == userId) .SingleOrDefaultAsync(); var cost = player.Laboratory.LaboratoryInnovations .Where(li => li.Innovation.Type == innovationType) .Select(li => li.Innovation.Cost) .FirstOrDefault(); var laboratoryInnovation = player.Laboratory.LaboratoryInnovations .Where(li => li.Innovation.Type == innovationType) .FirstOrDefault(); if (player.Laboratory.CurrentInnovation != null) { throw new GeneralGameException($"Nem tudsz több dolgot egyszerre fejleszteni!"); } if (laboratoryInnovation.Researched) { throw new GeneralGameException($"{laboratoryInnovation.Innovation.Name} már kifejlesztetted!"); } if (player.Stock.PearlAmount < laboratoryInnovation.Innovation.Cost) { throw new GeneralGameException($"Nincs elég gyöngyöd a {laboratoryInnovation.Innovation.Name} kifejlesztéséhez!"); } else { await _stockService.ReducePearl(player.Stock, laboratoryInnovation.Innovation.Cost); } var currentInnovation = new CurrentInnovation { InnovationType = innovationType, LaboratoryId = player.Laboratory.Id, TurnNeed = TIME_TO_RESEARCH_INNOVATION }; await InsertCurrentInnovation(currentInnovation, player.Laboratory); }
public float GetInnovationBonusPercentage(Laboratory laboratory, InnovationTypes innovationType) { var laboratoryInnovation = laboratory.LaboratoryInnovations .Where(li => li.Innovation.Type == innovationType) .SingleOrDefault(); float bonusPercentage = 0; if (laboratoryInnovation != null) { if (laboratoryInnovation.Researched) { bonusPercentage = laboratoryInnovation.Innovation.Percentage; } } return(bonusPercentage); }
/// <summary> /// It's zero if not researcehd by the player. /// </summary> /// <param name="playerId"></param> /// <param name="innovationType"></param> /// <returns>Innovation bonus percentage.</returns> public async Task <float> GetInnovationBonusPercentage(int playerId, InnovationTypes innovationType) { var laboratoryInnovation = await _dbContext.LaboratoryInnovations .Include(li => li.Laboratory) .Include(li => li.Innovation) .Where(li => li.Laboratory.PlayerId == playerId && li.Innovation.Type == innovationType) .SingleOrDefaultAsync(); float bonusPercentage = 0; if (laboratoryInnovation != null) { if (laboratoryInnovation.Researched) { bonusPercentage = laboratoryInnovation.Innovation.Percentage; } } return(bonusPercentage); }