Added spellcasting ability to spell lists

This commit is contained in:
Stefan Zermatten
2022-11-08 18:09:00 +02:00
parent 48291d2c8f
commit 03f87b0afa
8 changed files with 96 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import skill from './computeByType/computeSkill.js';
import pointBuy from './computeByType/computePointBuy.js';
import propertySlot from './computeByType/computeSlot.js';
import container from './computeByType/computeContainer.js';
import spellList from './computeByType/computeSpellList.js';
import _calculation from './computeByType/computeCalculation.js';
export default Object.freeze({
@@ -17,4 +18,5 @@ export default Object.freeze({
pointBuy,
propertySlot,
spell: action,
spellList,
});

View File

@@ -0,0 +1,6 @@
export default function computeSpelllist(computation, node) {
const prop = node.data;
const ability = computation.scope[prop.ability];
prop.abilityMod = ability?.modifier || 0;
}

View File

@@ -17,6 +17,12 @@ let SpellListSchema = createPropertySchema({
type: 'fieldToCompute',
optional: true,
},
// The variable name of the ability this spell relies on
ability: {
type: String,
optional: true,
max: STORAGE_LIMITS.variableName,
},
// Calculation of The attack roll bonus used by spell attacks in this list
attackRollBonus: {
type: 'fieldToCompute',
@@ -38,6 +44,12 @@ const ComputedOnlySpellListSchema = createPropertySchema({
type: 'computedOnlyField',
optional: true,
},
// Computed value determined by the ability
abilityMod: {
type: SimpleSchema.Integer,
optional: true,
removeBeforeCompute: true,
},
attackRollBonus: {
type: 'computedOnlyField',
optional: true,

View File

@@ -6,6 +6,12 @@
<div>
Spell Save DC: {{ model.dc && model.dc.value }}
</div>
<div v-if="model.ability">
Spell casting ability: {{ model.ability }}
</div>
<div v-if="model.ability">
Spell casting ability modifier: {{ model.abilityMod }}
</div>
<div>
Spell Attack Bonus: {{ model.attackRollBonus && model.attackRollBonus.value }}
</div>

View File

@@ -27,6 +27,15 @@
$emit('change', {path: ['maxPrepared', ...path], value, ack})"
/>
<smart-combobox
label="Spellcasting ability"
:value="model.ability"
hint="Which ability is used to cast spells in this spell list"
:items="abilityScoreList"
:error-messages="errors.ability"
@change="changeAbility"
/>
<computed-field
label="Spell save DC"
hint="The spell save DC of spells in this list"
@@ -67,9 +76,46 @@
<script lang="js">
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
import createListOfProperties from '/imports/ui/properties/forms/shared/lists/createListOfProperties.js';
export default {
mixins: [propertyFormMixin],
meteor: {
abilityScoreList() {
return createListOfProperties({
type: 'attribute',
attributeType: 'ability',
});
},
},
methods: {
changeAbility(value, ack) {
this.$emit('change', { path: ['ability'], value, ack })
const oldValue = this.model.ability;
const attackRollBonus = this.model.attackRollBonus?.calculation;
if (
!attackRollBonus ||
attackRollBonus === `proficiencyBonus + ${oldValue}.modifier`
) {
this.$emit('change', {
path: ['attackRollBonus', 'calculation'],
value: `proficiencyBonus + ${value}.modifier`
});
}
const dc = this.model.dc?.calculation;
if (
!dc ||
dc === `8 + proficiencyBonus + ${oldValue}.modifier`
) {
this.$emit('change', {
path: ['dc', 'calculation'],
value: `8 + proficiencyBonus + ${value}.modifier`
});
}
}
}
};
</script>

View File

@@ -13,6 +13,18 @@
center
:calculation="model.maxPrepared"
/>
<property-field
name="Spellcasting ability"
mono
:value="model.ability"
/>
<property-field
name="Spellcasting ability modifier"
large
center
signed
:value="model.abilityMod"
/>
<property-field
name="Spell Save DC"
large

View File

@@ -41,7 +41,7 @@
>
<slot>
<template v-if="value !== undefined">
{{ value }}
{{ valueText }}
</template>
<template v-else-if="calculation !== undefined">
{{ calculationText }}
@@ -117,6 +117,13 @@ export default {
if (!this.calculation) return;
return typeof this.calculation.value === 'string'
},
valueText() {
if (this.signed) {
return numberToSignedString(this.value);
} else {
return this.value;
}
},
calculationText(){
const calculation = this.calculation;
if (!calculation) {

View File

@@ -18,6 +18,10 @@ Allows [inline calculations](/docs/inline-calculations).
A [computed field](/docs/computed-fields) that determines how many spells can be considered ready to cast in this spell list.
### Spell casting ability
The spellcasting ablity for this spell list. The variable name of the ability can be accessed using `#spellList.ability` and the ability modifier with `#spellList.abilityMod`. Setting this field will automatically update Spell save DC and Attack roll bonus if they aren't set manually.
### Spell save DC
A [computed field](/docs/computed-fields) that determines the DC of saving throws in this spell list. Spells can access the DC of their spell list using `#spellList.dc`