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 1 commit
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
31 changes: 22 additions & 9 deletions src/module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,40 @@ 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,
save: itemData.save,
},
};

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,7 +191,12 @@ 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) {
Expand Down
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}}
<div class="card-buttons">
{{#if data.save}}
<button data-action="save" data-save="{{data.save}}">
{{lookup config.saves_long data.save}} - {{localize "OSE.spells.Save"}}
</button>
{{/if}}
</div>
</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>