not working inventory :c
This commit is contained in:
1 parent
f234b5d84d
commit
7a2c3d2f67
22 files changed
+2713
-49
No files matched your search
@@ -0,0 +1,113 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PetCompanion.Models;
|
||||
using PetCompanion.Services;
|
||||
|
||||
namespace PetCompanion.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/[controller]")]
|
||||
public class InventoryController : ControllerBase
|
||||
{
|
||||
private readonly PetInventoryService _inventoryService;
|
||||
private readonly ILogger<InventoryController> _logger;
|
||||
private readonly Guid userId = Guid.Parse("f5f4b3b3-3b7b-4b7b-8b7b-7b7b7b7b7b7b");
|
||||
|
||||
public InventoryController(
|
||||
ILogger<InventoryController> logger,
|
||||
PetInventoryService inventoryService)
|
||||
{
|
||||
_logger = logger;
|
||||
_inventoryService = inventoryService;
|
||||
}
|
||||
|
||||
[HttpGet("{petId}")]
|
||||
public async Task<IActionResult> GetInventory(string petId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var inventory = await _inventoryService.GetInventory(petId, userId.ToString());
|
||||
return Ok(inventory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{petId}/{itemId}/use")]
|
||||
public async Task<IActionResult> UseItem(string petId, int itemId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var updatedPet = await _inventoryService.UseItem(petId, userId.ToString(), itemId);
|
||||
return Ok(updatedPet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{petId}/{itemId}/equip")]
|
||||
public IActionResult EquipItem(string petId, int itemId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var updatedPet = _inventoryService.EquipItem(petId, userId.ToString(), itemId);
|
||||
return Ok(updatedPet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{petId}/{equipTarget}/unequip")]
|
||||
public IActionResult UnequipItem(string petId, ItemEquipTarget equipTarget)
|
||||
{
|
||||
try
|
||||
{
|
||||
var updatedPet = _inventoryService.UnequipItem(petId, userId.ToString(), equipTarget);
|
||||
return Ok(updatedPet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{petId}/{itemId}/drop")]
|
||||
public IActionResult DropItem(string petId, int itemId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var updatedPet = _inventoryService.DropItem(petId, userId.ToString(), itemId);
|
||||
return Ok(updatedPet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("{petId}/create")]
|
||||
public IActionResult AddItem(string petId, [FromBody] AddItemRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var updatedPet = _inventoryService.AddItemToPet(petId, userId.ToString(), request.ItemId, request.Quantity);
|
||||
return Ok(updatedPet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AddItemRequest
|
||||
{
|
||||
public int ItemId { get; set; }
|
||||
public int Quantity { get; set; } = 1;
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,18 @@ namespace PetCompanion.Controllers
|
||||
public class SkillController : ControllerBase
|
||||
{
|
||||
private readonly SkillService _skillService;
|
||||
private readonly PetSkillService _petSkillService;
|
||||
private readonly ILogger<SkillController> _logger;
|
||||
private Guid userId = Guid.Parse("f5f4b3b3-3b7b-4b7b-8b7b-7b7b7b7b7b7b");
|
||||
|
||||
public SkillController(
|
||||
ILogger<SkillController> logger,
|
||||
SkillService skillService)
|
||||
SkillService skillService,
|
||||
PetSkillService petSkillService)
|
||||
{
|
||||
_logger = logger;
|
||||
_skillService = skillService;
|
||||
_petSkillService = petSkillService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -26,12 +29,26 @@ namespace PetCompanion.Controllers
|
||||
return Ok(skills);
|
||||
}
|
||||
|
||||
[HttpGet("{petId}/skills")]
|
||||
public async Task<IActionResult> GetPetSkills(string petId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var skills = await _petSkillService.GetPetSkills(petId, userId.ToString());
|
||||
return Ok(skills);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("{petId}/allocate/{skillId}")]
|
||||
public async Task<IActionResult> AllocateSkillPoint(string petId, int skillId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _skillService.AllocateSkillPoint(petId, userId.ToString(), skillId);
|
||||
var result = await _petSkillService.AllocateSkillPoint(petId, userId.ToString(), skillId);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -15,6 +15,10 @@ namespace PetCompanion.Data
|
||||
public DbSet<Skill> Skills { get; set; }
|
||||
public DbSet<SkillEffect> SkillEffects { get; set; }
|
||||
public DbSet<PetSkill> PetSkills { get; set; }
|
||||
public DbSet<GameItem> GameItems { get; set; }
|
||||
public DbSet<Inventory> Inventories { get; set; }
|
||||
public DbSet<InventoryItem> InventoryItems { get; set; }
|
||||
public DbSet<EquippedItem> EquippedItems { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -48,11 +52,44 @@ namespace PetCompanion.Data
|
||||
.WithMany(s => s.Effects)
|
||||
.HasForeignKey(se => se.SkillId);
|
||||
|
||||
modelBuilder.Entity<InventoryItem>()
|
||||
.HasOne<Inventory>()
|
||||
.WithMany(i => i.Items)
|
||||
.HasForeignKey(ii => ii.InventoryId);
|
||||
|
||||
modelBuilder.Entity<InventoryItem>()
|
||||
.HasOne(ii => ii.GameItem);
|
||||
|
||||
modelBuilder.Entity<EquippedItem>()
|
||||
.HasOne(e => e.Pet)
|
||||
.WithMany(p => p.EquippedItemsList)
|
||||
.HasForeignKey(e => e.PetId);
|
||||
|
||||
modelBuilder.Entity<EquippedItem>()
|
||||
.HasOne(e => e.GameItem)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.GameItemId);
|
||||
|
||||
// Seed initial skills
|
||||
var skills = SkillsData.GetInitialSkills();
|
||||
foreach (var skill in skills)
|
||||
var skillWithoutEffects = SkillsData.GetInitialSkills().Select(s => new Skill
|
||||
{
|
||||
Id = s.Id,
|
||||
Name = s.Name,
|
||||
Type = s.Type,
|
||||
Description = s.Description,
|
||||
PointsCost = s.PointsCost,
|
||||
Icon = s.Icon,
|
||||
SkillsIdRequired = s.SkillsIdRequired
|
||||
}).ToList();
|
||||
|
||||
foreach (var skill in skillWithoutEffects)
|
||||
{
|
||||
modelBuilder.Entity<Skill>().HasData(skill);
|
||||
}
|
||||
|
||||
foreach (var skill in skills)
|
||||
{
|
||||
foreach (var effect in skill.Effects)
|
||||
{
|
||||
modelBuilder.Entity<SkillEffect>().HasData(effect);
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
ItemId,Item Name, Type, Rarity, Description,Price,Effect
|
||||
0,Apple,Material,Common,Crafting material (coming soon),0,Nothing
|
||||
1,Basic Kibble,Consumable,Common,Adds +20 food resources,0,ADD_FOOD_RESOURCES_20
|
||||
2,Superfood Smoothie,Consumable,Uncommon,Adds +30 food resources; Restores 5 Intelligence,0,ADD_FOOD_RESOURCES_30
|
||||
3,Energy Drink,Consumable,Rare,Reduces Cooldown by 5 min,0,REDUCE_COOLDOWN_5
|
||||
4,Golden Apple,Consumable,Legendary,Adds +20 Intelligence (Permanent); Adds +100 food resources,0,ADD_INTELLIGENCE_20
|
||||
5,Healing Potion,Consumable,Uncommon,Adds +20 to Health; Adds +20 food resources,0,ADD_HEALTH_20_AND_FOOD_20
|
||||
6,Charisma Cookie,Consumable,Rare,Adds +2 Charisma (Permanent),0,ADD_CHARISMA_2
|
||||
7,XP Booster,Consumable,Rare,Award +10 XP,0,ADD_XP_10
|
||||
8,Sleeping Draught,Consumable,Common,Reduces Cooldown for resting by 10 min,0,REDUCE_REST_COOLDOWN_10
|
||||
9,Mystery Meat,Consumable,Uncommon,Randomly ±2 to one stat (Permanent),0,ADD_RANDOM_STAT_2
|
||||
10,Elixir of Vitality,Consumable,Legendary,Fully restores all stats and health; Adds +1 Level,0,RESTORE_STATS;ADD_LEVEL_1
|
||||
11,Leather Hat,Equipment,Common,Helmet: +5 Max Health,0,ADD_MAX_HEALTH_5
|
||||
12,Wizard Hat,Equipment,Rare,Helmet: +15 Max Intelligence,0,ADD_MAX_INTELLIGENCE_15
|
||||
13,Knight's Armor,Equipment,Rare,Chest: +15 Max Strength,0,ADD_MAX_STRENGTH_15
|
||||
14,Golden Boots,Equipment,Uncommon,Legging: +10 Max Charisma,0,ADD_MAX_CHARISMA_10
|
||||
15,Laser Pointer,Equipment,Common,Weapon: +5 Max Strength,0,ADD_MAX_STRENGTH_5
|
||||
16,Celestial Crown,Equipment,Legendary,Helmet: +20 max to all stats,0,ADD_MAX_ALL_STATS_20
|
||||
17,Dragon Scale Shield,Equipment,Legendary,Weapon: +50 Max Health,0,ADD_MAX_HEALTH_50
|
||||
18,Feathers,Material,Common,Crafting material (coming soon),0,Nothing
|
||||
19,Phoenix Feather,Material,Legendary,Crafting material (coming soon),0,Nothing
|
||||
Id,Name,Type,Rarity,Description,Price,Effect,EquipTarget
|
||||
1,Apple,Material,Common,Crafting material (coming soon),0,Nothing,None
|
||||
2,Superfood Smoothie,Consumable,Uncommon,Adds +30 food resources; Restores 5 Intelligence,0,ADD_FOOD_RESOURCES_30,None
|
||||
3,Energy Drink,Consumable,Rare,Reduces Cooldown by 5 min,0,REDUCE_COOLDOWN_5,None
|
||||
4,Golden Apple,Consumable,Legendary,Adds +20 Intelligence (Permanent); Adds +100 food resources,0,ADD_INTELLIGENCE_20,None
|
||||
5,Healing Potion,Consumable,Uncommon,Adds +20 to Health; Adds +20 food resources,0,ADD_HEALTH_20_AND_FOOD_20,None
|
||||
6,Charisma Cookie,Consumable,Rare,Adds +2 Charisma (Permanent),0,ADD_CHARISMA_2,None
|
||||
7,XP Booster,Consumable,Rare,Award +10 XP,0,ADD_XP_10,None
|
||||
8,Sleeping Draught,Consumable,Common,Reduces Cooldown for resting by 10 min,0,REDUCE_REST_COOLDOWN_10,None
|
||||
9,Mystery Meat,Consumable,Uncommon,Randomly ±2 to one stat (Permanent),0,ADD_RANDOM_STAT_2,None
|
||||
10,Elixir of Vitality,Consumable,Legendary,Fully restores all stats and health; Adds +1 Level,0,RESTORE_STATS;ADD_LEVEL_1,None
|
||||
11,Leather Hat,Equipment,Common,Helmet: +5 Max Health,0,ADD_MAX_HEALTH_5,Head
|
||||
12,Wizard Hat,Equipment,Rare,Helmet: +15 Max Intelligence,0,ADD_MAX_INTELLIGENCE_15,Head
|
||||
13,Knight's Armor,Equipment,Rare,Chest: +15 Max Strength,0,ADD_MAX_STRENGTH_15,Body
|
||||
14,Golden Boots,Equipment,Uncommon,Legging: +10 Max Charisma,0,ADD_MAX_CHARISMA_10,Legs
|
||||
15,Laser Pointer,Equipment,Common,Weapon: +5 Max Strength,0,ADD_MAX_STRENGTH_5,Weapon
|
||||
16,Celestial Crown,Equipment,Legendary,Helmet: +20 max to all stats,0,ADD_MAX_ALL_STATS_20,Head
|
||||
17,Dragon Scale Shield,Equipment,Legendary,Weapon: +50 Max Health,0,ADD_MAX_HEALTH_50,Weapon
|
||||
18,Feathers,Material,Common,Crafting material (coming soon),0,Nothing,None
|
||||
19,Phoenix Feather,Material,Legendary,Crafting material (coming soon),0,Nothing,None
|
||||
21,Basic Kibble,Consumable,Common,Adds +20 food resources,0,ADD_FOOD_RESOURCES_20,None
|
||||
|
500 Internal Server Error
An error occurred: An error occurred Gitea Version: 28.0.0 |