moves roll mechanic into global file
parent
2ee6ed775b
commit
50c28cb380
|
|
@ -1,4 +1,5 @@
|
||||||
import BaseItem from "./baseItem.mjs";
|
import BaseItem from "./baseItem.mjs";
|
||||||
|
import {evaluateRoll} from "../globals/DSARoll.mjs";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
DocumentIdField,
|
DocumentIdField,
|
||||||
|
|
@ -130,7 +131,7 @@ export class SkillDataModel extends BaseItem {
|
||||||
|
|
||||||
let evaluated1 = (await roll1.evaluate())
|
let evaluated1 = (await roll1.evaluate())
|
||||||
|
|
||||||
const dsaDieRollEvaluated = this._evaluateRoll(evaluated1.terms[0].results, {
|
const dsaDieRollEvaluated = evaluateRoll(evaluated1.terms[0].results, {
|
||||||
taw: this.taw,
|
taw: this.taw,
|
||||||
werte: [this.probe[0], this.probe[1], this.probe[2]],
|
werte: [this.probe[0], this.probe[1], this.probe[2]],
|
||||||
})
|
})
|
||||||
|
|
@ -150,37 +151,4 @@ export class SkillDataModel extends BaseItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_evaluateRoll(rolledDice, {
|
|
||||||
taw,
|
|
||||||
lowerThreshold = 1,
|
|
||||||
upperThreshold = 20,
|
|
||||||
countToMeisterlich = 3,
|
|
||||||
countToPatzer = 3,
|
|
||||||
werte = []
|
|
||||||
}) {
|
|
||||||
let tap = taw;
|
|
||||||
let meisterlichCounter = 0;
|
|
||||||
let patzerCounter = 0;
|
|
||||||
let failCounter = 0;
|
|
||||||
|
|
||||||
rolledDice.forEach((rolledDie, index) => {
|
|
||||||
if (tap < 0 && rolledDie.result > werte[index]) {
|
|
||||||
tap -= rolledDie.result - werte[index];
|
|
||||||
if (tap < 0) { // konnte nicht vollständig ausgeglichen werden
|
|
||||||
failCounter++;
|
|
||||||
}
|
|
||||||
} else if (rolledDie.result > werte[index]) { // taw ist bereits aufgebraucht und wert kann nicht ausgeglichen werden
|
|
||||||
tap -= rolledDie.result - werte[index];
|
|
||||||
failCounter++;
|
|
||||||
}
|
|
||||||
if (rolledDie.result <= lowerThreshold) meisterlichCounter++;
|
|
||||||
if (rolledDie.result > upperThreshold) patzerCounter++;
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
tap,
|
|
||||||
meisterlich: meisterlichCounter === countToMeisterlich,
|
|
||||||
patzer: patzerCounter === countToPatzer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {[{result: Number}]|String} rolledDice either the result of a roll or a roll-formula
|
||||||
|
* @param {Number} value the value of this dice roll
|
||||||
|
* @param {[number]} werte an array of values that the dice roll is compared against
|
||||||
|
* @param {{getRollData:() => {} }} owner the actor of this roll that is required when rolledDice is a roll-formula
|
||||||
|
* @param {Number} lowerThreshold this is the threshold against a critical success is counted against
|
||||||
|
* @param {Number} upperThreshold this is the threshold against a critical fumble is counted against
|
||||||
|
* @param {Number} countToMeisterlich amount of critical success are needed for the dice roll to be a critical success
|
||||||
|
* @param {Number} countToPatzer amount of critical fumbles are needed for the dice roll to be a critical failure
|
||||||
|
* @returns {{tap: number, meisterlich: boolean, patzer: boolean, evaluated: Roll.Evaluated}}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const evaluateRoll = async (rolledDice, {
|
||||||
|
value,
|
||||||
|
werte = [],
|
||||||
|
owner,
|
||||||
|
lowerThreshold = 1,
|
||||||
|
upperThreshold = 20,
|
||||||
|
countToMeisterlich = 3,
|
||||||
|
countToPatzer = 3,
|
||||||
|
}) => {
|
||||||
|
let tap = value;
|
||||||
|
let meisterlichCounter = 0;
|
||||||
|
let patzerCounter = 0;
|
||||||
|
let failCounter = 0;
|
||||||
|
let evaluated = null
|
||||||
|
|
||||||
|
if (typeof rolledDice == "string") { // we need to roll it ourself
|
||||||
|
let roll1 = new Roll(rolledDice, owner.getRollData());
|
||||||
|
evaluated = await roll1.evaluate()
|
||||||
|
rolledDice = evaluated.terms[0].results
|
||||||
|
} else {
|
||||||
|
evaluated = rolledDice
|
||||||
|
}
|
||||||
|
|
||||||
|
rolledDice.forEach((rolledDie, index) => {
|
||||||
|
if (tap < 0 && rolledDie.result > werte[index]) {
|
||||||
|
tap -= rolledDie.result - werte[index];
|
||||||
|
if (tap < 0) { // konnte nicht vollständig ausgeglichen werden
|
||||||
|
failCounter++;
|
||||||
|
}
|
||||||
|
} else if (rolledDie.result > werte[index]) { // taw ist bereits aufgebraucht und wert kann nicht ausgeglichen werden
|
||||||
|
tap -= rolledDie.result - werte[index];
|
||||||
|
failCounter++;
|
||||||
|
}
|
||||||
|
if (rolledDie.result <= lowerThreshold) meisterlichCounter++;
|
||||||
|
if (rolledDie.result > upperThreshold) patzerCounter++;
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
tap,
|
||||||
|
meisterlich: meisterlichCounter === countToMeisterlich,
|
||||||
|
patzer: patzerCounter === countToPatzer,
|
||||||
|
evaluated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
evaluateRoll
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue