Refactor pet action management: rename PetAction to PetActionGather, update related models and services, and enhance resource gathering logic.
This commit is contained in:
121
Repositories/PetClassRepository.cs
Normal file
121
Repositories/PetClassRepository.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using pet_companion_api.Data;
|
||||
using pet_companion_api.Models;
|
||||
|
||||
namespace pet_companion_api.Repositories
|
||||
{
|
||||
public class PetClassRepository
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public PetClassRepository(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IEnumerable<PetClassInfo> GetAllPetClassesInfo()
|
||||
{
|
||||
return new List<PetClassInfo>
|
||||
{
|
||||
new PetClassInfo
|
||||
{
|
||||
Name = "Forest Spirit",
|
||||
Description = "A mystical guardian of nature, attuned to the forest's wisdom.",
|
||||
Modifiers = new List<Modifier>
|
||||
{
|
||||
new Modifier { Description = "-20% food consumption" },
|
||||
new Modifier { Description = "+15% wisdom generation" },
|
||||
new Modifier { Description = "Natural healing ability" }
|
||||
},
|
||||
Color = "emerald",
|
||||
Emoji = "🌿",
|
||||
Class = PetClass.FOREST_SPIRIT
|
||||
},
|
||||
new PetClassInfo
|
||||
{
|
||||
Name = "Ocean Guardian",
|
||||
Description = "A majestic creature of the deep, master of the seas.",
|
||||
Modifiers = new List<Modifier>
|
||||
{
|
||||
new Modifier { Description = "+20% resource gathering" },
|
||||
new Modifier { Description = "Water breathing" },
|
||||
new Modifier { Description = "Enhanced mobility" }
|
||||
},
|
||||
Color = "cyan",
|
||||
Emoji = "🌊",
|
||||
Class = PetClass.OCEAN_GUARDIAN
|
||||
},
|
||||
new PetClassInfo
|
||||
{
|
||||
Name = "Fire Elemental",
|
||||
Description = "A passionate spirit of flame, burning with inner strength.",
|
||||
Modifiers = new List<Modifier>
|
||||
{
|
||||
new Modifier { Description = "+25% strength gains" },
|
||||
new Modifier { Description = "Fire resistance" },
|
||||
new Modifier { Description = "Heat generation" }
|
||||
},
|
||||
Color = "red",
|
||||
Emoji = "🔥",
|
||||
Class = PetClass.FIRE_ELEMENTAL
|
||||
},
|
||||
new PetClassInfo
|
||||
{
|
||||
Name = "Mythical Beast",
|
||||
Description = "A legendary creature of ancient lore.",
|
||||
Modifiers = new List<Modifier>
|
||||
{
|
||||
new Modifier { Description = "+30% charisma" },
|
||||
new Modifier { Description = "Rare item finding" },
|
||||
new Modifier { Description = "Enhanced abilities at night" }
|
||||
},
|
||||
Color = "purple",
|
||||
Emoji = "🦄",
|
||||
Class = PetClass.MYTHICAL_BEAST
|
||||
},
|
||||
new PetClassInfo
|
||||
{
|
||||
Name = "Shadow Walker",
|
||||
Description = "A mysterious being that moves between light and darkness.",
|
||||
Modifiers = new List<Modifier>
|
||||
{
|
||||
new Modifier { Description = "Stealth abilities" },
|
||||
new Modifier { Description = "+25% junk value" },
|
||||
new Modifier { Description = "Night vision" }
|
||||
},
|
||||
Color = "violet",
|
||||
Emoji = "👻",
|
||||
Class = PetClass.SHADOW_WALKER
|
||||
},
|
||||
new PetClassInfo
|
||||
{
|
||||
Name = "Cyber Pet",
|
||||
Description = "A digital companion from the future.",
|
||||
Modifiers = new List<Modifier>
|
||||
{
|
||||
new Modifier { Description = "+30% intelligence growth" },
|
||||
new Modifier { Description = "Digital interface" },
|
||||
new Modifier { Description = "Quick processing" }
|
||||
},
|
||||
Color = "blue",
|
||||
Emoji = "🤖",
|
||||
Class = PetClass.CYBER_PET
|
||||
},
|
||||
new PetClassInfo
|
||||
{
|
||||
Name = "Bio-Mechanical Hybrid",
|
||||
Description = "A perfect fusion of organic life and advanced technology.",
|
||||
Modifiers = new List<Modifier>
|
||||
{
|
||||
new Modifier { Description = "Self-repair capability" },
|
||||
new Modifier { Description = "+20% all stats" },
|
||||
new Modifier { Description = "Resource optimization" }
|
||||
},
|
||||
Color = "teal",
|
||||
Emoji = "🦾",
|
||||
Class = PetClass.BIO_MECHANICAL
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,16 +6,16 @@ namespace pet_companion_api.Repositories
|
||||
{
|
||||
public class PetRepository
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext context;
|
||||
|
||||
public PetRepository(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public IEnumerable<Pet> GetPetsByUserId(string userId)
|
||||
{
|
||||
return _context.Pets
|
||||
return context.Pets
|
||||
.Where(p => p.UserId == userId)
|
||||
.Include(p => p.Stats)
|
||||
.Include(p => p.Resources)
|
||||
@@ -24,30 +24,42 @@ namespace pet_companion_api.Repositories
|
||||
|
||||
public Pet GetPetById(string petId, string userId)
|
||||
{
|
||||
return _context.Pets
|
||||
.FirstOrDefault(p => p.Id == petId && p.UserId == userId);
|
||||
return context.Pets
|
||||
.Where(p => p.Id == petId && p.UserId == userId)
|
||||
.Include(p => p.Stats)
|
||||
.Include(p => p.Resources)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public Pet CreatePet(Pet pet)
|
||||
{
|
||||
_context.Pets.Add(pet);
|
||||
_context.SaveChanges();
|
||||
context.Pets.Add(pet);
|
||||
context.SaveChanges();
|
||||
return pet;
|
||||
}
|
||||
|
||||
public Pet UpdatePet(Pet pet)
|
||||
{
|
||||
_context.Pets.Update(pet);
|
||||
_context.SaveChanges();
|
||||
context.Pets.Update(pet);
|
||||
context.SaveChanges();
|
||||
return pet;
|
||||
}
|
||||
|
||||
public Pet UpdatePetAction(Pet pet)
|
||||
{
|
||||
_context.Pets.Attach(pet);
|
||||
_context.Entry(pet).Property(p => p.PetAction).IsModified = true;
|
||||
_context.Entry(pet).Property(p => p.ActionSince).IsModified = true;
|
||||
_context.SaveChanges();
|
||||
context.Pets.Attach(pet);
|
||||
context.Entry(pet).Property(p => p.PetAction).IsModified = true;
|
||||
context.Entry(pet).Property(p => p.ActionSince).IsModified = true;
|
||||
context.SaveChanges();
|
||||
return pet;
|
||||
}
|
||||
|
||||
public Pet UpdatePetResources(Pet pet)
|
||||
{
|
||||
context.Pets.Attach(pet);
|
||||
context.Entry(pet).Reference(p => p.Resources).IsModified = true;
|
||||
context.Entry(pet).Property(p => p.ActionSince).IsModified = true;
|
||||
context.SaveChanges();
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user