Skip to content

Commit

Permalink
Refactor spell heightening to collaborators.
Browse files Browse the repository at this point in the history
Should make it easier to implement heightening in a testable way.
  • Loading branch information
Mendonn authored and shaun-newsome committed Apr 27, 2020
1 parent 6095d14 commit 1ebe1e2
Show file tree
Hide file tree
Showing 13 changed files with 785 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ module.exports = {
"global-require": "off"
}
}
]
],
parser: "babel-eslint",
};
142 changes: 130 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@babel/preset-env": "^7.9.5",
"archiver": "^3.1.1",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-plugin-transform-default-import": "^1.0.0",
"chalk": "^3.0.0",
"eslint": "^6.8.0",
Expand Down
23 changes: 6 additions & 17 deletions src/module/item/item.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Override and extend the basic :class:`Item` implementation
*/
import Spell from './spell.js';

export default class extends Item {
/**
* Roll the item to Chat, creating a chat card which contains follow up attack or damage roll options
Expand Down Expand Up @@ -751,36 +753,23 @@ export default class extends Item {

// Get data
const itemData = this.data.data;
const spellcastingEntry = this.actor.getOwnedItem(itemData.location.value);
const rollData = duplicate(this.actor.data.data);
const abl = spellcastingEntry.data.data.ability.value || 'int';
const parts = [itemData.damage.value];
const isHeal = itemData.spellType.value === 'heal';
const dtype = CONFIG.PF2E.damageTypes[itemData.damageType.value];

const spellLvl = parseInt(cardData.spellLvl);
const spell = new Spell(this.data, { castingActor: this.actor, castLevel: spellLvl })
const parts = spell.damageParts;

// Append damage type to title
const damageLabel = isHeal ? localize('PF2E.SpellTypeHeal') : localize('PF2E.DamageLabel');
let title = this.name + ' - ' + damageLabel;
if (dtype && !isHeal) title += ` (${dtype})`;

// Add item to roll data
rollData.mod = rollData.abilities[abl].mod;
rollData.mod = rollData.abilities[spell.spellcastingEntry.ability].mod;
rollData.item = itemData;

if (itemData.damage.applyMod) parts.push(rollData.abilities[abl].mod);
const scaling = itemData.scaling || {};
if (scaling.mode === 'level1' && scaling.formula !== '') {
// Scale cantrips & focus spells automatically.
if (itemData.level.value === 0 || itemData.level.value === 11) {
const scaling_parts = Array(Math.ceil(this.actor.data.data.details.level.value / 2) - 1).fill(scaling.formula);
parts.push(...scaling_parts);
} else if (itemData.level.value < spellLvl) {
const scaling_parts = Array(spellLvl - itemData.level.value).fill(scaling.formula);
parts.push(...scaling_parts);
}
}

// Call the roll helper utility
DicePF2e.damageRoll({
event,
Expand Down
Loading

0 comments on commit 1ebe1e2

Please sign in to comment.