ENH: Saving throws

master
U~man 2020-06-29 23:11:04 +02:00
parent cb7fd49d55
commit 816c4d4a36
8 changed files with 165 additions and 46 deletions

View File

@ -2,6 +2,13 @@
"OSE.Edit": "Edit",
"OSE.Delete": "Delete",
"OSE.Add": "Add",
"OSE.Cancel": "Cancel",
"OSE.Roll": "Roll",
"OSE.Formula": "Formula",
"OSE.SitMod": "Situational Modifier",
"OSE.RollMod": "Roll Mode",
"OSE.RollExample": "Roll Example",
"OSE.Name": "Name",
"OSE.Class": "Class",
@ -27,16 +34,17 @@
"OSE.scores.cha.long": "Charisma",
"OSE.scores.cha.short": "CHA",
"OSE.SavingThrow": "Saving Throw",
"OSE.saves.death.short": "D",
"OSE.saves.death.long": "Death, Poison",
"OSE.saves.wands.short": "W",
"OSE.saves.wands.long": "Wand",
"OSE.saves.wand.short": "W",
"OSE.saves.wand.long": "Wand",
"OSE.saves.paralysis.short": "P",
"OSE.saves.paralysis.long": "Paralysis, Petrify",
"OSE.saves.breath.short": "B",
"OSE.saves.breath.long": "Dragon Breath",
"OSE.saves.spells.short": "S",
"OSE.saves.spells.long": "Rod, Staff, Spell",
"OSE.saves.spell.short": "S",
"OSE.saves.spell.long": "Rod, Staff, Spell",
"OSE.Health": "Hit Points",
"OSE.HealthShort": "HP",

View File

