I am attempting to create a daemon that regulates skills. The goal are to have skills (inherit abilities rather than commands) that determine how good a player is at using a sword or casting a spell. For instance if a player wants to use a longsword(tier 1) they need to have the skill sword to be useful with the weapon, however, on top of that they need to be practiced in the longsword (tier 2) skill.
So far, Im not making much progress... this is what I have:
#include <lib.h>
#include <dirs.h>
inherit LIB_DAEMON;
private mapping skills = ([]);
varargs int AddSkill(string skill, int cls, int level)
{
if( !stringp(skill) ) {
error("Bad argument 1 to AddSkill().\n\tExpected: string, Got: " +
typeof(skill) + "\n");
}
if( !nullp(Skills[skill]) ) {
return 0;
}
if( !cls ) {
cls = 1;
}
if(!level){
level = 1;
}
else if( cls < 0 || cls > 4) {
return 0;
}
Skills[skill] = ([ "points" : 0, "level" : level, "class" : cls ]);
return 1;
}
mapping GetSkill(string skill) {
return copy(Skills[skill]);
}
void RemoveSkill(string skill) {
if( !Skills[skill] ) {
return;
}
map_delete(Skills, skill);
}
varargs void SetSkill(string skill, int level, mixed cls) {
int tmp;
if(cls && !intp(cls)) {
tmp = 1;
cls = tmp;
}
if( !stringp(skill) ) {
error("Bad argument 1 to SetSkill().\n\tExpected: string, Got: " +
typeof(skill) + "\n");
}
if( !cls ) {
if( Skills[skill] ) {
cls = Skills[skill]["class"];
}
else {
cls = 1;
}
}
else if( cls < 1 || cls > 4) {
return 0;
}
Skills[skill] = ([ "points" : 0, "level" : level, "class" : cls ]);
}
string array GetSkills() {
return keys(Skills);
}
mapping GetSkillsMap(){
return copy(Skills);
}
void eventReloadSkills() {
string array skills;
Skills = ([]);
skills = get_dir(DIR_SKILLS "/*.c");
foreach(string skill in skills) {
object ob = find_object(DIR_SKILS "/" + skill);
if( ob ) {
ob->eventDestruct();
}
if( ob = load_object(DIR_SKILLS "/" + skill) ) {
spell = ob->GetSkill();
if( skill ) {
Skills[skill] = ob;
}
}
}
}
object GetSkill(string skill) {
if( !Skills[skill] ) {
eventReloadSkills();
}
return Skills[skill];
}
Thoughts, help, examples would be great and very appreciated.