SBLS – Skill Based Leveling System Documentation
Table of Contents
SBLSCharacter script
The SBLSCharacter script is the main script that controls the system. You can add it to as many GameObjects as you want, and either have it use the default configuration file, or you can select a different configuration file (which is useful is you have different races, different types of characters, etc.).
Use
Simply add the SBLSCharacter script to a GameObject.
By default the SBLSCharacter script will try to find the default configuration file. If you untick Use Default Config, then it will use whatever configuration file you specify in the Custom config field in the inspector window.
Accessing SBLSCharacter via code
Firstly, as with all SBLS scripts, you need to specify the namespace at the top of the script.
using SBLS;
You then need to specify a variable of the SBLSCharacter type.
public SBLSCharacter character;
Then, simply load the component into the variable.
character = GetComponent<SBLSCharacter>();
Methods
The following methods can used on a SBLSCharacter instance.
public void setXp(int newXp)
This method will set the characters XP to the value passed in newXp. When called it will automatically check to see if the character has leveled up.It’s better to use adjustXp as it increments/decrements the total.
Example
character.setXp(10);
void adjustXp(int xpAdjustment)
This method will adjust the characters XP with the value passed in xpAdjustment. The number can be positive or negative. When called it will automatically check to see if the character has leveled up.
Example
character.adjustXp(13);
int getXp()
This method returns the current XP of the character
Example
Debug.Log(character.getXp());
void setNextXp(int newNextXp)
This method sets the XP required to get to the next level. Normally this is automatically set by what you’ve got in your configuration file.
Example
character.setNextXp(100);
int getNextXp()
This method returns the XP required to get to the next level.
Example
Debug.Log(character.getNextXp());
SBLSSkill getSkill(int skillNo)
This method returns an instance of the skill with the key of skillNo.
Example
SBLSSkill running = character.getSkill(0);
SBLSSkill getSkill(string skillName)
This method returns an instance of the skill with the name of skillName.
Example
SBLSSkill running = character.getSkill("Running");
void updateSkill(int skillNo, int xpAdjustment)
This method adjusts the skills XP. skillNo is the key of the skill, and xpAdjustment is the number to adjust the XP by. xpAdjustment can be positive or negative.
Example
character.updateSkill(0,3);
void updateSkill(string skillName, int xpAdjustment)
This method adjusts the skills XP. skillName is the name of the skill, and xpAdjustment is the number to adjust the XP by. xpAdjustment can be positive or negative.
Example
character.updateSkill("Running",3);
int getLevel()
This method returns the characters current level.
Example
int level = character.getLevel();
void setLevel(int newLevel)
This method sets the level of the character. This is generally done automatically using the configuration that you have set.
Example
character.setLevel(1);
SBLSConfiguration getConfig()
This method adjusts returns the current SBLSConfiguration that the character is using.
Example
SBLSConfig config = character.getConfig();
int getProgress(int width)
This method adjusts returns the width in integer of the current level progress. This is so you can easily create progress bars without having to mess up your code with math.
int width is the width of your progress bar.
Example
GUI.DrawTexture ( new Rect ((Screen.width / 2 - 20), 20, 500, 25), progressUnder );
GUI.DrawTexture ( new Rect ((Screen.width / 2 - 20), 20, character.getProgress (500), 25), mainLevelProgress );
void reset()
This method resets the character to default, removing any progress that has been made.
Example
character.reset();
void startQuest(SBLSQuestConfiguration questConfig)
This method starts the quest that is passed in the questConfig argument.
Example
character.startQuest(killBossQuest);
SBLSQuest findQuest(string questName)
This method looks for a quest specified in questName, and returns the quest if it’s found.
Example
SBLSQuest killBossQuest = character.findQuest("killBossQuest");
List getActiveQuests()
This method returns a List of the characters current active quests.
Example
List<SBLSQuest> activeQuests = character.getActiveQuests();
List getCompletedQuests()
This method returns a List of the characters completed quests.
Example
List<SBLSQuest> completedQuests = character.getCompletedQuests();
void questStepCompleted(string questName)
This method completes the current active quest step for the quest passed in questName.
Example
character.questStepCompleted("killBossQuest");
SBLSSkill
The SBLSSkill script is automatically included in the SBLSCharacter script, so you don’t need to add it to any of your GameObjects, and you access it through your SBLSCharacter instance.
Accessing SBLSCharacter via code
Firstly, as with all SBLS scripts, you need to specify the namespace at the top of the script.
using SBLS;
You then need to specify a variable of the SBLSCharacter type.
public SBLSCharacter character;
Then, simply load the component into the variable.
character = GetComponent<SBLSCharacter>();
The easiest way to access the skills is to use the SBLSCharacter getSkill method.
character.getSkill("skillName");
Variables
bool inUse
The inUse variable let’s SBLS know whether the current skill is being used or not. SBLS uses this for time based skills, and only updates the skill if it is being used.
Example
if (Input.GetKey(KeyCode.LeftShift)) {
// Let's run!
// We'll also add the current running level so we get faster as we level up
actualSpeed = runSpeed + character.getSkill("Running").getLevel();
character.getSkill("Running").inUse = true;
} else {
actualSpeed = speed;
// We're walking, better let the skill know
character.getSkill("Running").inUse = false;
}
Methods
The following methods can used on a SBLSSkill instance.
string getName()
This method returns the name of the skill. If you use the SBLSCharacter method getSkill(int skillNo), this is useful.
Example
character.getSkill(0).getName();
void setName(string newName)
This method sets the name of the skill. Only needed if you want to rename a skill during runtime.
Example
character.getSkill(0).setName("New Skill");
int getXp()
This method gets the current XP of the skill
Example
character.getSkill("Running").getXp();
void setXp()
This method sets the XP of the skill. This will set the total XP of the skill, and does not increment or decrement the value. After the XP is updated it automatically checks to see if the skill has leveled up.
Example
character.getSkill("Running").setXp(30);
void adjustXp(int xpAdjustment)
This method adjust the XP value of the skill. If xpAdjustment is positive it will add to the XP. If it is negative it will subtract from the XP. After the XP is adjusted it automatically checks to see if the skill has leveled up.
Example
character.getSkill("Running").adjustXp(10);
int getNextXp()
This method returns the XP required to reach the next level.
Example
int nextXP = character.getSkill("Running").getNextXp();
void setNextXp(int newXp)
This method sets XP required to reach the next level. This is automatically set based on your configuration settings.
Example
character.getSkill("Running").setNextXp(325);
int getLevel()
This method returns the current level of the skill
Example
int runningLevel = character.getSkill("Running").getLevel();
void setLevel(int newLevel)
This method sets the level of the skill. This is automatically set by SBLS, but would be useful if you wanted NPC or enemies to have specific skill levels.
Example
character.getSkill("Running").setLevel(5);
void setTimeUsed(float newTime)
This method sets the length of time the skill has been used for current level. This only affects skills that are set to be time based. Only use this for debugging purposes.
Example
character.getSkill("Running").setTimeUsed(15.0f);
float getTimeUsed()
This method returns the length of time that the skill has been used for the current level. This only returns a value for skills that are set to be time based.
Example
float runningTime = character.getSkill("Running").getTimeUsed();
void setTotalTimeUsed(float totalTime)
This method sets the total length of time the skill has been used. This only affects skills that are set to be time based. Only use this for debugging purposes.
Example
character.getSkill("Running").setTotalTimeUsed(10.0f);
float getTotalTimeUsed()
This method returns the length of time that the skill has been used for the current level. This only returns a value for skills that are set to be time based.
Example
float runningTime = character.getSkill("Running").getTotalTimeUsed();
SBLSCharacter getCharacter()
This method returns the SBLSCharacter instance that the skill belongs to.
Example
SBLSCharacter newCharacter = character.getSkill("Running").getgetCharacter();