Refactor namespaces to follow new naming convention and add item model classes
This commit is contained in:
25
Models/Enums/ItemEnums.cs
Normal file
25
Models/Enums/ItemEnums.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace Pet.Companion.Models.Enums
|
||||
{
|
||||
public enum ItemType
|
||||
{
|
||||
Consumable,
|
||||
Equipment,
|
||||
Material
|
||||
}
|
||||
|
||||
public enum ItemRarity
|
||||
{
|
||||
Common,
|
||||
Uncommon,
|
||||
Rare,
|
||||
Legendary
|
||||
}
|
||||
|
||||
public enum EquipmentSlot
|
||||
{
|
||||
Helmet,
|
||||
Chest,
|
||||
Leggings,
|
||||
Weapon
|
||||
}
|
||||
}
|
79
Models/GameItems.cs
Normal file
79
Models/GameItems.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Pet.Companion.Models.Enums;
|
||||
|
||||
namespace Pet.Companion.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);
|
||||
}
|
||||
}
|
||||
}
|
28
Models/Inventory.cs
Normal file
28
Models/Inventory.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Pet.Companion.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);
|
||||
}
|
||||
}
|
||||
}
|
50
Models/Item.cs
Normal file
50
Models/Item.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Pet.Companion.Models.Enums;
|
||||
|
||||
namespace Pet.Companion.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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Pet.Companion.Models.Enums;
|
||||
|
||||
namespace pet_companion_api.Models
|
||||
namespace Pet.Companion.Models
|
||||
{
|
||||
public class Pet
|
||||
{
|
||||
@@ -10,7 +11,11 @@ namespace pet_companion_api.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; }
|
||||
public int MaxHealth { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public bool IsDead { get; set; }
|
||||
|
||||
@@ -20,6 +25,16 @@ namespace pet_companion_api.Models
|
||||
public PetBasicAction PetBasicAction { get; set; }
|
||||
public DateTime BasicActionCooldown { get; set; }
|
||||
|
||||
public Dictionary<EquipmentSlot, EquipableItem> Equipment { get; set; } = new();
|
||||
|
||||
public Pet()
|
||||
{
|
||||
foreach (EquipmentSlot slot in Enum.GetValues(typeof(EquipmentSlot)))
|
||||
{
|
||||
Equipment[slot] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void IncrementIntelligence(int amount)
|
||||
{
|
||||
var newValue = Stats.Intelligence + amount;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace pet_companion_api.Models
|
||||
namespace Pet.Companion.Models
|
||||
{
|
||||
public enum PetBasicAction
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace pet_companion_api.Models
|
||||
namespace Pet.Companion.Models
|
||||
{
|
||||
public enum PetClass
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
|
||||
namespace pet_companion_api.Models
|
||||
namespace Pet.Companion.Models
|
||||
{
|
||||
public class PetClassInfo
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace pet_companion_api.Models
|
||||
namespace Pet.Companion.Models
|
||||
{
|
||||
public class PetCreationRequest
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace pet_companion_api.Models
|
||||
namespace Pet.Companion.Models
|
||||
{
|
||||
public class PetStats
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace pet_companion_api.Models
|
||||
namespace Pet.Companion.Models
|
||||
{
|
||||
public class PetUpdateActionRequest
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace pet_companion_api.Models
|
||||
namespace Pet.Companion.Models
|
||||
{
|
||||
public class Resources
|
||||
{
|
||||
|
Reference in New Issue
Block a user