Skip to content

Commit

Permalink
Merge pull request #497 from apewall/roll-spell-chat-card
Browse files Browse the repository at this point in the history
Get spell dice rolling
  • Loading branch information
anthonyronda authored Mar 29, 2024
2 parents 237d00b + 4e2f094 commit 9e36bca
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/module/helpers-dice.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const OseDice = {
title,
flavor,
data,
config: CONFIG.OSE,
};

// Optionally include a situational bonus
Expand Down
36 changes: 24 additions & 12 deletions src/module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,39 @@ export default class OseItem extends Item {
}

async rollFormula(options = {}) {
const data = this.system;
const itemData = this.system;

if (!data.roll) {
if (!itemData.roll) {
throw new Error("This Item does not have a formula to roll!");
}

const label = `${this.name}`;
const rollParts = [data.roll];
const rollParts = [itemData.roll];

const type = data.rollType;
const type = itemData.rollType;

const newData = {
const rollData = {
actor: this.actor,
item: this._source,
description: null,
save: itemData.save,
properties: this.system.autoTags,
roll: {
type,
target: data.rollTarget,
blindroll: data.blindroll,
target: itemData.rollTarget,
blindroll: itemData.blindroll,
},
};

if (this.type === "spell") {
rollData.description = itemData.description
};

// Roll and return
return OseDice.Roll({
event: options.event,
parts: rollParts,
data: newData,
data: rollData,
skipDialog: true,
speaker: ChatMessage.getSpeaker({ actor: this }),
flavor: game.i18n.format("OSE.roll.formula", { label }),
Expand All @@ -183,14 +190,18 @@ export default class OseItem extends Item {
cast: itemData.cast - 1,
},
});
await this.show({ skipDialog: true });

if (itemData.roll) {
await this.rollFormula()
} else {
await this.show({ skipDialog: true })
};
}

_getRollTag(data) {
if (data.roll) {
const roll = `${data.roll}${
data.rollTarget ? CONFIG.OSE.roll_type[data.rollType] : ""
}${data.rollTarget ? data.rollTarget : ""}`;
const roll = `${data.roll}${data.rollTarget ? CONFIG.OSE.roll_type[data.rollType] : ""
}${data.rollTarget ? data.rollTarget : ""}`;
return {
label: `${game.i18n.localize("OSE.items.Roll")} ${roll}`,
};
Expand Down Expand Up @@ -378,6 +389,7 @@ export default class OseItem extends Item {
hasSave: this.hasSave,
config: CONFIG.OSE,
};
templateData.rollFormula = new Roll(templateData.data.roll, templateData).formula;
templateData.data.properties = this.system.autoTags;

// Render the chat card template
Expand Down
12 changes: 6 additions & 6 deletions src/templates/chat/item-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ <h2>{{item.name}}</h2>
</button>
{{/if}}

{{#if data.roll}}
<button data-action="formula">{{ localize "OSE.Roll"}} {{rollFormula}} {{#if data.blindroll}}({{localize
'OSE.items.BlindRoll'}}){{/if}}</button>
{{/if}}

{{#if data.save}}
<button data-action="save" data-save="{{data.save}}">
{{lookup config.saves_long data.save}} - {{localize "OSE.spells.Save"}}
</button>
{{/if}}

{{#if data.roll}}
<button data-action="formula">{{ localize "OSE.Roll"}} {{data.roll}} {{#if data.blindroll}}({{localize
'OSE.items.BlindRoll'}}){{/if}}</button>
{{/if}}
</div>

<footer class="card-footer">
Expand All @@ -44,4 +44,4 @@ <h2>{{item.name}}</h2>
</footer>
</div>

</div>
</div>
20 changes: 18 additions & 2 deletions src/templates/chat/roll-result.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<section class="ose chat-card">
<div class="ose chat-card" data-actor-id="{{data.actor._id}}" data-item-id="{{data.item._id}}"
{{#if tokenId}}data-token-id="{{tokenId}}" {{/if}}>
<div class="ose chat-block">
<div class="flexrow chat-header">
<div class="chat-title"><h2>{{title}}</h2></div>
Expand All @@ -8,13 +9,28 @@
<div class="chat-img" style="background-image:url('{{data.actor.img}}')"></div>
{{/if}}
</div>
<div class="card-content">
{{{data.description}}}
</div>
<div class="blindable" data-blind="{{data.roll.blindroll}}">
{{#if result.details}}<div class="chat-details">{{{result.details}}}</div>{{/if}}
{{#if result.isFailure}}<div class='roll-result roll-fail'><b>{{localize 'OSE.Failure'}}</b> ({{result.target}})
</div>{{/if}}
{{#if result.isSuccess}}<div class='roll-result roll-success'><b>{{localize 'OSE.Success'}}</b>
({{result.target}})</div>{{/if}}
{{#if rollOSE}}<div>{{{rollOSE}}}</div>{{/if}}
{{#if data.save}}
<div class="card-buttons">
<button data-action="save" data-save="{{data.save}}">
{{lookup config.saves_long data.save}} - {{localize "OSE.spells.Save"}}
</button>
</div>
{{/if}}
</div>
<footer class="card-footer">
{{#each data.properties}}
<span>{{#if this.icon}}<i class="fas {{this.icon}}"></i>{{/if}}{{this.label}}</span>
{{/each}}
</footer>
</div>
</section>
</div>

0 comments on commit 9e36bca

Please sign in to comment.