Refactoring of Character class to add effect appliers and removers

This commit is contained in:
Thaum
2014-11-03 11:30:14 +00:00
parent e7f7f75436
commit 25b2a95f14
9 changed files with 139 additions and 93 deletions

View File

@@ -0,0 +1,12 @@
//Attributes are numerical values
Attribute = function(base){
//the unmodified value of the attribute
//should be zero for most attributes after a long rest
this.base = base;
//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
}

View File

@@ -0,0 +1,118 @@
DamageTypes = [
"acid", "bludgeoning", "cold", "fire", "force",
"lightning", "necrotic", "piercing", "poison", "psychic",
"radiant", "slashing", "thunder"
]
Conditions = {};
Conditions.Blinded = {
description: ["a blinded creature can't see and automatically fails any ability check that requires sight.",
"Attack rolls against the creature have advantage, and the creature's attack rolls have disadvantage."]
}
Conditions.Charmed = {
description: ["A charmed creature can't attack the charmer or target the charmer with harmful abilities or magical effects",
"The charmer has advantage on any ability check to interact socially with the creature."]
}
Conditions.Deafened = {
description: ["A deafened creature can't hear and automatically fails any ability check that requires hearing"]
}
Conditions.Frightened = {
description: []
}
Conditions.Grappled = {
description: [
"A grappled creature's speed becomes 0, and it can't benefit from any bonuses to its speed",
"The condition ends if the grappler is incapacitated",
"The conditions also ends if if an effect removes the\
grappled creature from the reach of the grappler or grappling\
effect, such as when a creature is hurled\
away by the thunderwave spell."
],
effects: [
{stat: "attributes.speed.max", value: 0}
]
}
Conditions.Incapacitated = {
effects: [
{stat: "attributes.actions.max", value: 0},
{stat: "attributes.reactions.max", value: 0},
{stat: "attributes.bonusActions.max", value: 0}
]
}
Conditions.Invisible = {
}
Conditions.Paralyzed = {
//implies incapacitated
effects: [
{stat: "skills.strengthSave.fail", value: 1},
{stat: "skills.dexteritySave.fail", value: 1},
{stat: "attributes.speed.max", value: 0}
]
}
_.extend(Conditions.Paralyzed, Conditions.Incapacitated);
Conditions.Petrified = {
effects: [
{stat: "attributes.weight.mul", value: 10},
{stat: "attributes.ageRate.max", value: 0},
{stat: "attributes.ageRate.min", value: 0},
{stat: "skills.strengthSave.fail", value: 1},
{stat: "skills.dexteritySave.fail", value: 1},
{stat: "attributes.speed.max", value: 0}
]
}
for(var i = 0, l = DamageTypes.length; i < l; i++){
var str = "vulnerability." + DamageTypes[i] + ".mul"
Conditions.Petrified.effects.push({stat: str, value: 0.5});
}
_.extend(Conditions.Petrified, Conditions.Incapacitated);
Conditions.Poisoned = {
description: []
}
Conditions.Prone = {
description: [],
effects: [
{stat: "skills.strengthAttack.disadvantage", value: 1},
{stat: "skills.dexterityAttack.disadvantage", value: 1},
{stat: "skills.rangedAttack.disadvantage", value: 1}
]
}
Conditions.Restrained = {
effects: [
{stat: "attributes.speed.max", value: 0}
]
}
Conditions.Stunned = {
//implies incapacitated
effects: [
{stat: "attributes.speed.max", value: 0},
{stat: "skills.strengthSave.fail", value: 1},
{stat: "skills.dexteritySave.fail", value: 1}
]
}
_.extend(Conditions.Stunned, Conditions.Incapacitated);
Conditions.Unconscious = {
//implies incapacitated
//implies prone
effects: [
{stat: "attributes.speed.max", value: 0},
{stat: "skills.strengthSave.fail", value: 1},
{stat: "skills.dexteritySave.fail", value: 1}
]
}
_.extend(Conditions.Unconscious, Conditions.Incapacitated);
_.extend(Conditions.Unconscious, Conditions.Prone);

View File

@@ -0,0 +1,47 @@
Effect = function(stat, value){
this.stat = stat;
this.value = value;
this._id = new Mongo.ObjectID()._str;
}
pushEffects = function(characterId, effectName, effectsArray){
//check that the arguments are of the right form
check(characterId, String);
check(effectName, String);
check(effectsArray, [{ _id: String, stat: String, value: Number}]);
for(var i = 0; i < effectsArray.length; i++){
var effect = effectsArray[i];
//check if the character exists with the field we are changing
var chk = {_id: characterId}; //right id
chk[effect.stat] = {$exists: true}; //has a field for the stat already
if(Characters.findOne(chk)){
var newEffect = {};
newEffect[effect.stat] = {_id: effect.id, name: effectName, value: effect.value};
//update the field
Characters.update(characterId, {$push: newEffect});
}
}
}
pullEffects = function(characterId, effectsArray){
//check that the arguments are of the right form
check(characterId, String);
check(effectsArray, [{ _id: String, stat: String, value: Number}]);
for(var i = 0; i < effectsArray.length; i++){
var effect = effectsArray[i];
//check if the character exists with the field we are changing
var chk = {_id: characterId}; //right id
chk[effect.stat] = {$exists: true}; //has a field for the stat already
if(Characters.findOne(chk)){
var effectToPull = {};
effectToPull[effect.stat] = {_id: effect.id};
//update the field
Characters.update(characterId, {$pull: effectToPull});
}
}
}

View File

@@ -0,0 +1,4 @@
Feature = function(name){
this.name = name;
this.description = description;
}

View File

@@ -0,0 +1,6 @@
HitDice = function(sides){
this.sides = sides;
this.bonus = 0;
this.number = 0;
this.max = 0;
}

View File

@@ -0,0 +1,18 @@
//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
}

View File

@@ -0,0 +1,11 @@
Spell = function(name){
this.name = name;
this.level = 0;
this.school = "";
this.range = "";
this.verbal = false;
this.somatic = false;
this.material = false;
this.duration = "";
this.description = "";
}