Experimenting with webhooks.

This commit is contained in:
Stefan Zermatten
2020-07-13 16:38:24 +02:00
parent 308168791b
commit 47345b3694
8 changed files with 152 additions and 14 deletions

View 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`,
});
}

View File

@@ -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': ''}`,
});
}

View File

@@ -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':