Refactoring of Character class to add effect appliers and removers
This commit is contained in:
@@ -10,17 +10,6 @@ Characters = new Meteor.Collection("characters", {
|
||||
}
|
||||
});
|
||||
|
||||
//Attributes are numerical values
|
||||
Attribute = function(base){
|
||||
this.base = base; //the unmodified value of the attribute
|
||||
//effects of the form {name: "Ring of Protection", value: 1}
|
||||
this.add = []; //bonuses added to the attribute
|
||||
this.mul = []; //multipliers to the attribute (after adding bonuses)
|
||||
this.min = []; //effects setting the minimum value of the attribute
|
||||
this.max = []; //effects setting the maximum value of the attribute
|
||||
this.conditional = []; //conditional modifiers
|
||||
}
|
||||
|
||||
var attributes = [
|
||||
{name: "strength"},
|
||||
{name: "dexterity"},
|
||||
@@ -32,18 +21,18 @@ var attributes = [
|
||||
{name: "experience"},
|
||||
{name: "proficiencyBonus",
|
||||
add: [
|
||||
{name: "Level 1", value: 2}
|
||||
new Effect("Level 1", 2)
|
||||
]
|
||||
},
|
||||
{name: "speed",
|
||||
add: [
|
||||
{name: "Base Speed", value: 30}
|
||||
new Effect("Base Speed", 30)
|
||||
]
|
||||
},
|
||||
{name: "armor",
|
||||
add: [
|
||||
{name: "Base Armor Class", value: 10},
|
||||
{name: "Dexterity Modifier", value: "skillMod skills.dexterityArmor"}
|
||||
new Effect("Base Armor Class", 10),
|
||||
new Effect("Dexterity Modifier", "skillMod skills.dexterityArmor")
|
||||
]
|
||||
},
|
||||
{name: "weight"},
|
||||
@@ -64,25 +53,6 @@ var attributes = [
|
||||
{name: "rages"}
|
||||
];
|
||||
|
||||
//Skills are bonuses to rolls: "+2" etc.
|
||||
//They are based off of some ability
|
||||
Skill = function(ability){
|
||||
//proficiencies of the form {name: "Jack of all Trades", value: 0.5}
|
||||
//only the highest is used
|
||||
this.proficiency = [];
|
||||
//ability name that this skill uses as base for roll
|
||||
this.ability = ability;
|
||||
this.add = [];
|
||||
this.mul = [];
|
||||
this.min = [];
|
||||
this.max = [];
|
||||
this.advantage = []; //effects granting advantage
|
||||
this.disadvantage = [];
|
||||
this.passiveAdd = []; //only added to passive checks
|
||||
this.fail = []; //all checks are failed
|
||||
this.conditional = []; //conditional modifiers
|
||||
}
|
||||
|
||||
var skills = [
|
||||
{skill: "strengthSave", ability: "strength"},
|
||||
{skill: "dexteritySave", ability: "dexterity"},
|
||||
@@ -292,53 +262,3 @@ getMod = function(score){
|
||||
signedString = function(number){
|
||||
return number > 0? "+" + number : "" + number;
|
||||
}
|
||||
|
||||
// turns dot notation strings into keys of root
|
||||
// argument formats:
|
||||
// 157, anything -> 157
|
||||
// "some.number", object -> object.some.number
|
||||
// "some.function", object -> object.some.function()
|
||||
// "some.function arg1 arg2", object -> object.some.function(arg1, arg2)
|
||||
pop = function(input, root){
|
||||
|
||||
if(typeof(input) === "string"){
|
||||
//we need root for this part
|
||||
if(root === undefined) return;
|
||||
|
||||
//this is a likely to fail if the string is malformed
|
||||
try{
|
||||
//split over spaces
|
||||
var parts = input.split(" ");
|
||||
|
||||
//for each word
|
||||
for (var i = 0; i < parts.length; i++){
|
||||
//split over dots
|
||||
var str = parts[i].split(".");
|
||||
|
||||
//start at root
|
||||
parts[i] = root;
|
||||
|
||||
//for each word between dots
|
||||
for (var j = 0; j < str.length; j++){
|
||||
parts[i] = parts[i][str[j]];
|
||||
}
|
||||
}
|
||||
|
||||
//pull the first word out, might be a function
|
||||
var func = parts.splice(0, 1)[0];
|
||||
|
||||
//if it's a function, apply the arguments to it
|
||||
if(_.isFunction(func)) return +func.apply(root, parts);
|
||||
|
||||
//if it's a number, return it
|
||||
if(!isNaN(func)) return +func;
|
||||
} catch (err) {
|
||||
//TODO pokemon catch statement is bad
|
||||
//"gotta catch em all"
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return +input;
|
||||
}
|
||||
Reference in New Issue
Block a user