//use selected caregiver, or possessed
const caregiver = token.actor ?? character;
//find my possessed character's companion
const defaultCompId = caregiver?.getFlag('mcdm-beastheart','ferolink')
if(!defaultCompId){
ui.notifications.error('Selected or assigned character is not a linked Caregiver')
return;
}
const companion = game.actors.get(defaultCompId);
//Perform needed updates
// 1) Class level adjustment
const careLevel = caregiver.items.find( item => item.system.identifier == 'beastheart')?.system.levels;
if(!careLevel) {
ui.notifications.error('Selected Caregiver does not have a Beastheart class item. Stopping updates.');
return;
}
const compClassItem = companion.items.find( item => item.system.identifier == 'moncom');
//Update the class item immediately in order to use the proper proficiency bonus later on
await compClassItem.update({'system.levels': careLevel});
// 2) Max HP Adjustment. Class item contains `@scale.moncom.hpbase` as the scalor
const base = Number(companion.getRollData().scale.moncom.hpbase);
if(isNaN(base)) {
ui.notifications.error('Could not derive HP scaling from "@scale.moncom.hpbase". Ensure this scale value is present and configured. Stopping updates.');
return;
}
const newMax = base + base * careLevel;
// 3) Spell DC Adjustment. At level 1 is 10+prof, at level 2+ its caregivers DC.
// All companions should be using Strength as default Spellcasting stat
const caregiverDC = caregiver.system.attributes.spelldc;
//get current spellcasting stat
const spellstat = companion.system.attributes.spellcasting;
if (spellstat.length !== 3) {
ui.notifications.warn('Companion does not have a defined spellcasting ability. Please select one in order to properly scale any saving throw DCs.')
}
const companionBaseDC = (companion.system.abilities[spellstat]?.mod ?? 0) + companion.system.attributes.prof + 8;
const dcModification = careLevel > 1 ? caregiverDC - companionBaseDC : companion.system.attributes.prof + 10 - companionBaseDC;
await companion.update({'system.attributes.hp.max': newMax, 'system.bonuses.spell.dc': `+ ${dcModification}`})
Template macro: