From a624ba1e73a7bd7d9adee97e0ec3879d9c90ba32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Henrique?= Date: Wed, 5 Feb 2025 20:10:38 -0300 Subject: [PATCH] feat: enhance pet management with new skills and inventory system --- src/services/api/api.ts | 61 ++++++++++++++------------------- src/types/Pet.ts | 14 ++++++-- src/types/PetCreationRequest.ts | 4 +-- src/types/Skills.ts | 26 ++++++++++++++ 4 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 src/types/Skills.ts diff --git a/src/services/api/api.ts b/src/services/api/api.ts index 58e258e..7bfd02d 100644 --- a/src/services/api/api.ts +++ b/src/services/api/api.ts @@ -2,56 +2,47 @@ import { ApiService } from './index'; import { Pet, Resources } from '../../types/Pet'; import { PetCreationRequest } from '../../types/PetCreationRequest'; import { PetUpdateActionRequest } from '../../types/PetUpdateActionRequest'; +import { PetSkill, Skill } from '../../types/Skills'; // Get API service instance const api = ApiService.getInstance(); export async function fetchPets(): Promise { - try { - const response = await api.get('/api/v1/pet'); - return response.data; - } catch (error: any) { - console.error('Failed to fetch pets:', error.message); - throw error; - } + const response = await api.get('/api/v1/pet'); + return response.data; } export async function createPet(data: PetCreationRequest): Promise { - try { - const response = await api.post('/api/v1/pet', data); - return response.data; - } catch (error: any) { - console.error('Failed to create pet:', error.message); - throw error; - } + const response = await api.post('/api/v1/pet', data); + return response.data; } export async function updatePetAction(petId: string, data: PetUpdateActionRequest): Promise { - try { - const response = await api.put(`/api/v1/pet/${petId}/action`, data); - return response.data; - } catch (error: any) { - console.error('Failed to update pet action:', error.message); - throw error; - } + const response = await api.put(`/api/v1/pet/${petId}/action`, data); + return response.data; } export async function getPetGatheredResources(petId: string): Promise { - try { - const response = await api.get(`/api/v1/pet/${petId}/resources/gathered`); - return response.data; - } catch (error: any) { - console.error('Failed to fetch pet gathered resources:', error.message); - throw error; - } + const response = await api.get(`/api/v1/pet/${petId}/resources/gathered`); + return response.data; } export async function putPetCollectResources(petId: string): Promise { - try { - const response = await api.put(`/api/v1/pet/${petId}/resources/collect`); - return response.data; - } catch (error: any) { - console.error('Failed to collect pet gathered resources:', error.message); - throw error; - } + const response = await api.put(`/api/v1/pet/${petId}/resources/collect`); + return response.data; +} + +export async function getAllSkills(): Promise { + const response = await api.get(`/api/v1/skill`); + return response.data; +} + +export async function getPetSkills(petId: string): Promise { + const response = await api.get(`/api/v1/skill/${petId}/pet`); + return response.data; +} + +export async function postAllocatePetSkill(petId: string, skillId: int): Promise { + const response = await api.get(`/api/v1/skill/${petId}/allocate/${skillId}`); + return response.data; } \ No newline at end of file diff --git a/src/types/Pet.ts b/src/types/Pet.ts index d17e261..37f68d8 100755 --- a/src/types/Pet.ts +++ b/src/types/Pet.ts @@ -25,9 +25,19 @@ export interface Pet { stats: PetStats; resources: Resources; level: number; - petBasicAction: PetBasicAction; - basicActionCooldown: Date; + experience: number; + health: number; + maxHealth: number; petGatherAction: PetGatherAction; + basicActionCooldown: Date; + petBasicAction: PetBasicAction; + skillPoints: number; + inventory: Inventory; +} + +export interface Inventory { + items: number[]; + capacity: number; } export interface PetClassInfo { diff --git a/src/types/PetCreationRequest.ts b/src/types/PetCreationRequest.ts index 66a7e20..6f0130a 100644 --- a/src/types/PetCreationRequest.ts +++ b/src/types/PetCreationRequest.ts @@ -1,6 +1,4 @@ -import { PetClass } from "./Pet"; - export interface PetCreationRequest { name: string; - class: PetClass; + class: string; } \ No newline at end of file diff --git a/src/types/Skills.ts b/src/types/Skills.ts new file mode 100644 index 0000000..77c818c --- /dev/null +++ b/src/types/Skills.ts @@ -0,0 +1,26 @@ +export interface Skill { + id: number; + name: string; + description: string; + type: string; + pointsCost: number; + icon: string; + skillsIdRequired: number | null; + effects: SkillEffect[]; +} + +export interface SkillEffect { + id: number; + skillId: number; + tier: string; + effect: string; + value: number; +} + +export interface PetSkill { + id: number; + petId: string; + skillId: number; + skill: Skill; + currentTier: string; +}