Started work on checks
This commit is contained in:
40
app/imports/api/creature/actions/doCheck.js
Normal file
40
app/imports/api/creature/actions/doCheck.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import roll from '/imports/parser/roll.js';
|
||||
|
||||
const doAction = new ValidatedMethod({
|
||||
name: 'creature.doCheck',
|
||||
validate: new SimpleSchema({
|
||||
actionId: SimpleSchema.RegEx.Id,
|
||||
targetId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true,
|
||||
},
|
||||
}).validator(),
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 10,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run({creatureId, attributeName}) {
|
||||
let creature = Creatures.findOne(creatureId);
|
||||
assertEditPermission(creature, this.userId);
|
||||
return doCheckWork({attributeName, creature});
|
||||
},
|
||||
});
|
||||
|
||||
function doCheckWork({attributeName, creature}){
|
||||
let att = creature.variables[attributeName];
|
||||
if (!att) throw new Meteor.Error('No such attribute',
|
||||
`This creature does not have a ${attributeName} property`);
|
||||
let bonus = att.attributeType === 'ability'? att.modifier : att.value;
|
||||
//Always roll 2d20 and let the advantage be decided in UI
|
||||
let rolls = roll(2,20);
|
||||
return {rolls, bonus};
|
||||
}
|
||||
|
||||
export default doAction;
|
||||
@@ -1,6 +1,7 @@
|
||||
import ParseNode from '/imports/parser/parseTree/ParseNode.js';
|
||||
import RollArrayNode from '/imports/parser/parseTree/RollArrayNode.js';
|
||||
import ErrorNode from '/imports/parser/parseTree/ErrorNode.js';
|
||||
import roll from '/imports/parser/roll.js';
|
||||
|
||||
export default class RollNode extends ParseNode {
|
||||
constructor({left, right}) {
|
||||
@@ -49,12 +50,7 @@ export default class RollNode extends ParseNode {
|
||||
context,
|
||||
});
|
||||
let diceSize = right.value;
|
||||
let randomSrc = DDP.randomStream('diceRoller');
|
||||
let values = [];
|
||||
for (let i = 0; i < number; i++){
|
||||
let roll = ~~(randomSrc.fraction() * diceSize) + 1
|
||||
values.push(roll);
|
||||
}
|
||||
let values = roll(number, diceSize);
|
||||
if (context){
|
||||
context.storeRoll({number, diceSize, values});
|
||||
}
|
||||
|
||||
9
app/imports/parser/roll.js
Normal file
9
app/imports/parser/roll.js
Normal file
@@ -0,0 +1,9 @@
|
||||
export default function roll(number, diceSize){
|
||||
let values = [];
|
||||
let randomSrc = DDP.randomStream('diceRoller');
|
||||
for (let i = 0; i < number; i++){
|
||||
let roll = ~~(randomSrc.fraction() * diceSize) + 1
|
||||
values.push(roll);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
9
app/imports/ui/components/rolls/check.vue
Normal file
9
app/imports/ui/components/rolls/check.vue
Normal file
@@ -0,0 +1,9 @@
|
||||
<template lang="html" />
|
||||
|
||||
<script>
|
||||
export default {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css" scoped>
|
||||
</style>
|
||||
1
dataSources/.gitignore
vendored
Normal file
1
dataSources/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Renders
|
||||
Reference in New Issue
Block a user