Initial commit
This commit is contained in:
53
Assets/Scripts/Skills.cs
Normal file
53
Assets/Scripts/Skills.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user