not working inventory :c
This commit is contained in:
+19
-11
@@ -7,18 +7,23 @@ namespace PetCompanion.Services
|
||||
{
|
||||
public class SkillService
|
||||
{
|
||||
private readonly ApplicationDbContext context;
|
||||
private readonly PetRepository petRepository;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly PetRepository _petRepository;
|
||||
private readonly PetSkillRepository _petSkillRepository;
|
||||
|
||||
public SkillService(ApplicationDbContext context, PetRepository petRepository)
|
||||
public SkillService(
|
||||
ApplicationDbContext context,
|
||||
PetRepository petRepository,
|
||||
PetSkillRepository petSkillRepository)
|
||||
{
|
||||
this.context = context;
|
||||
this.petRepository = petRepository;
|
||||
_context = context;
|
||||
_petRepository = petRepository;
|
||||
_petSkillRepository = petSkillRepository;
|
||||
}
|
||||
|
||||
public async Task<PetSkill> AllocateSkillPoint(string petId, string userId, int skillId)
|
||||
{
|
||||
var pet = await context.Pets
|
||||
var pet = await _context.Pets
|
||||
.Include(p => p.Skills)
|
||||
.FirstOrDefaultAsync(p => p.Id == petId && p.UserId == userId);
|
||||
|
||||
@@ -28,7 +33,7 @@ namespace PetCompanion.Services
|
||||
if (pet.SkillPoints <= 0)
|
||||
throw new Exception("No skill points available");
|
||||
|
||||
var skill = await context.Skills
|
||||
var skill = await _context.Skills
|
||||
.Include(s => s.Effects)
|
||||
.FirstOrDefaultAsync(s => s.Id == skillId);
|
||||
|
||||
@@ -45,6 +50,8 @@ namespace PetCompanion.Services
|
||||
var effect = skill.Effects.FirstOrDefault(e => e.Tier == existingSkill.CurrentTier);
|
||||
if (effect != null)
|
||||
effect.PetSkillUpgrade(ref pet);
|
||||
|
||||
await _petSkillRepository.SavePetSkill(existingSkill);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -54,21 +61,22 @@ namespace PetCompanion.Services
|
||||
SkillId = skillId,
|
||||
CurrentTier = SkillTier.I
|
||||
};
|
||||
pet.Skills.Add(newSkill);
|
||||
await _petSkillRepository.SavePetSkill(newSkill);
|
||||
|
||||
var effect = skill.Effects.FirstOrDefault(e => e.Tier == SkillTier.I);
|
||||
if (effect != null)
|
||||
effect.PetSkillUpgrade(ref pet);
|
||||
}
|
||||
|
||||
pet.SkillPoints--;
|
||||
await context.SaveChangesAsync();
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return pet.Skills.First(ps => ps.SkillId == skillId);
|
||||
return (await _petSkillRepository.GetPetSkills(petId)).First(ps => ps.SkillId == skillId);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Skill>> GetAvailableSkills()
|
||||
{
|
||||
return await context.Skills
|
||||
return await _context.Skills
|
||||
.Include(s => s.Effects)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user