Added buffs and standard conditions, no UI yet though

This commit is contained in:
Stefan Zermatten
2015-05-20 16:13:25 +02:00
parent 73cee52fff
commit fea02811ff
3 changed files with 436 additions and 13 deletions

View File

@@ -1,28 +1,51 @@
Buffs = new Mongo.Collection("buffs");
//buffs are temporary once applied and store things which expire and their expiry time
Schemas.Buff = new SimpleSchema({
//buff id
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id,
autoValue: function(){
if (!this.isSet) return Random.id();
},
},
charId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
},
//expiry time
expiry: {type: Number, optional: true},
duration: {type: Number},
name: {
type: String,
trim: false,
},
description: {
type: String,
optional: true,
trim: false,
},
enabled: {
type: Boolean,
defaultValue: true,
},
type: {
type: String,
allowedValues: [
"inate",
"custom",
],
},
"lifeTime.total": {
type: Number,
defaultValue: 0, //0 is infinite
min: 0,
},
"lifeTime.spent": {
type: Number,
defaultValue: 0,
min: 0,
},
color: {
type: String,
allowedValues: _.pluck(colorOptions, "key"),
defaultValue: "q",
},
});
Buffs.attachSchema(Schemas.Buff);
Buffs.attachBehaviour("softRemovable");
makeParent(Buffs, "name"); //parents of effects and attacks
makeParent(Buffs, ["name", "enabled"]); //parents of effects
Buffs.allow(CHARACTER_SUBSCHEMA_ALLOW);
Buffs.deny(CHARACTER_SUBSCHEMA_DENY);

View File

