inventory working :D
This commit is contained in:
+12
-12
@@ -21,11 +21,11 @@ namespace PetCompanion.Services
|
||||
_petSkillRepository = petSkillRepository;
|
||||
}
|
||||
|
||||
public async Task<PetSkill> AllocateSkillPoint(string petId, string userId, int skillId)
|
||||
public PetSkill AllocateSkillPoint(string petId, string userId, int skillId)
|
||||
{
|
||||
var pet = await _context.Pets
|
||||
var pet = _context.Pets
|
||||
.Include(p => p.Skills)
|
||||
.FirstOrDefaultAsync(p => p.Id == petId && p.UserId == userId);
|
||||
.FirstOrDefault(p => p.Id == petId && p.UserId == userId);
|
||||
|
||||
if (pet == null)
|
||||
throw new Exception("Pet not found");
|
||||
@@ -33,9 +33,9 @@ namespace PetCompanion.Services
|
||||
if (pet.SkillPoints <= 0)
|
||||
throw new Exception("No skill points available");
|
||||
|
||||
var skill = await _context.Skills
|
||||
var skill = _context.Skills
|
||||
.Include(s => s.Effects)
|
||||
.FirstOrDefaultAsync(s => s.Id == skillId);
|
||||
.FirstOrDefault(s => s.Id == skillId);
|
||||
|
||||
if (skill == null)
|
||||
throw new Exception("Skill not found");
|
||||
@@ -51,7 +51,7 @@ namespace PetCompanion.Services
|
||||
if (effect != null)
|
||||
effect.PetSkillUpgrade(ref pet);
|
||||
|
||||
await _petSkillRepository.SavePetSkill(existingSkill);
|
||||
_petSkillRepository.SavePetSkill(existingSkill);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -61,7 +61,7 @@ namespace PetCompanion.Services
|
||||
SkillId = skillId,
|
||||
CurrentTier = SkillTier.I
|
||||
};
|
||||
await _petSkillRepository.SavePetSkill(newSkill);
|
||||
_petSkillRepository.SavePetSkill(newSkill);
|
||||
|
||||
var effect = skill.Effects.FirstOrDefault(e => e.Tier == SkillTier.I);
|
||||
if (effect != null)
|
||||
@@ -69,16 +69,16 @@ namespace PetCompanion.Services
|
||||
}
|
||||
|
||||
pet.SkillPoints--;
|
||||
await _context.SaveChangesAsync();
|
||||
_context.SaveChanges();
|
||||
|
||||
return (await _petSkillRepository.GetPetSkills(petId)).First(ps => ps.SkillId == skillId);
|
||||
return _petSkillRepository.GetPetSkills(petId).First(ps => ps.SkillId == skillId);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Skill>> GetAvailableSkills()
|
||||
public IEnumerable<Skill> GetAvailableSkills()
|
||||
{
|
||||
return await _context.Skills
|
||||
return _context.Skills
|
||||
.Include(s => s.Effects)
|
||||
.ToListAsync();
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user