Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get spell dice rolling #497

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this come from rollData.roll.save or rollData.save?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comes from RollData.save, I've removed rollData.roll.save as it is not needed.

<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>