Skip to content

Commit

Permalink
Spells as activities
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPrimate committed Nov 12, 2024
1 parent a3e157c commit ca11337
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Psionic Power Parsing Failures fixed.
- Monsters attack parsing went _weird_. Monsters imported after 6.0.32 probably need reimporting.
- Improvements to Unarmed Strike Parsing.
- If you have munched spells, spells on items will be added as cast activities (characters only for now).

# 6.0.34

Expand Down
1 change: 1 addition & 0 deletions src/parser/enrichers/DDBItemEnricher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class DDBItemEnricher extends DDBEnricherAbstract {
"Belashyrra's Beholder Crown": () => ItemEnrichers.BelashyrrasBeholderCrown,
"Dust of Sneezing and Choking": () => ItemEnrichers.DustOfSneezingAndChoking,
"Moon Sickle": () => ItemEnrichers.MoonSickle,
"Circlet of Blasting": () => ItemEnrichers.CircletOfBlasting,
};

}
20 changes: 20 additions & 0 deletions src/parser/enrichers/item/CircletOfBlasting.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable class-methods-use-this */
import DDBEnricherMixin from "../mixins/DDBEnricherMixin.mjs";

export default class CircletOfBlasting extends DDBEnricherMixin {

customFunction({ name, activity }) {
if (name === "Scorching Ray") {
activity.data = foundry.utils.mergeObject(activity.data, {
spell: {
challenge: {
attack: "5",
override: true,
},
},
});
}
return activity;
}

}
1 change: 1 addition & 0 deletions src/parser/enrichers/item/_module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ export { default as WandOfFireballs } from "./WandOfFireballs.mjs";
export { default as WandOfMagicMissiles } from "./WandOfMagicMissiles.mjs";
export { default as WarriorsPasskey } from "./WarriorsPasskey.mjs";
export { default as Waterskin } from "./Waterskin.mjs";
export { default as CircletOfBlasting } from "./CircletOfBlasting.mjs";
6 changes: 6 additions & 0 deletions src/parser/enrichers/mixins/DDBBasicActivity.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ export default class DDBBasicActivity {
};
}

_generateCast({ castOverride = null } = {}) {
if (castOverride) {
this.data.spell = castOverride;
};
}

