refactor: improve structure of src
This commit is contained in:
parent
b74919b75b
commit
c5d4ec1abd
96 changed files with 146 additions and 157 deletions
65
src/documents/item/spell/spell.ts
Normal file
65
src/documents/item/spell/spell.ts
Normal file
|
@ -0,0 +1,65 @@
|
|||
// SPDX-FileCopyrightText: 2022 Johannes Loher
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { createCheckRoll } from "../../../dice/check-factory";
|
||||
import { notifications } from "../../../ui/notifications";
|
||||
import { getGame } from "../../../utils/utils";
|
||||
import { DS4Item } from "../item";
|
||||
import { calculateSpellPrice } from "./calculate-spell-price";
|
||||
|
||||
export class DS4Spell extends DS4Item {
|
||||
override prepareDerivedData(): void {
|
||||
this.data.data.rollable = this.data.data.equipped;
|
||||
this.data.data.price = calculateSpellPrice(this.data.data);
|
||||
}
|
||||
|
||||
override async roll(options: { speaker?: { token?: TokenDocument; alias?: string } } = {}): Promise<void> {
|
||||
const game = getGame();
|
||||
|
||||
if (!this.data.data.equipped) {
|
||||
return notifications.warn(
|
||||
game.i18n.format("DS4.WarningItemMustBeEquippedToBeRolled", {
|
||||
name: this.name,
|
||||
id: this.id,
|
||||
type: this.data.type,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.actor) {
|
||||
throw new Error(game.i18n.format("DS4.ErrorCannotRollUnownedItem", { name: this.name, id: this.id }));
|
||||
}
|
||||
|
||||
const ownerDataData = this.actor.data.data;
|
||||
const hasComplexModifier = this.data.data.spellModifier.complex !== "";
|
||||
if (hasComplexModifier === undefined) {
|
||||
notifications.info(
|
||||
game.i18n.format("DS4.InfoManuallyEnterSpellModifier", {
|
||||
name: this.name,
|
||||
spellModifier: this.data.data.spellModifier.complex,
|
||||
}),
|
||||
);
|
||||
}
|
||||
const spellType = this.data.data.spellType;
|
||||
const checkTargetNumber =
|
||||
ownerDataData.combatValues[spellType].total +
|
||||
(hasComplexModifier ? 0 : this.data.data.spellModifier.numerical);
|
||||
|
||||
const speaker = ChatMessage.getSpeaker({ actor: this.actor, ...options.speaker });
|
||||
await createCheckRoll(checkTargetNumber, {
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
|
||||
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
|
||||
flavor: "DS4.ItemSpellCheckFlavor",
|
||||
flavorData: { actor: speaker.alias ?? this.actor.name, spell: this.name },
|
||||
speaker,
|
||||
});
|
||||
|
||||
Hooks.callAll("ds4.rollItem", this);
|
||||
}
|
||||
}
|
||||
|
||||
export interface DS4Spell {
|
||||
data: foundry.data.ItemData & { type: "spell"; _source: { type: "spell" } };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue