Files
2026-09-02 21:14:02 +01:00

53 lines
1.4 KiB
C#

using UnityEngine;
// System.Serializable makes these show up in the Unity Inspector so you can debug NPC levels!
[System.Serializable]
public class Skills
{
public enum SkillType
{
Woodcutting,
Stonecutting,
Mining,
Building,
Farming // Added to match your Farmer job
}
public SkillType skillType;
public int skillExp;
public int skillLevel;
// 1. The Constructor: This runs automatically when the NPC learns the skill for the first time
public Skills(SkillType type)
{
skillType = type;
skillLevel = 1;
skillExp = 0;
}
// 2. The Math: Handles gaining XP and checking for level ups
public void AddExperience(int amount)
{
skillExp += amount;
// Example leveling formula: Level 1 requires 100xp, Level 2 requires 200xp, etc.
int xpRequiredForNextLevel = skillLevel * 100;
if (skillExp >= xpRequiredForNextLevel)
{
// Subtract the requirement but keep the rollover XP
skillExp -= xpRequiredForNextLevel;
skillLevel++;
Debug.Log($"Leveled up! {skillType} is now Level {skillLevel}");
}
}
public int GetLevel(SkillType type)
{
if (type == skillType)
return skillLevel;
Debug.LogWarning($"Requested level for {type} but this skill is {skillType}");
return 0;
}
}