//Login for players
mob
Login()
src << "Hello, [src]."
switch(input(src,"Pick your class") in list("Student","Squire")) //Players pick their class
if("Student")
src.class = "Student" //Set class to Student
//src = new/mob/Magic/Student() //mob casting
src << "You are now a <b>Student</b>!"
else
src.class = "Squire" //Set class to Squire
//src = new/mob/Melee/Squire() //mob casting
src << "You are now a <b>Squire</b>!"
..()
//Player variables and verbs
mob
var
class as text
list/unlockedclasses = list("Student","Squire")
list/uclasslevels = list(1,1)
Stat/CLevel/clvl = new()
Stat/CExperience/Cexp = new()
verb
GiveCExp()
set name= "Give Class EXP"
set category = "Give Stats"
var/e = rand(20,50)
src.Cexp.increaseCExp(src,e) //Call increaseCExp proc for CExperience datum
ChangeClass()
set name = "Change Class"
set category = "Class"
switch(input(src,"Are you sure you want to change your class?")in list("Yes","No"))
if("Yes")
src.class = input("What class do you want to change to?")in list(unlockedclasses)
UnlockedClasses()
set name = "Classes Unlocked"
set category = "Class"
src << "<center><b><u>Classes Unlocked:"
var/j
for(j = 1, j <= src.unlockedclasses.len,j++)
src << "<center><b> - [src.unlockedclasses[j]] Lvl. [src.uclasslevels[j]]<BR>"
Stat/CLevel
name = "Class Level"
abbr = "C. Lvl" //Goes into the statpanel
min = 1
var/evolveat as num //5 for Tier 1 classes, 10 for Tier 2+
max = 5 //Changes depending on the class
New(evnum)
current = 1
evolveat = evnum //Class level that unlocks the next class
proc
increase(mob/P,num)
current += num
if(current >= max)
current = max
P << "<center>CLASS Level: <b>MAX"
if(current == evolveat)
P<< "<center><b>You can now advance to the next class!"
var/tmp/index= P.unlockedclasses.Find("[P.class]",1,0) //Find class name in list
P.uclasslevels[index] = current //Update the level in the parallel list
changeMax(newmax)
max = newmax
Stat/CExperience
name = "Class Experience"
abbr = "C. EXP" //Goes into the statpanel
var/needed = 100
New()
current = 0
proc
increaseCExp(mob/P,num)
if(P.clvl.current == P.clvl.max)
else
P << "<b>Gained [num] Class Exp"
current += num
while(current >= needed)
P.clvl.increase(P,1)
P << "<center><b>CLASS LEVEL UP!</b> You are now a [P.class] level <b>[P.clvl.current]</b>!<BR>-----------------<BR>"
newNeeded(P.clvl.current)
newNeeded(clvl)
needed += (clvl*10) + 50
//Below is the Stat datum code
Stat
var
name
abbr as text
min = 0
current = 0
max as num
mob/Human/owner
bonus = 0 //Increased or decreased when you equip an item
/* Classes for mob casting and istype calls
mob
var
list/nextclass = list()
Melee
Squire
cname = "Squire"
Magic
cname = "Student"
*/
Problem description: I'm trying to make a class system resembling the type made famous by the Final Fantasy Tactics, and Fire Emblem, series. For those who're unfamiliar with either game, let me elaborate. Each player has a class, like Warrior, Magician, or Rogue. Each player has a class level for their class, which is used to gain class exp whenever they use their class' skills in battle. At certain class levels, the player learns a class skill, and/or can unlock a more powerful class for them to change/advance to later. The player can also change freely between classes and continue their progress. The way I have my classes currently, each player has a class level variable and class variable. When they change classes, the class' name and the level is added to lists. I don't think this way is efficient in the long run. I also tried creating mob datums for each class, but keeping track of class levels and advancements that way seems impossible to me. So in short, What would be the most efficient way to code a class system like this?
By far one of the most time consuming things about handling lists of things that you need to keep track of is iterating through the whole list when only part of it needs to be managed.
For instance, let's say we have a list of skill names that are stored associated to a level requirement.
Now, in order to check which skills we should learn at level 9, we really only need to know which skills have a value of 9.
Unfortunately, you have to iterate through the whole list every single time you want to level up. This wastes a ton of time.
Sorting algorithms are your friend. If you can guarantee that a list is in the correct order sequentially, you can actually check much smaller portions of the list in order to find only the portion that's relevant to your specific case.
Let's take a look at a really easy to implement sorting algorithm.
1) Look at the first and last items in the list. If seek is less than item 1, or greater than item size, stop the search. The value isn't in the list.
2) Halve the size of the list (rounded down) and store as value hsize.
3) Begin search at pivot point hsize+1 store as pos.
4) halve the size of hsize
5a) if seek is <= the value at position pos, subtract hsize from pos.
5b) else, add hsize from pos.
6a) if hsize>1 go to step 4
6b) else, return pos. The first incident of seek is at pos.
^This is a single example of this searching algorithm in action.
A very simplistic implementation:
Why do I recommend this approach? Well, it's much easier to build a list of what skills a player has when they swap classes than to keep track of it all. Our sorted list thing here will actually make our work way easier. Continued in the next post.