not working inventory :c

This commit is contained in:
2025-02-04 17:47:18 -03:00
parent f234b5d84d
commit 7a2c3d2f67
22 changed files with 2713 additions and 49 deletions

20
Models/EquippedItem.cs Normal file
View File

@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PetCompanion.Models
{
public class EquippedItem
{
[Key]
public int Id { get; set; }
public string PetId { get; set; }
[ForeignKey("PetId")]
public virtual Pet Pet { get; set; }
public ItemEquipTarget EquipTarget { get; set; }
public int GameItemId { get; set; }
[ForeignKey("GameItemId")]
public virtual GameItem GameItem { get; set; }
}
}

41
Models/GameItem.cs Normal file
View File

@@ -0,0 +1,41 @@
using System.ComponentModel.DataAnnotations;
namespace PetCompanion.Models
{
public class GameItem
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public ItemType Type { get; set; }
public ItemRarity Rarity { get; set; }
public string Description { get; set; }
public int Price { get; set; }
public string Effect { get; set; }
public ItemEquipTarget EquipTarget { get; set; }
}
public enum ItemType
{
Material,
Consumable,
Equipment
}
public enum ItemRarity
{
Common,
Uncommon,
Rare,
Legendary
}
public enum ItemEquipTarget
{
None,
Head,
Body,
Legs,
Weapon
}
}

26
Models/Inventory.cs Normal file
View File

@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
namespace PetCompanion.Models
{
public class Inventory
{
[Key, ForeignKey("Pet")]
public string PetId { get; set; }
[JsonIgnore]
public virtual Pet Pet { get; set; }
public virtual ICollection<InventoryItem> Items { get; set; } = new List<InventoryItem>();
public int Capacity { get; set; } = 20;
}
public class InventoryItem
{
[Key]
public int Id { get; set; }
public string InventoryId { get; set; }
public int GameItemId { get; set; }
public virtual GameItem GameItem { get; set; }
public int Quantity { get; set; }
}
}

View File

@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using PetCompanion.Models.Enums;
using System.ComponentModel.DataAnnotations.Schema;
namespace PetCompanion.Models
{
@@ -11,7 +11,6 @@ namespace PetCompanion.Models
public PetClass Class { get; set; }
public PetStats Stats { get; set; }
public Resources Resources { get; set; }
public Inventory Inventory { get; set; }
public int Level { get; set; }
public int Experience { get; set; }
public int Health { get; set; }
@@ -25,19 +24,30 @@ namespace PetCompanion.Models
public PetBasicAction PetBasicAction { get; set; }
public DateTime BasicActionCooldown { get; set; }
public Dictionary<EquipmentSlot, EquipableItem> Equipment { get; set; } = new();
public int SkillPoints { get; set; } = 2;
public virtual ICollection<PetSkill> Skills { get; set; } = new List<PetSkill>();
public Pet()
public virtual Inventory Inventory { get; set; }
[NotMapped]
public Dictionary<ItemEquipTarget, int> EquippedItems
{
foreach (EquipmentSlot slot in Enum.GetValues(typeof(EquipmentSlot)))
get => EquippedItemsList?.ToDictionary(e => e.EquipTarget, e => e.GameItemId) ?? new Dictionary<ItemEquipTarget, int>();
set
{
Equipment[slot] = null;
EquippedItemsList = value.Select(kvp => new EquippedItem
{
PetId = Id,
EquipTarget = kvp.Key,
GameItemId = kvp.Value
}).ToList();
}
}
public virtual ICollection<EquippedItem> EquippedItemsList { get; set; } = new List<EquippedItem>();
public Pet() { }
public void IncrementIntelligence(int amount)
{
var newValue = Stats.Intelligence + amount;

View File

@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace PetCompanion.Models
{
@@ -26,6 +27,7 @@ namespace PetCompanion.Models
public string Icon { get; set; }
public List<int>? SkillsIdRequired { get; set; }
public virtual ICollection<SkillEffect> Effects { get; set; }
[JsonIgnore]
public virtual ICollection<PetSkill> PetSkills { get; set; }
}
@@ -34,6 +36,7 @@ namespace PetCompanion.Models
[Key]
public int Id { get; set; }
public int SkillId { get; set; }
[JsonIgnore]
public virtual Skill Skill { get; set; }
public SkillTier Tier { get; set; }
public string Effect { get; set; }
@@ -74,6 +77,7 @@ namespace PetCompanion.Models
[Key]
public int Id { get; set; }
public string PetId { get; set; }
[JsonIgnore]
public virtual Pet Pet { get; set; }
public int SkillId { get; set; }
public virtual Skill Skill { get; set; }