Classes:
Here, I have two of the main functions of the Classes System. This system is interdependent with the Professions and Techniques Systems (which I haven't gotten around to starting today.)
setClass(object, class) sets the player's class if it hasn't been set already. This is pretty much the function which will be called when a player chooses his class through an interface in-game.
advanceClass(object) advances the player's class to the next possible tier from the prior class.
Also, there are quite a few echos there because I just finished the Class functions NOT TOO long ago, so those were there for debugging pretty much.
PHP Code:
public function setClass(object, class) {
temp.cdata = null;
temp.cbasevars = null;
temp.cbasevar = null;
temp.cmods = null;
temp.cwmods = null;
temp.finaldata = null;
if (!(object.type in {"player"}) || object.objecttype() != "TMudObject") {
error("Mud Object (#s) is not valid!", object.name);
return;
}
if (class == null) {
error("No class given to set!");
return;
}/*
if (classIsSet(object)) {
if (!(getClassTier(class) > object.class[2]) || ((getClassTier(class) - object.class[2]) != 1)) {
error("The given class (#s) does not have a higher tier than the current class! Or is not the next tier!", class);
return;
}
}*/
//else {
//echo("Class has not been set yet.");
if (!classIsSet(object)) {
echo("Class is not set.");
cdata = findNpc("DB_Classes").getClass(class);
if (cdata.size() > 0) {
echo("Found class data.");
cbasevars = {"classid", "classname", "tier", "description"};
//cmods = findNpc("DB_Classes").getClassVar(class, "statmods");
// May or may not do weapon proficiencies here
//cwmods = findNpc("DB_Classes").getClassVar(class, "weaponproficiencies");
echo("BASE VARS: " @ cbasevars);
echo("MODS: " @ cmods);
echo("Weapon Proficiencies: " @ cwmods);
for (cbasevar: cbasevars) {
echo("BASE VAR: " @ cbasevar);
finaldata.add(getClassVar(class, cbasevar));
}
echo("FINAL DATA: " @ finaldata);
object.class = finaldata;
}
}
}/*
public function unsetClass(object) {
}*/
public function advanceClass(object, next) {
temp.currenttier = null;
temp.nexttier = null;
temp.choices = null;
temp.choice = null;
temp.cbasevars = null;
temp.cbasevar = null;
temp.finaldata = null;
if (!(object.type in {"player"}) || object.objecttype() != "TMudObject") {
error("Mud Object (#s) is not valid!", object.name);
return;
}
if (!classIsSet(object)) {
error("Mud Object (#s)'s class has not yet been set!", object.name);
return;
}
currenttier = getClassTier(object.class[0]);
nexttier = currenttier + 1;
echo("CURRENT TIER: " @ currenttier);
echo("NEXT TIER: " @ nexttier);
if (currenttier != 0 && nexttier != 0 && nexttier > currenttier && (nexttier - currenttier) == 1) {
echo("Tier checks complete.");
choices = getClassVar(object.class[0], "nextclasses");
for (choice: choices) {
echo("NEXT CHOICE: " @ choice);
if (choice == next) {
cbasevars = {"classid", "classname", "tier", "description"};
for (cbasevar: cbasevars) {
finaldata.add(getClassVar(choice, cbasevar));
}
echo("FINAL ADVANCE DATA: " @ finaldata);
object.class = finaldata;
break;
}
}
}
}
Some Class data storage.
PHP Code:
/*** Classes Database ***
Author: Stan
*** Function List ***
LEGEND:
+ Public Function
- Private Function
SERVERSIDE:
(-) onCreated()
(+) getClass(cl)
(+) getClassVar(cl, cvar)
v1.0, 07/23/08, by Stan
ToDo:
* Map out the rest of the classes, (ugh!)
***/
function onCreated() {
/*
Indices:
0 Class Id
1 Class Name
2 Class Tier
3 Description
4 Next Classes
5 Stat Mods
6 Syngergy Bonus
7 Allowed Professions
*/
this.class_rebel = {
{"classid", "rebel"},
{"classname", "Rebel"},
{"tier", 1},
{"description", "A rebel."},
{"nextclasses", {
"bandit",
"begger",
"blader"}},
{"statmods", {
{"health", 0},
{"stamina", 0}}},
{"syngergies", {
{"test", 0}}},
{"allowedprofessions", {
""}}
};
this.class_apprentice = {
{"classid", "apprentice"},
{"classname", "Apprentice"},
{"tier", 1},
{"description", "An apprentice."},
{"nextclasses", {
"crafter",
"mechanic"}},
{"statmods", {
{"health", 0},
{"stamina", 0}}},
{"synergies", {
{"test", 0}}},
{"allowedprofessions", {
""}}
};
this.class_believer = {
{"classid", "believer"},
{"classname", "Believer"},
{"tier", 1},
{"description", "A believer."},
{"nextclasses", {
"gypsy",
"nurse"}},
{"statmods", {
{"health", 0},
{"stamina", 0}}},
{"synergies", {
{"test", 0}}},
{"allowedprofessions", {
""}}
};
this.class_gypsy = {
{"classid", "gypsy"},
{"classname", "Gypsy"},
{"tier", 1},
{"description", "A gypsy."},
{"nextclasses", {
"test"}},
{"statmods", {
{"health", 0},
{"stamina", 0}}},
{"synergies", {
{"test", 0}}},
{"allowedprofessions", {
""}}
};
}
public function getClass(cl) {
return this.(@ "class_" @ cl);
}
public function getClassVar(cl, cvar) {
temp.var = null;
for (var: this.(@ "class_" @ cl)) {
if (var[0] == cvar) {
return var[1];
}
}
}
Here a short little function for item application (using items etc.), it's more so used to interpret two arrays.
The first array, "scripts" is a list of functions to call when the item is applied. The second array, "scriptsparams" is a multi-dimensional array of params with each index of the array a sub-array of params that is to be sent with the function of the matching index in the "scripts" array.
PHP Code:
public function applyItem(id) {
temp.item = null;
temp.i = null;
temp.f = null;
temp.fparams = null;
item = findItemById(id);
if (item.type() != 2) {
return;
}
if (item.applyable) {
if (item.equippable) {
equipItem(item);
}
else {
for (i = 0; i < item.scripts.size(); i++) {
f = item.scripts[i];
fparams = item.scriptsparams[i];
if (this.hasFunction(@ f)) {
this.(@ f)(fparams[0], fparams[1], fparams[2], fparams[3], fparams[4], fparams[5], fparams[6], fparams[7]);
}
}
}
}
}
The next is pretty much basically data transfering, saving and loading for the player's mud object which contains most gameplay variables. These two functions are just the meat of the loading and saving of the player's game data. Or so you could say.
PHP Code:
public function loadObject() {
temp.file = null;
temp.var = null;
temp.i = null;
temp.data = null;
temp.item = null;
// Create object to load ini file to.
file = new TStaticVar();
file.joinedclasses = serverr.t.inifile;
file.load(getObjectPath());
// Checks if the loaded file has an object key
if ({"object", "items"} in file.keys) {
// Go through each var saved in the ini file's
// object key.
for (var: file.object.getdynamicvarnames()) {
// Load the var to the object
this.(@ var) = file.object.(@ var);
}
// Go through all file item vars
for (i: file.items.getdynamicvarnames()) {
// Create pointer to saved data
data = file.items.(@ i);
// Create item object then create pointer to it
item = createItem(i.substring(1), data[0], data[1]);
if (data[2] == true) { // Item was equipped
echo("was equipped.");
}
}
return true;
}
return false;
}
public function saveObject() {
temp.file = null;
temp.var = null;
temp.i = null;
temp.item = null;
// Create object to load data to
// to save to an ini file.
file = new TStaticVar();
file.joinedclasses = serverr.t.inifile;
// Clear keys for object and items
file.clearkey("object");
file.clearkey("items");
// Go through all object vars
for (var: Mud.objectvars) {
// Checks if the var should not be saved
// if so skips over.
if (var in Mud.nosavevars) {
continue;
}
// Load the var to the object to save
file.object.(@ var) = this.(@ var);
}
// Go through all the items
for (i = 0; i < this.items.size(); i++) {
// Make pointer to item object
item = this.items[i];
// Check for invalid item data
if (item.type() != 2 || item.qty =< 0 || item.id == 0 || item.id == null) {
continue;
}
// Create file vars
file.items.(@ "i" @ item.id) = {item.archetype, item.qty, item.equipped};
}
// Save data
file.save(getObjectPath(), 0);
}
Note: I replaced all "percent" signs with "#" signs.
Edit: Also,
Quote:
Originally Posted by DrakilorP2P
Anyone that think they can successfully make a popular server using that method is probably not a threat.
Also, you're still coming off as arrogant.
|
Not really trying to, I apologize for that.