_generateDamage({ includeBase = false, damageParts = null, onSave = null, scalingOverride = null, criticalDamage = null } = {}) {
if (damageParts) {
this.data.damage = {
Expand Down
4 changes: 4 additions & 0 deletions src/parser/enrichers/mixins/DDBEnricherAbstract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,8 @@ export default class DDBEnricherAbstract {
return uses;
}

customFunction(options = {}) {
return this.loadedEnricher?.customFunction(options);
}

}
6 changes: 6 additions & 0 deletions src/parser/enrichers/mixins/DDBEnricherMixin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,10 @@ export default class DDBEnricherMixin {
return false;
}


// eslint-disable-next-line no-unused-vars, no-empty-function
customFunction(options = {}) {

}

}
46 changes: 31 additions & 15 deletions src/parser/item/DDBItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class DDBItem extends mixins.DDBActivityFactoryMixin {

static async prepareSpellCompendiumIndex() {
await CompendiumHelper.loadCompendiumIndex("spells", {
fields: ["name", "flags.ddbimporter.id", "flags.ddbimporter.isLegacy"],
fields: ["name", "flags.ddbimporter.id", "flags.ddbimporter.definitionId", "flags.ddbimporter.isLegacy"],
});
}

Expand Down Expand Up @@ -2198,15 +2198,14 @@ export default class DDBItem extends mixins.DDBActivityFactoryMixin {
}

#addSpellAsCastActivity(spell) {
logger.warn(`Spell`, {
this: this,
spell,
});
logger.debug(`Adding spell ${spell.name} to item as spell link ${this.data.name}`);
const spellData = MagicItemMaker.buildMagicItemSpell(this.magicChargeType, spell);

const compendiumSpell = this.spellCompendium?.index.find((s) => s.flags.ddbimporter?.id === spellData.flags?.ddbimporter?.id);
const compendiumSpell = this.spellCompendium?.index.find((s) =>
s.flags.ddbimporter?.definitionId === spell.flags?.ddbimporter?.definitionId,
);

foundry.utils.setProperty(spell, "flags.ddbimporter.removeSpell", false);
if (!compendiumSpell) return false;

const castData = {
Expand Down Expand Up @@ -2269,11 +2268,9 @@ export default class DDBItem extends mixins.DDBActivityFactoryMixin {
}
: null;

if (foundry.utils.hasProperty(spell, "flags.ddbimporter.dndbeyond.overrideDC")
&& foundry.utils.hasProperty(spell, "flags.ddbimporter.dndbeyond.dc")
) {
castData.challenge.save = foundry.utils.getProperty(spell, "flags.ddbimporter.dndbeyond.dc") ?? null;
if (castData.challenge.save) {
castData.challenge.override = true;
castData.challenge.dc = foundry.utils.getProperty(spell, "flags.ddbimporter.dndbeyond.dc");
}

if (foundry.utils.hasProperty(spell, "flags.ddbimporter.dndbeyond.castAtLevel")) {
Expand All @@ -2293,16 +2290,32 @@ export default class DDBItem extends mixins.DDBActivityFactoryMixin {
consumptionOverride.scaling.max = scalingValue;
}

const activity = this._getCastActivity({ name: spell.name }, {
const options = {
castOverride: castData,
generateUses,
usesOverride,
consumptionOverride,
};

const activity = this._getCastActivity({ name: spell.name }, options);

this.enricher.customFunction({
name: spellData.name,
activity: activity,
});

// console.warn(`Spell ACtivity`, {
// activity,
// castData,
// options,
// spell,
// spellData,
// });

this.activities.push(activity);
foundry.utils.setProperty(this.data, `system.activities.${activity.data._id}`, activity.data);

foundry.utils.setProperty(spell, "flags.ddbimporter.removeSpell", true);
return true;

}
Expand Down Expand Up @@ -2527,18 +2540,21 @@ export default class DDBItem extends mixins.DDBActivityFactoryMixin {
}

if (!this.raw.itemSpells) return;
const failedSpells = [];
for (const spell of this.raw.itemSpells) {
const isItemSpell = spell.flags.ddbimporter.dndbeyond.lookup === "item"
&& spell.flags.ddbimporter.dndbeyond.lookupId === this.ddbDefinition.id;
if (isItemSpell) {
logger.debug(`Adding spell ${spell.name} to item ${this.data.name}`);
const success = this.#addSpellAsCastActivity(spell);
if (!success) failedSpells.push(spell);
this.#addSpellAsCastActivity(spell);
}
}

this.raw.itemSpells = failedSpells;
this.raw.itemSpells = this.raw.itemSpells.filter((spell) => {
const matchedSpell = foundry.utils.getProperty(spell, "flags.ddbimporter.removeSpell")
&& spell.flags.ddbimporter.dndbeyond.lookup === "item"
&& spell.flags.ddbimporter.dndbeyond.lookupId === this.ddbDefinition.id;
return !matchedSpell;
});

for (const spell of this.raw.itemSpells) {
const isItemSpell = spell.flags.ddbimporter.dndbeyond.lookup === "item"
Expand Down
2 changes: 1 addition & 1 deletion src/parser/item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ DDBCharacter.prototype.getInventory = async function getInventory(notifier = nul
if (item.effects.length > 0 && item.system.activities) {
for (const activityId of Object.keys(item.system.activities)) {
const activity = item.system.activities[activityId];
if (activity.effects.length !== 0) continue;
if (activity.effects?.length !== 0) continue;
if (foundry.utils.getProperty(activity, "flags.ddbimporter.noeffect")) continue;
for (const effect of item.effects) {
if (effect.transfer) continue;
Expand Down

0 comments on commit ca11337

Please sign in to comment.