@@ -0,0 +1,399 @@
Meteor.methods({
giveCondition: function(charId, conditionName) {
//check permission
if (!Meteor.call("canWriteCharacter", charId)){
throw new Meteor.Error(
"Access denied",
"You do not have permission to edit the assets of this character"
);
}
//get condition from constant
var condition = CONDITIONS[conditionName];
//check that condition exists
if (!condition) {
throw new Meteor.Error(
"Invalid condition",
conditionName + " is not a known condition"
);
}
//extend the buff
var buff = _.extend(
{charId: charId, type: "inate"}, condition.buff
);
//make sure the character doesn't already have the buff
var existingBuffs = Buffs.find(_.clone(buff)).count();
if (existingBuffs) return;
//remove exclusive conditions
_.each(condition.exclusiveConditions, function(exCond) {
Buffs.remove(exCond);
});
//insert the buff
var buffId = Buffs.insert(buff);
//extend and insert each effect
_.each(condition.effects, function(effect) {
effect = _.extend(
effect, {
charId: charId,
parent: {
id: buffId,
collection: "Buffs",
},
}
);
Effects.insert(effect);
});
//recurse for subConditions
_.each(condition.subConditions, function(subCondition) {
Meteor.call("giveCondition", charId, subCondition);
});
}
});
CONDITIONS = {
//Conditions
blind: {
buff: {
name: "Blind",
description: "A blinded creature cant see and automatically fails any ability check that requires sight.\n\nAttack rolls against the creature have advantage, and the creatures attack rolls have disadvantage.",
},
effects: [
{
stat: "perception",
operation: "conditional",
calculation: "You fail your perception check if it requires sight",
}
],
},
deaf: {
buff: {
name: "Deaf",
description: "A deafened creature cant hear and automatically fails any ability check that requires hearing.",
},
effects: [
{
stat: "perception",
operation: "conditional",
calculation: "You fail your perception check if it requires hearing",
}
],
},
frightened: {
buff: {
name: "Frightened",
description: "A frightened creature has disadvantage on ability checks and attack rolls while the source of its fear is within line of sight.\n\nThe creature cant willingly move closer to the source of its fear.",
}
},
grappled: {
buff:{
name: "Grappled",
description: "A grappled creatures speed becomes 0, and it cant benefit from any bonus to its speed.\n\nThe condition ends if the grappler is incapacitated.\n\nThe condition also ends 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 thunder wave spell.",
},
effects: [
{
stat: "speed",
operation: "max",
value: 0,
},
],
},
incapacitated: {
buff: {
name: "Incapacitated",
description: "An incapacitated creature cant take actions or reactions.",
}
},
invisible: {
buff: {
name: "Invisible",
description: "An invisible creature is impossible to see without the aid of magic or a special sense. For the purpose of hiding, the creature is heavily obscured. The creatures location can be detected by any noise it makes or any tracks it leaves.\n\nAttack rolls against the creature have disadvantage, and the creatures attack rolls have advantage.",
}
},
paralyzed: {
buff: {
name: "Paralyzed",
description: "A paralyzed creature is incapacitated and cant move or speak.\n\nAttack rolls against the creature have advantage.\n\nAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
},
effects: [
{
stat: "speed",
operation: "mul",
value: 0,
},
{
stat: "strengthSave",
operation: "fail",
},
{
stat: "dexteritySave",
operation: "fail",
},
],
subConditions: [
"incapacitated",
],
},
petrified: {
buff: {
name: "Petrified",
description: "A petrified creature is transformed, along with any nonmagical object it is wearing or carrying, into a solid inanimate substance (usually stone). Its weight increases by a factor of ten, and it ceases aging.\n\nA petrified creature is incapacitated and cant move or speak, and is unaware of its surroundings.\n\nAttack rolls against the creature have advantage.\n\nThe creature is immune to poison and disease, although a poison or disease already in its system is suspended, not neutralized.",
},
effects: (function() {
var effects = [
{stat: "speed", operation: "max", value: 0},
{stat: "strengthSave", operation: "fail"},
{stat: "dexteritySave", operation: "fail"},
];
_.each(
_.without(DAMAGE_MULTIPLIERS, "poisonMultiplier"),
function(multiplier){
effects.push({stat: multiplier, operation: "mul", value: 0.5});
}
);
effects.push({stat: "poisonMultiplier", operation: "mul", value: 0});
})(),
subConditions: [
"incapacitated",
],
},
poisoned: {
buff: {
name: "Poisoned",
description: "A poisoned creature has disadvantage on attack rolls and ability checks.",
},
effects: (function() {
return _.map(SKILLS, function(skill) {
return {stat: skill, operation: "disadvantage", value: 1};
});
})(),
},
prone: {
buff: {
name: "Prone",
description: "A prone creatures only movement option is to crawl, unless it stands up and thereby ends the condition.\n\nThe creature has disadvantage on attack rolls.\n\nAn attack roll against the creature has advantage if the attacker is within 5 feet of the creature. Otherwise, the attack roll has disadvantage.",
}
},
restrained: {
buff: {
name: "Restrained",
description: "A restrained creatures speed becomes 0, and it cant benefit from any bonus to its speed.\n\nAttack rolls against the creature have advantage, and the creatures attack rolls have disadvantage.\n\nThe creature has disadvantage on Dexterity saving throws.",
},
effects: [
{
stat: "speed",
operation: "max",
value: 0,
},
{
stat: "dexteritySave",
operation: "disadvantage",
value: 1,
},
],
},
stunned: {
buff: {
name: "Stunned",
description: "A stunned creature is incapacitated, cant move, and can speak only falteringly\n\nThe creature automatically fails Strength and Dexterity saving throws.\n\nAttack rolls against the creature have advantage.",
},
effects: [
{
stat: "speed",
operation: "max",
value: 0,
},
{
stat: "strengthSave",
operation: "fail",
},
{
stat: "dexteritySave",
operation: "fail",
},
],
subConditions: ["incapacitated"],
},
unconscious: {
buff: {
name: "Unconscious",
description: "An unconscious creature is incapacitated, cant move or speak, and is unaware of its surroundings.\n\nThe creature drops whatever its holding and falls prone.\n\nThe creature automatically fails Strength and Dexterity saving throws.\n\nAttack rolls against the creature have advantage.\n\nAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
},
subConditions: ["incapacitated", "prone"],
},
exhaustion1: {
buff: {
name: "Exhaustion - 1",
description: "Disadvantage on ability checks\n\nFinishing a long rest reduces a creatures exhaustion level by 1, provided that the creature has also ingested some food and drink.",
},
effects: (function() {
return _.map(SKILLS, function(skill) {
return {stat: skill, operation: "disadvantage", value: 1};
});
})(),
},
exhaustion2: {
buff: {
name: "Exhaustion - 2",
description: "Speed halved",
},
effects: [
{
stat: "speed",
operation: "mul",
value: 0.5,
}
],
subConditions: ["exhaustion1"],
},
exhaustion3: {
buff: {
name: "Exhaustion - 3",
description: "Disadvantage on attack rolls and saving throws",
},
effects: (function() {
return _.map(SAVES, function(skill) {
return {stat: skill, operation: "disadvantage", value: 1};
});
})(),
subConditions: ["exhaustion2"],
},
exhaustion4: {
buff: {
name: "Exhaustion - 4",
description: "Hit point maximum halved",
},
effects: [
{
stat: "hitPoints",
operation: "mul",
value: 0.5,
}
],
subConditions: ["exhaustion3"],
},
exhaustion5: {
buff: {
name: "Exhaustion - 5",
description: "Speed reduced to 0",
},
effects: [
{
stat: "speed",
operation: "max",
value: 0,
}
],
subConditions: ["exhaustion4"],
},
exhaustion6: {
buff: {
name: "Exhaustion - 6",
description: "You have died of exhaustion",
},
effects: [
{
stat: "hitPoints",
operation: "max",
value: 0,
}
],
subConditions: ["exhaustion5"],
},
encumbered: {
buff: {
name: "Encumbered",
description: "Encumbered characters move 10 feet slower",
},
effects: [
{
stat: "speed",
operation: "add",
value: -10,
}
],
exclusiveConditions: [
"heavilyEncumbered",
"overEncumbered",
"cantLift",
],
},
heavilyEncumbered: {
buff: {
name: "Heavily encumbered",
description: "Heavily encumbered characters move 20 feet slower and have disadvantage on ability checks, attack rolls, and saving thows that use Strength, Dexterity, or Constitution",
},
effects: [
{stat: "speed", operation: "add", value: -20},
{stat: "strengthSave", operation: "disadvantage", value: 1},
{stat: "dexteritySave", operation: "disadvantage", value: 1},
{stat: "constitutionSave", operation: "disadvantage", value: 1},
{stat: "athletics", operation: "disadvantage", value: 1},
{stat: "acrobatics", operation: "disadvantage", value: 1},
{stat: "sleightOfHand", operation: "disadvantage", value: 1},
{stat: "stealth", operation: "disadvantage", value: 1},
{stat: "initiative", operation: "disadvantage", value: 1},
],
exclusiveConditions: [
"encumbered",
"overEncumbered",
"cantLift",
],
},
overEncumbered: {
buff: {
name: "Over encumbered",
description: "Characters that can only just lift, push or drag their current load can only move at 5 feet and have disadvantage on ability checks, attack rolls, and saving thows that use Strength, Dexterity, or Constitution",
},
effects: [
{stat: "speed", operation: "max", value: 5},
{stat: "strengthSave", operation: "disadvantage", value: 1},
{stat: "dexteritySave", operation: "disadvantage", value: 1},
{stat: "constitutionSave", operation: "disadvantage", value: 1},
{stat: "athletics", operation: "disadvantage", value: 1},
{stat: "acrobatics", operation: "disadvantage", value: 1},
{stat: "sleightOfHand", operation: "disadvantage", value: 1},
{stat: "stealth", operation: "disadvantage", value: 1},
{stat: "initiative", operation: "disadvantage", value: 1},
],
exclusiveConditions: [
"encumbered",
"heavilyEncumbered",
"cantLift",
],
},
cantLift: {
buff: {
name: "Can't move load",
description: "This character cannot lift, push, or drag more than {30 * strength} pounds. Characters attempting to carry more than what they can lift, push, or drag can't move and have disadvantage on ability checks, attack rolls, and saving thows that use Strength, Dexterity, or Constitution",
},
effects: [
{stat: "speed", operation: "max", value: 0},
{stat: "strengthSave", operation: "disadvantage", value: 1},
{stat: "dexteritySave", operation: "disadvantage", value: 1},
{stat: "constitutionSave", operation: "disadvantage", value: 1},
{stat: "athletics", operation: "disadvantage", value: 1},
{stat: "acrobatics", operation: "disadvantage", value: 1},
{stat: "sleightOfHand", operation: "disadvantage", value: 1},
{stat: "stealth", operation: "disadvantage", value: 1},
{stat: "initiative", operation: "disadvantage", value: 1},
],
exclusiveConditions: [
"encumbered",
"heavilyEncumbered",
"overEncumbered",
],
},
};

View File

@@ -15,6 +15,7 @@ Meteor.publish("singleCharacter", function(characterId){
//get all the assets for this character including soft deleted ones
Actions.find ({charId: characterId}, {removed: true}),
Attacks.find ({charId: characterId}, {removed: true}),
Buffs.find ({charId: characterId}, {removed: true}),
Classes.find ({charId: characterId}, {removed: true}),
Containers.find ({charId: characterId}, {removed: true}),
Effects.find ({charId: characterId}, {removed: true}),