feat: enhance pet management with new skills and inventory system
This commit is contained in:
parent
dd32327383
commit
a624ba1e73
@ -2,56 +2,47 @@ import { ApiService } from './index';
|
|||||||
import { Pet, Resources } from '../../types/Pet';
|
import { Pet, Resources } from '../../types/Pet';
|
||||||
import { PetCreationRequest } from '../../types/PetCreationRequest';
|
import { PetCreationRequest } from '../../types/PetCreationRequest';
|
||||||
import { PetUpdateActionRequest } from '../../types/PetUpdateActionRequest';
|
import { PetUpdateActionRequest } from '../../types/PetUpdateActionRequest';
|
||||||
|
import { PetSkill, Skill } from '../../types/Skills';
|
||||||
|
|
||||||
// Get API service instance
|
// Get API service instance
|
||||||
const api = ApiService.getInstance();
|
const api = ApiService.getInstance();
|
||||||
|
|
||||||
export async function fetchPets(): Promise<Pet[]> {
|
export async function fetchPets(): Promise<Pet[]> {
|
||||||
try {
|
|
||||||
const response = await api.get<Pet[]>('/api/v1/pet');
|
const response = await api.get<Pet[]>('/api/v1/pet');
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Failed to fetch pets:', error.message);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createPet(data: PetCreationRequest): Promise<Pet> {
|
export async function createPet(data: PetCreationRequest): Promise<Pet> {
|
||||||
try {
|
|
||||||
const response = await api.post<Pet>('/api/v1/pet', data);
|
const response = await api.post<Pet>('/api/v1/pet', data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Failed to create pet:', error.message);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updatePetAction(petId: string, data: PetUpdateActionRequest): Promise<Pet> {
|
export async function updatePetAction(petId: string, data: PetUpdateActionRequest): Promise<Pet> {
|
||||||
try {
|
|
||||||
const response = await api.put<Pet>(`/api/v1/pet/${petId}/action`, data);
|
const response = await api.put<Pet>(`/api/v1/pet/${petId}/action`, data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Failed to update pet action:', error.message);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPetGatheredResources(petId: string): Promise<Resources> {
|
export async function getPetGatheredResources(petId: string): Promise<Resources> {
|
||||||
try {
|
|
||||||
const response = await api.get<Resources>(`/api/v1/pet/${petId}/resources/gathered`);
|
const response = await api.get<Resources>(`/api/v1/pet/${petId}/resources/gathered`);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Failed to fetch pet gathered resources:', error.message);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function putPetCollectResources(petId: string): Promise<Pet> {
|
export async function putPetCollectResources(petId: string): Promise<Pet> {
|
||||||
try {
|
|
||||||
const response = await api.put<Pet>(`/api/v1/pet/${petId}/resources/collect`);
|
const response = await api.put<Pet>(`/api/v1/pet/${petId}/resources/collect`);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error: any) {
|
}
|
||||||
console.error('Failed to collect pet gathered resources:', error.message);
|
|
||||||
throw error;
|
export async function getAllSkills(): Promise<Skill[]> {
|
||||||
}
|
const response = await api.get<Skill[]>(`/api/v1/skill`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPetSkills(petId: string): Promise<PetSkill[]> {
|
||||||
|
const response = await api.get<PetSkill[]>(`/api/v1/skill/${petId}/pet`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function postAllocatePetSkill(petId: string, skillId: int): Promise<PetSkill> {
|
||||||
|
const response = await api.get<PetSkill>(`/api/v1/skill/${petId}/allocate/${skillId}`);
|
||||||
|
return response.data;
|
||||||
}
|
}
|
@ -25,9 +25,19 @@ export interface Pet {
|
|||||||
stats: PetStats;
|
stats: PetStats;
|
||||||
resources: Resources;
|
resources: Resources;
|
||||||
level: number;
|
level: number;
|
||||||
petBasicAction: PetBasicAction;
|
experience: number;
|
||||||
basicActionCooldown: Date;
|
health: number;
|
||||||
|
maxHealth: number;
|
||||||
petGatherAction: PetGatherAction;
|
petGatherAction: PetGatherAction;
|
||||||
|
basicActionCooldown: Date;
|
||||||
|
petBasicAction: PetBasicAction;
|
||||||
|
skillPoints: number;
|
||||||
|
inventory: Inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Inventory {
|
||||||
|
items: number[];
|
||||||
|
capacity: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PetClassInfo {
|
export interface PetClassInfo {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { PetClass } from "./Pet";
|
|
||||||
|
|
||||||
export interface PetCreationRequest {
|
export interface PetCreationRequest {
|
||||||
name: string;
|
name: string;
|
||||||
class: PetClass;
|
class: string;
|
||||||
}
|
}
|
26
src/types/Skills.ts
Normal file
26
src/types/Skills.ts
Normal file
@ -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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user