Add skill management system: implement Skill and PetSkill models, create SkillController, and update ApplicationDbContext for skills
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
namespace PetCompanion.Models.Enums
|
||||
{
|
||||
public enum ItemType
|
||||
{
|
||||
Consumable,
|
||||
Equipment,
|
||||
Material
|
||||
}
|
||||
|
||||
public enum ItemRarity
|
||||
{
|
||||
Common,
|
||||
Uncommon,
|
||||
Rare,
|
||||
Legendary
|
||||
}
|
||||
|
||||
public enum EquipmentSlot
|
||||
{
|
||||
Helmet,
|
||||
Chest,
|
||||
Leggings,
|
||||
Weapon
|
||||
}
|
||||
}
|
@@ -1,79 +0,0 @@
|
||||
using PetCompanion.Models.Enums;
|
||||
|
||||
namespace PetCompanion.Models
|
||||
{
|
||||
public class MaterialItem : Item
|
||||
{
|
||||
public MaterialItem()
|
||||
{
|
||||
Type = ItemType.Material;
|
||||
}
|
||||
|
||||
public override void Use(ref Pet pet)
|
||||
{
|
||||
// Materials cannot be used directly
|
||||
}
|
||||
}
|
||||
|
||||
public class StatBoostEquipment : EquipableItem
|
||||
{
|
||||
public Dictionary<string, int> StatBoosts { get; set; } = new();
|
||||
|
||||
public override void Equip(ref Pet pet)
|
||||
{
|
||||
base.Equip(ref pet);
|
||||
if (IsEquipped)
|
||||
{
|
||||
foreach (var boost in StatBoosts)
|
||||
{
|
||||
switch (boost.Key.ToLower())
|
||||
{
|
||||
case "health":
|
||||
pet.MaxHealth += boost.Value;
|
||||
break;
|
||||
case "intelligence":
|
||||
pet.Stats.MaxIntelligence += boost.Value;
|
||||
break;
|
||||
case "strength":
|
||||
pet.Stats.MaxStrength += boost.Value;
|
||||
break;
|
||||
case "charisma":
|
||||
pet.Stats.MaxCharisma += boost.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Unequip(ref Pet pet)
|
||||
{
|
||||
if (IsEquipped)
|
||||
{
|
||||
foreach (var boost in StatBoosts)
|
||||
{
|
||||
switch (boost.Key.ToLower())
|
||||
{
|
||||
case "health":
|
||||
pet.MaxHealth -= boost.Value;
|
||||
break;
|
||||
case "intelligence":
|
||||
pet.Stats.MaxIntelligence -= boost.Value;
|
||||
break;
|
||||
case "strength":
|
||||
pet.Stats.MaxStrength -= boost.Value;
|
||||
break;
|
||||
case "charisma":
|
||||
pet.Stats.MaxCharisma -= boost.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
base.Unequip(ref pet);
|
||||
}
|
||||
|
||||
public override void Use(ref Pet pet)
|
||||
{
|
||||
Equip(ref pet);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
namespace PetCompanion.Models
|
||||
{
|
||||
public class Inventory
|
||||
{
|
||||
public List<Item> Items { get; set; } = new();
|
||||
public int Capacity { get; set; }
|
||||
|
||||
public bool AddItem(Item item)
|
||||
{
|
||||
if (Items.Count < Capacity)
|
||||
{
|
||||
Items.Add(item);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool RemoveItem(Item item)
|
||||
{
|
||||
return Items.Remove(item);
|
||||
}
|
||||
|
||||
public void TrashItem(Item item)
|
||||
{
|
||||
RemoveItem(item);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
using PetCompanion.Models.Enums;
|
||||
|
||||
namespace PetCompanion.Models
|
||||
{
|
||||
public abstract class Item
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public ItemType Type { get; set; }
|
||||
public ItemRarity Rarity { get; set; }
|
||||
|
||||
public abstract void Use(ref Pet pet);
|
||||
}
|
||||
|
||||
public abstract class EquipableItem : Item
|
||||
{
|
||||
public EquipmentSlot Slot { get; set; }
|
||||
public bool IsEquipped { get; set; }
|
||||
|
||||
public virtual void Equip(ref Pet pet)
|
||||
{
|
||||
if (!IsEquipped)
|
||||
{
|
||||
pet.Equipment[Slot]?.Unequip(ref pet);
|
||||
pet.Equipment[Slot] = this;
|
||||
IsEquipped = true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Unequip(ref Pet pet)
|
||||
{
|
||||
if (IsEquipped)
|
||||
{
|
||||
pet.Equipment[Slot] = null;
|
||||
IsEquipped = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsumableItem : Item
|
||||
{
|
||||
public Action<Pet> Effect { get; set; }
|
||||
|
||||
public override void Use(ref Pet pet)
|
||||
{
|
||||
Effect?.Invoke(pet);
|
||||
}
|
||||
}
|
||||
}
|
@@ -27,6 +27,9 @@ namespace PetCompanion.Models
|
||||
|
||||
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()
|
||||
{
|
||||
foreach (EquipmentSlot slot in Enum.GetValues(typeof(EquipmentSlot)))
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PetCompanion.Models
|
||||
{
|
||||
@@ -7,10 +8,20 @@ namespace PetCompanion.Models
|
||||
{
|
||||
[Key, ForeignKey("Pet")]
|
||||
public string PetId { get; set; }
|
||||
|
||||
// Display stats
|
||||
public int Intelligence { get; set; }
|
||||
public int Strength { get; set; }
|
||||
public int Charisma { get; set; }
|
||||
|
||||
// Hidden stats (not displayed to the API)
|
||||
[JsonIgnore]
|
||||
public int Luck { get; set; } // used for rarity of item finds
|
||||
[JsonIgnore]
|
||||
public int Agility { get; set; } // used for combat
|
||||
[JsonIgnore]
|
||||
public int Perception { get; set; } // used for number of itens found
|
||||
|
||||
public int MaxIntelligence { get; set; }
|
||||
public int MaxStrength { get; set; }
|
||||
public int MaxCharisma { get; set; }
|
||||
@@ -67,6 +78,10 @@ namespace PetCompanion.Models
|
||||
stats.MaxStrength = stats.Strength;
|
||||
stats.MaxCharisma = stats.Charisma;
|
||||
|
||||
stats.Luck = 1;
|
||||
stats.Agility = 1;
|
||||
stats.Perception = 1;
|
||||
|
||||
return stats;
|
||||
}
|
||||
}
|
||||
|
82
Models/Skill.cs
Normal file
82
Models/Skill.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PetCompanion.Models
|
||||
{
|
||||
public enum SkillType
|
||||
{
|
||||
GROUND,
|
||||
GRAND
|
||||
}
|
||||
|
||||
public enum SkillTier
|
||||
{
|
||||
I = 1,
|
||||
II = 2,
|
||||
III = 3
|
||||
}
|
||||
|
||||
public class Skill
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public SkillType Type { get; set; }
|
||||
public int PointsCost { get; set; }
|
||||
public string Icon { get; set; }
|
||||
public List<int>? SkillsIdRequired { get; set; }
|
||||
public virtual ICollection<SkillEffect> Effects { get; set; }
|
||||
public virtual ICollection<PetSkill> PetSkills { get; set; }
|
||||
}
|
||||
|
||||
public class SkillEffect
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public int SkillId { get; set; }
|
||||
public virtual Skill Skill { get; set; }
|
||||
public SkillTier Tier { get; set; }
|
||||
public string Effect { get; set; }
|
||||
public decimal Value { get; set; }
|
||||
|
||||
public void PetSkillUpgrade(ref Pet pet)
|
||||
{
|
||||
switch (Effect)
|
||||
{
|
||||
case "MaxHealth":
|
||||
pet.MaxHealth += (int)Value;
|
||||
break;
|
||||
case "MaxIntelligence":
|
||||
pet.Stats.MaxIntelligence += (int)Value;
|
||||
break;
|
||||
case "MaxStrength":
|
||||
pet.Stats.MaxStrength += (int)Value;
|
||||
break;
|
||||
case "MaxCharisma":
|
||||
pet.Stats.MaxCharisma += (int)Value;
|
||||
break;
|
||||
case "Luck":
|
||||
pet.Stats.Luck += (int)Value;
|
||||
break;
|
||||
case "Agility":
|
||||
pet.Stats.Agility += (int)Value;
|
||||
break;
|
||||
case "Perception":
|
||||
pet.Stats.Perception += (int)Value;
|
||||
break;
|
||||
// Add more effects as needed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PetSkill
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string PetId { get; set; }
|
||||
public virtual Pet Pet { get; set; }
|
||||
public int SkillId { get; set; }
|
||||
public virtual Skill Skill { get; set; }
|
||||
public SkillTier CurrentTier { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user