Experimenting with webhooks.
This commit is contained in:
21
app/imports/api/creature/actions/applyAttack.js
Normal file
21
app/imports/api/creature/actions/applyAttack.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import math from '/imports/math.js';
|
||||
if (Meteor.isServer){
|
||||
var sendWebhook = require('/imports/server/discord/webhook.js').default;
|
||||
}
|
||||
|
||||
export default function applyAttack({
|
||||
prop,
|
||||
//children,
|
||||
creature,
|
||||
//targets,
|
||||
//actionContext
|
||||
}){
|
||||
let result = math.roll(1, 20) + prop.rollBonusResult;
|
||||
if (Meteor.isClient){
|
||||
console.log(`${creature.name} makes a ${prop.name} attack! Rolls ${result} to hit`);
|
||||
}
|
||||
if (Meteor.isServer) sendWebhook({
|
||||
webhook: creature.webhook,
|
||||
message: `${creature.name} makes a ${prop.name} attack! Rolls ${result} to hit`,
|
||||
});
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
import evaluateAndRollString from '/imports/api/creature/computation/afterComputation/evaluateAndRollString.js';
|
||||
|
||||
if (Meteor.isServer){
|
||||
var sendWebhook = require('/imports/server/discord/webhook.js').default;
|
||||
}
|
||||
|
||||
export default function applyDamage({
|
||||
prop,
|
||||
creature,
|
||||
targets,
|
||||
//targets,
|
||||
actionContext
|
||||
}){
|
||||
let damageTargets = prop.target === 'self' ? [creature] : targets;
|
||||
//let damageTargets = prop.target === 'self' ? [creature] : targets;
|
||||
let scope = {
|
||||
...creature.variables,
|
||||
...actionContext,
|
||||
@@ -14,6 +18,10 @@ export default function applyDamage({
|
||||
let {result, errors} = evaluateAndRollString(prop.amount, scope);
|
||||
if (Meteor.isClient){
|
||||
errors.forEach(e => console.error(e));
|
||||
console.log(result);
|
||||
console.log(`${result} ${prop.damageType}${prop.damageType !== 'healing'? ' damage': ''}`);
|
||||
}
|
||||
if (Meteor.isServer) sendWebhook({
|
||||
webhook: creature.webhook,
|
||||
message: `${result} ${prop.damageType}${prop.damageType !== 'healing'? ' damage': ''}`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import applyAction from '/imports/api/creature/actions/applyAction.js';
|
||||
import applyAttack from '/imports/api/creature/actions/applyAttack.js';
|
||||
import applyDamage from '/imports/api/creature/actions/applyDamage.js';
|
||||
import applyBuff from '/imports/api/creature/actions/applyBuff.js';
|
||||
|
||||
@@ -15,7 +16,10 @@ function applyProperty(options){
|
||||
switch (prop.type){
|
||||
case 'action':
|
||||
case 'spell':
|
||||
applyAction(options);
|
||||
return true;
|
||||
case 'attack':
|
||||
applyAttack(options);
|
||||
applyAction(options);
|
||||
return true;
|
||||
case 'damage':
|
||||
|
||||
@@ -205,7 +205,7 @@ export function getName(doc){
|
||||
}
|
||||
|
||||
export function nodeArrayToTree(nodes){
|
||||
// Store a dict of all the nodes
|
||||
// Store a dict and list of all the nodes
|
||||
let nodeIndex = {};
|
||||
let nodeList = [];
|
||||
nodes.forEach( node => {
|
||||
@@ -233,13 +233,11 @@ export function nodeArrayToTree(nodes){
|
||||
return forest;
|
||||
}
|
||||
|
||||
export function nodesToTree({collection, ancestorId, filter, options}){
|
||||
if (!options) options = {};
|
||||
options.sort = {order: 1};
|
||||
let nodes = collection.find({
|
||||
'ancestors.id': ancestorId,
|
||||
removed: {$ne: true},
|
||||
...filter,
|
||||
}, options);
|
||||
export function nodesToTree({collection, ancestorId, filter = {}, options = {}}){
|
||||
if (!('ancestors.id' in filter)) filter['ancestors.id'] = ancestorId;
|
||||
if (!('removed' in filter)) filter['removed'] = {$ne: true};
|
||||
if (!options.sort) options.sort = {order: 1};
|
||||
if (!('order' in options.sort)) options.sort.order = 1;
|
||||
let nodes = collection.find(filter, options);
|
||||
return nodeArrayToTree(nodes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user