@ -8,10 +8,14 @@ export class OseActorSheet extends ActorSheet {
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
html.find('.saving-throw .attribute-name').click(ev => {
console.log('hey');
html.find('.saving-throw .attribute-name a').click(ev => {
let actorObject = this.actor;
let element = event.currentTarget;
let save = element.parentElement.parentElement.dataset.save;
actorObject.rollSave(save, { event: event });
})
super.activateListeners(html);
}
// Override to set resizable initial size

View File

@ -1,20 +1,29 @@
import { OseDice } from '../dice.js';
export class OseActor extends Actor {
/**
* Extends data from base Actor class
*/
prepareData() {
super.prepareData();
return this.data;
}
/* -------------------------------------------- */
/* -------------------------------------------- */
/* Socket Listeners and Handlers
/* -------------------------------------------- */
/** @override */
async createOwnedItem(itemData, options) {
return super.createOwnedItem(itemData, options);
}
/* -------------------------------------------- */
/* Rolls */
/* -------------------------------------------- */
rollSave(save, options = {}) {
const label = game.i18n.localize(`OSE.saves.${save}.long`);
const rollParts = ['1d20'];
// Roll and return
return OseDice.Roll({
event: options.event,
parts: rollParts,
data: this.data,
speaker: ChatMessage.getSpeaker({ actor: this }),
flavor: `${label} ${game.i18n.localize('OSE.SavingThrow')}`,
title: `${label} ${game.i18n.localize('OSE.SavingThrow')}`,
});
}
}

78
src/module/dice.js Normal file
View File

@ -0,0 +1,78 @@
export class OseDice {
// eslint-disable-next-line no-unused-vars
static async Roll({
parts = [],
data = {},
options = {},
event = null,
speaker = null,
flavor = null,
title = null,
item = false,
} = {}) {
let rollMode = game.settings.get("core", "rollMode");
let rolled = false;
let filtered = parts.filter(function (el) {
return el != "" && el;
});
const _roll = (form = null, raise = false) => {
// Optionally include a situational bonus
if (form !== null) data["bonus"] = form.bonus.value;
if (data["bonus"]) filtered.push(data["bonus"]);
const roll = new Roll(filtered.join(""), data).roll();
// Convert the roll to a chat message and return the roll
rollMode = form ? form.rollMode.value : rollMode;
roll.toMessage(
{
speaker: speaker,
flavor: flavor,
},
{ rollMode }
);
rolled = true;
return roll;
};
const template = "systems/ose/templates/chat/roll-dialog.html";
let dialogData = {
formula: filtered.join(" "),
data: data,
rollMode: rollMode,
rollModes: CONFIG.Dice.rollModes,
};
let buttons = {
ok: {
label: game.i18n.localize("OSE.Roll"),
icon: '<i class="fas fa-dice-d20"></i>',
callback: (html) => {
roll = _roll(html[0].children[0]);
},
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("OSE.Cancel"),
},
};
if (!item) delete buttons.raise;
const html = await renderTemplate(template, dialogData);
let roll;
//Create Dialog window
return new Promise((resolve) => {
new Dialog({
title: title,
content: html,
buttons: buttons,
default: "ok",
close: () => {
resolve(rolled ? roll : false)
},
}).render(true);
});
}
}

View File

@ -120,11 +120,11 @@
"morale": 0
},
"saves": {
"D": 10,
"W": 10,
"P": 10,
"B": 10,
"S": 10
"death": 10,
"wand": 10,
"paralysis": 10,
"breath": 10,
"spell": 10
},
"thac0": {
"value": 19,

View File

@ -129,34 +129,34 @@
{{!-- Saving throws --}}
<div class="attribute-group">
<ul class="attributes">
<li class="attribute saving-throw">
<li class="attribute saving-throw" data-save="death">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.death.long' }}"><a>{{ localize "OSE.saves.death.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.d.value" type="text" value="{{data.saves.d.value}}" placeholder="0"
<input name="data.saves.death.value" type="text" value="{{data.saves.death.value}}" placeholder="0"
data-dtype="Number" />
</li>
<li class="attribute saving-throw">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.wands.long' }}"><a>{{ localize "OSE.saves.wands.short" }}</a></h4>
<li class="attribute saving-throw" data-save="wand">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.wand.long' }}"><a>{{ localize "OSE.saves.wand.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.w.value" type="text" value="{{data.saves.w.value}}" placeholder="0"
<input name="data.saves.wand.value" type="text" value="{{data.saves.wand.value}}" placeholder="0"
data-dtype="Number" />
</li>
<li class="attribute saving-throw">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.paralysis.long' }}"><a>{{ localize "OSE.saves.paralysis.short" }</a></h4>
<li class="attribute saving-throw" data-save="paralysis">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.paralysis.long' }}"><a>{{ localize "OSE.saves.paralysis.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.p.value" type="text" value="{{data.saves.p.value}}" placeholder="0"
<input name="data.saves.paralysis.value" type="text" value="{{data.saves.paralysis.value}}" placeholder="0"
data-dtype="Number" />
</li>
<li class="attribute saving-throw">
<li class="attribute saving-throw" data-save="breath">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.breath.long' }}"><a>{{ localize "OSE.saves.breath.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.b.value" type="text" value="{{data.saves.b.value}}" placeholder="0"
<input name="data.saves.breath.value" type="text" value="{{data.saves.breath.value}}" placeholder="0"
data-dtype="Number" />
</li>
<li class="attribute saving-throw">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.spells.long' }}"><a>{{ localize "OSE.saves.spells.short" }}</a></h4>
<li class="attribute saving-throw" data-save="spell">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.spell.long' }}"><a>{{ localize "OSE.saves.spell.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.s.value" type="text" value="{{data.saves.s.value}}" placeholder="0" />
<input name="data.saves.spell.value" type="text" value="{{data.saves.spell.value}}" placeholder="0" />
</li>
</ul>
</div>

View File

@ -112,34 +112,34 @@
{{!-- Saving throws --}}
<div class="attribute-group">
<ul class="attributes">
<li class="attribute">
<li class="attribute saving-throw" data-save="death">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.death.long' }}"><a>{{ localize "OSE.saves.death.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.d.value" type="text" value="{{data.saves.d.value}}" placeholder="0"
<input name="data.saves.death.value" type="text" value="{{data.saves.death.value}}" placeholder="0"
data-dtype="Number" />
</li>
<li class="attribute">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.wands.long' }}"><a>{{ localize "OSE.saves.wands.short" }}</a></h4>
<li class="attribute saving-throw" data-save="wand">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.wand.long' }}"><a>{{ localize "OSE.saves.wand.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.w.value" type="text" value="{{data.saves.w.value}}" placeholder="0"
<input name="data.saves.wand.value" type="text" value="{{data.saves.wand.value}}" placeholder="0"
data-dtype="Number" />
</li>
<li class="attribute">
<li class="attribute saving-throw" data-save="paralysis">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.paralysis.long' }}"><a>{{ localize "OSE.saves.paralysis.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.p.value" type="text" value="{{data.saves.p.value}}" placeholder="0"
<input name="data.saves.paralysis.value" type="text" value="{{data.saves.paralysis.value}}" placeholder="0"
data-dtype="Number" />
</li>
<li class="attribute">
<li class="attribute saving-throw" data-save="breath">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.breath.long' }}"><a>{{ localize "OSE.saves.breath.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.b.value" type="text" value="{{data.saves.b.value}}" placeholder="0"
<input name="data.saves.breath.value" type="text" value="{{data.saves.breath.value}}" placeholder="0"
data-dtype="Number" />
</li>
<li class="attribute">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.spells.long' }}"><a>{{ localize "OSE.saves.spells.short" }}</a></h4>
<li class="attribute saving-throw" data-save="spell">
<h4 class="attribute-name box-title" title="{{ localize 'OSE.saves.spell.long' }}"><a>{{ localize "OSE.saves.spell.short" }}</a></h4>
<div class="attribute-value">
<input name="data.saves.s.value" type="text" value="{{data.saves.s.value}}" placeholder="0" />
<input name="data.saves.spell.value" type="text" value="{{data.saves.spell.value}}" placeholder="0" />
</li>
</ul>
</div>

View File

@ -0,0 +1,20 @@
<form>
<div class="form-group">
<label>{{localize "OSE.Formula"}}</label>
<input type="text" name="formula" value="{{formula}}" disabled />
</div>
<div class="form-group">
<label>{{localize "OSE.SitMod"}}</label>
<input type="text" name="bonus" value="" placeholder="{{localize 'OSE.RollExample'}}" />
</div>
<div class="form-group">
<label>{{localize "OSE.RollMode"}}</label>
<select name="rollMode">
{{#select rollMode}}
{{#each rollModes as |label mode|}}
<option value="{{mode}}">{{localize label}}</option>
{{/each}}
{{/select}}
</select>
</div>
</form>