Implemented and cleaned up character schemas

This commit is contained in:
Thaum
2014-11-13 08:44:21 +00:00
parent d80fb19dfe
commit 7ab97a17cc
27 changed files with 403 additions and 259 deletions

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 @@
Schemas = {};

View File

@@ -0,0 +1,44 @@
roll = function (n, d){
if(!isNaN(n)){
//first digit is a number
if(d === undefined){
d = n;
n = 1;
}
if(n > 500){
console.log(n + " > 500, cannot lift that many dice to roll them");
return;
}
var result = {sum: 0, rolls: []};
for (var i = 0; i < n; i++){
var roll = Math.floor(Random.fraction() * d + 1)
result.sum += roll;
result.rolls.push(roll);
}
return result;
}
console.log("rolling dice failed for inputs: ", n, d);
return {sum: 0, rolls: []};
}
rollDropLow = function(n, d, drop){
var r = roll(n,d)
r.rolls.sort(function(a, b){return a-b}); //sort ascending
r.rolls.splice(0, drop); //remove the lowest elements
r.sum = 0;
for (var i = 0, l = r.rolls.length; i , l ; i++){
sum += r.rolls[i];
}
return r;
}
rollDropHigh = function(n, d, drop){
var r = roll(n,d)
r.rolls.sort(function(a, b){return b-a}); //sort descending
r.rolls.splice(0, drop); //remove the highest elements
r.sum = 0;
for (var i = 0, l = r.rolls.length; i , l ; i++){
sum += r.rolls[i];
}
return r;
}

View File

@@ -0,0 +1,36 @@
evaluate = function(character, string){
string = string.replace(/\b[a-z]+\b/g, function(sub){
//skill mods
if(character.skills[sub]){
return +character.skillMod(character.skills[sub]);
}
//attributes
if(character.attributes[sub]){
return +character.attributeValue(character.attributes[sub]);
}
return sub;
});
try{
result = math.eval(string);
return result
} catch(e){
console.log(e)
return string;
}
}
evaluateString = function(character, string){
//define brackets as curly brackets around anything that isn't a curly bracket
var brackets = /\{[^\{\}]*\}/g;
var result = string.replace(brackets, function(exp){
var exp = exp.replace(/(\{|\})/g, "") //remove brackets
var span = jQuery('<span/>', {
title: exp,
text: evaluate(character, exp),
class: "calculatedValue"
});
return span.prop('outerHTML');
});
//this is going to return HTML, ensure it is santized!
return result;
}

File diff suppressed because one or more lines are too long

View File

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