Skip to content

Commit

Permalink
Fix method signatures for item actions
Browse files Browse the repository at this point in the history
  • Loading branch information
aaclayton committed Nov 21, 2019
1 parent 4a953a9 commit 006e611
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
6 changes: 3 additions & 3 deletions module/actor/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class Actor5e extends Actor {
if ( !usesSlots ) return item.roll();

// Configure the casting level and whether to consume a spell slot
let consume = true
let consume = true;
if ( configureDialog ) {
const spellFormData = await SpellCastDialog.create(this, item);
lvl = parseInt(spellFormData.get("level"));
Expand Down Expand Up @@ -197,7 +197,7 @@ export class Actor5e extends Actor {
* @param {string} skillId The skill id (e.g. "ins")
* @param {Object} options Options which configure how the skill check is rolled
*/
rollSkill(skillId, options) {
rollSkill(skillId, options={}) {
const skl = this.data.data.skills[skillId];
return Dice5e.d20Roll({
event: options.event,
Expand All @@ -216,7 +216,7 @@ export class Actor5e extends Actor {
* @param {String}abilityId The ability id (e.g. "str")
* @param {Object} options Options which configure how ability tests or saving throws are rolled
*/
rollAbility(abilityId, options) {
rollAbility(abilityId, options={}) {
const label = CONFIG.DND5E.abilities[abilityId];
new Dialog({
title: `${label} Ability Check`,
Expand Down
40 changes: 22 additions & 18 deletions module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ export class Item5e extends Item {
// Item type specific properties
const props = [];
const fn = this[`_${this.data.type}ChatData`];
if ( fn ) fn(data, labels, props);
if ( fn ) fn.bind(this)(data, labels, props);

// General equipment properties
if ( data.hasOwnProperty("equipped") && !["loot", "tool"].includes(this.data.type) ) {
props.push(
data.equipped ? "Equipped" : "Not Equipped",
data.proficient ? "Proficient": "Not Proficient",
)
);
}

// Ability activation properties
Expand All @@ -213,7 +213,7 @@ export class Item5e extends Item {
labels.activation,
labels.range,
labels.duration
)
);
}

// Filter properties and return
Expand Down Expand Up @@ -336,7 +336,7 @@ export class Item5e extends Item {
* Place an attack roll using an item (weapon, feat, spell, or equipment)
* Rely upon the Dice5e.d20Roll logic for the core implementation
*/
rollAttack(event) {
rollAttack(options={}) {
const itemData = this.data.data;
const actorData = this.actor.data.data;
if ( !this.hasAttack ) {
Expand All @@ -363,7 +363,7 @@ export class Item5e extends Item {

// Call the roll helper utility
Dice5e.d20Roll({
event: event,
event: options.event,
parts: parts,
actor: this.actor,
data: rollData,
Expand All @@ -372,7 +372,7 @@ export class Item5e extends Item {
critical: crit,
dialogOptions: {
width: 400,
top: event.clientY - 80,
top: options.event ? options.event.clientY - 80 : null,
left: window.innerWidth - 710
}
});
Expand All @@ -384,7 +384,7 @@ export class Item5e extends Item {
* Place a damage roll using an item (weapon, feat, spell, or equipment)
* Rely upon the Dice5e.damageRoll logic for the core implementation
*/
rollDamage(event, {versatile=false}={}) {
rollDamage({event, versatile=false}={}) {
const itemData = this.data.data;
const actorData = this.actor.data.data;
if ( !this.hasDamage ) {
Expand Down Expand Up @@ -422,7 +422,7 @@ export class Item5e extends Item {
speaker: ChatMessage.getSpeaker({actor: this.actor}),
dialogOptions: {
width: 400,
top: event.clientY - 80,
top: event ? event.clientY - 80 : null,
left: window.innerWidth - 710
}
});
Expand All @@ -449,7 +449,7 @@ export class Item5e extends Item {
/**
* Use a consumable item
*/
rollConsumable(event) {
rollConsumable(options={}) {
let itemData = this.data.data;
const labels = this.labels;
const formula = itemData.damage ? labels.damage : itemData.formula;
Expand Down Expand Up @@ -496,7 +496,11 @@ export class Item5e extends Item {

/* -------------------------------------------- */

async rollRecharge() {
/**
* Perform an ability recharge test for an item which uses the d6 recharge mechanic
* @prarm {Object} options
*/
async rollRecharge(options={}) {
const data = this.data.data;
if ( !data.recharge.value ) return;

Expand Down Expand Up @@ -532,7 +536,7 @@ export class Item5e extends Item {
* Roll a Tool Check
* Rely upon the Dice5e.d20Roll logic for the core implementation
*/
rollToolCheck(event) {
rollToolCheck(options={}) {
if ( this.type !== "tool" ) throw "Wrong item type!";
const itemData = this.data.data;

Expand All @@ -546,7 +550,7 @@ export class Item5e extends Item {

// Call the roll helper utility
Dice5e.d20Roll({
event: event,
event: options.event,
parts: parts,
data: rollData,
template: "systems/dnd5e/templates/chat/tool-roll-dialog.html",
Expand All @@ -555,7 +559,7 @@ export class Item5e extends Item {
flavor: (parts, data) => `${this.name} - ${CONFIG.DND5E.abilities[abl]} Check`,
dialogOptions: {
width: 400,
top: event.clientY - 80,
top: options.event ? event.clientY - 80 : null,
left: window.innerWidth - 710,
},
onClose: (html, parts, data) => {
Expand Down Expand Up @@ -600,18 +604,18 @@ export class Item5e extends Item {
const target = isTargetted ? this._getChatCardTarget(card) : null;

// Attack and Damage Rolls
if ( action === "attack" ) await item.rollAttack(event);
else if ( action === "damage" ) await item.rollDamage(event);
else if ( action === "versatile" ) await item.rollDamage(event, {versatile: true});
if ( action === "attack" ) await item.rollAttack({event});
else if ( action === "damage" ) await item.rollDamage({event});
else if ( action === "versatile" ) await item.rollDamage({event, versatile: true});

// Saving Throw
else if ( action === "save" ) await target.rollAbilitySave(button.dataset.ability, {event});

// Consumable usage
else if ( action === "consume" ) await item.rollConsumable(event);
else if ( action === "consume" ) await item.rollConsumable({event});

// Tool usage
else if ( action === "toolCheck" ) await item.rollToolCheck(event);
else if ( action === "toolCheck" ) await item.rollToolCheck({event});

// Re-enable the button
button.disabled = false;
Expand Down

0 comments on commit 006e611

Please sign in to comment.