Changed effect arrays to a single effect array array
This commit is contained in:
@@ -26,18 +26,18 @@ Schemas.Character = new SimpleSchema({
|
|||||||
|
|
||||||
//stats
|
//stats
|
||||||
hitPoints: {type: Schemas.Attribute},
|
hitPoints: {type: Schemas.Attribute},
|
||||||
"hitPoints.add": {
|
"hitPoints.effects": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [
|
defaultValue: [
|
||||||
{name: "Constitution modifier for each level", calculation: "level * constitutionMod"}
|
{name: "Constitution modifier for each level", calculation: "level * constitutionMod", operation: "add", type: "inate"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
experience: {type: Schemas.Attribute},
|
experience: {type: Schemas.Attribute},
|
||||||
proficiencyBonus: {type: Schemas.Attribute},
|
proficiencyBonus: {type: Schemas.Attribute},
|
||||||
"proficiencyBonus.add": {
|
"proficiencyBonus.effects": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [
|
defaultValue: [
|
||||||
{name: "Proficiency bonus by level", calculation: "floor(level / 4.1) + 2"}
|
{name: "Proficiency bonus by level", calculation: "floor(level / 4.1) + 2", operation: "add", type: "inate"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
speed: {type: Schemas.Attribute},
|
speed: {type: Schemas.Attribute},
|
||||||
@@ -45,10 +45,10 @@ Schemas.Character = new SimpleSchema({
|
|||||||
age: {type: Schemas.Attribute},
|
age: {type: Schemas.Attribute},
|
||||||
ageRate: {type: Schemas.Attribute},
|
ageRate: {type: Schemas.Attribute},
|
||||||
armor: {type: Schemas.Attribute},
|
armor: {type: Schemas.Attribute},
|
||||||
"armor.add": {
|
"armor.effects": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [
|
defaultValue: [
|
||||||
{name: "Dexterity Modifier", calculation: "dexterityArmor"}
|
{name: "Dexterity Modifier", calculation: "dexterityArmor", operation: "add", type: "inate"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -174,51 +174,51 @@ Schemas.Character = new SimpleSchema({
|
|||||||
|
|
||||||
strengthAttack: {type: Schemas.Skill},
|
strengthAttack: {type: Schemas.Skill},
|
||||||
"strengthAttack.ability": {type: String,defaultValue: "strength"},
|
"strengthAttack.ability": {type: String,defaultValue: "strength"},
|
||||||
"strengthAttack.proficiency": {
|
"strengthAttack.effects": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
|
defaultValue: [{name: "Attack Proficiency", value: 1, operation: "proficiency", type: "inate"}]
|
||||||
},
|
},
|
||||||
|
|
||||||
dexterityAttack: {type: Schemas.Skill},
|
dexterityAttack: {type: Schemas.Skill},
|
||||||
"dexterityAttack.ability": { type: String, defaultValue: "dexterity" },
|
"dexterityAttack.ability": { type: String, defaultValue: "dexterity" },
|
||||||
"dexterityAttack.proficiency": {
|
"dexterityAttack.proficiency": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
|
defaultValue: [{name: "Attack Proficiency", value: 1, operation: "proficiency", type: "inate"}]
|
||||||
},
|
},
|
||||||
|
|
||||||
constitutionAttack: {type: Schemas.Skill},
|
constitutionAttack: {type: Schemas.Skill},
|
||||||
"constitutionAttack.ability":{ type: String, defaultValue: "constitution" },
|
"constitutionAttack.ability":{ type: String, defaultValue: "constitution" },
|
||||||
"constitutionAttack.proficiency": {
|
"constitutionAttack.proficiency": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
|
defaultValue: [{name: "Attack Proficiency", value: 1, operation: "proficiency", type: "inate"}]
|
||||||
},
|
},
|
||||||
|
|
||||||
intelligenceAttack: {type: Schemas.Skill},
|
intelligenceAttack: {type: Schemas.Skill},
|
||||||
"intelligenceAttack.ability":{ type: String, defaultValue: "intelligence" },
|
"intelligenceAttack.ability":{ type: String, defaultValue: "intelligence" },
|
||||||
"intelligenceAttack.proficiency": {
|
"intelligenceAttack.proficiency": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
|
defaultValue: [{name: "Attack Proficiency", value: 1, operation: "proficiency", type: "inate"}]
|
||||||
},
|
},
|
||||||
|
|
||||||
wisdomAttack: {type: Schemas.Skill},
|
wisdomAttack: {type: Schemas.Skill},
|
||||||
"wisdomAttack.ability": { type: String, defaultValue: "wisdom" },
|
"wisdomAttack.ability": { type: String, defaultValue: "wisdom" },
|
||||||
"wisdomAttack.proficiency": {
|
"wisdomAttack.proficiency": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
|
defaultValue: [{name: "Attack Proficiency", value: 1, operation: "proficiency", type: "inate"}]
|
||||||
},
|
},
|
||||||
|
|
||||||
charismaAttack: {type: Schemas.Skill},
|
charismaAttack: {type: Schemas.Skill},
|
||||||
"charismaAttack.ability": { type: String, defaultValue: "charisma" },
|
"charismaAttack.ability": { type: String, defaultValue: "charisma" },
|
||||||
"charismaAttack.proficiency": {
|
"charismaAttack.proficiency": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
|
defaultValue: [{name: "Attack Proficiency", value: 1, operation: "proficiency", type: "inate"}]
|
||||||
},
|
},
|
||||||
|
|
||||||
rangedAttack: {type: Schemas.Skill},
|
rangedAttack: {type: Schemas.Skill},
|
||||||
"rangedAttack.ability": { type: String, defaultValue: "dexterity" },
|
"rangedAttack.ability": { type: String, defaultValue: "dexterity" },
|
||||||
"rangedAttack.proficiency": {
|
"rangedAttack.proficiency": {
|
||||||
type: [Schemas.Effect],
|
type: [Schemas.Effect],
|
||||||
defaultValue: [{_id: Random.id(),name: "Attack Proficiency",value: 1}]
|
defaultValue: [{name: "Attack Proficiency", value: 1, operation: "proficiency", type: "inate"}]
|
||||||
},
|
},
|
||||||
|
|
||||||
dexterityArmor: {type: Schemas.Skill},
|
dexterityArmor: {type: Schemas.Skill},
|
||||||
@@ -277,26 +277,23 @@ Characters.find({},{fields: {time: 1, expirations: 1, features: 1}}).observe({
|
|||||||
|
|
||||||
var attributeBase = function(charId, attribute){
|
var attributeBase = function(charId, attribute){
|
||||||
var value = 0;
|
var value = 0;
|
||||||
//add all values in add array
|
_.each(attribute.effects, function(effect){
|
||||||
_.each(attribute.add, function(effect){
|
switch(effect.operation) {
|
||||||
value += evaluateEffect(charId, effect);
|
case "add":
|
||||||
});
|
value += evaluateEffect(charId, effect);
|
||||||
|
break;
|
||||||
//multiply all values in mul array
|
case "mul":
|
||||||
_.each(attribute.mul, function(effect){
|
value *= evaluateEffect(charId, effect);
|
||||||
value *= evaluateEffect(charId, effect);
|
break;
|
||||||
});
|
case "min":
|
||||||
|
var min = evaluateEffect(charId, effect);
|
||||||
//largest min
|
value = value > min? value : min;
|
||||||
_.each(attribute.min, function(effect){
|
break;
|
||||||
var min = evaluateEffect(charId, effect);
|
case "max":
|
||||||
value = value > min? value : min;
|
var max = evaluateEffect(charId, effect);
|
||||||
});
|
value = value < max? value : max;
|
||||||
|
break;
|
||||||
//smallest max
|
}
|
||||||
_.each(attribute.max, function(effect){
|
|
||||||
var max = evaluateEffect(charId, effect);
|
|
||||||
value = value < max? value : max;
|
|
||||||
});
|
});
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -324,12 +321,12 @@ Characters.helpers({
|
|||||||
throw new Meteor.Error("Field not found", "Character's schema does not contain a field called: " + fieldName);
|
throw new Meteor.Error("Field not found", "Character's schema does not contain a field called: " + fieldName);
|
||||||
}
|
}
|
||||||
//duck typing to get the right value function
|
//duck typing to get the right value function
|
||||||
//.proficiency implies skill
|
//.ability implies skill
|
||||||
if (Schemas.Character.schema(fieldName + ".proficiency")){
|
if (Schemas.Character.schema(fieldName + ".ability")){
|
||||||
return this.skillMod(fieldName);
|
return this.skillMod(fieldName);
|
||||||
}
|
}
|
||||||
//base without proficiency implies attribute
|
//adjustment implies attribute
|
||||||
if (Schemas.Character.schema(fieldName + ".base")){
|
if (Schemas.Character.schema(fieldName + ".adjustment")){
|
||||||
return this.attributeValue(fieldName);
|
return this.attributeValue(fieldName);
|
||||||
}
|
}
|
||||||
//fall back to just returning the field itself
|
//fall back to just returning the field itself
|
||||||
@@ -424,26 +421,23 @@ Characters.helpers({
|
|||||||
//add multiplied proficiency bonus to modifier
|
//add multiplied proficiency bonus to modifier
|
||||||
mod += prof * this.attributeValue("proficiencyBonus");
|
mod += prof * this.attributeValue("proficiencyBonus");
|
||||||
|
|
||||||
//add all values in add array
|
_.each(skill.effects, function(effect){
|
||||||
_.each(skill.add, function(effect){
|
switch(effect.operation) {
|
||||||
mod += evaluateEffect(charId, effect);
|
case "add":
|
||||||
});
|
mod += evaluateEffect(charId, effect);
|
||||||
|
break;
|
||||||
//multiply all values in mul array
|
case "mul":
|
||||||
_.each(skill.mul, function(effect){
|
mod *= evaluateEffect(charId, effect);
|
||||||
mod *= evaluateEffect(charId, effect);
|
break;
|
||||||
});
|
case "min":
|
||||||
|
var min = evaluateEffect(charId, effect);
|
||||||
//largest min
|
mod = mod > min? mod : min;
|
||||||
_.each(skill.min, function(effect){
|
break;
|
||||||
var min = evaluateEffect(charId, effect);
|
case "max":
|
||||||
mod = mod > min? mod : min;
|
var max = evaluateEffect(charId, effect);
|
||||||
});
|
mod = mod < max? mod : max;
|
||||||
|
break;
|
||||||
//smallest max
|
}
|
||||||
_.each(skill.max, function(effect){
|
|
||||||
var max = evaluateEffect(charId, effect);
|
|
||||||
mod = mod < max? mod : max;
|
|
||||||
});
|
});
|
||||||
} finally{
|
} finally{
|
||||||
//this skill returns or fails, pull it from the array
|
//this skill returns or fails, pull it from the array
|
||||||
@@ -460,10 +454,12 @@ Characters.helpers({
|
|||||||
var charId = this._id;
|
var charId = this._id;
|
||||||
//return largest value in proficiency array
|
//return largest value in proficiency array
|
||||||
var prof = 0;
|
var prof = 0;
|
||||||
_.each(skill.proficiency, function(effect){
|
_.each(skill.effects, function(effect){
|
||||||
var newProf = evaluateEffect(charId, effect);
|
if(effect.operation === "proficiency"){
|
||||||
if (newProf > prof){
|
var newProf = evaluateEffect(charId, effect);
|
||||||
prof = newProf;
|
if (newProf > prof){
|
||||||
|
prof = newProf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return prof;
|
return prof;
|
||||||
@@ -476,8 +472,10 @@ Characters.helpers({
|
|||||||
var charId = this._id
|
var charId = this._id
|
||||||
var mod = +this.skillMod(skillName);
|
var mod = +this.skillMod(skillName);
|
||||||
var value = 10 + mod;
|
var value = 10 + mod;
|
||||||
_.each(skill.passiveAdd, function(effect){
|
_.each(skill.effects, function(effect){
|
||||||
value += evaluateEffect(charId, effect);
|
if(effect.operation === "passiveAdd"){
|
||||||
|
value += evaluateEffect(charId, effect);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return value;
|
return value;
|
||||||
//TODO decide whether (dis)advantage gives (-)+5 to passive checks
|
//TODO decide whether (dis)advantage gives (-)+5 to passive checks
|
||||||
|
|||||||
@@ -6,11 +6,7 @@ Schemas.Attribute = new SimpleSchema({
|
|||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
//effect arrays
|
//effect arrays
|
||||||
add: { type: [Schemas.Effect], defaultValue: [] },
|
effects: { type: [Schemas.Effect], defaultValue: [] },
|
||||||
mul: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
min: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
max: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
conditional:{ type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
reset: {
|
reset: {
|
||||||
type: String,
|
type: String,
|
||||||
defaultValue: "longRest",
|
defaultValue: "longRest",
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ Schemas.Effect = new SimpleSchema({
|
|||||||
name: {
|
name: {
|
||||||
type: String
|
type: String
|
||||||
},
|
},
|
||||||
|
operation: {
|
||||||
|
type: String,
|
||||||
|
defaultValue: "add",
|
||||||
|
allowedValues: ["proficiency","add","mul","min","max","advantage","disadvantage","passiveAdd","fail","conditional","passiveAdd"]
|
||||||
|
},
|
||||||
value: {
|
value: {
|
||||||
type: Number,
|
type: Number,
|
||||||
decimal: true,
|
decimal: true,
|
||||||
@@ -28,4 +33,4 @@ Schemas.Effect = new SimpleSchema({
|
|||||||
defaultValue: "default",
|
defaultValue: "default",
|
||||||
allowedValues: ["default", "inate", "class", "race", "feat", "equippedMagic", "equippedMundane", "external"]
|
allowedValues: ["default", "inate", "class", "race", "feat", "equippedMagic", "equippedMundane", "external"]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1,25 +1,5 @@
|
|||||||
Schemas.Skill = new SimpleSchema({
|
Schemas.Skill = new SimpleSchema({
|
||||||
//attribute name that this skill used as base mod for roll
|
//attribute name that this skill used as base mod for roll
|
||||||
ability: { type: String, defaultValue: "" },
|
ability: { type: String, defaultValue: "" },
|
||||||
//multiplied by profBonus and added to base mod
|
effects: { type: [Schemas.Effect], defaultValue: [] },
|
||||||
//only highest value proficiency is used
|
|
||||||
proficiency: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//added to base mod
|
|
||||||
add: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//multiplied by base + adds
|
|
||||||
mul: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//lower bounds, highest used
|
|
||||||
min: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//upper bounds, lowest used
|
|
||||||
max: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//things giving advantage
|
|
||||||
advantage: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//things giving disadvantage
|
|
||||||
disadvantage: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//added to passive checks only
|
|
||||||
passiveAdd: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//things causing all rolls to fail
|
|
||||||
fail: { type: [Schemas.Effect], defaultValue: [] },
|
|
||||||
//things that only apply sometimes
|
|
||||||
conditional: { type: [Schemas.Effect], defaultValue: [] }
|
|
||||||
});
|
});
|
||||||
@@ -42,17 +42,34 @@ Template.skillRow.helpers({
|
|||||||
return "profNone.png";
|
return "profNone.png";
|
||||||
},
|
},
|
||||||
failSkill: function(){
|
failSkill: function(){
|
||||||
return Template.parentData(1).getField(this.skill).fail.length > 0;
|
var skill = Template.parentData(1).getField(this.skill);
|
||||||
|
_.each(skill.effets, function(effect){
|
||||||
|
if (effect.operation === "fail"){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
advantage: function(){
|
advantage: function(){
|
||||||
var adv = Template.parentData(1).getField(this.skill).advantage.length;
|
var adv = 0;
|
||||||
var disadv = Template.parentData(1).getField(this.skill).disadvantage.length;
|
var disadv = 0;
|
||||||
|
var skill = Template.parentData(1).getField(this.skill);
|
||||||
|
_.each(skill.effets, function(effect){
|
||||||
|
if (effect.operation === "advantage"){
|
||||||
|
adv ++;
|
||||||
|
} else if (effect.operation === "disadvantage") {
|
||||||
|
disadv ++;
|
||||||
|
}
|
||||||
|
})
|
||||||
if(adv > 0 && disadv === 0) return "advantage";
|
if(adv > 0 && disadv === 0) return "advantage";
|
||||||
if(disadv > 0 && adv === 0) return "disadvantage";
|
if(disadv > 0 && adv === 0) return "disadvantage";
|
||||||
},
|
},
|
||||||
conditionals: function(){
|
conditionals: function(){
|
||||||
if(Template.parentData(1).getField(this.skill).conditional.length > 0){
|
var skill = Template.parentData(1).getField(this.skill);
|
||||||
return "conditionals";
|
_.each(skill.effets, function(effect){
|
||||||
}
|
if (effect.operation === "conditional"){
|
||||||
|
return "conditionals";
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -19,10 +19,10 @@ evaluate = function(charId, string){
|
|||||||
return sub;
|
return sub;
|
||||||
});
|
});
|
||||||
try{
|
try{
|
||||||
result = math.eval(string);
|
var result = math.eval(string);
|
||||||
return result
|
return result;
|
||||||
} catch(e){
|
} catch(e){
|
||||||
console.log(e)
|
console.log("Failed to evaluate ", string);
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user