Initial release for FoundryVTT
This commit is contained in:
45
modules/donjon-et-cie-item.mjs
Normal file
45
modules/donjon-et-cie-item.mjs
Normal file
@@ -0,0 +1,45 @@
|
||||
import { DonjonEtCieRollDialog } from "./applications/donjon-et-cie-roll-dialog.mjs";
|
||||
import { DonjonEtCieUtility } from "./donjon-et-cie-utility.mjs";
|
||||
|
||||
export class DonjonEtCieItem extends Item {
|
||||
async _preCreate(data, options, user) {
|
||||
await super._preCreate(data, options, user);
|
||||
|
||||
const currentImg = data.img ?? this.img;
|
||||
if (currentImg && !currentImg.startsWith("icons/svg/")) return;
|
||||
|
||||
this.updateSource({ img: DonjonEtCieUtility.getDefaultItemIcon(this.type) });
|
||||
}
|
||||
|
||||
get usageDie() {
|
||||
return Number(this.system.delta ?? 0);
|
||||
}
|
||||
|
||||
async roll() {
|
||||
if (this.type === "arme") return DonjonEtCieRollDialog.createWeapon(this.actor, this);
|
||||
if (this.type === "sortilege") return DonjonEtCieRollDialog.createSpell(this.actor, this);
|
||||
if (this.usageDie) return DonjonEtCieRollDialog.createUsage(this);
|
||||
return this.postToChat();
|
||||
}
|
||||
|
||||
async rollDamage() {
|
||||
if (!this.system.degats) return null;
|
||||
return DonjonEtCieRollDialog.createDamage(this.actor, this);
|
||||
}
|
||||
|
||||
async postToChat() {
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
"systems/fvtt-donjon-et-cie/templates/chat/item-card.hbs",
|
||||
{
|
||||
item: this,
|
||||
usageLabel: DonjonEtCieUtility.formatUsageDie(this.usageDie)
|
||||
}
|
||||
);
|
||||
|
||||
return ChatMessage.create({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
|
||||
user: game.user.id,
|
||||
content
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user