Started work on character log for rolls to be stored

This commit is contained in:
Stefan Zermatten
2020-09-29 22:34:30 +02:00
parent 75ab43da00
commit a6a96fc19f
12 changed files with 190 additions and 45 deletions

View File

@@ -40,7 +40,12 @@ let CreatureSettingsSchema = new SimpleSchema({
optional: true,
min: 0,
max: 1,
}
},
discordWebhook: {
type: String,
optional: true,
max: 200,
},
});
let CreatureSchema = new SimpleSchema({

View File

@@ -1,5 +1,10 @@
import spendResources from '/imports/api/creature/actions/spendResources.js'
import {insertCreatureLog} from '/imports/api/creature/log/CreatureLogs.js';
export default function applyAction({prop}){
export default function applyAction({prop, creature}){
spendResources(prop);
insertCreatureLog({
log: prop.name,
creature,
});
}

View File

@@ -1,7 +1,5 @@
import math from '/imports/math.js';
//if (Meteor.isServer){
// var sendWebhook = require('/imports/server/discord/webhook.js').default;
//}
import {insertCreatureLog} from '/imports/api/creature/log/CreatureLogs.js';
export default function applyAttack({
prop,
@@ -11,11 +9,8 @@ export default function applyAttack({
//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`,
//});
insertCreatureLog({
log: `${prop.name} attack. ${result} to hit`,
creature,
});
}

View File

@@ -19,8 +19,8 @@ function applyProperty(options){
applyAction(options);
return true;
case 'attack':
applyAttack(options);
applyAction(options);
applyAttack(options);
return true;
case 'damage':
applyDamage(options);

View File

@@ -0,0 +1,54 @@
import SimpleSchema from 'simpl-schema';
if (Meteor.isServer){
var sendWebhookAsCreature = require('/imports/server/discord/sendWebhook.js').sendWebhookAsCreature;
}
let CreatureLogs = new Mongo.Collection('creatureLogs');
let CreatureLogSchema = new SimpleSchema({
text: {
type: String,
},
type: {
type: String,
allowedValues: ['roll', 'change', 'damage', 'info'],
defaultValue: 'info',
},
// The real-world date that it occured, usually sorted by date
date: {
type: Date,
autoValue: function() {
// If the date isn't set, set it to now
if (!this.isSet) {
return new Date();
}
},
index: 1,
},
creatureId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
index: 1,
},
});
CreatureLogs.attachSchema(CreatureLogSchema);
// This function should only be called by trusted code. No permission checks
const insertCreatureLog = function({log, creature}){
if (typeof log === 'string'){
log = {text: log};
}
log.creatureId = creature._id;
let id = CreatureLogs.insert(log);
if (Meteor.isServer){
sendWebhookAsCreature({
creature,
content: log.text,
});
}
return id;
};
export default CreatureLogs;
export { CreatureLogSchema, insertCreatureLog};