Crafting Attempt 1
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Server.Data.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Types of crafting skills
|
||||
/// </summary>
|
||||
public enum CraftingSkillType
|
||||
{
|
||||
Smithing = 0, // Weapons, Armor (metal-based)
|
||||
Fletching = 1, // Bows, Arrows, Crossbows
|
||||
Jewelry = 2, // Rings, Amulets, Accessories
|
||||
Alchemy = 3, // Potions, Resource Transmutation
|
||||
Academic = 4 // Scrolls, Spellbooks, Enchantments
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A character's progress in a crafting skill
|
||||
/// </summary>
|
||||
[Table("dungeon_character_crafting_skills")]
|
||||
public class DungeonCharacterCraftingSkill
|
||||
{
|
||||
[Key]
|
||||
public ulong Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public ulong CharacterId { get; set; }
|
||||
|
||||
[Required]
|
||||
public CraftingSkillType SkillType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current level in this crafting skill (1-100)
|
||||
/// </summary>
|
||||
public int Level { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// XP progress toward next level
|
||||
/// </summary>
|
||||
public long Experience { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Total items crafted with this skill
|
||||
/// </summary>
|
||||
public int TotalItemsCrafted { get; set; } = 0;
|
||||
|
||||
// Navigation
|
||||
public virtual DungeonCharacter? Character { get; set; }
|
||||
|
||||
// Helper methods
|
||||
[NotMapped]
|
||||
public long ExperienceForNextLevel => GetXpForLevel(Level + 1);
|
||||
|
||||
[NotMapped]
|
||||
public float ProgressToNextLevel => Level >= 100 ? 1f : (float)Experience / ExperienceForNextLevel;
|
||||
|
||||
/// <summary>
|
||||
/// Number of stat rolls when crafting (increases with level)
|
||||
/// Level 1-19: 1 roll
|
||||
/// Level 20-39: 2 rolls
|
||||
/// Level 40-59: 3 rolls
|
||||
/// Level 60-79: 4 rolls
|
||||
/// Level 80-99: 5 rolls
|
||||
/// Level 100: 6 rolls
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public int StatRollCount => Math.Min(6, 1 + (Level / 20));
|
||||
|
||||
/// <summary>
|
||||
/// Minimum stat roll value (increases with level)
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public int MinStatRoll => 1 + (Level / 10);
|
||||
|
||||
/// <summary>
|
||||
/// Maximum stat roll value (increases with level)
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public int MaxStatRoll => 5 + (Level / 5);
|
||||
|
||||
/// <summary>
|
||||
/// XP required to reach a specific level
|
||||
/// Uses exponential curve: base * level^2
|
||||
/// </summary>
|
||||
public static long GetXpForLevel(int level)
|
||||
{
|
||||
if (level <= 1) return 0;
|
||||
return (long)(100 * Math.Pow(level, 2.2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// XP gained from crafting an item of a certain tier
|
||||
/// </summary>
|
||||
public static int GetCraftingXp(int itemTier, int craftingLevel)
|
||||
{
|
||||
// Base XP from tier
|
||||
int baseXp = itemTier * 25;
|
||||
|
||||
// Bonus for crafting items near your level
|
||||
int levelDiff = Math.Abs(itemTier * 10 - craftingLevel);
|
||||
float multiplier = Math.Max(0.1f, 1.0f - (levelDiff * 0.05f));
|
||||
|
||||
return (int)(baseXp * multiplier);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Static helper for crafting skill calculations
|
||||
/// </summary>
|
||||
public static class CraftingSkillHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Get which crafting skill is used for a given item type
|
||||
/// </summary>
|
||||
public static CraftingSkillType? GetSkillForItemType(ItemType itemType, string itemName = "")
|
||||
{
|
||||
switch (itemType)
|
||||
{
|
||||
case ItemType.Weapon:
|
||||
// Check if it's a bow/crossbow (fletching) or metal weapon (smithing)
|
||||
if (itemName.Contains("bow", StringComparison.OrdinalIgnoreCase) ||
|
||||
itemName.Contains("arrow", StringComparison.OrdinalIgnoreCase) ||
|
||||
itemName.Contains("crossbow", StringComparison.OrdinalIgnoreCase))
|
||||
return CraftingSkillType.Fletching;
|
||||
return CraftingSkillType.Smithing;
|
||||
|
||||
case ItemType.Armor:
|
||||
return CraftingSkillType.Smithing;
|
||||
|
||||
case ItemType.Accessory:
|
||||
return CraftingSkillType.Jewelry;
|
||||
|
||||
case ItemType.Consumable:
|
||||
// Check if it's a scroll (academic) or potion (alchemy)
|
||||
if (itemName.Contains("scroll", StringComparison.OrdinalIgnoreCase) ||
|
||||
itemName.Contains("tome", StringComparison.OrdinalIgnoreCase) ||
|
||||
itemName.Contains("book", StringComparison.OrdinalIgnoreCase))
|
||||
return CraftingSkillType.Academic;
|
||||
return CraftingSkillType.Alchemy;
|
||||
|
||||
case ItemType.Material:
|
||||
return null; // Materials aren't crafted directly
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user