Refactor inventory unequip logic to use item ID instead of equip target; update README for inventory and skill tree progress

This commit is contained in:
2025-02-05 20:37:12 -03:00
parent 5289910270
commit f553196ca0
5 changed files with 32 additions and 17 deletions

View File

@@ -79,7 +79,8 @@ namespace PetCompanion.Services
// If there's already an item equipped in that slot, unequip it first
if (pet.EquippedItems.ContainsKey(gameItem.EquipTarget))
{
UnequipItem(petId, userId, gameItem.EquipTarget);
var equippedItemId = pet.EquippedItems[gameItem.EquipTarget];
UnequipItem(petId, userId, equippedItemId);
}
// Apply equipment effects
@@ -96,17 +97,18 @@ namespace PetCompanion.Services
return petRepository.UpdatePet(pet);
}
public Pet UnequipItem(string petId, string userId, ItemEquipTarget equipTarget)
public Pet UnequipItem(string petId, string userId, int itemId)
{
var pet = petRepository.GetPetById(petId, userId);
if (pet == null)
throw new Exception("Pet not found");
if (!pet.EquippedItems.ContainsKey(equipTarget))
var equipTarget = pet.EquippedItems.FirstOrDefault(kvp => kvp.Value == itemId).Key;
if (equipTarget == ItemEquipTarget.None)
throw new Exception("No item equipped in that slot");
var equippedItemId = pet.EquippedItems[equipTarget];
var equippedItem = gameItemsRepository.GetById(equippedItemId);
var equippedItem = gameItemsRepository.GetById(itemId);
if (equippedItem != null)
{
@@ -114,7 +116,7 @@ namespace PetCompanion.Services
gameItemService.RemoveItemEffect(pet, equippedItem);
// Add item back to inventory
pet.Inventory.Items.Add(equippedItemId);
pet.Inventory.Items.Add(itemId);
}
pet.EquippedItems.Remove(equipTarget);

View File

@@ -32,6 +32,7 @@ namespace PetCompanion.Services
if (pet.SkillPoints <= 0)
throw new Exception("No skill points available");
var skill = _petSkillRepository.GetSkill(skillId);
var skills = _petSkillRepository.GetPetSkills(petId);
var existingSkill = skills.FirstOrDefault(s => s.SkillId == skillId);
@@ -45,6 +46,11 @@ namespace PetCompanion.Services
}
else
{
if (!skill.SkillsIdRequired.TrueForAll(ni => pet.Skills.Any(s => s.SkillId == ni)))
{
throw new Exception("Missing required skill");
}
existingSkill = new PetSkill
{
PetId = petId,