Refactor pet action management: rename PetAction to PetActionGather, update related models and services, and enhance resource gathering logic.
This commit is contained in:
@@ -6,10 +6,12 @@ namespace pet_companion_api.Services
|
||||
public class PetService
|
||||
{
|
||||
private readonly PetRepository petRepository;
|
||||
private readonly PetClassService _petClassService;
|
||||
|
||||
public PetService(PetRepository petRepository)
|
||||
public PetService(PetRepository petRepository, PetClassService petClassService)
|
||||
{
|
||||
this.petRepository = petRepository;
|
||||
_petClassService = petClassService;
|
||||
}
|
||||
|
||||
public IEnumerable<Pet> GetAllPets(Guid userId)
|
||||
@@ -29,7 +31,7 @@ namespace pet_companion_api.Services
|
||||
Stats = PetStats.BuildFromClass(petRequest.Class),
|
||||
Resources = new Resources(),
|
||||
ActionSince = DateTime.UtcNow,
|
||||
PetAction = PetAction.IDLE,
|
||||
PetAction = PetActionGather.IDLE,
|
||||
IsDead = false
|
||||
};
|
||||
|
||||
@@ -44,10 +46,50 @@ namespace pet_companion_api.Services
|
||||
throw new Exception("Pet not found");
|
||||
}
|
||||
|
||||
pet.PetAction = actionRequest.PetAction;
|
||||
if (actionRequest.Action.HasValue)
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
else if (actionRequest.PetActionGather.HasValue)
|
||||
{
|
||||
pet.PetAction = actionRequest.PetActionGather.Value;
|
||||
pet.ActionSince = DateTime.UtcNow;
|
||||
|
||||
return petRepository.UpdatePetAction(pet);
|
||||
}
|
||||
|
||||
return pet;
|
||||
}
|
||||
|
||||
public Resources GetGatheredResources(string petId, string userId)
|
||||
{
|
||||
var pet = petRepository.GetPetById(petId, userId);
|
||||
|
||||
if (pet == null)
|
||||
{
|
||||
throw new Exception("Pet not found");
|
||||
}
|
||||
|
||||
return _petClassService.CalculateGatheredResources(pet.Stats, pet.Level, pet.PetAction, pet.ActionSince);
|
||||
}
|
||||
|
||||
public Pet UpdatePetResources(string petId, string userId)
|
||||
{
|
||||
var pet = petRepository.GetPetById(petId, userId);
|
||||
if (pet == null)
|
||||
{
|
||||
throw new Exception("Pet not found");
|
||||
}
|
||||
|
||||
var gatheredResources = _petClassService.CalculateGatheredResources(pet.Stats, pet.Level, pet.PetAction, pet.ActionSince);
|
||||
|
||||
pet.Resources.Wisdom += gatheredResources.Wisdom;
|
||||
pet.Resources.Gold += gatheredResources.Gold;
|
||||
pet.Resources.Food += gatheredResources.Food;
|
||||
pet.Resources.Junk += gatheredResources.Junk;
|
||||
pet.ActionSince = DateTime.UtcNow;
|
||||
|
||||
return petRepository.UpdatePetAction(pet);
|
||||
return petRepository.UpdatePetResources(pet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user