Attributes of type spell slot now store their slot level

This commit is contained in:
Stefan Zermatten
2020-06-23 01:36:21 +02:00
parent c44aeac198
commit e572807082
3 changed files with 33 additions and 2 deletions

View File

@@ -1,9 +1,10 @@
import computeStat from '/imports/api/creature/computation/computeStat.js';
import applyToggles from '/imports/api/creature/computation/applyToggles.js';
import evaluateCalculation from '/imports/api/creature/computation/evaluateCalculation.js';
export default function combineStat(stat, aggregator, memo){
if (stat.type === 'attribute'){
combineAttribute(stat, aggregator);
combineAttribute(stat, aggregator, memo);
} else if (stat.type === 'skill'){
combineSkill(stat, aggregator, memo);
} else if (stat.type === 'damageMultiplier'){
@@ -28,13 +29,18 @@ function getAggregatorResult(stat, aggregator){
return result;
}
function combineAttribute(stat, aggregator){
function combineAttribute(stat, aggregator, memo){
stat.value = getAggregatorResult(stat, aggregator);
stat.baseValue = aggregator.statBaseValue;
stat.baseValueErrors = aggregator.baseValueErrors;
if (stat.attributeType === 'ability') {
stat.modifier = Math.floor((stat.value - 10) / 2);
}
if (stat.attributeType === 'spellSlot'){
let {value, errors} = evaluateCalculation(stat.spellSlotLevelCalculation, memo);
stat.spellSlotLevelValue = value,
stat.spellSlotLevelErrors = errors;
}
stat.currentValue = stat.value - (stat.damage || 0);
stat.hide = aggregator.hasNoEffects &&
stat.baseValue === undefined ||

View File

@@ -39,6 +39,11 @@ let AttributeSchema = new SimpleSchema({
type: String,
allowedValues: ['d4', 'd6', 'd8', 'd10', 'd12', 'd20'],
optional: true,
},
// For type spellSlot, the level needs to be stored separately
spellSlotLevelCalculation: {
type: String,
optional: true,
},
// The starting value, before effects
baseValueCalculation: {
@@ -81,6 +86,18 @@ let ComputedOnlyAttributeSchema = new SimpleSchema({
},
'baseValueErrors.$': {
type: ErrorSchema,
},
// The result of spellSlotLevelCalculation
spellSlotLevelValue: {
type: SimpleSchema.oneOf(Number, String, Boolean),
optional: true,
},
spellSlotLevelErrors: {
type: Array,
optional: true,
},
'spellSlotLevelErrors.$': {
type: ErrorSchema,
},
// The computed value of the attribute
value: {

View File

@@ -47,6 +47,14 @@
:menu-props="{auto: true, lazy: true}"
@change="change('hitDiceSize', ...arguments)"
/>
<text-field
v-if="model.attributeType === 'spellSlot'"
label="Spell slot level"
:value="model.spellSlotLevelCalculation"
:error-messages="errors.spellSlotLevelCalculation"
@change="change('spellSlotLevelCalculation', ...arguments)"
/>
<calculation-error-list :errors="model.spellSlotLevelErrors" />
<text-area
label="Description"
:value="model.description"