diff --git a/app/imports/api/creature/actions/doCheck.js b/app/imports/api/creature/actions/doCheck.js index f4f2182c..76e421a3 100644 --- a/app/imports/api/creature/actions/doCheck.js +++ b/app/imports/api/creature/actions/doCheck.js @@ -5,15 +5,18 @@ 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({ +const doCheck = new ValidatedMethod({ name: 'creature.doCheck', validate: new SimpleSchema({ - actionId: SimpleSchema.RegEx.Id, - targetId: { + creatureId: { type: String, regEx: SimpleSchema.RegEx.Id, optional: true, }, + attributeName: { + type: String, + optional: true, + }, }).validator(), mixins: [RateLimiterMixin], rateLimit: { @@ -23,18 +26,31 @@ const doAction = new ValidatedMethod({ run({creatureId, attributeName}) { let creature = Creatures.findOne(creatureId); assertEditPermission(creature, this.userId); - return doCheckWork({attributeName, creature}); + let bonus = getAttributeValue({creature, attributeName}) + return doCheckWork({bonus}); }, }); -function doCheckWork({attributeName, creature}){ +function getAttributeValue({creature, attributeName}){ 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}; + return bonus || 0; } -export default doAction; +export function doCheckWork({bonus, advantage = 0}){ + let rolls = roll(2,20); + let chosenRoll; + if (advantage === 1){ + chosenRoll = Math.max.apply(rolls); + } else if (advantage === -1){ + chosenRoll = Math.min.apply(rolls); + } else { + chosenRoll = rolls[0]; + } + let result = chosenRoll + bonus; + return {rolls, bonus, chosenRoll, result}; +} + +export default doCheck; diff --git a/app/imports/ui/components/rolls/Check.vue b/app/imports/ui/components/rolls/Check.vue new file mode 100644 index 00000000..c130fd06 --- /dev/null +++ b/app/imports/ui/components/rolls/Check.vue @@ -0,0 +1,100 @@ + + + + + diff --git a/app/imports/ui/components/rolls/check.vue b/app/imports/ui/components/rolls/check.vue index 3abdba55..c130fd06 100644 --- a/app/imports/ui/components/rolls/check.vue +++ b/app/imports/ui/components/rolls/check.vue @@ -1,9 +1,100 @@ -